libbtrfsutil: add subvolume iterator helpers
[platform/upstream/btrfs-progs.git] / libbtrfsutil / python / btrfsutilpy.h
1 /*
2  * Copyright (C) 2018 Facebook
3  *
4  * This file is part of libbtrfsutil.
5  *
6  * libbtrfsutil is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * libbtrfsutil is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with libbtrfsutil.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef BTRFSUTILPY_H
21 #define BTRFSUTILPY_H
22
23 #define PY_SSIZE_T_CLEAN
24
25 #include <stdbool.h>
26 #include <stddef.h>
27 #include <Python.h>
28 #include "structmember.h"
29
30 #include <btrfsutil.h>
31
32 typedef struct {
33         PyObject_HEAD
34         struct btrfs_util_qgroup_inherit *inherit;
35 } QgroupInherit;
36
37 extern PyTypeObject BtrfsUtilError_type;
38 extern PyStructSequence_Desc SubvolumeInfo_desc;
39 extern PyTypeObject SubvolumeInfo_type;
40 extern PyTypeObject SubvolumeIterator_type;
41 extern PyTypeObject QgroupInherit_type;
42
43 /*
44  * Helpers for path arguments based on posixmodule.c in CPython.
45  */
46 struct path_arg {
47         bool allow_fd;
48         char *path;
49         int fd;
50         Py_ssize_t length;
51         PyObject *object;
52         PyObject *cleanup;
53 };
54 int path_converter(PyObject *o, void *p);
55 void path_cleanup(struct path_arg *path);
56
57 void SetFromBtrfsUtilError(enum btrfs_util_error err);
58 void SetFromBtrfsUtilErrorWithPath(enum btrfs_util_error err,
59                                    struct path_arg *path);
60 void SetFromBtrfsUtilErrorWithPaths(enum btrfs_util_error err,
61                                     struct path_arg *path1,
62                                     struct path_arg *path2);
63
64 PyObject *filesystem_sync(PyObject *self, PyObject *args, PyObject *kwds);
65 PyObject *start_sync(PyObject *self, PyObject *args, PyObject *kwds);
66 PyObject *wait_sync(PyObject *self, PyObject *args, PyObject *kwds);
67 PyObject *is_subvolume(PyObject *self, PyObject *args, PyObject *kwds);
68 PyObject *subvolume_id(PyObject *self, PyObject *args, PyObject *kwds);
69 PyObject *subvolume_path(PyObject *self, PyObject *args, PyObject *kwds);
70 PyObject *subvolume_info(PyObject *self, PyObject *args, PyObject *kwds);
71 PyObject *get_subvolume_read_only(PyObject *self, PyObject *args, PyObject *kwds);
72 PyObject *set_subvolume_read_only(PyObject *self, PyObject *args, PyObject *kwds);
73 PyObject *get_default_subvolume(PyObject *self, PyObject *args, PyObject *kwds);
74 PyObject *set_default_subvolume(PyObject *self, PyObject *args, PyObject *kwds);
75 PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds);
76
77 void add_module_constants(PyObject *m);
78
79 #endif /* BTRFSUTILPY_H */