2
* mountP.h - private library header file
4
* Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
6
* This file may be redistributed under the terms of the
7
* GNU Lesser General Public License.
10
#ifndef _LIBMOUNT_PRIVATE_H
11
#define _LIBMOUNT_PRIVATE_H
17
#include <sys/types.h>
25
#define CONFIG_LIBMOUNT_ASSERT
26
#define CONFIG_LIBMOUNT_DEBUG
28
#ifdef CONFIG_LIBMOUNT_ASSERT
35
#if defined(TEST_PROGRAM) && !defined(LIBMOUNT_DEBUG)
36
#define CONFIG_LIBMOUNT_DEBUG
39
#define MNT_DEBUG_INIT (1 << 1)
40
#define MNT_DEBUG_CACHE (1 << 2)
41
#define MNT_DEBUG_OPTIONS (1 << 3)
42
#define MNT_DEBUG_LOCKS (1 << 4)
43
#define MNT_DEBUG_TAB (1 << 5)
44
#define MNT_DEBUG_FS (1 << 6)
45
#define MNT_DEBUG_OPTS (1 << 7)
46
#define MNT_DEBUG_UPDATE (1 << 8)
47
#define MNT_DEBUG_UTILS (1 << 9)
48
#define MNT_DEBUG_CXT (1 << 10)
49
#define MNT_DEBUG_DIFF (1 << 11)
50
#define MNT_DEBUG_ALL 0xFFFF
52
#ifdef CONFIG_LIBMOUNT_DEBUG
56
# define DBG(m,x) do { \
57
if ((MNT_DEBUG_ ## m) & libmount_debug_mask) {\
58
fprintf(stderr, "libmount: %8s: ", # m); \
63
# define DBG_FLUSH do { fflush(stderr); } while(0)
65
extern int libmount_debug_mask;
67
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
68
mnt_debug(const char *mesg, ...)
72
vfprintf(stderr, mesg, ap);
77
static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
78
mnt_debug_h(void *handler, const char *mesg, ...)
82
fprintf(stderr, "[%p]: ", handler);
84
vfprintf(stderr, mesg, ap);
89
#else /* !CONFIG_LIBMOUNT_DEBUG */
90
# define DBG(m,x) do { ; } while(0)
91
# define DBG_FLUSH do { ; } while(0)
94
/* extension for files in the /etc/fstab.d directory */
95
#define MNT_MNTTABDIR_EXT ".fstab"
97
/* library private paths */
98
#define MNT_RUNTIME_TOPDIR "/run"
99
#define MNT_RUNTIME_TOPDIR_OLD "/dev"
101
#define MNT_PATH_UTAB MNT_RUNTIME_TOPDIR "/mount/utab"
102
#define MNT_PATH_UTAB_OLD MNT_RUNTIME_TOPDIR_OLD "/.mount/utab"
104
#define MNT_UTAB_HEADER "# libmount utab file\n"
109
int (*body)(struct libmnt_test *ts, int argc, char *argv[]);
114
extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]);
118
extern int endswith(const char *s, const char *sx);
119
extern int startswith(const char *s, const char *sx);
121
extern int mnt_chdir_to_parent(const char *target, char **filename);
122
extern char *mnt_get_username(const uid_t uid);
123
extern int mnt_get_uid(const char *username, uid_t *uid);
124
extern int mnt_get_gid(const char *groupname, gid_t *gid);
125
extern int mnt_in_group(gid_t gid);
127
extern char *mnt_get_mountpoint(const char *path);
128
extern char *mnt_get_fs_root(const char *path, const char *mountpoint);
129
extern int mnt_open_uniq_filename(const char *filename, char **name);
130
extern int mnt_has_regular_utab(const char **utab, int *writable);
131
extern const char *mnt_get_utab_path(void);
133
extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
134
extern void mnt_free_filesystems(char **filesystems);
137
extern struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
138
struct libmnt_fs *fs,
139
unsigned long mountflags,
146
struct list_head *p; /* current position */
147
struct list_head *head; /* start position */
148
int direction; /* MNT_ITER_{FOR,BACK}WARD */
151
#define IS_ITER_FORWARD(_i) ((_i)->direction == MNT_ITER_FORWARD)
152
#define IS_ITER_BACKWARD(_i) ((_i)->direction == MNT_ITER_BACKWARD)
154
#define MNT_ITER_INIT(itr, list) \
156
(itr)->p = IS_ITER_FORWARD(itr) ? \
157
(list)->next : (list)->prev; \
158
(itr)->head = (list); \
161
#define MNT_ITER_ITERATE(itr, res, restype, member) \
163
res = list_entry((itr)->p, restype, member); \
164
(itr)->p = IS_ITER_FORWARD(itr) ? \
165
(itr)->p->next : (itr)->p->prev; \
170
* This struct represents one entry in mtab/fstab/mountinfo file.
171
* (note that fstab[1] means the first column from fstab, and so on...)
174
struct list_head ents;
176
int id; /* mountinfo[1]: ID */
177
int parent; /* mountinfo[2]: parent */
178
dev_t devno; /* mountinfo[3]: st_dev */
180
char *bindsrc; /* utab, full path from fstab[1] for bind mounts */
182
char *source; /* fstab[1], mountinfo[10]:
183
* source dev, file, dir or TAG */
184
char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
185
char *tagval; /* tag value */
187
char *root; /* mountinfo[4]: root of the mount within the FS */
188
char *target; /* mountinfo[5], fstab[2]: mountpoint */
189
char *fstype; /* mountinfo[9], fstab[3]: filesystem type */
191
char *optstr; /* fstab[4], merged options */
192
char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */
193
char *fs_optstr; /* mountinfo[11]: fs-dependent options */
194
char *user_optstr; /* userspace mount options */
195
char *attrs; /* mount attributes */
197
int freq; /* fstab[5]: dump frequency in days */
198
int passno; /* fstab[6]: pass number on parallel fsck */
200
int flags; /* MNT_FS_* flags */
202
void *userdata; /* library independent data */
208
#define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */
209
#define MNT_FS_NET (1 << 2) /* network filesystem */
210
#define MNT_FS_SWAP (1 << 3) /* swap device */
211
#define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
212
#define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */
214
extern int __mnt_fs_get_flags(struct libmnt_fs *fs);
215
extern int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags);
219
* mtab/fstab/mountinfo file
221
struct libmnt_table {
222
int fmt; /* MNT_FMT_* file format */
223
int nents; /* number of valid entries */
225
struct libmnt_cache *cache; /* canonicalized paths/tags cache */
227
int (*errcb)(struct libmnt_table *tb,
228
const char *filename, int line);
230
struct list_head ents; /* list of entries (libmnt_fs) */
233
extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt);
240
MNT_FMT_FSTAB, /* /etc/{fs,m}tab */
241
MNT_FMT_MTAB = MNT_FMT_FSTAB, /* alias */
242
MNT_FMT_MOUNTINFO, /* /proc/#/mountinfo */
243
MNT_FMT_UTAB /* /dev/.mount/utab */
248
* Mount context -- high-level API
250
struct libmnt_context
252
int action; /* MNT_ACT_{MOUNT,UMOUNT} */
253
int restricted; /* root or not? */
255
char *fstype_pattern; /* for mnt_match_fstype() */
256
char *optstr_pattern; /* for mnt_match_options() */
258
struct libmnt_fs *fs; /* filesystem description (type, mountpoint, device, ...) */
260
struct libmnt_table *fstab; /* fstab (or mtab for some remounts) entries */
261
struct libmnt_table *mtab; /* mtab entries */
263
int (*table_errcb)(struct libmnt_table *tb, /* callback for libmnt_table structs */
264
const char *filename, int line);
266
int optsmode; /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
267
int loopdev_fd; /* open loopdev */
269
unsigned long mountflags; /* final mount(2) flags */
270
const void *mountdata; /* final mount(2) data, string or binary data */
272
unsigned long user_mountflags; /* MNT_MS_* (loop=, user=, ...) */
274
struct libmnt_cache *cache; /* paths cache */
275
struct libmnt_lock *lock; /* mtab lock */
276
struct libmnt_update *update;/* mtab/utab update */
278
const char *mtab_path; /* path to mtab */
279
int mtab_writable; /* is mtab writable */
281
const char *utab_path; /* path to utab */
282
int utab_writable; /* is utab writable */
284
int flags; /* private context flags */
285
int ambi; /* libblkid returns ambivalent result */
287
char *helper; /* name of the used /sbin/[u]mount.<type> helper */
288
int helper_status; /* helper wait(2) status */
289
int helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */
291
char *orig_user; /* original (non-fixed) user= option */
293
int syscall_status; /* 1: not called yet, 0: success, <0: -errno */
297
#define MNT_FL_NOMTAB (1 << 1)
298
#define MNT_FL_FAKE (1 << 2)
299
#define MNT_FL_SLOPPY (1 << 3)
300
#define MNT_FL_VERBOSE (1 << 4)
301
#define MNT_FL_NOHELPERS (1 << 5)
302
#define MNT_FL_LOOPDEL (1 << 6)
303
#define MNT_FL_LAZY (1 << 7)
304
#define MNT_FL_FORCE (1 << 8)
305
#define MNT_FL_NOCANONICALIZE (1 << 9)
306
#define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */
308
#define MNT_FL_EXTERN_FS (1 << 15) /* cxt->fs is not private */
309
#define MNT_FL_EXTERN_FSTAB (1 << 16) /* cxt->fstab is not private */
310
#define MNT_FL_EXTERN_CACHE (1 << 17) /* cxt->cache is not private */
312
#define MNT_FL_MOUNTDATA (1 << 20)
313
#define MNT_FL_TAB_APPLIED (1 << 21) /* mtab/fstab merged to cxt->fs */
314
#define MNT_FL_MOUNTFLAGS_MERGED (1 << 22) /* MS_* flags was read from optstr */
315
#define MNT_FL_SAVED_USER (1 << 23)
316
#define MNT_FL_PREPARED (1 << 24)
317
#define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */
318
#define MNT_FL_LOOPDEV_READY (1 << 26) /* /dev/loop<N> initialized by library */
321
#define MNT_FL_DEFAULT 0
324
extern int mnt_lock_use_simplelock(struct libmnt_lock *ml, int enable);
327
extern const struct libmnt_optmap *mnt_optmap_get_entry(
328
struct libmnt_optmap const **maps,
329
int nmaps, const char *name,
331
const struct libmnt_optmap **mapent);
334
extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
335
extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next);
336
extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next);
337
extern int mnt_optstr_fix_secontext(char **optstr, char *value, size_t valsz, char **next);
338
extern int mnt_optstr_fix_user(char **optstr);
341
extern struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs);
342
extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source);
343
extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype);
346
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
347
extern int mnt_context_prepare_target(struct libmnt_context *cxt);
348
extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
349
extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
350
const char *name, const char *type);
351
extern int mnt_context_prepare_update(struct libmnt_context *cxt);
352
extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
353
extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
354
extern int mnt_context_update_tabs(struct libmnt_context *cxt);
356
extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
357
extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
359
extern int mnt_context_is_loopdev(struct libmnt_context *cxt);
360
extern int mnt_context_setup_loopdev(struct libmnt_context *cxt);
361
extern int mnt_context_delete_loopdev(struct libmnt_context *cxt);
362
extern int mnt_context_clear_loopdev(struct libmnt_context *cxt);
365
extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
366
extern int mnt_update_set_filename(struct libmnt_update *upd,
367
const char *filename, int userspace_only);
369
#endif /* _LIBMOUNT_PRIVATE_H */