]>
Commit | Line | Data |
---|---|---|
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> | |
0fe91fb5 KZ |
26 | #include <stdint.h> |
27 | #include <inttypes.h> | |
cc492b3d | 28 | |
486d3972 | 29 | #include "c.h" |
0fe91fb5 | 30 | |
efab4b61 | 31 | #include "list.h" |
cedd8e5f | 32 | #include "debug.h" |
0a8980b7 | 33 | #include "buffer.h" |
486d3972 | 34 | #include "libmount.h" |
69b7e41e | 35 | |
c2c50a4b KZ |
36 | #include "mount-api-utils.h" |
37 | ||
c12cec75 KZ |
38 | /* |
39 | * Debug | |
40 | */ | |
35333416 | 41 | #define MNT_DEBUG_HELP (1 << 0) |
3f31a959 KZ |
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) | |
4e92d2b0 | 47 | #define MNT_DEBUG_FS (1 << 6) |
35333416 KZ |
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) | |
372112e9 | 52 | #define MNT_DEBUG_MONITOR (1 << 11) |
2cd28fc8 | 53 | #define MNT_DEBUG_BTRFS (1 << 12) |
7bbde59c | 54 | #define MNT_DEBUG_LOOP (1 << 13) |
e6a49887 | 55 | #define MNT_DEBUG_VERITY (1 << 14) |
8241fb00 | 56 | #define MNT_DEBUG_HOOK (1 << 15) |
add9d458 | 57 | #define MNT_DEBUG_OPTLIST (1 << 16) |
0affb7ae | 58 | #define MNT_DEBUG_STATMNT (1 << 17) |
372112e9 | 59 | |
45c1fe0c | 60 | #define MNT_DEBUG_ALL 0xFFFFFF |
c12cec75 | 61 | |
d7365821 | 62 | UL_DEBUG_DECLARE_MASK(libmount); |
83a78332 KZ |
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_) | |
3f31a959 | 66 | |
6d00cfb2 KZ |
67 | #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libmount) |
68 | #include "debugobj.h" | |
69 | ||
ea848180 KZ |
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 | ||
9354fea3 | 82 | /* extension for files in the directory */ |
9826a637 KZ |
83 | #define MNT_MNTTABDIR_EXT ".fstab" |
84 | ||
0532ba1d | 85 | /* library private paths */ |
a362ae60 | 86 | #define MNT_RUNTIME_TOPDIR "/run" |
7ae195af | 87 | /* private userspace mount table */ |
a362ae60 | 88 | #define MNT_PATH_UTAB MNT_RUNTIME_TOPDIR "/mount/utab" |
7ae195af KZ |
89 | /* temporary mount target */ |
90 | #define MNT_PATH_TMPTGT MNT_RUNTIME_TOPDIR "/mount/tmptgt" | |
0532ba1d | 91 | |
dd369652 KZ |
92 | #define MNT_UTAB_HEADER "# libmount utab file\n" |
93 | ||
c12cec75 | 94 | #ifdef TEST_PROGRAM |
68164f6c | 95 | struct libmnt_test { |
c12cec75 | 96 | const char *name; |
68164f6c | 97 | int (*body)(struct libmnt_test *ts, int argc, char *argv[]); |
c12cec75 KZ |
98 | const char *usage; |
99 | }; | |
100 | ||
77417bc0 | 101 | /* test.c */ |
ba2bdf41 | 102 | extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]); |
c12cec75 KZ |
103 | #endif |
104 | ||
4e345324 KZ |
105 | /* private tab_listmount.c */ |
106 | struct libmnt_listmnt; | |
107 | ||
69b7e41e | 108 | /* utils.c */ |
2c6b25f0 KZ |
109 | extern int mnt_valid_tagname(const char *tagname); |
110 | ||
6a52473e | 111 | extern const char *mnt_statfs_get_fstype(struct statfs *vfs); |
dad88cb3 KZ |
112 | extern int is_file_empty(const char *name); |
113 | ||
90cd46cb OO |
114 | extern int mnt_is_readonly(const char *path) |
115 | __attribute__((nonnull)); | |
90cd46cb | 116 | |
ba2bdf41 KZ |
117 | extern int mnt_parse_offset(const char *str, size_t len, uintmax_t *res); |
118 | ||
119 | extern int mnt_chdir_to_parent(const char *target, char **filename); | |
b49103ed | 120 | |
69b7e41e | 121 | extern char *mnt_get_username(const uid_t uid); |
ba2bdf41 KZ |
122 | extern int mnt_get_uid(const char *username, uid_t *uid); |
123 | extern int mnt_get_gid(const char *groupname, gid_t *gid); | |
722c9697 | 124 | extern int mnt_parse_uid(const char *user, size_t user_len, uid_t *gid); |
125 | extern int mnt_parse_gid(const char *group, size_t group_len, gid_t *gid); | |
126 | extern int mnt_parse_mode(const char *mode, size_t mode_len, mode_t *gid); | |
188dc15a | 127 | extern int mnt_in_group(gid_t gid); |
a1e8af75 | 128 | |
ba2bdf41 | 129 | extern int mnt_open_uniq_filename(const char *filename, char **name); |
90cd46cb | 130 | |
77417bc0 KZ |
131 | extern int mnt_has_regular_utab(const char **utab, int *writable); |
132 | extern const char *mnt_get_utab_path(void); | |
0bb44be3 | 133 | |
ba2bdf41 | 134 | extern int mnt_get_filesystems(char ***filesystems, const char *pattern); |
0f32f1e2 KZ |
135 | extern void mnt_free_filesystems(char **filesystems); |
136 | ||
ba2bdf41 | 137 | extern char *mnt_get_kernel_cmdline_option(const char *name); |
0d754dee | 138 | |
f2663ba7 KZ |
139 | extern int mnt_safe_stat(const char *target, struct stat *st); |
140 | extern int mnt_safe_lstat(const char *target, struct stat *st); | |
0d754dee | 141 | extern int mnt_is_path(const char *target); |
f308ec19 | 142 | |
7ae195af KZ |
143 | extern int mnt_tmptgt_unshare(int *old_ns_fd); |
144 | extern int mnt_tmptgt_cleanup(int old_ns_fd); | |
e311e731 | 145 | |
2dfadc24 KZ |
146 | extern int mnt_id_from_fd(int fd, uint64_t *uniq_id, int *id); |
147 | ||
c4c66355 | 148 | /* tab.c */ |
60d29f82 | 149 | extern int is_mountinfo(struct libmnt_table *tb); |
4709c9e6 KZ |
150 | extern int mnt_table_set_parser_fltrcb( struct libmnt_table *tb, |
151 | int (*cb)(struct libmnt_fs *, void *), | |
ba2bdf41 | 152 | void *data); |
4709c9e6 | 153 | |
e9d52e6e | 154 | extern int __mnt_table_parse_mountinfo(struct libmnt_table *tb, |
6a52473e KZ |
155 | const char *filename, |
156 | struct libmnt_table *u_tb); | |
157 | ||
c8b9eceb KZ |
158 | extern struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb, |
159 | struct libmnt_fs *fs, | |
160 | unsigned long mountflags, | |
161 | char **fsroot); | |
6a52473e | 162 | |
71ed3b83 KZ |
163 | extern int __mnt_table_is_fs_mounted( struct libmnt_table *tb, |
164 | struct libmnt_fs *fstab_fs, | |
165 | const char *tgt_prefix); | |
166 | ||
22147e08 IK |
167 | extern int mnt_table_enable_noautofs(struct libmnt_table *tb, int ignore); |
168 | extern int mnt_table_is_noautofs(struct libmnt_table *tb); | |
169 | ||
4e345324 KZ |
170 | /* tab_listmount.c */ |
171 | extern int mnt_table_next_lsmnt(struct libmnt_table *tb, int direction); | |
172 | extern int mnt_table_reset_listmount(struct libmnt_table *tb); | |
173 | extern int mnt_table_want_listmount(struct libmnt_table *tb); | |
174 | ||
efab4b61 KZ |
175 | /* |
176 | * Generic iterator | |
177 | */ | |
68164f6c | 178 | struct libmnt_iter { |
efab4b61 KZ |
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 | ||
6729c112 KZ |
194 | #define MNT_ITER_GET_ENTRY(itr, restype, member) \ |
195 | list_entry((itr)->p, restype, member) | |
196 | ||
197 | #define MNT_ITER_ITERATE(itr) \ | |
efab4b61 | 198 | do { \ |
efab4b61 KZ |
199 | (itr)->p = IS_ITER_FORWARD(itr) ? \ |
200 | (itr)->p->next : (itr)->p->prev; \ | |
201 | } while(0) | |
202 | ||
078edb2d | 203 | |
0affb7ae KZ |
204 | /* |
205 | * statmount setting; shared between tables and filesystems | |
206 | */ | |
207 | struct 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 | ||
d115ee9b | 218 | /* |
e9d52e6e | 219 | * This struct represents one entry in a fstab/mountinfo file. |
dd369652 | 220 | * (note that fstab[1] means the first column from fstab, and so on...) |
d115ee9b | 221 | */ |
68164f6c | 222 | struct libmnt_fs { |
d115ee9b | 223 | struct list_head ents; |
9d5eb4c4 | 224 | struct libmnt_table *tab; |
d115ee9b | 225 | |
26d0c0ae | 226 | int refcount; /* reference counter */ |
faa3d718 KZ |
227 | |
228 | unsigned int opts_age; /* to sync with optlist */ | |
229 | struct libmnt_optlist *optlist; | |
230 | ||
d115ee9b | 231 | int id; /* mountinfo[1]: ID */ |
57ab4dc3 | 232 | uint64_t uniq_id; /* unique node ID; statx(STATX_MNT_ID_UNIQUE); statmount->mnt_id */ |
0affb7ae KZ |
233 | uint64_t ns_id; /* namespace ID; statmount->mnt_ns_id */ |
234 | ||
6ad929bb | 235 | int parent; /* mountinfo[2]: parent */ |
57ab4dc3 | 236 | uint64_t uniq_parent; /* unique parent ID; statmount->mnt_parent_id */ |
6ad929bb | 237 | dev_t devno; /* mountinfo[3]: st_dev */ |
d115ee9b | 238 | |
dd369652 KZ |
239 | char *bindsrc; /* utab, full path from fstab[1] for bind mounts */ |
240 | ||
ce4dd666 | 241 | char *source; /* fstab[1], mountinfo[10], swaps[1]: |
d115ee9b KZ |
242 | * source dev, file, dir or TAG */ |
243 | char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/ | |
244 | char *tagval; /* tag value */ | |
245 | ||
0b3953a3 | 246 | char *root; /* mountinfo[4]: root of the mount within the FS */ |
d115ee9b KZ |
247 | char *target; /* mountinfo[5], fstab[2]: mountpoint */ |
248 | char *fstype; /* mountinfo[9], fstab[3]: filesystem type */ | |
249 | ||
f2b3a3a3 | 250 | char *optstr; /* fstab[4], merged options */ |
d115ee9b | 251 | char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */ |
ba353afb | 252 | |
e47a1931 | 253 | char *opt_fields; /* mountinfo[7]: optional fields */ |
ba353afb KZ |
254 | uint64_t propagation; /* statmmount() or parsed opt_fields */ |
255 | ||
6ad929bb | 256 | char *fs_optstr; /* mountinfo[11]: fs-dependent options */ |
76a06ca4 KZ |
257 | char *user_optstr; /* userspace mount options */ |
258 | char *attrs; /* mount attributes */ | |
d115ee9b | 259 | |
6ad929bb | 260 | int freq; /* fstab[5]: dump frequency in days */ |
d115ee9b KZ |
261 | int passno; /* fstab[6]: pass number on parallel fsck */ |
262 | ||
ce4dd666 KZ |
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 | ||
3fca8422 | 269 | int flags; /* MNT_FS_* flags */ |
f7f29b56 | 270 | pid_t tid; /* /proc/<tid>/mountinfo otherwise zero */ |
26b4f9e4 | 271 | |
0affb7ae KZ |
272 | uint64_t stmnt_done; /* mask of already called masks */ |
273 | struct libmnt_statmnt *stmnt; /* statmount() stuff */ | |
274 | ||
cb90e24e OO |
275 | char *comment; /* fstab comment */ |
276 | ||
26b4f9e4 | 277 | void *userdata; /* library independent data */ |
d115ee9b KZ |
278 | }; |
279 | ||
280 | /* | |
281 | * fs flags | |
282 | */ | |
911238af KZ |
283 | #define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */ |
284 | #define MNT_FS_NET (1 << 2) /* network filesystem */ | |
9dd75aa6 | 285 | #define MNT_FS_SWAP (1 << 3) /* swap device */ |
309139c7 | 286 | #define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */ |
a362ae60 | 287 | #define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */ |
309139c7 | 288 | |
ec7c579a KZ |
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 \ | |
e89fd102 | 294 | && ((FLAGS) & ~((FS)->stmnt_done))) \ |
ec7c579a KZ |
295 | mnt_fs_fetch_statmount((FS), (FLAGS)); }) |
296 | #endif | |
297 | ||
0affb7ae | 298 | |
6bd8b7a7 | 299 | /* |
e9d52e6e | 300 | * fstab/mountinfo file |
6bd8b7a7 | 301 | */ |
68164f6c | 302 | struct libmnt_table { |
6bd8b7a7 | 303 | int fmt; /* MNT_FMT_* file format */ |
26d0c0ae | 304 | int nents; /* number of entries */ |
c9f1585e | 305 | int refcount; /* reference counter */ |
cb90e24e OO |
306 | int comms; /* enable/disable comment parsing */ |
307 | char *comm_intro; /* First comment in file */ | |
308 | char *comm_tail; /* Last comment in file */ | |
6bd8b7a7 | 309 | |
68164f6c | 310 | struct libmnt_cache *cache; /* canonicalized paths/tags cache */ |
6bd8b7a7 | 311 | |
68164f6c KZ |
312 | int (*errcb)(struct libmnt_table *tb, |
313 | const char *filename, int line); | |
9fd75d76 | 314 | |
4709c9e6 KZ |
315 | int (*fltrcb)(struct libmnt_fs *fs, void *data); |
316 | void *fltrcb_data; | |
317 | ||
4e345324 | 318 | struct libmnt_listmnt *lsmnt; /* listmount() stuff */ |
0affb7ae KZ |
319 | struct libmnt_statmnt *stmnt; /* statmount() stuff */ |
320 | ||
22147e08 | 321 | int noautofs; /* ignore autofs mounts */ |
4709c9e6 | 322 | |
68164f6c | 323 | struct list_head ents; /* list of entries (libmnt_fs) */ |
d58b3157 | 324 | void *userdata; |
6bd8b7a7 KZ |
325 | }; |
326 | ||
06ff935e | 327 | extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt, int empty_for_enoent); |
dd369652 KZ |
328 | |
329 | /* | |
330 | * Tab file format | |
331 | */ | |
332 | enum { | |
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 */ | |
ce4dd666 KZ |
337 | MNT_FMT_UTAB, /* /run/mount/utab */ |
338 | MNT_FMT_SWAPS /* /proc/swaps */ | |
dd369652 KZ |
339 | }; |
340 | ||
6498ece0 | 341 | /* |
8241fb00 KZ |
342 | * Context hooks |
343 | * | |
344 | * TODO: this will be public one day when libmount will support modules for | |
345 | * stuff like veritydev.c. | |
6498ece0 | 346 | */ |
8241fb00 | 347 | enum { |
5e69b21b KZ |
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 */ | |
8241fb00 | 352 | |
5e69b21b KZ |
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 */ | |
8241fb00 | 356 | |
5e69b21b | 357 | MNT_STAGE_POST = 200 /* all is done */ |
8241fb00 | 358 | }; |
6498ece0 | 359 | |
8241fb00 KZ |
360 | struct libmnt_hookset { |
361 | const char *name; /* hook set name */ | |
bd599524 KZ |
362 | |
363 | int firststage; | |
364 | int (*firstcall)(struct libmnt_context *, const struct libmnt_hookset *, void *); | |
365 | ||
8241fb00 | 366 | int (*deinit)(struct libmnt_context *, const struct libmnt_hookset *); /* cleanup function */ |
6498ece0 | 367 | }; |
6bd8b7a7 | 368 | |
8241fb00 KZ |
369 | /* built-in hooks */ |
370 | extern const struct libmnt_hookset hookset_mount_legacy; | |
2b1db095 | 371 | extern const struct libmnt_hookset hookset_mount; |
093f2245 | 372 | extern const struct libmnt_hookset hookset_mkdir; |
b0a165dc | 373 | extern const struct libmnt_hookset hookset_subdir; |
ee99f438 | 374 | extern const struct libmnt_hookset hookset_owner; |
0bbc62dd | 375 | extern const struct libmnt_hookset hookset_idmap; |
3611b10c | 376 | extern const struct libmnt_hookset hookset_loopdev; |
7f5f350b KZ |
377 | #ifdef HAVE_CRYPTSETUP |
378 | extern const struct libmnt_hookset hookset_veritydev; | |
379 | #endif | |
1a75b4f9 | 380 | #ifdef HAVE_LIBSELINUX |
d5c515dc | 381 | extern const struct libmnt_hookset hookset_selinux; |
1a75b4f9 | 382 | #endif |
8241fb00 | 383 | |
8241fb00 KZ |
384 | extern int mnt_context_deinit_hooksets(struct libmnt_context *cxt); |
385 | extern const struct libmnt_hookset *mnt_context_get_hookset(struct libmnt_context *cxt, const char *name); | |
386 | ||
387 | extern int mnt_context_set_hookset_data(struct libmnt_context *cxt, | |
388 | const struct libmnt_hookset *hs, | |
389 | void *data); | |
390 | ||
391 | extern void *mnt_context_get_hookset_data(struct libmnt_context *cxt, | |
392 | const struct libmnt_hookset *hs); | |
393 | ||
394 | extern int mnt_context_has_hook(struct libmnt_context *cxt, | |
395 | const struct libmnt_hookset *hs, | |
396 | int stage, | |
397 | void *data); | |
398 | ||
399 | extern 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 *)); | |
211bb3c9 KZ |
406 | extern 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 *)); | |
8241fb00 KZ |
414 | |
415 | extern int mnt_context_remove_hook(struct libmnt_context *cxt, | |
416 | const struct libmnt_hookset *hs, | |
417 | int stage, | |
418 | void **data); | |
419 | extern int mnt_context_call_hooks(struct libmnt_context *cxt, int stage); | |
420 | ||
421 | /* | |
422 | * Namespace | |
423 | */ | |
4917d842 VD |
424 | struct libmnt_ns { |
425 | int fd; /* file descriptor of namespace, -1 when inactive */ | |
426 | struct libmnt_cache *cache; /* paths cache associated with NS */ | |
427 | }; | |
428 | ||
1bb1d80b KZ |
429 | /* |
430 | * Mount context -- high-level API | |
431 | */ | |
68164f6c | 432 | struct libmnt_context |
1bb1d80b KZ |
433 | { |
434 | int action; /* MNT_ACT_{MOUNT,UMOUNT} */ | |
1bb1d80b KZ |
435 | int restricted; /* root or not? */ |
436 | ||
437 | char *fstype_pattern; /* for mnt_match_fstype() */ | |
438 | char *optstr_pattern; /* for mnt_match_options() */ | |
439 | ||
6ad929bb | 440 | struct libmnt_fs *fs; /* filesystem description (type, mountpoint, device, ...) */ |
68164f6c | 441 | |
e9d52e6e KZ |
442 | struct libmnt_table *fstab; /* fstab entries */ |
443 | struct libmnt_table *mountinfo; /* already mounted filesystems */ | |
6a52473e | 444 | struct libmnt_table *utab; /* rarely used by umount only */ |
1bb1d80b | 445 | |
d84508cf KZ |
446 | int (*table_errcb)(struct libmnt_table *tb, /* callback for libmnt_table structs */ |
447 | const char *filename, int line); | |
448 | ||
4709c9e6 KZ |
449 | int (*table_fltrcb)(struct libmnt_fs *fs, void *data); /* callback for libmnt_table structs */ |
450 | void *table_fltrcb_data; | |
451 | ||
1a7a421e KZ |
452 | char *(*pwd_get_cb)(struct libmnt_context *); /* get encryption password */ |
453 | void (*pwd_release_cb)(struct libmnt_context *, char *); /* release password */ | |
454 | ||
1bb1d80b KZ |
455 | int optsmode; /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */ |
456 | ||
1bb1d80b KZ |
457 | const void *mountdata; /* final mount(2) data, string or binary data */ |
458 | ||
5b783fe3 KZ |
459 | struct libmnt_cache *cache; /* paths cache */ |
460 | struct libmnt_lock *lock; /* utab lock */ | |
461 | struct libmnt_update *update; /* utab update */ | |
01790c7d | 462 | |
5b783fe3 | 463 | struct libmnt_optlist *optlist; /* parsed mount options */ |
01790c7d | 464 | struct libmnt_optlist *optlist_saved; /* save/apply context template */ |
1d0cd73f | 465 | |
93c0f69d KZ |
466 | const struct libmnt_optmap *map_linux; /* system options map */ |
467 | const struct libmnt_optmap *map_userspace; /* userspace options map */ | |
468 | ||
1a02c7a7 | 469 | const char *mountinfo_path; /* usually /proc/self/moutinfo */ |
1d0cd73f | 470 | |
6ad929bb PU |
471 | const char *utab_path; /* path to utab */ |
472 | int utab_writable; /* is utab writable */ | |
1bb1d80b | 473 | |
71ed3b83 KZ |
474 | char *tgt_prefix; /* path used for all targets */ |
475 | ||
1bb1d80b | 476 | int flags; /* private context flags */ |
1bb1d80b KZ |
477 | |
478 | char *helper; /* name of the used /sbin/[u]mount.<type> helper */ | |
479 | int helper_status; /* helper wait(2) status */ | |
97e23b5e | 480 | int helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */ |
1bb1d80b | 481 | |
d2c97887 KZ |
482 | pid_t *children; /* "mount -a --fork" PIDs */ |
483 | int nchildren; /* number of children */ | |
484 | pid_t pid; /* 0=parent; PID=child */ | |
485 | ||
97e23b5e | 486 | int syscall_status; /* 1: not called yet, 0: success, <0: -errno */ |
11afc49b | 487 | const char *syscall_name; /* failed syscall name */ |
33c42f5b KZ |
488 | |
489 | char **mesgs; /* library or kernel messages (NULL terminated array) */ | |
ea848180 | 490 | |
4917d842 VD |
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 | ||
22147e08 | 495 | unsigned int enabled_textdomain : 1; /* bindtextdomain() called */ |
8241fb00 | 496 | unsigned int noautofs : 1; /* ignore autofs mounts */ |
77bc38ce | 497 | unsigned int has_selinux_opt : 1; /* temporary for broken fsconfig() syscall */ |
8149f7b6 | 498 | unsigned int force_clone : 1; /* OPEN_TREE_CLONE */ |
8241fb00 KZ |
499 | |
500 | struct list_head hooksets_datas; /* global hooksets data */ | |
501 | struct list_head hooksets_hooks; /* global hooksets data */ | |
1bb1d80b KZ |
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) | |
ea8f06f9 | 514 | #define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */ |
d2c97887 | 515 | #define MNT_FL_FORK (1 << 12) |
e39cbb76 | 516 | #define MNT_FL_NOSWAPMATCH (1 << 13) |
6dede2f2 | 517 | #define MNT_FL_RWONLY_MOUNT (1 << 14) /* explicit mount -w; never try read-only */ |
3d1c41c8 | 518 | #define MNT_FL_ONLYONCE (1 << 15) |
1bb1d80b | 519 | |
1bb1d80b | 520 | #define MNT_FL_MOUNTDATA (1 << 20) |
e9d52e6e | 521 | #define MNT_FL_TAB_APPLIED (1 << 21) /* fstab merged to cxt->fs */ |
1bb1d80b KZ |
522 | #define MNT_FL_MOUNTFLAGS_MERGED (1 << 22) /* MS_* flags was read from optstr */ |
523 | #define MNT_FL_SAVED_USER (1 << 23) | |
dbde1923 | 524 | #define MNT_FL_PREPARED (1 << 24) |
8c0797e7 | 525 | #define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */ |
dc4dbbf1 | 526 | #define MNT_FL_MOUNTOPTS_FIXED (1 << 27) |
150e696d | 527 | #define MNT_FL_TABPATHS_CHECKED (1 << 28) |
6dede2f2 | 528 | #define MNT_FL_FORCED_RDONLY (1 << 29) /* mounted read-only on write-protected device */ |
e6a49887 | 529 | #define MNT_FL_VERITYDEV_READY (1 << 30) /* /dev/mapper/<FOO> initialized by the library */ |
1bb1d80b KZ |
530 | |
531 | /* default flags */ | |
532 | #define MNT_FL_DEFAULT 0 | |
533 | ||
e82b77e9 | 534 | /* Flags usable with MS_BIND|MS_REMOUNT */ |
36a3923c | 535 | #define MNT_BIND_SETTABLE (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY|MS_NOSYMFOLLOW) |
e82b77e9 | 536 | |
e828630a | 537 | |
078edb2d | 538 | /* optmap.c */ |
68164f6c KZ |
539 | extern const struct libmnt_optmap *mnt_optmap_get_entry( |
540 | struct libmnt_optmap const **maps, | |
90cd46cb OO |
541 | int nmaps, |
542 | const char *name, | |
68164f6c | 543 | size_t namelen, |
ba2bdf41 | 544 | const struct libmnt_optmap **mapent); |
078edb2d | 545 | |
188dc15a | 546 | /* optstr.c */ |
ba2bdf41 | 547 | extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end); |
722e4d47 | 548 | extern int mnt_optstr_get_missing(const char *optstr, const char *wanted, char **missing); |
188dc15a | 549 | |
0a8980b7 KZ |
550 | extern int mnt_buffer_append_option(struct ul_buffer *buf, |
551 | const char *name, size_t namesz, | |
10dd0712 | 552 | const char *val, size_t valsz, int quoted); |
0a8980b7 | 553 | |
add9d458 KZ |
554 | /* optlist.h */ |
555 | struct libmnt_opt; | |
556 | struct libmnt_optlist; | |
557 | ||
558 | extern struct libmnt_optlist *mnt_new_optlist(void); | |
559 | extern void mnt_ref_optlist(struct libmnt_optlist *ls); | |
560 | extern void mnt_unref_optlist(struct libmnt_optlist *ls); | |
01790c7d KZ |
561 | extern struct libmnt_optlist *mnt_copy_optlist(struct libmnt_optlist *ls); |
562 | extern int mnt_optlist_is_empty(struct libmnt_optlist *ls); | |
faa3d718 | 563 | extern unsigned int mnt_optlist_get_age(struct libmnt_optlist *ls); |
add9d458 KZ |
564 | extern int mnt_optlist_register_map(struct libmnt_optlist *ls, const struct libmnt_optmap *map); |
565 | extern int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt); | |
1017f628 KZ |
566 | extern int mnt_optlist_remove_named(struct libmnt_optlist *ls, const char *name, |
567 | const struct libmnt_optmap *map); | |
d74ae826 KZ |
568 | extern int mnt_optlist_remove_flags(struct libmnt_optlist *ls, unsigned long flags, |
569 | const struct libmnt_optmap *map); | |
add9d458 KZ |
570 | extern int mnt_optlist_next_opt(struct libmnt_optlist *ls, |
571 | struct libmnt_iter *itr, struct libmnt_opt **opt); | |
572 | extern struct libmnt_opt *mnt_optlist_get_opt(struct libmnt_optlist *ls, | |
573 | unsigned long id, const struct libmnt_optmap *map); | |
574 | extern struct libmnt_opt *mnt_optlist_get_named(struct libmnt_optlist *ls, | |
1017f628 | 575 | const char *name, const struct libmnt_optmap *map); |
add9d458 KZ |
576 | extern int mnt_optlist_set_optstr(struct libmnt_optlist *ls, const char *optstr, |
577 | const struct libmnt_optmap *map); | |
578 | extern int mnt_optlist_append_optstr(struct libmnt_optlist *ls, const char *optstr, | |
579 | const struct libmnt_optmap *map); | |
580 | extern int mnt_optlist_prepend_optstr(struct libmnt_optlist *ls, const char *optstr, | |
581 | const struct libmnt_optmap *map); | |
582 | extern int mnt_optlist_append_flags(struct libmnt_optlist *ls, unsigned long flags, | |
583 | const struct libmnt_optmap *map); | |
584 | extern int mnt_optlist_set_flags(struct libmnt_optlist *ls, unsigned long flags, | |
585 | const struct libmnt_optmap *map); | |
586 | extern 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); | |
b3b890f4 KZ |
590 | /* "what" argument */ |
591 | enum { | |
94c5c1da KZ |
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, | |
0dea3c01 KZ |
595 | /* Options as expected by mount.<type> helpers */ |
596 | MNT_OL_FLTR_HELPERS, | |
597 | /* Options as expected in mtab */ | |
598 | MNT_OL_FLTR_MTAB, | |
94c5c1da KZ |
599 | /* All options -- include mapped, unknown and external options */ |
600 | MNT_OL_FLTR_ALL, | |
0dea3c01 | 601 | /* All unknown options -- exclude external (usually FS specific options) */ |
94c5c1da KZ |
602 | MNT_OL_FLTR_UNKNOWN, |
603 | ||
604 | __MNT_OL_FLTR_COUNT /* keep it last */ | |
b3b890f4 KZ |
605 | }; |
606 | ||
e84f01c1 | 607 | |
add9d458 | 608 | extern int mnt_optlist_get_flags(struct libmnt_optlist *ls, unsigned long *flags, |
b3b890f4 | 609 | const struct libmnt_optmap *map, unsigned int what); |
e84f01c1 KZ |
610 | |
611 | /* recursive status for mnt_optlist_get_attrs() */ | |
612 | #define MNT_OL_REC 1 | |
613 | #define MNT_OL_NOREC 2 | |
614 | ||
615 | extern int mnt_optlist_get_attrs(struct libmnt_optlist *ls, uint64_t *set, uint64_t *clr, int rec); | |
616 | ||
5b783fe3 | 617 | extern int mnt_optlist_get_optstr(struct libmnt_optlist *ol, const char **optstr, |
b3b890f4 | 618 | const struct libmnt_optmap *map, unsigned int what); |
d6e8427d KZ |
619 | extern int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr, |
620 | const struct libmnt_optmap *map, unsigned int what); | |
b3b890f4 | 621 | |
add9d458 KZ |
622 | extern int mnt_optlist_get_propagation(struct libmnt_optlist *ls); |
623 | extern int mnt_optlist_is_propagation_only(struct libmnt_optlist *ls); | |
b3b890f4 | 624 | extern int mnt_optlist_is_remount(struct libmnt_optlist *ls); |
03b2e73a | 625 | extern int mnt_optlist_is_rpropagation(struct libmnt_optlist *ls); |
90437060 | 626 | extern int mnt_optlist_is_bind(struct libmnt_optlist *ls); |
2b1db095 | 627 | extern int mnt_optlist_is_rbind(struct libmnt_optlist *ls); |
90437060 KZ |
628 | extern int mnt_optlist_is_move(struct libmnt_optlist *ls); |
629 | extern int mnt_optlist_is_rdonly(struct libmnt_optlist *ls); | |
624061f7 | 630 | extern int mnt_optlist_is_silent(struct libmnt_optlist *ls); |
90437060 | 631 | |
b3b890f4 KZ |
632 | extern int mnt_optlist_merge_opts(struct libmnt_optlist *ls); |
633 | ||
add9d458 | 634 | extern int mnt_opt_has_value(struct libmnt_opt *opt); |
b3b890f4 KZ |
635 | extern const char *mnt_opt_get_value(struct libmnt_opt *opt); |
636 | extern const char *mnt_opt_get_name(struct libmnt_opt *opt); | |
e1d05613 KZ |
637 | extern const struct libmnt_optmap *mnt_opt_get_map(struct libmnt_opt *opt); |
638 | extern const struct libmnt_optmap *mnt_opt_get_mapent(struct libmnt_opt *opt); | |
d74ae826 | 639 | extern int mnt_opt_set_external(struct libmnt_opt *opt, int enable); |
b3b890f4 KZ |
640 | extern int mnt_opt_set_value(struct libmnt_opt *opt, const char *str); |
641 | extern int mnt_opt_set_u64value(struct libmnt_opt *opt, uint64_t num); | |
642 | extern int mnt_opt_set_quoted_value(struct libmnt_opt *opt, const char *str); | |
6753e6f6 | 643 | extern int mnt_opt_is_external(struct libmnt_opt *opt); |
0c548534 | 644 | extern int mnt_opt_is_sepnodata(struct libmnt_opt *opt); |
4095c5bb | 645 | extern int mnt_opt_value_with(struct libmnt_opt *opt, const char *str); |
add9d458 | 646 | |
d115ee9b | 647 | /* fs.c */ |
faa3d718 KZ |
648 | extern int mnt_fs_follow_optlist(struct libmnt_fs *fs, struct libmnt_optlist *ol); |
649 | extern struct libmnt_fs *mnt_copy_mtab_fs(struct libmnt_fs *fs); | |
90cd46cb OO |
650 | extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source) |
651 | __attribute__((nonnull(1))); | |
652 | extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype) | |
653 | __attribute__((nonnull(1))); | |
8241fb00 KZ |
654 | extern int __mnt_fs_set_target_ptr(struct libmnt_fs *fs, char *tgt) |
655 | __attribute__((nonnull(1))); | |
078edb2d | 656 | |
1bb1d80b | 657 | /* context.c */ |
6b871f46 KZ |
658 | extern void mnt_context_syscall_save_status(struct libmnt_context *cxt, |
659 | const char *syscallname, int success); | |
660 | extern void mnt_context_syscall_reset_status(struct libmnt_context *cxt); | |
661 | ||
189a1bf3 | 662 | extern struct libmnt_context *mnt_copy_context(struct libmnt_context *o); |
150e696d KZ |
663 | extern int mnt_context_utab_writable(struct libmnt_context *cxt); |
664 | extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt); | |
665 | ||
0f9b2438 KZ |
666 | extern int mnt_context_within_helper(struct libmnt_context *cxt); |
667 | ||
e9d52e6e KZ |
668 | extern int mnt_context_get_mountinfo(struct libmnt_context *cxt, struct libmnt_table **tb); |
669 | extern int mnt_context_get_mountinfo_for_target(struct libmnt_context *cxt, | |
670 | struct libmnt_table **mountinfo, const char *tgt); | |
7deae03f | 671 | |
ba2bdf41 | 672 | extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt); |
b1f03df7 | 673 | extern int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type); |
ba2bdf41 | 674 | extern int mnt_context_guess_fstype(struct libmnt_context *cxt); |
68164f6c | 675 | extern int mnt_context_prepare_helper(struct libmnt_context *cxt, |
ba2bdf41 KZ |
676 | const char *name, const char *type); |
677 | extern int mnt_context_prepare_update(struct libmnt_context *cxt); | |
678 | extern int mnt_context_merge_mflags(struct libmnt_context *cxt); | |
679 | extern int mnt_context_update_tabs(struct libmnt_context *cxt); | |
90cd46cb | 680 | |
ba2bdf41 KZ |
681 | extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg); |
682 | extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg); | |
90cd46cb | 683 | |
33c42f5b KZ |
684 | extern void mnt_context_reset_mesgs(struct libmnt_context *cxt); |
685 | extern int mnt_context_append_mesg(struct libmnt_context *cxt, const char *msg); | |
686 | extern int mnt_context_sprintf_mesg(struct libmnt_context *cxt, const char *msg, ...); | |
8369f2a7 | 687 | extern int mnt_context_read_mesgs(struct libmnt_context *cxt, int fd); |
c4023572 | 688 | |
6498ece0 KZ |
689 | extern int mnt_context_propagation_only(struct libmnt_context *cxt) |
690 | __attribute__((nonnull)); | |
691 | ||
ba2bdf41 | 692 | extern int mnt_context_delete_loopdev(struct libmnt_context *cxt); |
7f8b2bf3 | 693 | |
d2c97887 KZ |
694 | extern int mnt_fork_context(struct libmnt_context *cxt); |
695 | ||
4709c9e6 | 696 | extern int mnt_context_set_tabfilter(struct libmnt_context *cxt, |
90cd46cb | 697 | int (*fltr)(struct libmnt_fs *, void *), |
ba2bdf41 | 698 | void *data); |
4709c9e6 | 699 | |
b77e3e34 KZ |
700 | extern int mnt_context_get_generic_excode(int rc, char *buf, size_t bufsz, const char *fmt, ...) |
701 | __attribute__ ((__format__ (__printf__, 4, 5))); | |
ea848180 KZ |
702 | extern int mnt_context_get_mount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz); |
703 | extern int mnt_context_get_umount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz); | |
704 | ||
e83c09d4 KZ |
705 | extern int mnt_context_has_template(struct libmnt_context *cxt); |
706 | extern int mnt_context_apply_template(struct libmnt_context *cxt); | |
707 | extern int mnt_context_save_template(struct libmnt_context *cxt); | |
708 | ||
7a56878d KZ |
709 | extern int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs); |
710 | ||
5b783fe3 KZ |
711 | extern struct libmnt_optlist *mnt_context_get_optlist(struct libmnt_context *cxt); |
712 | ||
a904aefe KZ |
713 | extern int mnt_context_is_xnocanonicalize(struct libmnt_context *cxt, const char *type); |
714 | ||
97e23b5e | 715 | /* tab_update.c */ |
54482492 | 716 | extern int mnt_update_emit_event(struct libmnt_update *upd); |
e9d52e6e | 717 | extern int mnt_update_set_filename(struct libmnt_update *upd, const char *filename); |
b94b5929 | 718 | extern int mnt_update_already_done(struct libmnt_update *upd); |
9218c967 KZ |
719 | extern int mnt_update_start(struct libmnt_update *upd); |
720 | extern int mnt_update_end(struct libmnt_update *upd); | |
97e23b5e | 721 | |
2cd28fc8 SB |
722 | #if __linux__ |
723 | /* btrfs.c */ | |
724 | extern uint64_t btrfs_get_default_subvol_id(const char *path); | |
725 | #endif | |
726 | ||
9040c090 | 727 | #ifdef USE_LIBMOUNT_MOUNTFD_SUPPORT |
2b1db095 KZ |
728 | /* fsconfig/fsopen based stuff */ |
729 | struct libmnt_sysapi { | |
730 | int fd_fs; /* FD from fsopen() or fspick() */ | |
731 | int fd_tree; /* FD from fsmount() or open_tree() */ | |
8149f7b6 | 732 | |
ae19f754 KZ |
733 | char *subdir; /* Linux >= 6.15 can directly open subdir; |
734 | * hook_subdir sets this variable */ | |
735 | ||
8149f7b6 | 736 | unsigned int is_new_fs : 1 ; /* fd_fs comes from fsopen() */ |
2b1db095 | 737 | }; |
1d53aed4 KZ |
738 | |
739 | static inline struct libmnt_sysapi *mnt_context_get_sysapi(struct libmnt_context *cxt) | |
740 | { | |
741 | return mnt_context_get_hookset_data(cxt, &hookset_mount); | |
742 | } | |
2a684833 KZ |
743 | |
744 | int mnt_context_open_tree(struct libmnt_context *cxt, const char *path, unsigned long mflg); | |
745 | ||
2b1db095 KZ |
746 | #endif |
747 | ||
078edb2d | 748 | #endif /* _LIBMOUNT_PRIVATE_H */ |