]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libmount/src/mountP.h
dd16f8c96c97e0403ed18bae1305b92046341f8a
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * mountP.h - private library header file
5 * This file is part of libmount from util-linux project.
7 * Copyright (C) 2008-2018 Karel Zak <kzak@redhat.com>
9 * libmount is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 #ifndef _LIBMOUNT_PRIVATE_H
15 #define _LIBMOUNT_PRIVATE_H
21 #include <sys/types.h>
35 #define MNT_DEBUG_HELP (1 << 0)
36 #define MNT_DEBUG_INIT (1 << 1)
37 #define MNT_DEBUG_CACHE (1 << 2)
38 #define MNT_DEBUG_OPTIONS (1 << 3)
39 #define MNT_DEBUG_LOCKS (1 << 4)
40 #define MNT_DEBUG_TAB (1 << 5)
41 #define MNT_DEBUG_FS (1 << 6)
42 #define MNT_DEBUG_UPDATE (1 << 7)
43 #define MNT_DEBUG_UTILS (1 << 8)
44 #define MNT_DEBUG_CXT (1 << 9)
45 #define MNT_DEBUG_DIFF (1 << 10)
46 #define MNT_DEBUG_MONITOR (1 << 11)
47 #define MNT_DEBUG_BTRFS (1 << 12)
48 #define MNT_DEBUG_LOOP (1 << 13)
50 #define MNT_DEBUG_ALL 0xFFFF
52 UL_DEBUG_DECLARE_MASK(libmount
);
53 #define DBG(m, x) __UL_DBG(libmount, MNT_DEBUG_, m, x)
54 #define ON_DBG(m, x) __UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
55 #define DBG_FLUSH __UL_DBG_FLUSH(libmount, MNT_DEBUG_)
57 #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libmount)
61 * NLS -- the library has to be independent on main program, so define
62 * UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
64 * Now we use util-linux.po (=PACKAGE), rather than maintain the texts
65 * in the separate libmount.po file.
67 #define LIBMOUNT_TEXTDOMAIN PACKAGE
68 #define UL_TEXTDOMAIN_EXPLICIT LIBMOUNT_TEXTDOMAIN
72 /* extension for files in the directory */
73 #define MNT_MNTTABDIR_EXT ".fstab"
75 /* library private paths */
76 #define MNT_RUNTIME_TOPDIR "/run"
77 #define MNT_RUNTIME_TOPDIR_OLD "/dev"
79 #define MNT_PATH_UTAB MNT_RUNTIME_TOPDIR "/mount/utab"
80 #define MNT_PATH_UTAB_OLD MNT_RUNTIME_TOPDIR_OLD "/.mount/utab"
82 #define MNT_UTAB_HEADER "# libmount utab file\n"
87 int (*body
)(struct libmnt_test
*ts
, int argc
, char *argv
[]);
92 extern int mnt_run_test(struct libmnt_test
*tests
, int argc
, char *argv
[]);
96 extern int mnt_valid_tagname(const char *tagname
);
97 extern int append_string(char **a
, const char *b
);
99 extern const char *mnt_statfs_get_fstype(struct statfs
*vfs
);
100 extern int is_procfs_fd(int fd
);
101 extern int is_file_empty(const char *name
);
103 extern int mnt_is_readonly(const char *path
)
104 __attribute__((nonnull
));
106 extern int mnt_parse_offset(const char *str
, size_t len
, uintmax_t *res
);
108 extern int mnt_chdir_to_parent(const char *target
, char **filename
);
110 extern char *mnt_get_username(const uid_t uid
);
111 extern int mnt_get_uid(const char *username
, uid_t
*uid
);
112 extern int mnt_get_gid(const char *groupname
, gid_t
*gid
);
113 extern int mnt_in_group(gid_t gid
);
115 extern int mnt_open_uniq_filename(const char *filename
, char **name
);
117 extern int mnt_has_regular_utab(const char **utab
, int *writable
);
118 extern const char *mnt_get_utab_path(void);
120 extern int mnt_get_filesystems(char ***filesystems
, const char *pattern
);
121 extern void mnt_free_filesystems(char **filesystems
);
123 extern char *mnt_get_kernel_cmdline_option(const char *name
);
124 extern int mnt_stat_mountpoint(const char *target
, struct stat
*st
);
125 extern FILE *mnt_get_procfs_memstream(int fd
, char **membuf
);
128 extern int is_mountinfo(struct libmnt_table
*tb
);
129 extern int mnt_table_set_parser_fltrcb( struct libmnt_table
*tb
,
130 int (*cb
)(struct libmnt_fs
*, void *),
133 extern int __mnt_table_parse_mtab(struct libmnt_table
*tb
,
134 const char *filename
,
135 struct libmnt_table
*u_tb
);
137 extern struct libmnt_fs
*mnt_table_get_fs_root(struct libmnt_table
*tb
,
138 struct libmnt_fs
*fs
,
139 unsigned long mountflags
,
142 extern int __mnt_table_is_fs_mounted( struct libmnt_table
*tb
,
143 struct libmnt_fs
*fstab_fs
,
144 const char *tgt_prefix
);
150 struct list_head
*p
; /* current position */
151 struct list_head
*head
; /* start position */
152 int direction
; /* MNT_ITER_{FOR,BACK}WARD */
155 #define IS_ITER_FORWARD(_i) ((_i)->direction == MNT_ITER_FORWARD)
156 #define IS_ITER_BACKWARD(_i) ((_i)->direction == MNT_ITER_BACKWARD)
158 #define MNT_ITER_INIT(itr, list) \
160 (itr)->p = IS_ITER_FORWARD(itr) ? \
161 (list)->next : (list)->prev; \
162 (itr)->head = (list); \
165 #define MNT_ITER_ITERATE(itr, res, restype, member) \
167 res = list_entry((itr)->p, restype, member); \
168 (itr)->p = IS_ITER_FORWARD(itr) ? \
169 (itr)->p->next : (itr)->p->prev; \
174 * This struct represents one entry in a mtab/fstab/mountinfo file.
175 * (note that fstab[1] means the first column from fstab, and so on...)
178 struct list_head ents
;
179 struct libmnt_table
*tab
;
181 int refcount
; /* reference counter */
182 int id
; /* mountinfo[1]: ID */
183 int parent
; /* mountinfo[2]: parent */
184 dev_t devno
; /* mountinfo[3]: st_dev */
186 char *bindsrc
; /* utab, full path from fstab[1] for bind mounts */
188 char *source
; /* fstab[1], mountinfo[10], swaps[1]:
189 * source dev, file, dir or TAG */
190 char *tagname
; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
191 char *tagval
; /* tag value */
193 char *root
; /* mountinfo[4]: root of the mount within the FS */
194 char *target
; /* mountinfo[5], fstab[2]: mountpoint */
195 char *fstype
; /* mountinfo[9], fstab[3]: filesystem type */
197 char *optstr
; /* fstab[4], merged options */
198 char *vfs_optstr
; /* mountinfo[6]: fs-independent (VFS) options */
199 char *opt_fields
; /* mountinfo[7]: optional fields */
200 char *fs_optstr
; /* mountinfo[11]: fs-dependent options */
201 char *user_optstr
; /* userspace mount options */
202 char *attrs
; /* mount attributes */
204 int freq
; /* fstab[5]: dump frequency in days */
205 int passno
; /* fstab[6]: pass number on parallel fsck */
208 char *swaptype
; /* swaps[2]: device type (partition, file, ...) */
209 off_t size
; /* swaps[3]: swaparea size */
210 off_t usedsize
; /* swaps[4]: used size */
211 int priority
; /* swaps[5]: swap priority */
213 int flags
; /* MNT_FS_* flags */
214 pid_t tid
; /* /proc/<tid>/mountinfo otherwise zero */
216 char *comment
; /* fstab comment */
218 void *userdata
; /* library independent data */
224 #define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */
225 #define MNT_FS_NET (1 << 2) /* network filesystem */
226 #define MNT_FS_SWAP (1 << 3) /* swap device */
227 #define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
228 #define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */
230 #define mnt_fs_is_regular(_f) (!(mnt_fs_is_pseudofs(_f) \
231 || mnt_fs_is_netfs(_f) \
232 || mnt_fs_is_swaparea(_f)))
235 * mtab/fstab/mountinfo file
237 struct libmnt_table
{
238 int fmt
; /* MNT_FMT_* file format */
239 int nents
; /* number of entries */
240 int refcount
; /* reference counter */
241 int comms
; /* enable/disable comment parsing */
242 char *comm_intro
; /* First comment in file */
243 char *comm_tail
; /* Last comment in file */
245 struct libmnt_cache
*cache
; /* canonicalized paths/tags cache */
247 int (*errcb
)(struct libmnt_table
*tb
,
248 const char *filename
, int line
);
250 int (*fltrcb
)(struct libmnt_fs
*fs
, void *data
);
254 struct list_head ents
; /* list of entries (libmnt_fs) */
258 extern struct libmnt_table
*__mnt_new_table_from_file(const char *filename
, int fmt
, int empty_for_enoent
);
265 MNT_FMT_FSTAB
, /* /etc/{fs,m}tab */
266 MNT_FMT_MTAB
= MNT_FMT_FSTAB
, /* alias */
267 MNT_FMT_MOUNTINFO
, /* /proc/#/mountinfo */
268 MNT_FMT_UTAB
, /* /run/mount/utab */
269 MNT_FMT_SWAPS
/* /proc/swaps */
275 struct libmnt_addmount
{
276 unsigned long mountflags
;
278 struct list_head mounts
;
282 int fd
; /* file descriptor of namespace, -1 when inactive */
283 struct libmnt_cache
*cache
; /* paths cache associated with NS */
287 * Mount context -- high-level API
289 struct libmnt_context
291 int action
; /* MNT_ACT_{MOUNT,UMOUNT} */
292 int restricted
; /* root or not? */
294 char *fstype_pattern
; /* for mnt_match_fstype() */
295 char *optstr_pattern
; /* for mnt_match_options() */
297 struct libmnt_fs
*fs
; /* filesystem description (type, mountpoint, device, ...) */
298 struct libmnt_fs
*fs_template
; /* used for @fs on mnt_reset_context() */
300 struct libmnt_table
*fstab
; /* fstab (or mtab for some remounts) entries */
301 struct libmnt_table
*mtab
; /* mtab entries */
302 struct libmnt_table
*utab
; /* rarely used by umount only */
304 int (*table_errcb
)(struct libmnt_table
*tb
, /* callback for libmnt_table structs */
305 const char *filename
, int line
);
307 int (*table_fltrcb
)(struct libmnt_fs
*fs
, void *data
); /* callback for libmnt_table structs */
308 void *table_fltrcb_data
;
310 char *(*pwd_get_cb
)(struct libmnt_context
*); /* get encryption password */
311 void (*pwd_release_cb
)(struct libmnt_context
*, char *); /* release password */
313 int optsmode
; /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
314 int loopdev_fd
; /* open loopdev */
316 unsigned long mountflags
; /* final mount(2) flags */
317 const void *mountdata
; /* final mount(2) data, string or binary data */
319 unsigned long user_mountflags
; /* MNT_MS_* (loop=, user=, ...) */
321 struct list_head addmounts
; /* additional mounts */
323 struct libmnt_cache
*cache
; /* paths cache */
324 struct libmnt_lock
*lock
; /* mtab lock */
325 struct libmnt_update
*update
;/* mtab/utab update */
327 const char *mtab_path
; /* path to mtab */
328 int mtab_writable
; /* is mtab writable */
330 const char *utab_path
; /* path to utab */
331 int utab_writable
; /* is utab writable */
333 char *tgt_prefix
; /* path used for all targets */
335 int flags
; /* private context flags */
337 char *helper
; /* name of the used /sbin/[u]mount.<type> helper */
338 int helper_status
; /* helper wait(2) status */
339 int helper_exec_status
; /* 1: not called yet, 0: success, <0: -errno */
341 char *orig_user
; /* original (non-fixed) user= option */
343 pid_t
*children
; /* "mount -a --fork" PIDs */
344 int nchildren
; /* number of children */
345 pid_t pid
; /* 0=parent; PID=child */
348 int syscall_status
; /* 1: not called yet, 0: success, <0: -errno */
350 struct libmnt_ns ns_orig
; /* original namespace */
351 struct libmnt_ns ns_tgt
; /* target namespace */
352 struct libmnt_ns
*ns_cur
; /* pointer to current namespace */
354 unsigned int enabled_textdomain
: 1; /* bindtextdomain() called */
358 #define MNT_FL_NOMTAB (1 << 1)
359 #define MNT_FL_FAKE (1 << 2)
360 #define MNT_FL_SLOPPY (1 << 3)
361 #define MNT_FL_VERBOSE (1 << 4)
362 #define MNT_FL_NOHELPERS (1 << 5)
363 #define MNT_FL_LOOPDEL (1 << 6)
364 #define MNT_FL_LAZY (1 << 7)
365 #define MNT_FL_FORCE (1 << 8)
366 #define MNT_FL_NOCANONICALIZE (1 << 9)
367 #define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */
368 #define MNT_FL_FORK (1 << 12)
369 #define MNT_FL_NOSWAPMATCH (1 << 13)
370 #define MNT_FL_RWONLY_MOUNT (1 << 14) /* explicit mount -w; never try read-only */
372 #define MNT_FL_MOUNTDATA (1 << 20)
373 #define MNT_FL_TAB_APPLIED (1 << 21) /* mtab/fstab merged to cxt->fs */
374 #define MNT_FL_MOUNTFLAGS_MERGED (1 << 22) /* MS_* flags was read from optstr */
375 #define MNT_FL_SAVED_USER (1 << 23)
376 #define MNT_FL_PREPARED (1 << 24)
377 #define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */
378 #define MNT_FL_LOOPDEV_READY (1 << 26) /* /dev/loop<N> initialized by the library */
379 #define MNT_FL_MOUNTOPTS_FIXED (1 << 27)
380 #define MNT_FL_TABPATHS_CHECKED (1 << 28)
381 #define MNT_FL_FORCED_RDONLY (1 << 29) /* mounted read-only on write-protected device */
384 #define MNT_FL_DEFAULT 0
386 /* Flags usable with MS_BIND|MS_REMOUNT */
387 #define MNT_BIND_SETTABLE (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY)
390 extern int mnt_lock_use_simplelock(struct libmnt_lock
*ml
, int enable
);
393 extern const struct libmnt_optmap
*mnt_optmap_get_entry(
394 struct libmnt_optmap
const **maps
,
398 const struct libmnt_optmap
**mapent
);
401 extern int mnt_optstr_remove_option_at(char **optstr
, char *begin
, char *end
);
402 extern int mnt_optstr_fix_gid(char **optstr
, char *value
, size_t valsz
, char **next
);
403 extern int mnt_optstr_fix_uid(char **optstr
, char *value
, size_t valsz
, char **next
);
404 extern int mnt_optstr_fix_secontext(char **optstr
, char *value
, size_t valsz
, char **next
);
405 extern int mnt_optstr_fix_user(char **optstr
);
408 extern struct libmnt_fs
*mnt_copy_mtab_fs(const struct libmnt_fs
*fs
)
409 __attribute__((nonnull
));
410 extern int __mnt_fs_set_source_ptr(struct libmnt_fs
*fs
, char *source
)
411 __attribute__((nonnull(1)));
412 extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs
*fs
, char *fstype
)
413 __attribute__((nonnull(1)));
416 extern struct libmnt_context
*mnt_copy_context(struct libmnt_context
*o
);
417 extern int mnt_context_mtab_writable(struct libmnt_context
*cxt
);
418 extern int mnt_context_utab_writable(struct libmnt_context
*cxt
);
419 extern const char *mnt_context_get_writable_tabpath(struct libmnt_context
*cxt
);
421 extern int mnt_context_get_mtab_for_target(struct libmnt_context
*cxt
,
422 struct libmnt_table
**mtab
, const char *tgt
);
424 extern int mnt_context_prepare_srcpath(struct libmnt_context
*cxt
);
425 extern int mnt_context_prepare_target(struct libmnt_context
*cxt
);
426 extern int mnt_context_guess_srcpath_fstype(struct libmnt_context
*cxt
, char **type
);
427 extern int mnt_context_guess_fstype(struct libmnt_context
*cxt
);
428 extern int mnt_context_prepare_helper(struct libmnt_context
*cxt
,
429 const char *name
, const char *type
);
430 extern int mnt_context_prepare_update(struct libmnt_context
*cxt
);
431 extern int mnt_context_merge_mflags(struct libmnt_context
*cxt
);
432 extern int mnt_context_update_tabs(struct libmnt_context
*cxt
);
434 extern int mnt_context_umount_setopt(struct libmnt_context
*cxt
, int c
, char *arg
);
435 extern int mnt_context_mount_setopt(struct libmnt_context
*cxt
, int c
, char *arg
);
437 extern int mnt_context_is_loopdev(struct libmnt_context
*cxt
)
438 __attribute__((nonnull
));
440 extern int mnt_context_propagation_only(struct libmnt_context
*cxt
)
441 __attribute__((nonnull
));
443 extern struct libmnt_addmount
*mnt_new_addmount(void);
444 extern void mnt_free_addmount(struct libmnt_addmount
*ad
);
446 extern int mnt_context_setup_loopdev(struct libmnt_context
*cxt
);
447 extern int mnt_context_delete_loopdev(struct libmnt_context
*cxt
);
448 extern int mnt_context_clear_loopdev(struct libmnt_context
*cxt
);
450 extern int mnt_fork_context(struct libmnt_context
*cxt
);
452 extern int mnt_context_set_tabfilter(struct libmnt_context
*cxt
,
453 int (*fltr
)(struct libmnt_fs
*, void *),
456 extern int mnt_context_get_generic_excode(int rc
, char *buf
, size_t bufsz
, char *fmt
, ...);
457 extern int mnt_context_get_mount_excode(struct libmnt_context
*cxt
, int mntrc
, char *buf
, size_t bufsz
);
458 extern int mnt_context_get_umount_excode(struct libmnt_context
*cxt
, int mntrc
, char *buf
, size_t bufsz
);
460 extern int mnt_context_has_template(struct libmnt_context
*cxt
);
461 extern int mnt_context_apply_template(struct libmnt_context
*cxt
);
462 extern int mnt_context_save_template(struct libmnt_context
*cxt
);
464 extern int mnt_context_apply_fs(struct libmnt_context
*cxt
, struct libmnt_fs
*fs
);
467 extern int mnt_update_set_filename(struct libmnt_update
*upd
,
468 const char *filename
, int userspace_only
);
469 extern int mnt_update_already_done(struct libmnt_update
*upd
,
470 struct libmnt_lock
*lc
);
474 extern uint64_t btrfs_get_default_subvol_id(const char *path
);
477 #endif /* _LIBMOUNT_PRIVATE_H */