summaryrefslogtreecommitdiff
path: root/libbtrfsutil/python/subvolume.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-01-18 13:39:57 -0800
committerDavid Sterba <dsterba@suse.com>2018-03-06 11:28:36 +0100
commit172c0d1a1218187f20460988a3c3d6212748f825 (patch)
tree31c30ae8f17850224bcdff37c85ec0198d033f02 /libbtrfsutil/python/subvolume.c
parent0d36261bd54a93b1b1b616bdd32d33b3f4278f09 (diff)
libbtrfsutil: add btrfs_util_[gs]et_read_only()
In the future, btrfs_util_[gs]et_subvolume_flags() might be useful, but since these are the only subvolume flags we've defined in all this time, this will do for now. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'libbtrfsutil/python/subvolume.c')
-rw-r--r--libbtrfsutil/python/subvolume.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/libbtrfsutil/python/subvolume.c b/libbtrfsutil/python/subvolume.c
index 31b6ca2e..76487865 100644
--- a/libbtrfsutil/python/subvolume.c
+++ b/libbtrfsutil/python/subvolume.c
@@ -215,6 +215,61 @@ PyStructSequence_Desc SubvolumeInfo_desc = {
PyTypeObject SubvolumeInfo_type;
+PyObject *get_subvolume_read_only(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ static char *keywords[] = {"path", NULL};
+ struct path_arg path = {.allow_fd = true};
+ enum btrfs_util_error err;
+ bool read_only;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds,
+ "O&:get_subvolume_read_only",
+ keywords, &path_converter, &path))
+ return NULL;
+
+ if (path.path) {
+ err = btrfs_util_get_subvolume_read_only(path.path, &read_only);
+ } else {
+ err = btrfs_util_get_subvolume_read_only_fd(path.fd,
+ &read_only);
+ }
+ if (err) {
+ SetFromBtrfsUtilErrorWithPath(err, &path);
+ path_cleanup(&path);
+ return NULL;
+ }
+
+ path_cleanup(&path);
+ return PyBool_FromLong(read_only);
+}
+
+PyObject *set_subvolume_read_only(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ static char *keywords[] = {"path", "read_only", NULL};
+ struct path_arg path = {.allow_fd = true};
+ enum btrfs_util_error err;
+ int read_only = 1;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds,
+ "O&|p:set_subvolume_read_only",
+ keywords, &path_converter, &path,
+ &read_only))
+ return NULL;
+
+ if (path.path)
+ err = btrfs_util_set_subvolume_read_only(path.path, read_only);
+ else
+ err = btrfs_util_set_subvolume_read_only_fd(path.fd, read_only);
+ if (err) {
+ SetFromBtrfsUtilErrorWithPath(err, &path);
+ path_cleanup(&path);
+ return NULL;
+ }
+
+ path_cleanup(&path);
+ Py_RETURN_NONE;
+}
+
PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *keywords[] = {"path", "async", "qgroup_inherit", NULL};