Debian Codegraph @

libmount/python/context.c

raw
1 /*
2 * Python bindings for the libmount library.
3 *
4 * Copyright (C) 2013, Red Hat, Inc. All rights reserved.
5 * Written by Ondrej Oprala and Karel Zak
6 *
7 * This file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://gnu.org/licenses/>.
19 */
20 #include "pylibmount.h"
21
22 static PyMemberDef Context_members[] = {
23 { NULL }
24 };
25
26 static PyObject *Context_set_tables_errcb(ContextObjext *self, PyObject *func,
27 void *closure __attribute__((unused)))
28 {
29 if (!func) {
30 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
31 return NULL;
32 }
33
34 if (!PyCallable_Check(func))
35 return NULL;
36
37 PyObject *tmp = self->table_errcb;
38 Py_INCREF(func);
39 self->table_errcb = func;
40 Py_XDECREF(tmp);
41
42 return UL_IncRef(self);
43 }
44
45 static void Context_dealloc(ContextObjext *self)
46 {
47 if (!self->cxt) /* if init fails */
48 return;
49
50 Py_XDECREF(mnt_context_get_fs_userdata(self->cxt));
51 Py_XDECREF(mnt_context_get_fstab_userdata(self->cxt));
52 Py_XDECREF(mnt_context_get_mtab_userdata(self->cxt));
53
54 mnt_free_context(self->cxt);
55 PyFree(self);
56 }
57
58 static PyObject *Context_new(PyTypeObject *type,
59 PyObject *args __attribute__((unused)),
60 PyObject *kwds __attribute__((unused)))
61 {
62 ContextObjext *self = (ContextObjext*) type->tp_alloc(type, 0);
63
64 if (self) {
65 self->cxt = NULL;
66 self->table_errcb = NULL;
67 }
68
69 return (PyObject *)self;
70 }
71
72 /*
73 * Note there is no pointer to encapsulating object needed here, since Cxt is
74 * on top of the Context(Table(Filesystem)) hierarchy
75 */
76 #define Context_HELP "Context(source=None, target=None, fstype=None, " \
77 "options=None, mflags=0, fstype_pattern=None, " \
78 "options_pattern=None, fs=None, fstab=None, optsmode=0)"
79 static int Context_init(ContextObjext *self, PyObject *args, PyObject *kwds)
80 {
81 char *source = NULL, *target = NULL, *fstype = NULL;
82 char *options = NULL, *fstype_pattern = NULL, *options_pattern = NULL;
83 unsigned long mflags = 0;
84 int optsmode = 0, syscall_status = 1;
85 FsObject *fs = NULL;
86 TableObject *fstab = NULL;
87 int rc = 0;
88 char *kwlist[] = {
89 "source", "target", "fstype",
90 "options", "mflags", "fstype_pattern",
91 "options_pattern", "fs", "fstab",
92 "optsmode", NULL
93 };
94
95 if (!PyArg_ParseTupleAndKeywords(
96 args, kwds, "|sssskssO!O!i", kwlist,
97 &source, &target, &fstype, &options, &mflags,
98 &fstype_pattern, &options_pattern, &FsType, &fs,
99 &TableType, &fstab, &optsmode, &syscall_status)) {
100 PyErr_SetString(PyExc_TypeError, ARG_ERR);
101 return -1;
102 }
103
104 if (self->cxt)
105 mnt_free_context(self->cxt);
106
107 self->cxt = mnt_new_context();
108 if (!self->cxt) {
109 PyErr_SetString(PyExc_MemoryError, MEMORY_ERR);
110 return -1;
111 }
112
113 if (source && (rc = mnt_context_set_source(self->cxt, source))) {
114 UL_RaiseExc(-rc);
115 return -1;
116 }
117
118 if (target && (rc = mnt_context_set_target(self->cxt, target))) {
119 UL_RaiseExc(-rc);
120 return -1;
121 }
122
123 if (fstype && (rc = mnt_context_set_fstype(self->cxt, fstype))) {
124 UL_RaiseExc(-rc);
125 return -1;
126 }
127
128 if (options && (rc = mnt_context_set_options(self->cxt, options))) {
129 UL_RaiseExc(-rc);
130 return -1;
131 }
132
133 if (fstype_pattern && (rc = mnt_context_set_fstype_pattern(self->cxt, fstype_pattern))) {
134 UL_RaiseExc(-rc);
135 return -1;
136 }
137
138 if (options_pattern && (rc = mnt_context_set_options_pattern(self->cxt, options_pattern))) {
139 UL_RaiseExc(-rc);
140 return -1;
141 }
142
143 if (fs && (rc = mnt_context_set_fs(self->cxt, fs->fs))) {
144 UL_RaiseExc(-rc);
145 return -1;
146 }
147
148 if (fstab && (rc = mnt_context_set_fstab(self->cxt, fstab->tab))) {
149 UL_RaiseExc(-rc);
150 return -1;
151 }
152
153 if (optsmode && (rc = mnt_context_set_optsmode(self->cxt, optsmode))) {
154 UL_RaiseExc(-rc);
155 return -1;
156 }
157
158 mnt_context_set_mflags(self->cxt, mflags);
159 mnt_context_set_optsmode(self->cxt, optsmode);
160 mnt_context_set_tables_errcb(self->cxt, pymnt_table_parser_errcb);
161
162 return 0;
163 }
164
165 #define Context_enable_fake_HELP "enable_fake(enable)\n\n" \
166 "Enable/disable fake mounting (see mount(8) man page, option -f).\n" \
167 "\n" \
168 "Returns self or raises an exception in case of an error."
169 static PyObject *Context_enable_fake(ContextObjext *self, PyObject *args, PyObject *kwds)
170 {
171 int rc;
172 int enable;
173 char *kwlist[] = { "enable", NULL };
174
175 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
176 PyErr_SetString(PyExc_TypeError, ARG_ERR);
177 return NULL;
178 }
179 rc = mnt_context_enable_fake(self->cxt, enable);
180 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
181 }
182
183 #define Context_enable_force_HELP "enable_force(enable)\n\n" \
184 "Enable/disable force umounting (see umount(8) man page, option -f).\n" \
185 "\n" \
186 "Returns self or raises an exception in case of an error."
187 static PyObject *Context_enable_force(ContextObjext *self, PyObject *args, PyObject *kwds)
188 {
189 int rc;
190 int enable;
191 char *kwlist[] = { "enable", NULL };
192
193 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
194 PyErr_SetString(PyExc_TypeError, ARG_ERR);
195 return NULL;
196 }
197 rc = mnt_context_enable_force(self->cxt, enable);
198 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
199 }
200
201 #define Context_enable_lazy_HELP "enable_lazy(enable)\n\n" \
202 "Enable/disable lazy umount (see umount(8) man page, option -l).\n" \
203 "\n" \
204 "Returns self or raises an exception in case of an error."
205 static PyObject *Context_enable_lazy(ContextObjext *self, PyObject *args, PyObject *kwds)
206 {
207 int rc;
208 int enable;
209 char *kwlist[] = { "enable", NULL };
210
211 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
212 PyErr_SetString(PyExc_TypeError, ARG_ERR);
213 return NULL;
214 }
215 rc = mnt_context_enable_lazy(self->cxt, enable);
216 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
217 }
218
219 #define Context_enable_loopdel_HELP "enable_loopdel(enable)\n\n" \
220 "Enable/disable loop delete (destroy) after umount (see umount(8), option -d)\n" \
221 "\n" \
222 "Returns self or raises an exception in case of an error."
223 static PyObject *Context_enable_loopdel(ContextObjext *self, PyObject *args, PyObject *kwds)
224 {
225 int rc;
226 int enable;
227 char *kwlist[] = { "enable", NULL };
228
229 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
230 PyErr_SetString(PyExc_TypeError, ARG_ERR);
231 return NULL;
232 }
233 rc = mnt_context_enable_loopdel(self->cxt, enable);
234 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
235 }
236
237 #define Context_enable_rdonly_umount_HELP "enable_rdonly_umount(enable)\n\n" \
238 "Enable/disable read-only remount on failed umount(2)\n "\
239 "(see umount(8) man page, option -r).\n" \
240 "\n" \
241 "Returns self or raises an exception in case of an error."
242 static PyObject *Context_enable_rdonly_umount(ContextObjext *self, PyObject *args, PyObject *kwds)
243 {
244 int rc;
245 int enable;
246 char *kwlist[] = { "enable", NULL };
247
248 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
249 PyErr_SetString(PyExc_TypeError, ARG_ERR);
250 return NULL;
251 }
252 rc = mnt_context_enable_rdonly_umount(self->cxt, enable);
253 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
254 }
255
256 #define Context_enable_sloppy_HELP "enable_sloppy(enable)\n\n" \
257 "Set/unset sloppy mounting (see mount(8) man page, option -s).\n" \
258 "\n" \
259 "Returns self or raises an exception in case of an error."
260 static PyObject *Context_enable_sloppy(ContextObjext *self, PyObject *args, PyObject *kwds)
261 {
262 int rc;
263 int enable;
264 char *kwlist[] = { "enable", NULL };
265
266 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
267 PyErr_SetString(PyExc_TypeError, ARG_ERR);
268 return NULL;
269 }
270 rc = mnt_context_enable_sloppy(self->cxt, enable);
271 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
272 }
273
274 #define Context_enable_verbose_HELP "enable_verbose(enable)\n\n" \
275 "Enable/disable verbose output (TODO: not implemented yet)\n" \
276 "\n" \
277 "Returns self or raises an exception in case of an error."
278 static PyObject *Context_enable_verbose(ContextObjext *self, PyObject *args, PyObject *kwds)
279 {
280 int rc;
281 int enable;
282 char *kwlist[] = { "enable", NULL };
283
284 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
285 PyErr_SetString(PyExc_TypeError, ARG_ERR);
286 return NULL;
287 }
288 rc = mnt_context_enable_verbose(self->cxt, enable);
289 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
290 }
291
292 #define Context_enable_fork_HELP "enable_fork(enable)\n\n" \
293 "Enable/disable fork(2) call in Cxt.next_mount()(not yet implemented) (see mount(8) man\n" \
294 "page, option -F).\n" \
295 "\n" \
296 "Returns self or raises an exception in case of an error."
297 static PyObject *Context_enable_fork(ContextObjext *self, PyObject *args, PyObject *kwds)
298 {
299 int rc;
300 int enable;
301 char *kwlist[] = {"enable", NULL};
302
303 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &enable)) {
304 PyErr_SetString(PyExc_TypeError, ARG_ERR);
305 return NULL;
306 }
307 rc = mnt_context_enable_fork(self->cxt, enable);
308 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
309 }
310
311 #define Context_disable_canonicalize_HELP "disable_canonicalize(disable)\n\n" \
312 "Enable/disable paths canonicalization and tags evaluation. The libmount context\n" \
313 "canonicalizes paths when searching fstab and when preparing source and target paths\n" \
314 "for mount(2) syscall.\n" \
315 "\n" \
316 "This function has effect to the private (within context) fstab instance only\n" \
317 "(see Cxt.fstab).\n" \
318 "Returns self or raises an exception in case of an error."
319 static PyObject *Context_disable_canonicalize(ContextObjext *self, PyObject *args, PyObject *kwds)
320 {
321 int rc;
322 int disable;
323 char *kwlist[] = {"disable", NULL};
324
325 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &disable)) {
326 PyErr_SetString(PyExc_TypeError, ARG_ERR);
327 return NULL;
328 }
329 rc = mnt_context_disable_canonicalize(self->cxt, disable);
330 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
331 }
332
333 #define Context_disable_helpers_HELP "disable_helpers(disable)\n\n" \
334 "Enable/disable /sbin/[u]mount.* helpers (see mount(8) man page, option -i).\n" \
335 "\n" \
336 "Returns self or raises an exception in case of an error."
337 static PyObject *Context_disable_helpers(ContextObjext *self, PyObject *args, PyObject *kwds)
338 {
339 int rc;
340 int disable;
341 char *kwlist[] = {"disable", NULL};
342
343 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &disable)) {
344 PyErr_SetString(PyExc_TypeError, ARG_ERR);
345 return NULL;
346 }
347 rc = mnt_context_disable_helpers(self->cxt, disable);
348 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
349 }
350
351 #define Context_disable_mtab_HELP "disable_mtab(disable)\n\n" \
352 "Disable/enable mtab update (see mount(8) man page, option -n).\n" \
353 "\n" \
354 "Returns self or raises an exception in case of an error."
355 static PyObject *Context_disable_mtab(ContextObjext *self, PyObject *args, PyObject *kwds)
356 {
357 int rc;
358 int disable;
359 char *kwlist[] = {"disable", NULL };
360
361 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &disable)) {
362 PyErr_SetString(PyExc_TypeError, ARG_ERR);
363 return NULL;
364 }
365 rc = mnt_context_disable_mtab(self->cxt, disable);
366 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
367 }
368
369 #define Context_disable_swapmatch_HELP "disable_swapmatch(disable)\n\n" \
370 "Disable/enable swap between source and target for mount(8) if only one path\n" \
371 "is specified.\n" \
372 "\n" \
373 "Returns self or raises an exception in case of an error."
374 static PyObject *Context_disable_swapmatch(ContextObjext *self, PyObject *args, PyObject *kwds)
375 {
376 int rc;
377 int disable;
378 char *kwlist[] = { "disable", NULL };
379
380 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &disable)) {
381 PyErr_SetString(PyExc_TypeError, ARG_ERR);
382 return NULL;
383 }
384 rc = mnt_context_disable_swapmatch(self->cxt, disable);
385 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
386 }
387
388 static int Context_set_source(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
389 {
390 char *source;
391 int rc = 0;
392
393 if (!value) {
394 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
395 return -1;
396 }
397 if (!(source = pystos(value)))
398 return -1;
399
400 rc = mnt_context_set_source(self->cxt, source);
401 if (rc) {
402 UL_RaiseExc(-rc);
403 return -1;
404 }
405 return 0;
406 }
407
408 static int Context_set_mountdata(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
409 {
410 char *mountdata;
411 int rc = 0;
412
413 if (!value) {
414 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
415 return -1;
416 }
417 if (!(mountdata = pystos(value)))
418 return -1;
419
420 rc = mnt_context_set_mountdata(self->cxt, mountdata);
421 if (rc) {
422 UL_RaiseExc(-rc);
423 return -1;
424 }
425 return 0;
426 }
427
428 static int Context_set_target(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
429 {
430 char * target;
431 int rc = 0;
432
433 if (!value) {
434 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
435 return -1;
436 }
437 if (!(target = pystos(value)))
438 return -1;
439
440 rc = mnt_context_set_target(self->cxt, target);
441 if (rc) {
442 UL_RaiseExc(-rc);
443 return -1;
444 }
445 return 0;
446 }
447
448 static int Context_set_fstype(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
449 {
450 char * fstype;
451 int rc = 0;
452
453 if (!value) {
454 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
455 return -1;
456 }
457 if (!(fstype = pystos(value)))
458 return -1;
459
460 rc = mnt_context_set_fstype(self->cxt, fstype);
461 if (rc) {
462 UL_RaiseExc(-rc);
463 return -1;
464 }
465 return 0;
466 }
467
468 static int Context_set_options(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
469 {
470 char * options;
471 int rc = 0;
472
473 if (!value) {
474 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
475 return -1;
476 }
477 if (!(options = pystos(value)))
478 return -1;
479
480 rc = mnt_context_set_options(self->cxt, options);
481 if (rc) {
482 UL_RaiseExc(-rc);
483 return -1;
484 }
485 return 0;
486 }
487
488 static int Context_set_fstype_pattern(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
489 {
490 char * fstype_pattern;
491 int rc = 0;
492
493 if (!value) {
494 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
495 return -1;
496 }
497 if (!(fstype_pattern = pystos(value)))
498 return -1;
499
500 rc = mnt_context_set_fstype_pattern(self->cxt, fstype_pattern);
501 if (rc) {
502 UL_RaiseExc(-rc);
503 return -1;
504 }
505 return 0;
506 }
507
508 static int Context_set_options_pattern(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
509 {
510 char * options_pattern;
511 int rc = 0;
512
513 if (!value) {
514 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
515 return -1;
516 }
517 if (!(options_pattern = pystos(value)))
518 return -1;
519
520 rc = mnt_context_set_options_pattern(self->cxt, options_pattern);
521 if (rc) {
522 UL_RaiseExc(-rc);
523 return -1;
524 }
525 return 0;
526 }
527
528 static int Context_set_fs(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
529 {
530 FsObject *fs;
531
532 if (!value) {
533 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
534 return -1;
535 }
536 if (!PyArg_Parse(value, "O!", &FsType, &fs)) {
537 PyErr_SetString(PyExc_TypeError, ARG_ERR);
538 return -1;
539 }
540 Py_INCREF(fs);
541 Py_XDECREF(mnt_context_get_fs_userdata(self->cxt));
542
543 return mnt_context_set_fs(self->cxt, fs->fs);
544 }
545
546 static int Context_set_fstab(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
547 {
548 TableObject *fstab;
549
550 if (!value) {
551 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
552 return -1;
553 }
554 if (!PyArg_Parse(value, "O!", &TableType, &fstab)) {
555 PyErr_SetString(PyExc_TypeError, ARG_ERR);
556 return -1;
557 }
558 Py_INCREF(fstab);
559 Py_XDECREF(mnt_context_get_fstab_userdata(self->cxt));
560
561 return mnt_context_set_fstab(self->cxt, fstab->tab);
562 }
563
564 static int Context_set_optsmode(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
565 {
566 int optsmode;
567
568 if (!value) {
569 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
570 return -1;
571 }
572 if (!PyLong_Check(value)) {
573 PyErr_SetString(PyExc_TypeError, ARG_ERR);
574 return -1;
575 }
576 optsmode = PyLong_AsLong(value);
577 return mnt_context_set_optsmode(self->cxt, optsmode);
578 }
579
580 static int Context_set_syscall_status(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
581 {
582 int syscall_status;
583
584 if (!value) {
585 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
586 return -1;
587 }
588 if (!PyLong_Check(value)) {
589 PyErr_SetString(PyExc_TypeError, ARG_ERR);
590 return -1;
591 }
592 syscall_status = PyLong_AsLong(value);
593 return mnt_context_set_syscall_status(self->cxt, syscall_status);
594 }
595
596 static int Context_set_user_mflags(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
597 {
598 unsigned long flags;
599
600 if (!value) {
601 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
602 return -1;
603 }
604 if (!PyLong_Check(value)) {
605 PyErr_SetString(PyExc_TypeError, ARG_ERR);
606 return -1;
607 }
608 flags = PyLong_AsUnsignedLong(value);
609 return mnt_context_set_mflags(self->cxt, flags);
610
611 }
612
613 static int Context_set_mflags(ContextObjext *self, PyObject *value, void *closure __attribute__((unused)))
614 {
615 unsigned long flags;
616
617 if (!value) {
618 PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
619 return -1;
620 }
621 if (!PyLong_Check(value)) {
622 PyErr_SetString(PyExc_TypeError, ARG_ERR);
623 return -1;
624 }
625 flags = PyLong_AsUnsignedLong(value);
626 return mnt_context_set_mflags(self->cxt, flags);
627 }
628
629 /* returns a flags integer (behavior differs from C API) */
630 static PyObject *Context_get_mflags(ContextObjext *self)
631 {
632 unsigned long flags;
633
634 PyObject *result;
635 mnt_context_get_mflags(self->cxt, &flags);
636 result = Py_BuildValue("k", flags);
637
638 if (!result)
639 PyErr_SetString(PyExc_RuntimeError, CONSTRUCT_ERR);
640 return result;
641
642 }
643 /* returns a flags integer (behavior differs from C API) */
644 static PyObject *Context_get_user_mflags(ContextObjext *self)
645 {
646 unsigned long flags;
647
648 PyObject *result;
649 mnt_context_get_user_mflags(self->cxt, &flags);
650 result = Py_BuildValue("k", flags);
651
652 if (!result)
653 PyErr_SetString(PyExc_RuntimeError, CONSTRUCT_ERR);
654 return result;
655
656 }
657 #define Context_reset_status_HELP "reset_status()\n\n" \
658 "Resets mount(2) and mount.type statuses, so Cxt.do_mount() or\n" \
659 "Cxt.do_umount() could be again called with the same settings.\n" \
660 "\n" \
661 "BE CAREFUL -- after this soft reset the libmount will NOT parse mount\n" \
662 "options, evaluate permissions or apply stuff from fstab.\n" \
663 "\n" \
664 "Returns self or raises an exception in case of an error."
665 static PyObject *Context_reset_status(ContextObjext *self)
666 {
667 int rc = mnt_context_reset_status(self->cxt);
668
669 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
670 }
671
672 #define Context_is_fake_HELP "is_fake()\n\n" \
673 "Returns True if fake flag is enabled or False"
674 static PyObject *Context_is_fake(ContextObjext *self)
675 {
676 return PyBool_FromLong(mnt_context_is_fake(self->cxt));
677 }
678
679 #define Context_is_force_HELP "is_force()\n\n" \
680 "Returns True if force umounting flag is enabled or False"
681 static PyObject *Context_is_force(ContextObjext *self)
682 {
683 return PyBool_FromLong(mnt_context_is_force(self->cxt));
684 }
685
686 #define Context_is_lazy_HELP "is_lazy()\n\n" \
687 "Returns True if lazy umount is enabled or False"
688 static PyObject *Context_is_lazy(ContextObjext *self)
689 {
690 return PyBool_FromLong(mnt_context_is_lazy(self->cxt));
691 }
692
693 #define Context_is_nomtab_HELP "is_nomtab()\n\n" \
694 "Returns True if no-mtab is enabled or False"
695 static PyObject *Context_is_nomtab(ContextObjext *self)
696 {
697 return PyBool_FromLong(mnt_context_is_nomtab(self->cxt));
698 }
699
700 #define Context_is_rdonly_umount_HELP "is_rdonly_umount()\n\n" \
701 "Enable/disable read-only remount on failed umount(2)\n" \
702 "(see umount(8) man page, option -r).\n" \
703 "\n" \
704 "Returns self on success, raises an exception in case of error."
705 static PyObject *Context_is_rdonly_umount(ContextObjext *self)
706 {
707 int rc = mnt_context_is_rdonly_umount(self->cxt);
708 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
709 }
710
711 #define Context_is_restricted_HELP "is_restricted()\n\n" \
712 "Returns False for unrestricted mount (user is root), or True for non-root mounts"
713 static PyObject *Context_is_restricted(ContextObjext *self)
714 {
715 return PyBool_FromLong(mnt_context_is_restricted(self->cxt));
716 }
717
718 #define Context_is_sloppy_HELP "is_sloppy()\n\n" \
719 "Returns True if sloppy flag is enabled or False"
720 static PyObject *Context_is_sloppy(ContextObjext *self)
721 {
722 return PyBool_FromLong(mnt_context_is_sloppy(self->cxt));
723 }
724
725 #define Context_is_verbose_HELP "is_verbose()\n\n" \
726 "Returns True if verbose flag is enabled or False"
727 static PyObject *Context_is_verbose(ContextObjext *self)
728 {
729 return PyBool_FromLong(mnt_context_is_verbose(self->cxt));
730 }
731 #define Context_is_fs_mounted_HELP "is_fs_mounted(fs, mounted)\n\n" \
732 "Returns self or raises an exception in case of an error."
733 static PyObject *Context_is_fs_mounted(ContextObjext *self, PyObject *args, PyObject *kwds)
734 {
735 char *kwlist[] = {"fs", "mounted", NULL};
736 FsObject *fs;
737 int mounted;
738
739 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!i", kwlist,
740 &FsType, &fs, &mounted)) {
741 PyErr_SetString(PyExc_TypeError, ARG_ERR);
742 return NULL;
743 }
744 return PyBool_FromLong(mnt_context_is_fs_mounted(self->cxt, fs->fs, &mounted));
745 }
746
747 #define Context_is_child_HELP "is_child()\n\n" \
748 "Returns True if mount -F enabled and the current context is child, or False"
749 static PyObject *Context_is_child(ContextObjext *self)
750 {
751 return PyBool_FromLong(mnt_context_is_child(self->cxt));
752 }
753
754 #define Context_is_fork_HELP "is_fork()\n\n" \
755 "Returns True if fork (mount -F) is enabled or False"
756 static PyObject *Context_is_fork(ContextObjext *self)
757 {
758 return PyBool_FromLong(mnt_context_is_fork(self->cxt));
759 }
760
761 #define Context_is_parent_HELP "is_parent()\n\n" \
762 "Returns True if mount -F enabled and the current context is parent, or False"
763 static PyObject *Context_is_parent(ContextObjext *self)
764 {
765 return PyBool_FromLong(mnt_context_is_parent(self->cxt));
766 }
767
768 #define Context_is_loopdel_HELP "is_loopdel()\n\n" \
769 "Returns True if loop device should be deleted after umount (umount -d) or False."
770 static PyObject *Context_is_loopdel(ContextObjext *self)
771 {
772 return PyBool_FromLong(mnt_context_is_loopdel(self->cxt));
773 }
774
775 #define Context_is_nocanonicalize_HELP "is_nocanonicalize()\n\n" \
776 "Returns True if no-canonicalize mode enabled or False."
777 static PyObject *Context_is_nocanonicalize(ContextObjext *self)
778 {
779 return PyBool_FromLong(mnt_context_is_nocanonicalize(self->cxt));
780 }
781
782 #define Context_is_nohelpers_HELP "is_nohelpers()\n\n" \
783 "Returns True if helpers are disabled (mount -i) or False."
784 static PyObject *Context_is_nohelpers(ContextObjext *self)
785 {
786 return PyBool_FromLong(mnt_context_is_nohelpers(self->cxt));
787 }
788
789 #define Context_syscall_called_HELP "syscall_called()\n\n" \
790 "Returns True if mount(2) syscall has been called, or False."
791 static PyObject *Context_syscall_called(ContextObjext *self)
792 {
793 return PyBool_FromLong(mnt_context_syscall_called(self->cxt));
794 }
795
796 #define Context_is_swapmatch_HELP "is_swapmatch()\n\n" \
797 "Returns True if swap between source and target is allowed (default is True) or False."
798 static PyObject *Context_is_swapmatch(ContextObjext *self)
799 {
800 return PyBool_FromLong(mnt_context_is_swapmatch(self->cxt));
801 }
802
803 #define Context_tab_applied_HELP "tab_applied()\n\n" \
804 "Returns True if fstab (or mtab) has been applied to the context, False otherwise."
805 static PyObject *Context_tab_applied(ContextObjext *self)
806 {
807 return PyBool_FromLong(mnt_context_tab_applied(self->cxt));
808 }
809
810 #define Context_apply_fstab_HELP "apply_fstab()\n\n" \
811 "This function is optional.\n" \
812 "\n" \
813 "Returns self or raises an exception in case of an error."
814 static PyObject *Context_apply_fstab(ContextObjext *self)
815 {
816 int rc = mnt_context_apply_fstab(self->cxt);
817 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
818 }
819
820 #define Context_helper_executed_HELP "helper_executed()\n\n" \
821 "Returns True if mount.type helper has been executed, or False."
822 static PyObject *Context_helper_executed(ContextObjext *self)
823 {
824 return PyBool_FromLong(mnt_context_helper_executed(self->cxt));
825 }
826
827 static PyObject *Context_get_source(ContextObjext *self)
828 {
829 return PyObjectResultStr(mnt_context_get_source(self->cxt));
830 }
831
832 static PyObject *Context_get_target(ContextObjext *self)
833 {
834 return PyObjectResultStr(mnt_context_get_target(self->cxt));
835 }
836
837 static PyObject *Context_get_options(ContextObjext *self)
838 {
839 return PyObjectResultStr(mnt_context_get_options(self->cxt));
840 }
841
842 static PyObject *Context_get_fstype(ContextObjext *self)
843 {
844 return PyObjectResultStr(mnt_context_get_fstype(self->cxt));
845 }
846
847 static PyObject *Context_get_fs(ContextObjext *self)
848 {
849 return PyObjectResultFs(mnt_context_get_fs(self->cxt));
850 }
851
852 static PyObject *Context_get_fstab(ContextObjext *self)
853 {
854 struct libmnt_table *tab = NULL;
855
856 if (mnt_context_get_fstab(self->cxt, &tab) != 0 || !tab)
857 return NULL;
858 return PyObjectResultTab(tab);
859 }
860
861 static PyObject *Context_get_mtab(ContextObjext *self)
862 {
863 struct libmnt_table *tab = NULL;
864
865 if (mnt_context_get_mtab(self->cxt, &tab) != 0 || !tab)
866 return NULL;
867 return PyObjectResultTab(tab);
868 }
869
870 static PyObject *Context_get_optsmode(ContextObjext *self)
871 {
872 return PyObjectResultInt(mnt_context_get_optsmode(self->cxt));
873 }
874
875 static PyObject *Context_get_status(ContextObjext *self)
876 {
877 return PyObjectResultInt(mnt_context_get_status(self->cxt));
878 }
879
880 static PyObject *Context_get_syscall_errno(ContextObjext *self)
881 {
882 return PyObjectResultInt(mnt_context_get_syscall_errno(self->cxt));
883 }
884
885 #define Context_do_mount_HELP "do_mount()\n\n" \
886 "Call mount(2) or mount.type helper. Unnecessary for Cxt.mount().\n" \
887 "\n" \
888 "Note that this function could be called only once. If you want to mount\n" \
889 "another source or target than you have to call Cxt.reset_context().\n" \
890 "\n" \
891 "If you want to call mount(2) for the same source and target with a different\n" \
892 "mount flags or fstype then call Cxt.reset_status() and then try\n" \
893 "again Cxt.do_mount().\n" \
894 "\n" \
895 "WARNING: non-zero return code does not mean that mount(2) syscall or\n" \
896 "mount.type helper wasn't successfully called.\n" \
897 "\n" \
898 "Check Cxt.status after error!\n" \
899 "\n" \
900 "Returns self on success or an exception in case of other errors."
901 static PyObject *Context_do_mount(ContextObjext *self)
902 {
903 int rc = mnt_context_do_mount(self->cxt);
904 return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
905 }
906
907 #define Context_do_umount_HELP "do_umount()\n\n" \
908 "Umount filesystem by umount(2) or fork()+exec(/sbin/umount.type).\n" \
909 "Unnecessary for Cxt.umount().\n" \
910 "\n" \
911 "See also Cxt.disable_helpers().\n" \
912 "\n" \
913 "WARNING: non-zero return code does not mean that umount(2) syscall or\n" \
914 "umount.type helper wasn't successfully called.\n" \
915 "\n" \
916 "Check Cxt.status after error!\n" \
917 "\n" \
918 "Returns self on success or an exception in case of other errors."
919 static PyObject *Context_do_umount(ContextObjext *self)
920 {
921 int rc = mnt_context_do_umount(self->cxt);
922 return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
923 }
924
925 #define Context_mount_HELP "mount()\n\n" \
926 "High-level, mounts filesystem by mount(2) or fork()+exec(/sbin/mount.type).\n" \
927 "\n" \
928 "This is similar to:\n" \
929 "\n" \
930 "Cxt.prepare_mount();\n" \
931 "Cxt.do_mount();\n" \
932 "Cxt.finalize_mount();\n" \
933 "\n" \
934 "See also Cxt.disable_helper().\n" \
935 "\n" \
936 "Note that this function could be called only once. If you want to mount with\n" \
937 "different setting than you have to call Cxt.reset_context(). It's NOT enough\n" \
938 "to call Cxt.reset_status() if you want call this function more than\n" \
939 "once, whole context has to be reset.\n" \
940 "\n" \
941 "WARNING: non-zero return code does not mean that mount(2) syscall or\n" \
942 "mount.type helper wasn't successfully called.\n" \
943 "\n" \
944 "Check Cxt.status after error!\n" \
945 "\n" \
946 "Returns self on success or an exception in case of other errors."
947 static PyObject *Context_mount(ContextObjext *self)
948 {
949 int rc = mnt_context_mount(self->cxt);
950 return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
951 }
952
953 #define Context_umount_HELP "umount()\n\n" \
954 "High-level, umounts filesystem by umount(2) or fork()+exec(/sbin/umount.type).\n" \
955 "\n" \
956 "This is similar to:\n" \
957 "\n" \
958 "Cxt.prepare_umount();\n" \
959 "Cxt.do_umount();\n" \
960 "Cxt.finalize_umount();\n" \
961 "\n" \
962 "See also Cxt.disable_helpers().\n" \
963 "\n" \
964 "WARNING: non-zero return code does not mean that umount(2) syscall or\n" \
965 "umount.type helper wasn't successfully called.\n" \
966 "\n" \
967 "Check Cxt.status after error!\n" \
968 "\n" \
969 "Returns self on success or an exception in case of other errors."
970 static PyObject *Context_umount(ContextObjext *self)
971 {
972 int rc = mnt_context_umount(self->cxt);
973 return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
974 }
975
976 #define Context_finalize_mount_HELP "finalize_mount()\n\n" \
977 "Mtab update, etc. Unnecessary for Cxt.mount(), but should be called\n" \
978 "after Cxt.do_mount(). See also Cxt.syscall_status.\n" \
979 "\n" \
980 "Returns self or raises an exception in case of an error."
981 static PyObject *Context_finalize_mount(ContextObjext *self)
982 {
983 int rc = mnt_context_finalize_mount(self->cxt);
984 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
985 }
986
987 #define Context_prepare_umount_HELP "prepare_umount()\n\n" \
988 "Prepare context for umounting, unnecessary for Cxt.umount().\n" \
989 "\n" \
990 "Returns self or raises an exception in case of an error."
991 static PyObject *Context_prepare_umount(ContextObjext *self)
992 {
993 int rc = mnt_context_prepare_umount(self->cxt);
994 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
995 }
996
997 #define Context_prepare_mount_HELP "prepare_mount()\n\n" \
998 "Prepare context for mounting, unnecessary for Cxt.mount().\n" \
999 "\n" \
1000 "Returns self or raises an exception in case of an error."
1001 static PyObject *Context_prepare_mount(ContextObjext *self)
1002 {
1003 int rc = mnt_context_prepare_mount(self->cxt);
1004 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1005 }
1006
1007 #define Context_finalize_umount_HELP "finalize_umount()\n\n" \
1008 "Mtab update, etc. Unnecessary for Cxt.umount(), but should be called\n" \
1009 "after Cxt.do_umount(). See also Cxt.syscall_status.\n" \
1010 "\n" \
1011 "Returns self on success, raises LibmountError if target filesystem not found, or other exception on error."
1012 static PyObject *Context_finalize_umount(ContextObjext *self)
1013 {
1014 int rc = mnt_context_finalize_umount(self->cxt);
1015 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1016 }
1017
1018 #define Context_find_umount_fs_HELP "find_umount_fs(tgt, pfs)\n\n" \
1019 "Returns self or raises an exception in case of an error."
1020 static PyObject *Context_find_umount_fs(ContextObjext *self, PyObject *args, PyObject *kwds)
1021 {
1022 int rc;
1023 char *kwlist[] = { "tgt", "pfs", NULL };
1024 char *tgt = NULL;
1025 FsObject *fs;
1026
1027 if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!", kwlist, &tgt, &FsType, &fs)) {
1028 PyErr_SetString(PyExc_TypeError, ARG_ERR);
1029 return NULL;
1030 }
1031
1032 rc = mnt_context_find_umount_fs(self->cxt, tgt, &fs->fs);
1033 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1034 }
1035
1036 #define Context_append_options_HELP "append_options(optstr)\n\n" \
1037 "Returns self or raises an exception in case of an error."
1038 static PyObject *Context_append_options(ContextObjext *self, PyObject *args, PyObject *kwds)
1039 {
1040 int rc;
1041 char *kwlist[] = {"optstr", NULL};
1042 char *optstr = NULL;
1043
1044 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &optstr)) {
1045 PyErr_SetString(PyExc_TypeError, ARG_ERR);
1046 return NULL;
1047 }
1048
1049 rc = mnt_context_append_options(self->cxt, optstr);
1050 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1051 }
1052
1053 #define Context_helper_setopt_HELP "helper_setopt(c, arg)\n\n" \
1054 "This function applies [u]mount.type command line option (for example parsed\n" \
1055 "by getopt or getopt_long) to cxt. All unknown options are ignored and\n" \
1056 "then ValueError is raised.\n" \
1057 "\n" \
1058 "Returns self on success, raises ValueError if c is unknown or other exception in case of an error."
1059 static PyObject *Context_helper_setopt(ContextObjext *self, PyObject *args, PyObject *kwds)
1060 {
1061 int rc;
1062 int c;
1063 char *arg;
1064 char *kwlist[] = { "c", "arg", NULL };
1065
1066 if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &c, &arg)) {
1067 PyErr_SetString(PyExc_TypeError, ARG_ERR);
1068 return NULL;
1069 }
1070
1071 rc = mnt_context_helper_setopt(self->cxt, c, arg);
1072 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1073 }
1074
1075 #define Context_init_helper_HELP "init_helper(action, flags)\n\n" \
1076 "This function informs libmount that it is used from [u]mount.type helper.\n" \
1077 "\n" \
1078 "The function also calls Cxt.disable_helpers() to avoid calling\n" \
1079 "mount.type helpers recursively. If you really want to call another\n" \
1080 "mount.type helper from your helper then you have to explicitly enable this\n" \
1081 "feature by:\n" \
1082 "\n" \
1083 "Cxt.disable_helpers(False);\n" \
1084 "\n" \
1085 "Returns self or raises an exception in case of an error."
1086 static PyObject *Context_init_helper(ContextObjext *self, PyObject *args, PyObject *kwds)
1087 {
1088 int rc;
1089 int action, flags;
1090 char *kwlist[] = {"action", "flags", NULL};
1091
1092 if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwlist, &action, &flags)) {
1093 PyErr_SetString(PyExc_TypeError, ARG_ERR);
1094 return NULL;
1095 }
1096
1097 rc = mnt_context_init_helper(self->cxt, action, flags);
1098 return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
1099 }
1100
1101 static PyGetSetDef Context_getseters[] = {
1102 {"tables_errcb", NULL, (setter)Context_set_tables_errcb, "error callback function", NULL},
1103 {"status", (getter)Context_get_status, NULL, "status", NULL},
1104 {"source", (getter)Context_get_source, (setter)Context_set_source, "source", NULL},
1105 {"target", (getter)Context_get_target, (setter)Context_set_target, "target", NULL},
1106 {"fstype", (getter)Context_get_fstype, (setter)Context_set_fstype, "fstype", NULL},
1107 {"options", (getter)Context_get_options, (setter)Context_set_options, "options", NULL},
1108 {"mflags", (getter)Context_get_mflags, (setter)Context_set_mflags, "mflags", NULL},
1109 {"mountdata", NULL, (setter)Context_set_mountdata, "mountdata", NULL},
1110 {"fstype_pattern", NULL, (setter)Context_set_fstype_pattern, "fstype_pattern", NULL},
1111 {"options_pattern", NULL, (setter)Context_set_options_pattern, "options_pattern", NULL},
1112 {"fs", (getter)Context_get_fs, (setter)Context_set_fs, "filesystem description (type, mountpoint, device, ...)", NULL},
1113 {"mtab", (getter)Context_get_mtab, NULL, "mtab entries", NULL},
1114 {"fstab", (getter)Context_get_fstab, (setter)Context_set_fstab, "fstab (or mtab for some remounts)", NULL},
1115 {"optsmode", (getter)Context_get_optsmode, (setter)Context_set_optsmode, "fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE}", NULL},
1116 {"syscall_errno", (getter)Context_get_syscall_errno, (setter)Context_set_syscall_status, "1: not_called yet, 0: success, <0: -errno", NULL},
1117 {"user_mflags", (getter)Context_get_user_mflags, (setter)Context_set_user_mflags, "user mflags", NULL},
1118 {NULL}
1119 };
1120 static PyMethodDef Context_methods[] = {
1121 {"find_umount_fs", (PyCFunction)Context_find_umount_fs, METH_VARARGS|METH_KEYWORDS, Context_find_umount_fs_HELP},
1122 {"reset_status", (PyCFunction)Context_reset_status, METH_NOARGS, Context_reset_status_HELP},
1123 {"helper_executed", (PyCFunction)Context_helper_executed, METH_NOARGS, Context_helper_executed_HELP},
1124 {"init_helper", (PyCFunction)Context_init_helper, METH_VARARGS|METH_KEYWORDS, Context_init_helper_HELP},
1125 {"helper_setopt", (PyCFunction)Context_helper_setopt, METH_VARARGS|METH_KEYWORDS, Context_helper_setopt_HELP},
1126 {"append_options", (PyCFunction)Context_append_options, METH_VARARGS|METH_KEYWORDS, Context_append_options_HELP},
1127 {"apply_fstab", (PyCFunction)Context_apply_fstab, METH_NOARGS, Context_apply_fstab_HELP},
1128 {"disable_canonicalize", (PyCFunction)Context_disable_canonicalize, METH_VARARGS|METH_KEYWORDS, Context_disable_canonicalize_HELP},
1129 {"disable_helpers", (PyCFunction)Context_disable_helpers, METH_VARARGS|METH_KEYWORDS, Context_disable_helpers_HELP},
1130 {"disable_mtab", (PyCFunction)Context_disable_mtab, METH_VARARGS|METH_KEYWORDS, Context_disable_mtab_HELP},
1131 {"do_mount", (PyCFunction)Context_do_mount, METH_NOARGS, Context_do_mount_HELP},
1132 {"do_umount", (PyCFunction)Context_do_umount, METH_NOARGS , Context_do_umount_HELP},
1133 {"enable_fake", (PyCFunction)Context_enable_fake, METH_VARARGS|METH_KEYWORDS, Context_enable_fake_HELP},
1134 {"enable_force", (PyCFunction)Context_enable_force, METH_VARARGS|METH_KEYWORDS, Context_enable_force_HELP},
1135 {"enable_lazy", (PyCFunction)Context_enable_lazy, METH_VARARGS|METH_KEYWORDS, Context_enable_lazy_HELP},
1136 {"enable_loopdel", (PyCFunction)Context_enable_loopdel, METH_VARARGS|METH_KEYWORDS, Context_enable_loopdel_HELP},
1137 {"enable_rdonly_umount", (PyCFunction)Context_enable_rdonly_umount, METH_VARARGS|METH_KEYWORDS, Context_enable_rdonly_umount_HELP},
1138 {"enable_sloppy", (PyCFunction)Context_enable_sloppy, METH_VARARGS|METH_KEYWORDS, Context_enable_sloppy_HELP},
1139 {"enable_verbose", (PyCFunction)Context_enable_verbose, METH_VARARGS|METH_KEYWORDS, Context_enable_verbose_HELP},
1140 {"enable_fork", (PyCFunction)Context_enable_fork, METH_VARARGS|METH_KEYWORDS, Context_enable_fork_HELP},
1141 {"finalize_mount", (PyCFunction)Context_finalize_mount, METH_NOARGS, Context_finalize_mount_HELP},
1142 {"finalize_umount", (PyCFunction)Context_finalize_umount, METH_NOARGS, Context_finalize_umount_HELP},
1143 {"is_fake", (PyCFunction)Context_is_fake, METH_NOARGS, Context_is_fake_HELP},
1144 {"is_force", (PyCFunction)Context_is_force, METH_NOARGS, Context_is_force_HELP},
1145 {"is_fork", (PyCFunction)Context_is_fork, METH_NOARGS, Context_is_fork_HELP},
1146 {"is_fs_mounted", (PyCFunction)Context_is_fs_mounted, METH_VARARGS|METH_KEYWORDS, Context_is_fs_mounted_HELP},
1147 {"is_lazy", (PyCFunction)Context_is_lazy, METH_NOARGS, Context_is_lazy_HELP},
1148 {"is_nomtab", (PyCFunction)Context_is_nomtab, METH_NOARGS, Context_is_nomtab_HELP},
1149 {"is_rdonly_umount", (PyCFunction)Context_is_rdonly_umount, METH_NOARGS, Context_is_rdonly_umount_HELP},
1150 {"is_restricted", (PyCFunction)Context_is_restricted, METH_NOARGS, Context_is_restricted_HELP},
1151 {"is_sloppy", (PyCFunction)Context_is_sloppy, METH_NOARGS, Context_is_sloppy_HELP},
1152 {"is_verbose", (PyCFunction)Context_is_verbose, METH_NOARGS, Context_is_verbose_HELP},
1153 {"is_child", (PyCFunction)Context_is_child, METH_NOARGS, Context_is_child_HELP},
1154 {"is_parent", (PyCFunction)Context_is_parent, METH_NOARGS, Context_is_parent_HELP},
1155 {"is_loopdel", (PyCFunction)Context_is_loopdel, METH_NOARGS, Context_is_loopdel_HELP},
1156 {"is_nocanonicalize", (PyCFunction)Context_is_nocanonicalize, METH_NOARGS, Context_is_nocanonicalize_HELP},
1157 {"is_nohelpers", (PyCFunction)Context_is_nohelpers, METH_NOARGS, Context_is_nohelpers_HELP},
1158 {"is_swapmatch", (PyCFunction)Context_is_swapmatch, METH_NOARGS, Context_is_swapmatch_HELP},
1159 {"mount", (PyCFunction)Context_mount, METH_NOARGS, Context_mount_HELP},
1160 {"prepare_mount", (PyCFunction)Context_prepare_mount, METH_NOARGS, Context_prepare_mount_HELP},
1161 {"prepare_umount", (PyCFunction)Context_prepare_umount, METH_NOARGS, Context_prepare_umount_HELP},
1162 {"umount", (PyCFunction)Context_umount, METH_NOARGS, Context_umount_HELP},
1163 {"syscall_called", (PyCFunction)Context_syscall_called, METH_NOARGS, Context_syscall_called_HELP},
1164 {"disable_swapmatch", (PyCFunction)Context_disable_swapmatch, METH_VARARGS|METH_KEYWORDS, Context_disable_swapmatch_HELP},
1165 {"tab_applied", (PyCFunction)Context_tab_applied, METH_NOARGS, Context_tab_applied_HELP},
1166 {NULL}
1167 };
1168
1169 static PyObject *Context_repr(ContextObjext *self)
1170 {
1171 return PyUnicode_FromFormat("<libmount.Context object at %p, restricted=%s>",
1172 self, mnt_context_is_restricted(self->cxt) ? "True" : "False");
1173 }
1174
1175 PyTypeObject ContextType = {
1176 PyVarObject_HEAD_INIT(NULL, 0)
1177 .tp_name = "libmount.Context",
1178 .tp_basicsize = sizeof(ContextObjext),
1179 .tp_dealloc = (destructor)Context_dealloc,
1180 .tp_repr = (reprfunc) Context_repr,
1181 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1182 .tp_doc = Context_HELP,
1183 .tp_methods = Context_methods,
1184 .tp_members = Context_members,
1185 .tp_getset = Context_getseters,
1186 .tp_init = (initproc)Context_init,
1187 .tp_new = Context_new,
1188 };
1189
1190 void Context_AddModuleObject(PyObject *mod)
1191 {
1192 if (PyType_Ready(&ContextType) < 0)
1193 return;
1194
1195 DBG(CXT, pymnt_debug("add to module"));
1196
1197 Py_INCREF(&ContextType);
1198 PyModule_AddObject(mod, "Context", (PyObject *)&ContextType);
1199 }
1200
1201