summaryrefslogtreecommitdiffstats
path: root/libmount/python/pylibmount.h
blob: bf3278defd6c65dea4fba117a51c524379570deb (plain) (blame)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef UTIL_LINUX_PYLIBMOUNT_H
#define UTIL_LINUX_PYLIBMOUNT_H

#include <Python.h>
#include <structmember.h>

#include "c.h"
#include "libmount.h"

#define CONFIG_PYLIBMOUNT_DEBUG

#define PYMNT_DEBUG_INIT	(1 << 1)
#define PYMNT_DEBUG_TAB		(1 << 2)
#define PYMNT_DEBUG_FS		(1 << 3)
#define PYMNT_DEBUG_CXT		(1 << 4)

#ifdef CONFIG_PYLIBMOUNT_DEBUG
# include <stdio.h>
# include <stdarg.h>

# define DBG(m, x)	do { \
				if ((PYMNT_DEBUG_ ## m) & pylibmount_debug_mask) { \
					fprintf(stderr, "%d: pylibmount: %6s: ", getpid(), # m); \
					x; \
				} \
			} while (0)

extern int pylibmount_debug_mask;

static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
pymnt_debug(const char *mesg, ...)
{
	va_list ap;
	va_start(ap, mesg);
	vfprintf(stderr, mesg, ap);
	va_end(ap);
	fputc('\n', stderr);
}

static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
pymnt_debug_h(void *handler, const char *mesg, ...)
{
	va_list ap;

	if (handler)
		fprintf(stderr, "[%p]: ", handler);
	va_start(ap, mesg);
	vfprintf(stderr, mesg, ap);
	va_end(ap);
	fputc('\n', stderr);
}

#else /* !CONFIG_PYLIBMOUNT_DEBUG */
# define DBG(m,x) do { ; } while (0)
#endif


#define NODEL_ATTR	"This attribute cannot be deleted"
#define CONSTRUCT_ERR	"Error during object construction"
#define ARG_ERR		"Invalid number or type of arguments"
#define NOFS_ERR	"No filesystems to mount"
#define MEMORY_ERR	strerror(ENOMEM)
#define CONV_ERR	"Type conversion failed"

/*
 * fs.c
 */
typedef struct {
	PyObject_HEAD
	struct libmnt_fs *fs;
} FsObject;

extern PyTypeObject FsType;

extern PyObject *PyObjectResultFs(struct libmnt_fs *fs);
extern void FS_AddModuleObject(PyObject *mod);

/*
 * tab.c
 */
typedef struct {
	PyObject_HEAD

	struct libmnt_table		*tab;
	struct libmnt_iter		*iter;
	PyObject			*errcb;
} TableObject;

extern PyTypeObject TableType;

extern PyObject *PyObjectResultTab(struct libmnt_table *tab);

extern void Table_unref(struct libmnt_table *tab);
extern void Table_AddModuleObject(PyObject *mod);

extern int pymnt_table_parser_errcb(struct libmnt_table *tb, const char *filename, int line);

#ifdef __linux__

/*
 * context.c
 */
typedef struct {
	PyObject_HEAD

	struct libmnt_context		*cxt;
	PyObject			*table_errcb;

} ContextObjext;

extern PyTypeObject ContextType;
extern void Context_AddModuleObject(PyObject *mod);

#endif /* __linux__ */

/*
 * misc
 */
extern PyObject *LibmountError;
extern PyObject *UL_IncRef(void *killme);
extern void *UL_RaiseExc(int e);

extern PyObject *PyObjectResultInt(int i);
extern PyObject *PyObjectResultStr(const char *s);

extern char *pystos(PyObject *pys);
extern void PyFree(void *o);



#endif /* UTIL_LINUX_PYLIBMOUNT */