]> git.ipfire.org Git - thirdparty/util-linux.git/blame_incremental - libmount/src/mountP.h
taskset: Accept 0 pid for current process
[thirdparty/util-linux.git] / libmount / src / mountP.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * mountP.h - private library header file
4 *
5 * This file is part of libmount from util-linux project.
6 *
7 * Copyright (C) 2008-2018 Karel Zak <kzak@redhat.com>
8 *
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.
13 */
14#ifndef _LIBMOUNT_PRIVATE_H
15#define _LIBMOUNT_PRIVATE_H
16
17#include <errno.h>
18#include <stdlib.h>
19#include <string.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22#include <sys/vfs.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <stdarg.h>
26#include <stdint.h>
27#include <inttypes.h>
28
29#include "c.h"
30
31#include "list.h"
32#include "debug.h"
33#include "buffer.h"
34#include "libmount.h"
35
36#include "mount-api-utils.h"
37
38/*
39 * Debug
40 */
41#define MNT_DEBUG_HELP (1 << 0)
42#define MNT_DEBUG_INIT (1 << 1)
43#define MNT_DEBUG_CACHE (1 << 2)
44#define MNT_DEBUG_OPTIONS (1 << 3)
45#define MNT_DEBUG_LOCKS (1 << 4)
46#define MNT_DEBUG_TAB (1 << 5)
47#define MNT_DEBUG_FS (1 << 6)
48#define MNT_DEBUG_UPDATE (1 << 7)
49#define MNT_DEBUG_UTILS (1 << 8)
50#define MNT_DEBUG_CXT (1 << 9)
51#define MNT_DEBUG_DIFF (1 << 10)
52#define MNT_DEBUG_MONITOR (1 << 11)
53#define MNT_DEBUG_BTRFS (1 << 12)
54#define MNT_DEBUG_LOOP (1 << 13)
55#define MNT_DEBUG_VERITY (1 << 14)
56#define MNT_DEBUG_HOOK (1 << 15)
57#define MNT_DEBUG_OPTLIST (1 << 16)
58#define MNT_DEBUG_STATMNT (1 << 17)
59
60#define MNT_DEBUG_ALL 0xFFFFFF
61
62UL_DEBUG_DECLARE_MASK(libmount);
63#define DBG(m, x) __UL_DBG(libmount, MNT_DEBUG_, m, x)
64#define ON_DBG(m, x) __UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
65#define DBG_FLUSH __UL_DBG_FLUSH(libmount, MNT_DEBUG_)
66
67#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libmount)
68#include "debugobj.h"
69
70/*
71 * NLS -- the library has to be independent on main program, so define
72 * UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
73 *
74 * Now we use util-linux.po (=PACKAGE), rather than maintain the texts
75 * in the separate libmount.po file.
76 */
77#define LIBMOUNT_TEXTDOMAIN PACKAGE
78#define UL_TEXTDOMAIN_EXPLICIT LIBMOUNT_TEXTDOMAIN
79#include "nls.h"
80
81
82/* extension for files in the directory */
83#define MNT_MNTTABDIR_EXT ".fstab"
84
85/* library private paths */
86#define MNT_RUNTIME_TOPDIR "/run"
87/* private userspace mount table */
88#define MNT_PATH_UTAB MNT_RUNTIME_TOPDIR "/mount/utab"
89/* temporary mount target */
90#define MNT_PATH_TMPTGT MNT_RUNTIME_TOPDIR "/mount/tmptgt"
91
92#define MNT_UTAB_HEADER "# libmount utab file\n"
93
94#ifdef TEST_PROGRAM
95struct libmnt_test {
96 const char *name;
97 int (*body)(struct libmnt_test *ts, int argc, char *argv[]);
98 const char *usage;
99};
100
101/* test.c */
102extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]);
103#endif
104
105/* private tab_listmount.c */
106struct libmnt_listmnt;
107
108/* utils.c */
109extern int mnt_valid_tagname(const char *tagname);
110
111extern const char *mnt_statfs_get_fstype(struct statfs *vfs);
112extern int is_file_empty(const char *name);
113
114extern int mnt_is_readonly(const char *path)
115 __attribute__((nonnull));
116
117extern int mnt_parse_offset(const char *str, size_t len, uintmax_t *res);
118
119extern int mnt_chdir_to_parent(const char *target, char **filename);
120
121extern char *mnt_get_username(const uid_t uid);
122extern int mnt_get_uid(const char *username, uid_t *uid);
123extern int mnt_get_gid(const char *groupname, gid_t *gid);
124extern int mnt_parse_uid(const char *user, size_t user_len, uid_t *gid);
125extern int mnt_parse_gid(const char *group, size_t group_len, gid_t *gid);
126extern int mnt_parse_mode(const char *mode, size_t mode_len, mode_t *gid);
127extern int mnt_in_group(gid_t gid);
128
129extern int mnt_open_uniq_filename(const char *filename, char **name);
130
131extern int mnt_has_regular_utab(const char **utab, int *writable);
132extern const char *mnt_get_utab_path(void);
133
134extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
135extern void mnt_free_filesystems(char **filesystems);
136
137extern char *mnt_get_kernel_cmdline_option(const char *name);
138
139extern int mnt_safe_stat(const char *target, struct stat *st);
140extern int mnt_safe_lstat(const char *target, struct stat *st);
141extern int mnt_is_path(const char *target);
142
143extern int mnt_tmptgt_unshare(int *old_ns_fd);
144extern int mnt_tmptgt_cleanup(int old_ns_fd);
145
146extern int mnt_id_from_fd(int fd, uint64_t *uniq_id, int *id);
147
148/* tab.c */
149extern int is_mountinfo(struct libmnt_table *tb);
150extern int mnt_table_set_parser_fltrcb( struct libmnt_table *tb,
151 int (*cb)(struct libmnt_fs *, void *),
152 void *data);
153
154extern int __mnt_table_parse_mountinfo(struct libmnt_table *tb,
155 const char *filename,
156 struct libmnt_table *u_tb);
157
158extern struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
159 struct libmnt_fs *fs,
160 unsigned long mountflags,
161 char **fsroot);
162
163extern int __mnt_table_is_fs_mounted( struct libmnt_table *tb,
164 struct libmnt_fs *fstab_fs,
165 const char *tgt_prefix);
166
167extern int mnt_table_enable_noautofs(struct libmnt_table *tb, int ignore);
168extern int mnt_table_is_noautofs(struct libmnt_table *tb);
169
170/* tab_listmount.c */
171extern int mnt_table_next_lsmnt(struct libmnt_table *tb, int direction);
172extern int mnt_table_reset_listmount(struct libmnt_table *tb);
173extern int mnt_table_want_listmount(struct libmnt_table *tb);
174
175/*
176 * Generic iterator
177 */
178struct libmnt_iter {
179 struct list_head *p; /* current position */
180 struct list_head *head; /* start position */
181 int direction; /* MNT_ITER_{FOR,BACK}WARD */
182};
183
184#define IS_ITER_FORWARD(_i) ((_i)->direction == MNT_ITER_FORWARD)
185#define IS_ITER_BACKWARD(_i) ((_i)->direction == MNT_ITER_BACKWARD)
186
187#define MNT_ITER_INIT(itr, list) \
188 do { \
189 (itr)->p = IS_ITER_FORWARD(itr) ? \
190 (list)->next : (list)->prev; \
191 (itr)->head = (list); \
192 } while(0)
193
194#define MNT_ITER_GET_ENTRY(itr, restype, member) \
195 list_entry((itr)->p, restype, member)
196
197#define MNT_ITER_ITERATE(itr) \
198 do { \
199 (itr)->p = IS_ITER_FORWARD(itr) ? \
200 (itr)->p->next : (itr)->p->prev; \
201 } while(0)
202
203
204/*
205 * statmount setting; shared between tables and filesystems
206 */
207struct libmnt_statmnt {
208 int refcount;
209 uint64_t mask; /* default statmount() mask */
210
211 struct ul_statmount *buf;
212 size_t bufsiz;
213
214 unsigned int disabled: 1; /* enable or disable statmount() */
215};
216
217
218/*
219 * This struct represents one entry in a fstab/mountinfo file.
220 * (note that fstab[1] means the first column from fstab, and so on...)
221 */
222struct libmnt_fs {
223 struct list_head ents;
224 struct libmnt_table *tab;
225
226 int refcount; /* reference counter */
227
228 unsigned int opts_age; /* to sync with optlist */
229 struct libmnt_optlist *optlist;
230
231 int id; /* mountinfo[1]: ID */
232 uint64_t uniq_id; /* unique node ID; statx(STATX_MNT_ID_UNIQUE); statmount->mnt_id */
233 uint64_t ns_id; /* namespace ID; statmount->mnt_ns_id */
234
235 int parent; /* mountinfo[2]: parent */
236 uint64_t uniq_parent; /* unique parent ID; statmount->mnt_parent_id */
237 dev_t devno; /* mountinfo[3]: st_dev */
238
239 char *bindsrc; /* utab, full path from fstab[1] for bind mounts */
240
241 char *source; /* fstab[1], mountinfo[10], swaps[1]:
242 * source dev, file, dir or TAG */
243 char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
244 char *tagval; /* tag value */
245
246 char *root; /* mountinfo[4]: root of the mount within the FS */
247 char *target; /* mountinfo[5], fstab[2]: mountpoint */
248 char *fstype; /* mountinfo[9], fstab[3]: filesystem type */
249
250 char *optstr; /* fstab[4], merged options */
251 char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */
252
253 char *opt_fields; /* mountinfo[7]: optional fields */
254 uint64_t propagation; /* statmmount() or parsed opt_fields */
255
256 char *fs_optstr; /* mountinfo[11]: fs-dependent options */
257 char *user_optstr; /* userspace mount options */
258 char *attrs; /* mount attributes */
259
260 int freq; /* fstab[5]: dump frequency in days */
261 int passno; /* fstab[6]: pass number on parallel fsck */
262
263 /* /proc/swaps */
264 char *swaptype; /* swaps[2]: device type (partition, file, ...) */
265 off_t size; /* swaps[3]: swaparea size */
266 off_t usedsize; /* swaps[4]: used size */
267 int priority; /* swaps[5]: swap priority */
268
269 int flags; /* MNT_FS_* flags */
270 pid_t tid; /* /proc/<tid>/mountinfo otherwise zero */
271
272 uint64_t stmnt_done; /* mask of already called masks */
273 struct libmnt_statmnt *stmnt; /* statmount() stuff */
274
275 char *comment; /* fstab comment */
276
277 void *userdata; /* library independent data */
278};
279
280/*
281 * fs flags
282 */
283#define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */
284#define MNT_FS_NET (1 << 2) /* network filesystem */
285#define MNT_FS_SWAP (1 << 3) /* swap device */
286#define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
287#define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */
288
289#ifdef HAVE_STATMOUNT_API
290# define mnt_fs_try_statmount(FS, MEMBER, FLAGS) __extension__ ({ \
291 if (!(FS)->MEMBER \
292 && (FS)->stmnt \
293 && !(FS)->stmnt->disabled \
294 && ((FLAGS) & ~((FS)->stmnt_done))) \
295 mnt_fs_fetch_statmount((FS), (FLAGS)); })
296#endif
297
298
299/*
300 * fstab/mountinfo file
301 */
302struct libmnt_table {
303 int fmt; /* MNT_FMT_* file format */
304 int nents; /* number of entries */
305 int refcount; /* reference counter */
306 int comms; /* enable/disable comment parsing */
307 char *comm_intro; /* First comment in file */
308 char *comm_tail; /* Last comment in file */
309
310 struct libmnt_cache *cache; /* canonicalized paths/tags cache */
311
312 int (*errcb)(struct libmnt_table *tb,
313 const char *filename, int line);
314
315 int (*fltrcb)(struct libmnt_fs *fs, void *data);
316 void *fltrcb_data;
317
318 struct libmnt_listmnt *lsmnt; /* listmount() stuff */
319 struct libmnt_statmnt *stmnt; /* statmount() stuff */
320
321 int noautofs; /* ignore autofs mounts */
322
323 struct list_head ents; /* list of entries (libmnt_fs) */
324 void *userdata;
325};
326
327extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt, int empty_for_enoent);
328
329/*
330 * Tab file format
331 */
332enum {
333 MNT_FMT_GUESS,
334 MNT_FMT_FSTAB, /* /etc/{fs,m}tab */
335 MNT_FMT_MTAB = MNT_FMT_FSTAB, /* alias */
336 MNT_FMT_MOUNTINFO, /* /proc/#/mountinfo */
337 MNT_FMT_UTAB, /* /run/mount/utab */
338 MNT_FMT_SWAPS /* /proc/swaps */
339};
340
341/*
342 * Context hooks
343 *
344 * TODO: this will be public one day when libmount will support modules for
345 * stuff like veritydev.c.
346 */
347enum {
348 MNT_STAGE_PREP_SOURCE = 1, /* mount source preparation */
349 MNT_STAGE_PREP_TARGET, /* mount target preparation */
350 MNT_STAGE_PREP_OPTIONS, /* mount options preparation */
351 MNT_STAGE_PREP, /* all prepared */
352
353 MNT_STAGE_MOUNT_PRE = 100, /* before mount */
354 MNT_STAGE_MOUNT, /* mount(2) or fsmount(2) or tree-clone */
355 MNT_STAGE_MOUNT_POST, /* after mount */
356
357 MNT_STAGE_POST = 200 /* all is done */
358};
359
360struct libmnt_hookset {
361 const char *name; /* hook set name */
362
363 int firststage;
364 int (*firstcall)(struct libmnt_context *, const struct libmnt_hookset *, void *);
365
366 int (*deinit)(struct libmnt_context *, const struct libmnt_hookset *); /* cleanup function */
367};
368
369/* built-in hooks */
370extern const struct libmnt_hookset hookset_mount_legacy;
371extern const struct libmnt_hookset hookset_mount;
372extern const struct libmnt_hookset hookset_mkdir;
373extern const struct libmnt_hookset hookset_subdir;
374extern const struct libmnt_hookset hookset_owner;
375extern const struct libmnt_hookset hookset_idmap;
376extern const struct libmnt_hookset hookset_loopdev;
377#ifdef HAVE_CRYPTSETUP
378extern const struct libmnt_hookset hookset_veritydev;
379#endif
380#ifdef HAVE_LIBSELINUX
381extern const struct libmnt_hookset hookset_selinux;
382#endif
383
384extern int mnt_context_deinit_hooksets(struct libmnt_context *cxt);
385extern const struct libmnt_hookset *mnt_context_get_hookset(struct libmnt_context *cxt, const char *name);
386
387extern int mnt_context_set_hookset_data(struct libmnt_context *cxt,
388 const struct libmnt_hookset *hs,
389 void *data);
390
391extern void *mnt_context_get_hookset_data(struct libmnt_context *cxt,
392 const struct libmnt_hookset *hs);
393
394extern int mnt_context_has_hook(struct libmnt_context *cxt,
395 const struct libmnt_hookset *hs,
396 int stage,
397 void *data);
398
399extern int mnt_context_append_hook(struct libmnt_context *cxt,
400 const struct libmnt_hookset *hs,
401 int stage,
402 void *data,
403 int (*func)(struct libmnt_context *,
404 const struct libmnt_hookset *,
405 void *));
406extern int mnt_context_insert_hook(struct libmnt_context *cxt,
407 const char *after,
408 const struct libmnt_hookset *hs,
409 int stage,
410 void *data,
411 int (*func)(struct libmnt_context *,
412 const struct libmnt_hookset *,
413 void *));
414
415extern int mnt_context_remove_hook(struct libmnt_context *cxt,
416 const struct libmnt_hookset *hs,
417 int stage,
418 void **data);
419extern int mnt_context_call_hooks(struct libmnt_context *cxt, int stage);
420
421/*
422 * Namespace
423 */
424struct libmnt_ns {
425 int fd; /* file descriptor of namespace, -1 when inactive */
426 struct libmnt_cache *cache; /* paths cache associated with NS */
427};
428
429/*
430 * Mount context -- high-level API
431 */
432struct libmnt_context
433{
434 int action; /* MNT_ACT_{MOUNT,UMOUNT} */
435 int restricted; /* root or not? */
436
437 char *fstype_pattern; /* for mnt_match_fstype() */
438 char *optstr_pattern; /* for mnt_match_options() */
439
440 struct libmnt_fs *fs; /* filesystem description (type, mountpoint, device, ...) */
441
442 struct libmnt_table *fstab; /* fstab entries */
443 struct libmnt_table *mountinfo; /* already mounted filesystems */
444 struct libmnt_table *utab; /* rarely used by umount only */
445
446 int (*table_errcb)(struct libmnt_table *tb, /* callback for libmnt_table structs */
447 const char *filename, int line);
448
449 int (*table_fltrcb)(struct libmnt_fs *fs, void *data); /* callback for libmnt_table structs */
450 void *table_fltrcb_data;
451
452 char *(*pwd_get_cb)(struct libmnt_context *); /* get encryption password */
453 void (*pwd_release_cb)(struct libmnt_context *, char *); /* release password */
454
455 int optsmode; /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
456
457 const void *mountdata; /* final mount(2) data, string or binary data */
458
459 struct libmnt_cache *cache; /* paths cache */
460 struct libmnt_lock *lock; /* utab lock */
461 struct libmnt_update *update; /* utab update */
462
463 struct libmnt_optlist *optlist; /* parsed mount options */
464 struct libmnt_optlist *optlist_saved; /* save/apply context template */
465
466 const struct libmnt_optmap *map_linux; /* system options map */
467 const struct libmnt_optmap *map_userspace; /* userspace options map */
468
469 const char *mountinfo_path; /* usually /proc/self/moutinfo */
470
471 const char *utab_path; /* path to utab */
472 int utab_writable; /* is utab writable */
473
474 char *tgt_prefix; /* path used for all targets */
475
476 int flags; /* private context flags */
477
478 char *helper; /* name of the used /sbin/[u]mount.<type> helper */
479 int helper_status; /* helper wait(2) status */
480 int helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */
481
482 pid_t *children; /* "mount -a --fork" PIDs */
483 int nchildren; /* number of children */
484 pid_t pid; /* 0=parent; PID=child */
485
486 int syscall_status; /* 1: not called yet, 0: success, <0: -errno */
487 const char *syscall_name; /* failed syscall name */
488
489 char **mesgs; /* library or kernel messages (NULL terminated array) */
490
491 struct libmnt_ns ns_orig; /* original namespace */
492 struct libmnt_ns ns_tgt; /* target namespace */
493 struct libmnt_ns *ns_cur; /* pointer to current namespace */
494
495 unsigned int enabled_textdomain : 1; /* bindtextdomain() called */
496 unsigned int noautofs : 1; /* ignore autofs mounts */
497 unsigned int has_selinux_opt : 1; /* temporary for broken fsconfig() syscall */
498 unsigned int force_clone : 1; /* OPEN_TREE_CLONE */
499
500 struct list_head hooksets_datas; /* global hooksets data */
501 struct list_head hooksets_hooks; /* global hooksets data */
502};
503
504/* flags */
505#define MNT_FL_NOMTAB (1 << 1)
506#define MNT_FL_FAKE (1 << 2)
507#define MNT_FL_SLOPPY (1 << 3)
508#define MNT_FL_VERBOSE (1 << 4)
509#define MNT_FL_NOHELPERS (1 << 5)
510#define MNT_FL_LOOPDEL (1 << 6)
511#define MNT_FL_LAZY (1 << 7)
512#define MNT_FL_FORCE (1 << 8)
513#define MNT_FL_NOCANONICALIZE (1 << 9)
514#define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */
515#define MNT_FL_FORK (1 << 12)
516#define MNT_FL_NOSWAPMATCH (1 << 13)
517#define MNT_FL_RWONLY_MOUNT (1 << 14) /* explicit mount -w; never try read-only */
518#define MNT_FL_ONLYONCE (1 << 15)
519
520#define MNT_FL_MOUNTDATA (1 << 20)
521#define MNT_FL_TAB_APPLIED (1 << 21) /* fstab merged to cxt->fs */
522#define MNT_FL_MOUNTFLAGS_MERGED (1 << 22) /* MS_* flags was read from optstr */
523#define MNT_FL_SAVED_USER (1 << 23)
524#define MNT_FL_PREPARED (1 << 24)
525#define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */
526#define MNT_FL_MOUNTOPTS_FIXED (1 << 27)
527#define MNT_FL_TABPATHS_CHECKED (1 << 28)
528#define MNT_FL_FORCED_RDONLY (1 << 29) /* mounted read-only on write-protected device */
529#define MNT_FL_VERITYDEV_READY (1 << 30) /* /dev/mapper/<FOO> initialized by the library */
530
531/* default flags */
532#define MNT_FL_DEFAULT 0
533
534/* Flags usable with MS_BIND|MS_REMOUNT */
535#define MNT_BIND_SETTABLE (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY|MS_NOSYMFOLLOW)
536
537
538/* optmap.c */
539extern const struct libmnt_optmap *mnt_optmap_get_entry(
540 struct libmnt_optmap const **maps,
541 int nmaps,
542 const char *name,
543 size_t namelen,
544 const struct libmnt_optmap **mapent);
545
546/* optstr.c */
547extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
548extern int mnt_optstr_get_missing(const char *optstr, const char *wanted, char **missing);
549
550extern int mnt_buffer_append_option(struct ul_buffer *buf,
551 const char *name, size_t namesz,
552 const char *val, size_t valsz, int quoted);
553
554/* optlist.h */
555struct libmnt_opt;
556struct libmnt_optlist;
557
558extern struct libmnt_optlist *mnt_new_optlist(void);
559extern void mnt_ref_optlist(struct libmnt_optlist *ls);
560extern void mnt_unref_optlist(struct libmnt_optlist *ls);
561extern struct libmnt_optlist *mnt_copy_optlist(struct libmnt_optlist *ls);
562extern int mnt_optlist_is_empty(struct libmnt_optlist *ls);
563extern unsigned int mnt_optlist_get_age(struct libmnt_optlist *ls);
564extern int mnt_optlist_register_map(struct libmnt_optlist *ls, const struct libmnt_optmap *map);
565extern int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt);
566extern int mnt_optlist_remove_named(struct libmnt_optlist *ls, const char *name,
567 const struct libmnt_optmap *map);
568extern int mnt_optlist_remove_flags(struct libmnt_optlist *ls, unsigned long flags,
569 const struct libmnt_optmap *map);
570extern int mnt_optlist_next_opt(struct libmnt_optlist *ls,
571 struct libmnt_iter *itr, struct libmnt_opt **opt);
572extern struct libmnt_opt *mnt_optlist_get_opt(struct libmnt_optlist *ls,
573 unsigned long id, const struct libmnt_optmap *map);
574extern struct libmnt_opt *mnt_optlist_get_named(struct libmnt_optlist *ls,
575 const char *name, const struct libmnt_optmap *map);
576extern int mnt_optlist_set_optstr(struct libmnt_optlist *ls, const char *optstr,
577 const struct libmnt_optmap *map);
578extern int mnt_optlist_append_optstr(struct libmnt_optlist *ls, const char *optstr,
579 const struct libmnt_optmap *map);
580extern int mnt_optlist_prepend_optstr(struct libmnt_optlist *ls, const char *optstr,
581 const struct libmnt_optmap *map);
582extern int mnt_optlist_append_flags(struct libmnt_optlist *ls, unsigned long flags,
583 const struct libmnt_optmap *map);
584extern int mnt_optlist_set_flags(struct libmnt_optlist *ls, unsigned long flags,
585 const struct libmnt_optmap *map);
586extern int mnt_optlist_insert_flags(struct libmnt_optlist *ls, unsigned long flags,
587 const struct libmnt_optmap *map,
588 unsigned long after,
589 const struct libmnt_optmap *after_map);
590/* "what" argument */
591enum {
592 /* Default -- if @map specified then returns all options for the map, otherwise
593 * returns all options including uknonwn options, exclude external options */
594 MNT_OL_FLTR_DFLT = 0,
595 /* Options as expected by mount.<type> helpers */
596 MNT_OL_FLTR_HELPERS,
597 /* Options as expected in mtab */
598 MNT_OL_FLTR_MTAB,
599 /* All options -- include mapped, unknown and external options */
600 MNT_OL_FLTR_ALL,
601 /* All unknown options -- exclude external (usually FS specific options) */
602 MNT_OL_FLTR_UNKNOWN,
603
604 __MNT_OL_FLTR_COUNT /* keep it last */
605};
606
607
608extern int mnt_optlist_get_flags(struct libmnt_optlist *ls, unsigned long *flags,
609 const struct libmnt_optmap *map, unsigned int what);
610
611/* recursive status for mnt_optlist_get_attrs() */
612#define MNT_OL_REC 1
613#define MNT_OL_NOREC 2
614
615extern int mnt_optlist_get_attrs(struct libmnt_optlist *ls, uint64_t *set, uint64_t *clr, int rec);
616
617extern int mnt_optlist_get_optstr(struct libmnt_optlist *ol, const char **optstr,
618 const struct libmnt_optmap *map, unsigned int what);
619extern int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr,
620 const struct libmnt_optmap *map, unsigned int what);
621
622extern int mnt_optlist_get_propagation(struct libmnt_optlist *ls);
623extern int mnt_optlist_is_propagation_only(struct libmnt_optlist *ls);
624extern int mnt_optlist_is_remount(struct libmnt_optlist *ls);
625extern int mnt_optlist_is_rpropagation(struct libmnt_optlist *ls);
626extern int mnt_optlist_is_bind(struct libmnt_optlist *ls);
627extern int mnt_optlist_is_rbind(struct libmnt_optlist *ls);
628extern int mnt_optlist_is_move(struct libmnt_optlist *ls);
629extern int mnt_optlist_is_rdonly(struct libmnt_optlist *ls);
630extern int mnt_optlist_is_silent(struct libmnt_optlist *ls);
631
632extern int mnt_optlist_merge_opts(struct libmnt_optlist *ls);
633
634extern int mnt_opt_has_value(struct libmnt_opt *opt);
635extern const char *mnt_opt_get_value(struct libmnt_opt *opt);
636extern const char *mnt_opt_get_name(struct libmnt_opt *opt);
637extern const struct libmnt_optmap *mnt_opt_get_map(struct libmnt_opt *opt);
638extern const struct libmnt_optmap *mnt_opt_get_mapent(struct libmnt_opt *opt);
639extern int mnt_opt_set_external(struct libmnt_opt *opt, int enable);
640extern int mnt_opt_set_value(struct libmnt_opt *opt, const char *str);
641extern int mnt_opt_set_u64value(struct libmnt_opt *opt, uint64_t num);
642extern int mnt_opt_set_quoted_value(struct libmnt_opt *opt, const char *str);
643extern int mnt_opt_is_external(struct libmnt_opt *opt);
644extern int mnt_opt_is_sepnodata(struct libmnt_opt *opt);
645extern int mnt_opt_value_with(struct libmnt_opt *opt, const char *str);
646
647/* fs.c */
648extern int mnt_fs_follow_optlist(struct libmnt_fs *fs, struct libmnt_optlist *ol);
649extern struct libmnt_fs *mnt_copy_mtab_fs(struct libmnt_fs *fs);
650extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
651 __attribute__((nonnull(1)));
652extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype)
653 __attribute__((nonnull(1)));
654extern int __mnt_fs_set_target_ptr(struct libmnt_fs *fs, char *tgt)
655 __attribute__((nonnull(1)));
656
657/* context.c */
658extern void mnt_context_syscall_save_status(struct libmnt_context *cxt,
659 const char *syscallname, int success);
660extern void mnt_context_syscall_reset_status(struct libmnt_context *cxt);
661
662extern struct libmnt_context *mnt_copy_context(struct libmnt_context *o);
663extern int mnt_context_utab_writable(struct libmnt_context *cxt);
664extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);
665
666extern int mnt_context_within_helper(struct libmnt_context *cxt);
667
668extern int mnt_context_get_mountinfo(struct libmnt_context *cxt, struct libmnt_table **tb);
669extern int mnt_context_get_mountinfo_for_target(struct libmnt_context *cxt,
670 struct libmnt_table **mountinfo, const char *tgt);
671
672extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
673extern int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type);
674extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
675extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
676 const char *name, const char *type);
677extern int mnt_context_prepare_update(struct libmnt_context *cxt);
678extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
679extern int mnt_context_update_tabs(struct libmnt_context *cxt);
680
681extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
682extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
683
684extern void mnt_context_reset_mesgs(struct libmnt_context *cxt);
685extern int mnt_context_append_mesg(struct libmnt_context *cxt, const char *msg);
686extern int mnt_context_sprintf_mesg(struct libmnt_context *cxt, const char *msg, ...);
687extern int mnt_context_read_mesgs(struct libmnt_context *cxt, int fd);
688
689extern int mnt_context_propagation_only(struct libmnt_context *cxt)
690 __attribute__((nonnull));
691
692extern int mnt_context_delete_loopdev(struct libmnt_context *cxt);
693
694extern int mnt_fork_context(struct libmnt_context *cxt);
695
696extern int mnt_context_set_tabfilter(struct libmnt_context *cxt,
697 int (*fltr)(struct libmnt_fs *, void *),
698 void *data);
699
700extern int mnt_context_get_generic_excode(int rc, char *buf, size_t bufsz, const char *fmt, ...)
701 __attribute__ ((__format__ (__printf__, 4, 5)));
702extern int mnt_context_get_mount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz);
703extern int mnt_context_get_umount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz);
704
705extern int mnt_context_has_template(struct libmnt_context *cxt);
706extern int mnt_context_apply_template(struct libmnt_context *cxt);
707extern int mnt_context_save_template(struct libmnt_context *cxt);
708
709extern int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs);
710
711extern struct libmnt_optlist *mnt_context_get_optlist(struct libmnt_context *cxt);
712
713extern int mnt_context_is_xnocanonicalize(struct libmnt_context *cxt, const char *type);
714
715/* tab_update.c */
716extern int mnt_update_emit_event(struct libmnt_update *upd);
717extern int mnt_update_set_filename(struct libmnt_update *upd, const char *filename);
718extern int mnt_update_already_done(struct libmnt_update *upd);
719extern int mnt_update_start(struct libmnt_update *upd);
720extern int mnt_update_end(struct libmnt_update *upd);
721
722#if __linux__
723/* btrfs.c */
724extern uint64_t btrfs_get_default_subvol_id(const char *path);
725#endif
726
727#ifdef USE_LIBMOUNT_MOUNTFD_SUPPORT
728/* fsconfig/fsopen based stuff */
729struct libmnt_sysapi {
730 int fd_fs; /* FD from fsopen() or fspick() */
731 int fd_tree; /* FD from fsmount() or open_tree() */
732
733 char *subdir; /* Linux >= 6.15 can directly open subdir;
734 * hook_subdir sets this variable */
735
736 unsigned int is_new_fs : 1 ; /* fd_fs comes from fsopen() */
737};
738
739static inline struct libmnt_sysapi *mnt_context_get_sysapi(struct libmnt_context *cxt)
740{
741 return mnt_context_get_hookset_data(cxt, &hookset_mount);
742}
743
744int mnt_context_open_tree(struct libmnt_context *cxt, const char *path, unsigned long mflg);
745
746#endif
747
748#endif /* _LIBMOUNT_PRIVATE_H */