-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-btrfs.c
73 lines (59 loc) · 1.4 KB
/
python-btrfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <Python.h>
#include <uuid/uuid.h>
#include "list.h"
#include "utils.h"
#include "volumes.h"
/* ----------------------------------------------------------------------
* Method tables and other bureaucracy
*/
PyObject*
btrfs_list_subvolumes(PyObject *module)
{
struct list_head *all_uuids;
struct btrfs_fs_devices *fs_devices;
struct list_head *cur_uuid;
char uuidbuf[37];
int ret;
PyObject *list;
PyObject *str;
ret = btrfs_scan_one_dir("/dev", 0);
if (ret) {
PyErr_SetString(PyExc_RuntimeError, "Could not scan /dev");
return NULL;
}
list = PyList_New(0);
if (!list)
return NULL;
all_uuids = btrfs_scanned_uuids();
list_for_each(cur_uuid, all_uuids) {
fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
list);
uuid_unparse(fs_devices->fsid, uuidbuf);
str = PyString_FromString(uuidbuf);
if (!str) {
Py_DECREF(list);
return PyErr_NoMemory();
}
if (PyList_Append(list, str) < 0) {
Py_DECREF(str);
Py_DECREF(list);
return PyErr_NoMemory();
}
Py_DECREF(str);
}
return list;
}
static PyMethodDef btrfs_methods[] = {
/* LVM methods */
{ "list_subvolumes", (PyCFunction)btrfs_list_subvolumes, METH_NOARGS },
// { "vgOpen", (PyCFunction)liblvm_lvm_vg_open, METH_VARARGS },
{ NULL, NULL} /* sentinel */
};
PyMODINIT_FUNC
initbtrfs(void)
{
PyObject *m;
m = Py_InitModule3("btrfs", btrfs_methods, "Btrfs module");
if (m == NULL)
return;
}