1 #ifndef UTIL_LINUX_PYLIBMOUNT_H
2 #define UTIL_LINUX_PYLIBMOUNT_H
3
4 #include <Python.h>
5 #include <structmember.h>
6
7 #include "c.h"
8 #include "libmount.h"
9
10 #define CONFIG_PYLIBMOUNT_DEBUG
11
12 #define PYMNT_DEBUG_INIT (1 << 1)
13 #define PYMNT_DEBUG_TAB (1 << 2)
14 #define PYMNT_DEBUG_FS (1 << 3)
15 #define PYMNT_DEBUG_CXT (1 << 4)
16
17 #ifdef CONFIG_PYLIBMOUNT_DEBUG
18 # include <stdio.h>
19 # include <stdarg.h>
20
21 # define DBG(m, x) do { \
22 if ((PYMNT_DEBUG_ ## m) & pylibmount_debug_mask) { \
23 fprintf(stderr, "%d: pylibmount: %6s: ", getpid(), # m); \
24 x; \
25 } \
26 } while (0)
27
28 extern int pylibmount_debug_mask;
29
30 static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
31 pymnt_debug(const char *mesg, ...)
32 {
33 va_list ap;
34 va_start(ap, mesg);
35 vfprintf(stderr, mesg, ap);
36 va_end(ap);
37 fputc('\n', stderr);
38 }
39
40 static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
41 pymnt_debug_h(void *handler, const char *mesg, ...)
42 {
43 va_list ap;
44
45 if (handler)
46 fprintf(stderr, "[%p]: ", handler);
47 va_start(ap, mesg);
48 vfprintf(stderr, mesg, ap);
49 va_end(ap);
50 fputc('\n', stderr);
51 }
52
53 #else /* !CONFIG_PYLIBMOUNT_DEBUG */
54 # define DBG(m,x) do { ; } while (0)
55 #endif
56
57
58 #define NODEL_ATTR "This attribute cannot be deleted"
59 #define CONSTRUCT_ERR "Error during object construction"
60 #define ARG_ERR "Invalid number or type of arguments"
61 #define NOFS_ERR "No filesystems to mount"
62 #define MEMORY_ERR strerror(ENOMEM)
63 #define CONV_ERR "Type conversion failed"
64
65 /*
66 * fs.c
67 */
68 typedef struct {
69 PyObject_HEAD
70 struct libmnt_fs *fs;
71 } FsObject;
72
73 extern PyTypeObject FsType;
74
75 extern PyObject *PyObjectResultFs(struct libmnt_fs *fs);
76 extern void FS_AddModuleObject(PyObject *mod);
77
78 /*
79 * tab.c
80 */
81 typedef struct {
82 PyObject_HEAD
83
84 struct libmnt_table *tab;
85 struct libmnt_iter *iter;
86 PyObject *errcb;
87 } TableObject;
88
89 extern PyTypeObject TableType;
90
91 extern PyObject *PyObjectResultTab(struct libmnt_table *tab);
92
93 extern void Table_unref(struct libmnt_table *tab);
94 extern void Table_AddModuleObject(PyObject *mod);
95
96 extern int pymnt_table_parser_errcb(struct libmnt_table *tb, const char *filename, int line);
97
98 #ifdef __linux__
99
100 /*
101 * context.c
102 */
103 typedef struct {
104 PyObject_HEAD
105
106 struct libmnt_context *cxt;
107 PyObject *table_errcb;
108
109 } ContextObjext;
110
111 extern PyTypeObject ContextType;
112 extern void Context_AddModuleObject(PyObject *mod);
113
114 #endif /* __linux__ */
115
116 /*
117 * misc
118 */
119 extern PyObject *LibmountError;
120 extern PyObject *UL_IncRef(void *killme);
121 extern void *UL_RaiseExc(int e);
122
123 extern PyObject *PyObjectResultInt(int i);
124 extern PyObject *PyObjectResultStr(const char *s);
125
126 extern char *pystos(PyObject *pys);
127 extern void PyFree(void *o);
128
129
130
131 #endif /* UTIL_LINUX_PYLIBMOUNT */