]> git.ipfire.org Git - thirdparty/util-linux.git/blob - shlibs/mount/src/mountP.h
libmount: improve parsers return codes
[thirdparty/util-linux.git] / shlibs / mount / src / mountP.h
1 /*
2 * mountP.h - private library header file
3 *
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
5 *
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
8 */
9
10 #ifndef _LIBMOUNT_PRIVATE_H
11 #define _LIBMOUNT_PRIVATE_H
12
13 #include <sys/types.h>
14 #include <errno.h>
15 #include "c.h"
16
17 #define USE_UNSTABLE_LIBMOUNT_API
18
19 #include "mount.h"
20 #include "list.h"
21
22 /* features */
23 #define CONFIG_LIBMOUNT_ASSERT
24 #define CONFIG_LIBMOUNT_DEBUG
25
26 #ifdef CONFIG_LIBMOUNT_ASSERT
27 #include <assert.h>
28 #endif
29
30 /*
31 * Debug
32 */
33 #if defined(TEST_PROGRAM) && !defined(LIBMOUNT_DEBUG)
34 #define CONFIG_LIBMOUNT_DEBUG
35 #endif
36
37 #define MNT_DEBUG_INIT (1 << 1)
38 #define MNT_DEBUG_CACHE (1 << 2)
39 #define MNT_DEBUG_OPTIONS (1 << 3)
40 #define MNT_DEBUG_LOCKS (1 << 4)
41 #define MNT_DEBUG_TAB (1 << 5)
42 #define MNT_DEBUG_FS (1 << 6)
43 #define MNT_DEBUG_OPTS (1 << 7)
44 #define MNT_DEBUG_UPDATE (1 << 8)
45 #define MNT_DEBUG_UTILS (1 << 9)
46 #define MNT_DEBUG_CXT (1 << 10)
47 #define MNT_DEBUG_ALL 0xFFFF
48
49 #ifdef CONFIG_LIBMOUNT_DEBUG
50 # include <stdio.h>
51 # include <stdarg.h>
52
53 # define DBG(m,x) do { \
54 if ((MNT_DEBUG_ ## m) & libmount_debug_mask) {\
55 fprintf(stderr, "libmount: %s: ", # m); \
56 x; \
57 } \
58 } while(0)
59
60 extern int libmount_debug_mask;
61
62 static inline void mnt_debug(const char *mesg, ...)
63 {
64 va_list ap;
65 va_start(ap, mesg);
66 vfprintf(stderr, mesg, ap);
67 va_end(ap);
68 fputc('\n', stderr);
69 }
70
71 static inline void mnt_debug_h(void *handler, const char *mesg, ...)
72 {
73 va_list ap;
74
75 fprintf(stderr, "[%p]: ", handler);
76 va_start(ap, mesg);
77 vfprintf(stderr, mesg, ap);
78 va_end(ap);
79 fputc('\n', stderr);
80 }
81
82 #else /* !CONFIG_LIBMOUNT_DEBUG */
83 # define DBG(m,x)
84 #endif
85
86 /* extension for files in the /etc/fstab.d directory */
87 #define MNT_MNTTABDIR_EXT ".fstab"
88
89 /* library private paths */
90 #define MNT_PATH_RUNDIR "/var/run/mount"
91 #define MNT_PATH_MOUNTINFO MNT_PATH_RUNDIR "/mountinfo"
92
93 #ifdef TEST_PROGRAM
94 struct mtest {
95 const char *name;
96 int (*body)(struct mtest *ts, int argc, char *argv[]);
97 const char *usage;
98 };
99
100 /* utils.c */
101 extern int mnt_run_test(struct mtest *tests, int argc, char *argv[]);
102 #endif
103
104 /* utils.c */
105 extern char *mnt_getenv_safe(const char *arg);
106 extern int endswith(const char *s, const char *sx);
107 extern int startswith(const char *s, const char *sx);
108
109 extern char *mnt_get_username(const uid_t uid);
110 extern int mnt_get_uid(const char *username, uid_t *uid);
111 extern int mnt_get_gid(const char *groupname, gid_t *gid);
112 extern int mnt_in_group(gid_t gid);
113
114 extern int mnt_has_regular_mtab(void);
115
116 extern char *mnt_get_mountpoint(const char *path);
117 extern char *mnt_get_fs_root(const char *path, const char *mountpoint);
118
119 /*
120 * Generic iterator
121 */
122 struct _mnt_iter {
123 struct list_head *p; /* current position */
124 struct list_head *head; /* start position */
125 int direction; /* MNT_ITER_{FOR,BACK}WARD */
126 };
127
128 #define IS_ITER_FORWARD(_i) ((_i)->direction == MNT_ITER_FORWARD)
129 #define IS_ITER_BACKWARD(_i) ((_i)->direction == MNT_ITER_BACKWARD)
130
131 #define MNT_ITER_INIT(itr, list) \
132 do { \
133 (itr)->p = IS_ITER_FORWARD(itr) ? \
134 (list)->next : (list)->prev; \
135 (itr)->head = (list); \
136 } while(0)
137
138 #define MNT_ITER_ITERATE(itr, res, restype, member) \
139 do { \
140 res = list_entry((itr)->p, restype, member); \
141 (itr)->p = IS_ITER_FORWARD(itr) ? \
142 (itr)->p->next : (itr)->p->prev; \
143 } while(0)
144
145
146 /*
147 * This struct represents one entry in mtab/fstab/mountinfo file.
148 */
149 struct _mnt_fs {
150 struct list_head ents;
151
152 int id; /* mountinfo[1]: ID */
153 int parent; /* moutninfo[2]: parent */
154 dev_t devno; /* moutninfo[3]: st_dev */
155
156 char *source; /* fstab[1]: mountinfo[10]:
157 * source dev, file, dir or TAG */
158 char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
159 char *tagval; /* tag value */
160
161 char *root; /* mountinfo[4]: root of the mount within the FS */
162 char *target; /* mountinfo[5], fstab[2]: mountpoint */
163 char *fstype; /* mountinfo[9], fstab[3]: filesystem type */
164
165 char *optstr; /* mountinfo[6,11], fstab[4]: option string */
166 char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */
167 char *fs_optstr; /* mountinfo[11]: fs-depend options */
168
169 int freq; /* fstab[5]: dump frequency in days */
170 int passno; /* fstab[6]: pass number on parallel fsck */
171
172 int flags; /* MNT_FS_* flags */
173
174 void *userdata; /* library independent data */
175 };
176
177 /*
178 * fs flags
179 */
180 #define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */
181 #define MNT_FS_NET (1 << 2) /* network filesystem */
182 #define MNT_FS_SWAP (1 << 3) /* swap device */
183
184 /*
185 * mtab/fstab/mountinfo file
186 */
187 struct _mnt_tab {
188 int fmt; /* MNT_FMT_* file format */
189 int nents; /* number of valid entries */
190
191 mnt_cache *cache; /* canonicalized paths/tags cache */
192
193 int (*errcb)(mnt_tab *tb, const char *filename,
194 int line, int flag);
195
196 struct list_head ents; /* list of entries (mentry) */
197 };
198
199
200 /* optmap.c */
201 extern const struct mnt_optmap *mnt_optmap_get_entry(struct mnt_optmap const **maps,
202 int nmaps, const char *name,
203 size_t namelen, const struct mnt_optmap **mapent);
204 extern int mnt_optmap_enum_to_number(const struct mnt_optmap *mapent,
205 const char *rawdata, size_t len);
206 extern const char *mnt_optmap_get_type(const struct mnt_optmap *mapent);
207 extern int mnt_optmap_require_value(const struct mnt_optmap *mapent);
208
209 /* optstr.c */
210 extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
211
212 /* fs.c */
213 extern int __mnt_fs_set_source_ptr(mnt_fs *fs, char *source);
214 extern int __mnt_fs_set_fstype_ptr(mnt_fs *fs, char *fstype);
215 extern int __mnt_fs_set_optstr_ptr(mnt_fs *fs, char *optstr, int split);
216 extern int __mnt_fs_set_optstr(mnt_fs *fs, const char *optstr, int split);
217
218 #endif /* _LIBMOUNT_PRIVATE_H */