]> git.ipfire.org Git - thirdparty/util-linux.git/blame - libmount/src/mountP.h
libmount: handle btrfs default subvolume mount
[thirdparty/util-linux.git] / libmount / src / mountP.h
CommitLineData
f4ab4ae8
KZ
1/*
2 * mountP.h - private library header file
3 *
90cd46cb 4 * Copyright (C) 2008-2012 Karel Zak <kzak@redhat.com>
f4ab4ae8
KZ
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
abc3d154 13#include <errno.h>
486d3972
KZ
14#include <stdlib.h>
15#include <string.h>
16#include <sys/stat.h>
17#include <sys/types.h>
6a52473e 18#include <sys/vfs.h>
486d3972 19#include <unistd.h>
83a78332
KZ
20#include <stdio.h>
21#include <stdarg.h>
cc492b3d 22
486d3972 23#include "c.h"
efab4b61 24#include "list.h"
cedd8e5f 25#include "debug.h"
486d3972 26#include "libmount.h"
69b7e41e 27
c12cec75
KZ
28/*
29 * Debug
30 */
35333416 31#define MNT_DEBUG_HELP (1 << 0)
3f31a959
KZ
32#define MNT_DEBUG_INIT (1 << 1)
33#define MNT_DEBUG_CACHE (1 << 2)
34#define MNT_DEBUG_OPTIONS (1 << 3)
35#define MNT_DEBUG_LOCKS (1 << 4)
36#define MNT_DEBUG_TAB (1 << 5)
4e92d2b0 37#define MNT_DEBUG_FS (1 << 6)
35333416
KZ
38#define MNT_DEBUG_UPDATE (1 << 7)
39#define MNT_DEBUG_UTILS (1 << 8)
40#define MNT_DEBUG_CXT (1 << 9)
41#define MNT_DEBUG_DIFF (1 << 10)
372112e9 42#define MNT_DEBUG_MONITOR (1 << 11)
2cd28fc8 43#define MNT_DEBUG_BTRFS (1 << 12)
372112e9 44
3f31a959 45#define MNT_DEBUG_ALL 0xFFFF
c12cec75 46
d7365821 47UL_DEBUG_DECLARE_MASK(libmount);
83a78332
KZ
48#define DBG(m, x) __UL_DBG(libmount, MNT_DEBUG_, m, x)
49#define ON_DBG(m, x) __UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
50#define DBG_FLUSH __UL_DBG_FLUSH(libmount, MNT_DEBUG_)
3f31a959 51
9354fea3 52/* extension for files in the directory */
9826a637
KZ
53#define MNT_MNTTABDIR_EXT ".fstab"
54
0532ba1d 55/* library private paths */
a362ae60
KZ
56#define MNT_RUNTIME_TOPDIR "/run"
57#define MNT_RUNTIME_TOPDIR_OLD "/dev"
58
59#define MNT_PATH_UTAB MNT_RUNTIME_TOPDIR "/mount/utab"
60#define MNT_PATH_UTAB_OLD MNT_RUNTIME_TOPDIR_OLD "/.mount/utab"
0532ba1d 61
dd369652
KZ
62#define MNT_UTAB_HEADER "# libmount utab file\n"
63
c12cec75 64#ifdef TEST_PROGRAM
68164f6c 65struct libmnt_test {
c12cec75 66 const char *name;
68164f6c 67 int (*body)(struct libmnt_test *ts, int argc, char *argv[]);
c12cec75
KZ
68 const char *usage;
69};
70
77417bc0 71/* test.c */
ba2bdf41 72extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]);
c12cec75
KZ
73#endif
74
69b7e41e 75/* utils.c */
2c6b25f0 76extern int mnt_valid_tagname(const char *tagname);
40b27864 77extern int append_string(char **a, const char *b);
2c6b25f0 78
6a52473e 79extern const char *mnt_statfs_get_fstype(struct statfs *vfs);
dad88cb3
KZ
80extern int is_file_empty(const char *name);
81
90cd46cb
OO
82extern int mnt_is_readonly(const char *path)
83 __attribute__((nonnull));
90cd46cb 84
ba2bdf41
KZ
85extern int mnt_parse_offset(const char *str, size_t len, uintmax_t *res);
86
87extern int mnt_chdir_to_parent(const char *target, char **filename);
b49103ed 88
69b7e41e 89extern char *mnt_get_username(const uid_t uid);
ba2bdf41
KZ
90extern int mnt_get_uid(const char *username, uid_t *uid);
91extern int mnt_get_gid(const char *groupname, gid_t *gid);
188dc15a 92extern int mnt_in_group(gid_t gid);
a1e8af75 93
ba2bdf41 94extern int mnt_open_uniq_filename(const char *filename, char **name);
90cd46cb 95
77417bc0
KZ
96extern int mnt_has_regular_utab(const char **utab, int *writable);
97extern const char *mnt_get_utab_path(void);
0bb44be3 98
ba2bdf41 99extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
0f32f1e2
KZ
100extern void mnt_free_filesystems(char **filesystems);
101
ba2bdf41 102extern char *mnt_get_kernel_cmdline_option(const char *name);
6589a163 103extern int mnt_stat_mountpoint(const char *target, struct stat *st);
f308ec19 104
c4c66355 105/* tab.c */
60d29f82 106extern int is_mountinfo(struct libmnt_table *tb);
4709c9e6
KZ
107extern int mnt_table_set_parser_fltrcb( struct libmnt_table *tb,
108 int (*cb)(struct libmnt_fs *, void *),
ba2bdf41 109 void *data);
4709c9e6 110
6a52473e
KZ
111extern int __mnt_table_parse_mtab(struct libmnt_table *tb,
112 const char *filename,
113 struct libmnt_table *u_tb);
114
c8b9eceb
KZ
115extern struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
116 struct libmnt_fs *fs,
117 unsigned long mountflags,
118 char **fsroot);
6a52473e 119
efab4b61
KZ
120/*
121 * Generic iterator
122 */
68164f6c 123struct libmnt_iter {
efab4b61
KZ
124 struct list_head *p; /* current position */
125 struct list_head *head; /* start position */
126 int direction; /* MNT_ITER_{FOR,BACK}WARD */
127};
128
129#define IS_ITER_FORWARD(_i) ((_i)->direction == MNT_ITER_FORWARD)
130#define IS_ITER_BACKWARD(_i) ((_i)->direction == MNT_ITER_BACKWARD)
131
132#define MNT_ITER_INIT(itr, list) \
133 do { \
134 (itr)->p = IS_ITER_FORWARD(itr) ? \
135 (list)->next : (list)->prev; \
136 (itr)->head = (list); \
137 } while(0)
138
139#define MNT_ITER_ITERATE(itr, res, restype, member) \
140 do { \
141 res = list_entry((itr)->p, restype, member); \
142 (itr)->p = IS_ITER_FORWARD(itr) ? \
143 (itr)->p->next : (itr)->p->prev; \
144 } while(0)
145
078edb2d 146
d115ee9b 147/*
d58b3157 148 * This struct represents one entry in a mtab/fstab/mountinfo file.
dd369652 149 * (note that fstab[1] means the first column from fstab, and so on...)
d115ee9b 150 */
68164f6c 151struct libmnt_fs {
d115ee9b
KZ
152 struct list_head ents;
153
26d0c0ae 154 int refcount; /* reference counter */
d115ee9b 155 int id; /* mountinfo[1]: ID */
6ad929bb
PU
156 int parent; /* mountinfo[2]: parent */
157 dev_t devno; /* mountinfo[3]: st_dev */
d115ee9b 158
dd369652
KZ
159 char *bindsrc; /* utab, full path from fstab[1] for bind mounts */
160
ce4dd666 161 char *source; /* fstab[1], mountinfo[10], swaps[1]:
d115ee9b
KZ
162 * source dev, file, dir or TAG */
163 char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
164 char *tagval; /* tag value */
165
0b3953a3 166 char *root; /* mountinfo[4]: root of the mount within the FS */
d115ee9b
KZ
167 char *target; /* mountinfo[5], fstab[2]: mountpoint */
168 char *fstype; /* mountinfo[9], fstab[3]: filesystem type */
169
f2b3a3a3 170 char *optstr; /* fstab[4], merged options */
d115ee9b 171 char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */
e47a1931 172 char *opt_fields; /* mountinfo[7]: optional fields */
6ad929bb 173 char *fs_optstr; /* mountinfo[11]: fs-dependent options */
76a06ca4
KZ
174 char *user_optstr; /* userspace mount options */
175 char *attrs; /* mount attributes */
d115ee9b 176
6ad929bb 177 int freq; /* fstab[5]: dump frequency in days */
d115ee9b
KZ
178 int passno; /* fstab[6]: pass number on parallel fsck */
179
ce4dd666
KZ
180 /* /proc/swaps */
181 char *swaptype; /* swaps[2]: device type (partition, file, ...) */
182 off_t size; /* swaps[3]: swaparea size */
183 off_t usedsize; /* swaps[4]: used size */
184 int priority; /* swaps[5]: swap priority */
185
3fca8422 186 int flags; /* MNT_FS_* flags */
f7f29b56 187 pid_t tid; /* /proc/<tid>/mountinfo otherwise zero */
26b4f9e4 188
cb90e24e
OO
189 char *comment; /* fstab comment */
190
26b4f9e4 191 void *userdata; /* library independent data */
d115ee9b
KZ
192};
193
194/*
195 * fs flags
196 */
911238af
KZ
197#define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */
198#define MNT_FS_NET (1 << 2) /* network filesystem */
9dd75aa6 199#define MNT_FS_SWAP (1 << 3) /* swap device */
309139c7 200#define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
a362ae60 201#define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */
309139c7 202
c70d9d76
KZ
203#define mnt_fs_is_regular(_f) (!(mnt_fs_is_pseudofs(_f) \
204 || mnt_fs_is_netfs(_f) \
205 || mnt_fs_is_swaparea(_f)))
d115ee9b 206
6bd8b7a7
KZ
207/*
208 * mtab/fstab/mountinfo file
209 */
68164f6c 210struct libmnt_table {
6bd8b7a7 211 int fmt; /* MNT_FMT_* file format */
26d0c0ae 212 int nents; /* number of entries */
c9f1585e 213 int refcount; /* reference counter */
cb90e24e
OO
214 int comms; /* enable/disable comment parsing */
215 char *comm_intro; /* First comment in file */
216 char *comm_tail; /* Last comment in file */
6bd8b7a7 217
68164f6c 218 struct libmnt_cache *cache; /* canonicalized paths/tags cache */
6bd8b7a7 219
68164f6c
KZ
220 int (*errcb)(struct libmnt_table *tb,
221 const char *filename, int line);
9fd75d76 222
4709c9e6
KZ
223 int (*fltrcb)(struct libmnt_fs *fs, void *data);
224 void *fltrcb_data;
225
226
68164f6c 227 struct list_head ents; /* list of entries (libmnt_fs) */
d58b3157 228 void *userdata;
6bd8b7a7
KZ
229};
230
ba2bdf41 231extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt);
dd369652
KZ
232
233/*
234 * Tab file format
235 */
236enum {
237 MNT_FMT_GUESS,
238 MNT_FMT_FSTAB, /* /etc/{fs,m}tab */
239 MNT_FMT_MTAB = MNT_FMT_FSTAB, /* alias */
240 MNT_FMT_MOUNTINFO, /* /proc/#/mountinfo */
ce4dd666
KZ
241 MNT_FMT_UTAB, /* /run/mount/utab */
242 MNT_FMT_SWAPS /* /proc/swaps */
dd369652
KZ
243};
244
6498ece0
KZ
245/*
246 * Additional mounts
247 */
248struct libmnt_addmount {
249 unsigned long mountflags;
250
251 struct list_head mounts;
252};
6bd8b7a7 253
1bb1d80b
KZ
254/*
255 * Mount context -- high-level API
256 */
68164f6c 257struct libmnt_context
1bb1d80b
KZ
258{
259 int action; /* MNT_ACT_{MOUNT,UMOUNT} */
1bb1d80b
KZ
260 int restricted; /* root or not? */
261
262 char *fstype_pattern; /* for mnt_match_fstype() */
263 char *optstr_pattern; /* for mnt_match_options() */
264
6ad929bb 265 struct libmnt_fs *fs; /* filesystem description (type, mountpoint, device, ...) */
68164f6c 266
6ad929bb 267 struct libmnt_table *fstab; /* fstab (or mtab for some remounts) entries */
68164f6c 268 struct libmnt_table *mtab; /* mtab entries */
6a52473e 269 struct libmnt_table *utab; /* rarely used by umount only */
1bb1d80b 270
d84508cf
KZ
271 int (*table_errcb)(struct libmnt_table *tb, /* callback for libmnt_table structs */
272 const char *filename, int line);
273
4709c9e6
KZ
274 int (*table_fltrcb)(struct libmnt_fs *fs, void *data); /* callback for libmnt_table structs */
275 void *table_fltrcb_data;
276
1a7a421e
KZ
277 char *(*pwd_get_cb)(struct libmnt_context *); /* get encryption password */
278 void (*pwd_release_cb)(struct libmnt_context *, char *); /* release password */
279
1bb1d80b 280 int optsmode; /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
7f8b2bf3 281 int loopdev_fd; /* open loopdev */
1bb1d80b
KZ
282
283 unsigned long mountflags; /* final mount(2) flags */
284 const void *mountdata; /* final mount(2) data, string or binary data */
285
286 unsigned long user_mountflags; /* MNT_MS_* (loop=, user=, ...) */
287
6498ece0
KZ
288 struct list_head addmounts; /* additional mounts */
289
68164f6c
KZ
290 struct libmnt_cache *cache; /* paths cache */
291 struct libmnt_lock *lock; /* mtab lock */
292 struct libmnt_update *update;/* mtab/utab update */
1d0cd73f 293
6ad929bb
PU
294 const char *mtab_path; /* path to mtab */
295 int mtab_writable; /* is mtab writable */
1d0cd73f 296
6ad929bb
PU
297 const char *utab_path; /* path to utab */
298 int utab_writable; /* is utab writable */
1bb1d80b
KZ
299
300 int flags; /* private context flags */
1bb1d80b
KZ
301
302 char *helper; /* name of the used /sbin/[u]mount.<type> helper */
303 int helper_status; /* helper wait(2) status */
97e23b5e 304 int helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */
1bb1d80b
KZ
305
306 char *orig_user; /* original (non-fixed) user= option */
307
d2c97887
KZ
308 pid_t *children; /* "mount -a --fork" PIDs */
309 int nchildren; /* number of children */
310 pid_t pid; /* 0=parent; PID=child */
311
312
97e23b5e 313 int syscall_status; /* 1: not called yet, 0: success, <0: -errno */
1bb1d80b
KZ
314};
315
316/* flags */
317#define MNT_FL_NOMTAB (1 << 1)
318#define MNT_FL_FAKE (1 << 2)
319#define MNT_FL_SLOPPY (1 << 3)
320#define MNT_FL_VERBOSE (1 << 4)
321#define MNT_FL_NOHELPERS (1 << 5)
322#define MNT_FL_LOOPDEL (1 << 6)
323#define MNT_FL_LAZY (1 << 7)
324#define MNT_FL_FORCE (1 << 8)
325#define MNT_FL_NOCANONICALIZE (1 << 9)
ea8f06f9 326#define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */
d2c97887 327#define MNT_FL_FORK (1 << 12)
e39cbb76 328#define MNT_FL_NOSWAPMATCH (1 << 13)
1bb1d80b 329
1bb1d80b 330#define MNT_FL_MOUNTDATA (1 << 20)
cf94e97f 331#define MNT_FL_TAB_APPLIED (1 << 21) /* mtab/fstab merged to cxt->fs */
1bb1d80b
KZ
332#define MNT_FL_MOUNTFLAGS_MERGED (1 << 22) /* MS_* flags was read from optstr */
333#define MNT_FL_SAVED_USER (1 << 23)
dbde1923 334#define MNT_FL_PREPARED (1 << 24)
8c0797e7 335#define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */
d58b3157 336#define MNT_FL_LOOPDEV_READY (1 << 26) /* /dev/loop<N> initialized by the library */
dc4dbbf1 337#define MNT_FL_MOUNTOPTS_FIXED (1 << 27)
150e696d 338#define MNT_FL_TABPATHS_CHECKED (1 << 28)
1bb1d80b
KZ
339
340/* default flags */
341#define MNT_FL_DEFAULT 0
342
5eb00eb4 343/* lock.c */
ba2bdf41 344extern int mnt_lock_use_simplelock(struct libmnt_lock *ml, int enable);
5eb00eb4 345
078edb2d 346/* optmap.c */
68164f6c
KZ
347extern const struct libmnt_optmap *mnt_optmap_get_entry(
348 struct libmnt_optmap const **maps,
90cd46cb
OO
349 int nmaps,
350 const char *name,
68164f6c 351 size_t namelen,
ba2bdf41 352 const struct libmnt_optmap **mapent);
078edb2d 353
188dc15a 354/* optstr.c */
ba2bdf41
KZ
355extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
356extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next);
357extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next);
358extern int mnt_optstr_fix_secontext(char **optstr, char *value, size_t valsz, char **next);
359extern int mnt_optstr_fix_user(char **optstr);
188dc15a 360
d115ee9b 361/* fs.c */
90cd46cb
OO
362extern struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs)
363 __attribute__((nonnull));
364extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
365 __attribute__((nonnull(1)));
366extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype)
367 __attribute__((nonnull(1)));
078edb2d 368
1bb1d80b 369/* context.c */
150e696d
KZ
370extern int mnt_context_mtab_writable(struct libmnt_context *cxt);
371extern int mnt_context_utab_writable(struct libmnt_context *cxt);
372extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);
373
7deae03f
KZ
374extern int mnt_context_get_mtab_for_target(struct libmnt_context *cxt,
375 struct libmnt_table **mtab, const char *tgt);
376
ba2bdf41
KZ
377extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
378extern int mnt_context_prepare_target(struct libmnt_context *cxt);
b1f03df7 379extern int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type);
ba2bdf41 380extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
68164f6c 381extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
ba2bdf41
KZ
382 const char *name, const char *type);
383extern int mnt_context_prepare_update(struct libmnt_context *cxt);
384extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
385extern int mnt_context_update_tabs(struct libmnt_context *cxt);
90cd46cb 386
ba2bdf41
KZ
387extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
388extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
90cd46cb
OO
389
390extern int mnt_context_is_loopdev(struct libmnt_context *cxt)
391 __attribute__((nonnull));
ba2bdf41 392
6498ece0
KZ
393extern int mnt_context_propagation_only(struct libmnt_context *cxt)
394 __attribute__((nonnull));
395
396extern struct libmnt_addmount *mnt_new_addmount(void);
397extern void mnt_free_addmount(struct libmnt_addmount *ad);
398
ba2bdf41
KZ
399extern int mnt_context_setup_loopdev(struct libmnt_context *cxt);
400extern int mnt_context_delete_loopdev(struct libmnt_context *cxt);
401extern int mnt_context_clear_loopdev(struct libmnt_context *cxt);
7f8b2bf3 402
d2c97887
KZ
403extern int mnt_fork_context(struct libmnt_context *cxt);
404
4709c9e6 405extern int mnt_context_set_tabfilter(struct libmnt_context *cxt,
90cd46cb 406 int (*fltr)(struct libmnt_fs *, void *),
ba2bdf41 407 void *data);
4709c9e6 408
97e23b5e 409/* tab_update.c */
68164f6c 410extern int mnt_update_set_filename(struct libmnt_update *upd,
ba2bdf41 411 const char *filename, int userspace_only);
7e0c0619
KZ
412extern int mnt_update_already_done(struct libmnt_update *upd,
413 struct libmnt_lock *lc);
97e23b5e 414
2cd28fc8
SB
415#if __linux__
416/* btrfs.c */
417extern uint64_t btrfs_get_default_subvol_id(const char *path);
418#endif
419
078edb2d 420#endif /* _LIBMOUNT_PRIVATE_H */