Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / libbtrfsutil / python / filesystem.c
blob627ed19332bf5d95592134c6b0aaa057e41254fb
1 /*
2 * Copyright (C) 2018 Facebook
4 * This file is part of libbtrfsutil.
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.
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.
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/>.
20 #include "btrfsutilpy.h"
22 PyObject *filesystem_sync(PyObject *self, PyObject *args, PyObject *kwds)
24 static char *keywords[] = {"path", NULL};
25 struct path_arg path = {.allow_fd = true};
26 enum btrfs_util_error err;
28 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:sync", keywords,
29 &path_converter, &path))
30 return NULL;
32 if (path.path)
33 err = btrfs_util_sync(path.path);
34 else
35 err = btrfs_util_sync_fd(path.fd);
36 if (err) {
37 SetFromBtrfsUtilErrorWithPath(err, &path);
38 path_cleanup(&path);
39 return NULL;
42 path_cleanup(&path);
43 Py_RETURN_NONE;
46 PyObject *start_sync(PyObject *self, PyObject *args, PyObject *kwds)
48 static char *keywords[] = {"path", NULL};
49 struct path_arg path = {.allow_fd = true};
50 uint64_t transid;
51 enum btrfs_util_error err;
53 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:start_sync", keywords,
54 &path_converter, &path))
55 return NULL;
57 if (path.path)
58 err = btrfs_util_start_sync(path.path, &transid);
59 else
60 err = btrfs_util_start_sync_fd(path.fd, &transid);
61 if (err) {
62 SetFromBtrfsUtilErrorWithPath(err, &path);
63 path_cleanup(&path);
64 return NULL;
67 path_cleanup(&path);
68 return PyLong_FromUnsignedLongLong(transid);
71 PyObject *wait_sync(PyObject *self, PyObject *args, PyObject *kwds)
73 static char *keywords[] = {"path", "transid", NULL};
74 struct path_arg path = {.allow_fd = true};
75 unsigned long long transid = 0;
76 enum btrfs_util_error err;
78 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|K:wait_sync", keywords,
79 &path_converter, &path, &transid))
80 return NULL;
82 if (path.path)
83 err = btrfs_util_wait_sync(path.path, transid);
84 else
85 err = btrfs_util_wait_sync_fd(path.fd, transid);
86 if (err) {
87 SetFromBtrfsUtilErrorWithPath(err, &path);
88 path_cleanup(&path);
89 return NULL;
92 path_cleanup(&path);
93 Py_RETURN_NONE;