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