]> git.ipfire.org Git - thirdparty/util-linux.git/blob - libmount/src/libmount.h.in
Merge branch 'lsns--Q' of https://github.com/masatake/util-linux
[thirdparty/util-linux.git] / libmount / src / libmount.h.in
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3 * libmount.h - libmount API
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 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #ifndef _LIBMOUNT_MOUNT_H
25 #define _LIBMOUNT_MOUNT_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <stdio.h>
32 #include <mntent.h>
33 #include <sys/types.h>
34
35 /* Make sure libc MS_* definitions are used by default. Note that MS_* flags
36 * may be already defined by linux/fs.h or another file -- in this case we
37 * don't want to include sys/mount.h at all to avoid collisions.
38 */
39 #if defined(__linux__) && !defined(MS_RDONLY)
40 # include <sys/mount.h>
41 #endif
42
43 #define LIBMOUNT_VERSION "@LIBMOUNT_VERSION@"
44 #define LIBMOUNT_MAJOR_VERSION @LIBMOUNT_MAJOR_VERSION@
45 #define LIBMOUNT_MINOR_VERSION @LIBMOUNT_MINOR_VERSION@
46 #define LIBMOUNT_PATCH_VERSION @LIBMOUNT_PATCH_VERSION@
47
48 /**
49 * libmnt_cache:
50 *
51 * Stores canonicalized paths and evaluated tags
52 */
53 struct libmnt_cache;
54
55 /**
56 * libmnt_lock:
57 *
58 * Stores information about the locked file
59 */
60 struct libmnt_lock;
61
62 /**
63 * libmnt_iter:
64 *
65 * Generic iterator (stores state about lists)
66 */
67 struct libmnt_iter;
68
69 /**
70 * libmnt_optmap:
71 * @name: option name[=type] where type is printf-like type specifier")
72 * @id: option ID or MS_* flags (e.g MS_RDONLY)
73 * @mask: MNT_{NOMTAB,INVERT,...} mask
74 *
75 * Mount options description (map)
76 */
77 struct libmnt_optmap
78 {
79 const char *name;
80 int id;
81 int mask;
82 };
83
84 /*
85 * mount options map masks
86 */
87 #define MNT_INVERT (1 << 1) /* invert the mountflag */
88 #define MNT_NOMTAB (1 << 2) /* skip in the mtab option string */
89 #define MNT_PREFIX (1 << 3) /* prefix used for some options (e.g. "x-foo") */
90 #define MNT_NOHLPS (1 << 4) /* don't add the option to mount.<type> helpers command line */
91 #define MNT_NOFSTAB (1 << 5) /* not expected in fstab */
92 #define MNT_SUPERBLOCK (1 << 6) /* MS_* for mount(2), otherwise requires fsconfig() */
93
94 /**
95 * libmnt_fs:
96 *
97 * Parsed fstab or mountinfo entry
98 */
99 struct libmnt_fs;
100
101 /**
102 * libmnt_table:
103 *
104 * List of struct libmnt_fs entries (parsed fstab or mountinfo)
105 */
106 struct libmnt_table;
107
108 /**
109 * libmnt_update
110 *
111 * utab update description
112 */
113 struct libmnt_update;
114
115 /**
116 * libmnt_context
117 *
118 * Mount/umount status
119 */
120 struct libmnt_context;
121
122 /**
123 * libmnt_monitor
124 *
125 * Mount tables monitor
126 */
127 struct libmnt_monitor;
128
129 /**
130 * libmnt_tabdiff:
131 *
132 * Stores mountinfo state
133 */
134 struct libmnt_tabdiff;
135
136 /**
137 * libmnt_ns:
138 *
139 * Describes mount namespace
140 */
141 struct libmnt_ns;
142
143 /*
144 * Actions
145 */
146 enum {
147 MNT_ACT_MOUNT = 1,
148 MNT_ACT_UMOUNT
149 };
150
151 /*
152 * Errors -- by default libmount returns -errno for generic errors (ENOMEM,
153 * EINVAL, ...) and for mount(2) errors, but for some specific operations it
154 * returns private error codes. Note that maximum system errno value should be
155 * 4095 on UNIXes.
156 *
157 * See also mnt_context_get_syscall_errno() and mnt_context_get_helper_status().
158 */
159 /**
160 * MNT_ERR_NOFSTAB:
161 *
162 * not found required entry in fstab
163 */
164 #define MNT_ERR_NOFSTAB 5000
165 /**
166 * MNT_ERR_NOFSTYPE:
167 *
168 * failed to detect filesystem type
169 */
170 #define MNT_ERR_NOFSTYPE 5001
171 /**
172 * MNT_ERR_NOSOURCE:
173 *
174 * required mount source undefined
175 */
176 #define MNT_ERR_NOSOURCE 5002
177 /**
178 * MNT_ERR_LOOPDEV:
179 *
180 * loopdev setup failed, errno set by libc
181 */
182 #define MNT_ERR_LOOPDEV 5003
183 /**
184 * MNT_ERR_MOUNTOPT:
185 *
186 * failed to parse/use userspace mount options
187 */
188 #define MNT_ERR_MOUNTOPT 5004
189 /**
190 * MNT_ERR_APPLYFLAGS:
191 *
192 * failed to apply MS_PROPAGATION flags, and MOUNT_ATTR_* attributes for
193 * mount_setattr(2)
194 */
195 #define MNT_ERR_APPLYFLAGS 5005
196 /**
197 * MNT_ERR_AMBIFS:
198 *
199 * libblkid detected more filesystems on the device
200 */
201 #define MNT_ERR_AMBIFS 5006
202 /**
203 * MNT_ERR_LOOPOVERLAP:
204 *
205 * detected overlapping loop device that cannot be re-used
206 */
207 #define MNT_ERR_LOOPOVERLAP 5007
208 /**
209 * MNT_ERR_LOCK:
210 *
211 * failed to lock utab or so.
212 */
213 #define MNT_ERR_LOCK 5008
214 /**
215 * MNT_ERR_NAMESPACE:
216 *
217 * failed to switch namespace
218 */
219 #define MNT_ERR_NAMESPACE 5009
220 /**
221 * MNT_ERR_ONLYONCE:
222 *
223 * filesystem mounted, but --onlyonce specified
224 */
225 #define MNT_ERR_ONLYONCE 5010
226 /**
227 * MNT_ERR_CHOWN:
228 *
229 * filesystem mounted, but subsequent X-mount.owner=/X-mount.group= lchown(2) failed
230 */
231 #define MNT_ERR_CHOWN 5011
232 /**
233 * MNT_ERR_CHMOD:
234 *
235 * filesystem mounted, but subsequent X-mount.mode= chmod(2) failed
236 */
237 #define MNT_ERR_CHMOD 5012
238 /**
239 * MNT_ERR_IDMAP:
240 *
241 * filesystem mounted, but subsequent X-mount.idmap= failed
242 */
243 #define MNT_ERR_IDMAP 5013
244
245
246 /*
247 * Overall return codes -- based on mount(8) and umount(8) return codes.
248 * See mnt_context_get_excode() for more details.
249 */
250
251 /**
252 * MNT_EX_SUCCESS:
253 *
254 * [u]mount(8) exit code: no errors
255 */
256 #define MNT_EX_SUCCESS 0
257
258 /**
259 * MNT_EX_USAGE:
260 *
261 * [u]mount(8) exit code: incorrect invocation or permission
262 */
263 #define MNT_EX_USAGE 1
264
265 /**
266 * MNT_EX_SYSERR:
267 *
268 * [u]mount(8) exit code: out of memory, cannot fork, ...
269 */
270 #define MNT_EX_SYSERR 2
271
272 /**
273 * MNT_EX_SOFTWARE:
274 *
275 * [u]mount(8) exit code: internal mount bug or wrong version
276 */
277 #define MNT_EX_SOFTWARE 4
278
279 /**
280 * MNT_EX_USER:
281 *
282 * [u]mount(8) exit code: user interrupt
283 */
284 #define MNT_EX_USER 8
285
286 /**
287 * MNT_EX_FILEIO:
288 *
289 * [u]mount(8) exit code: problems writing, locking, ... utab
290 */
291 #define MNT_EX_FILEIO 16
292
293 /**
294 * MNT_EX_FAIL:
295 *
296 * [u]mount(8) exit code: mount failure
297 */
298 #define MNT_EX_FAIL 32
299
300 /**
301 * MNT_EX_SOMEOK:
302 *
303 * [u]mount(8) exit code: some mount succeeded; usually when executed with
304 * --all options. Never returned by libmount.
305 */
306 #define MNT_EX_SOMEOK 64
307
308
309
310 #ifndef __GNUC_PREREQ
311 # if defined __GNUC__ && defined __GNUC_MINOR__
312 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
313 # else
314 # define __GNUC_PREREQ(maj, min) 0
315 # endif
316 #endif
317
318 #ifndef __ul_attribute__
319 # if __GNUC_PREREQ (3, 4)
320 # define __ul_attribute__(_a_) __attribute__(_a_)
321 # else
322 # define __ul_attribute__(_a_)
323 # endif
324 #endif
325
326
327 /* init.c */
328 extern void mnt_init_debug(int mask);
329
330 /* version.c */
331 extern int mnt_parse_version_string(const char *ver_string);
332 extern int mnt_get_library_version(const char **ver_string);
333 extern int mnt_get_library_features(const char ***features);
334
335 /* utils.c */
336 extern char *mnt_mangle(const char *str)
337 __ul_attribute__((warn_unused_result));
338 extern char *mnt_unmangle(const char *str)
339 __ul_attribute__((warn_unused_result));
340
341 extern int mnt_tag_is_valid(const char *tag);
342 extern int mnt_fstype_is_netfs(const char *type);
343 extern int mnt_fstype_is_pseudofs(const char *type);
344
345 extern int mnt_match_fstype(const char *type, const char *pattern)
346 __ul_attribute__((warn_unused_result));
347 extern int mnt_match_options(const char *optstr, const char *pattern)
348 __ul_attribute__((warn_unused_result));
349 extern const char *mnt_get_fstab_path(void);
350 extern const char *mnt_get_swaps_path(void);
351 extern const char *mnt_get_mtab_path(void);
352 extern int mnt_has_regular_mtab(const char **mtab, int *writable);
353 extern char *mnt_get_mountpoint(const char *path)
354 __ul_attribute__((warn_unused_result));
355 extern int mnt_guess_system_root(dev_t devno, struct libmnt_cache *cache, char **path)
356 __ul_attribute__((nonnull(3)));
357
358 /* cache.c */
359 extern struct libmnt_cache *mnt_new_cache(void)
360 __ul_attribute__((warn_unused_result));
361 extern void mnt_free_cache(struct libmnt_cache *cache);
362
363 extern void mnt_ref_cache(struct libmnt_cache *cache);
364 extern void mnt_unref_cache(struct libmnt_cache *cache);
365
366 extern int mnt_cache_set_targets(struct libmnt_cache *cache,
367 struct libmnt_table *mountinfo);
368 extern int mnt_cache_set_sbprobe(struct libmnt_cache *cache, int flags);
369 extern int mnt_cache_read_tags(struct libmnt_cache *cache, const char *devname);
370
371 extern int mnt_cache_device_has_tag(struct libmnt_cache *cache,
372 const char *devname,
373 const char *token,
374 const char *value);
375
376 extern char *mnt_cache_find_tag_value(struct libmnt_cache *cache,
377 const char *devname, const char *token);
378
379 extern char *mnt_get_fstype(const char *devname, int *ambi,
380 struct libmnt_cache *cache)
381 __ul_attribute__((warn_unused_result));
382 extern char *mnt_resolve_path(const char *path, struct libmnt_cache *cache)
383 __ul_attribute__((warn_unused_result));
384 extern char *mnt_resolve_target(const char *path, struct libmnt_cache *cache)
385 __ul_attribute__((warn_unused_result));
386 extern char *mnt_resolve_tag(const char *token, const char *value,
387 struct libmnt_cache *cache)
388 __ul_attribute__((warn_unused_result));
389 extern char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache)
390 __ul_attribute__((warn_unused_result));
391 extern char *mnt_pretty_path(const char *path, struct libmnt_cache *cache)
392 __ul_attribute__((warn_unused_result));
393
394 /* optstr.c */
395 extern int mnt_optstr_next_option(char **optstr, char **name, size_t *namesz,
396 char **value, size_t *valuesz);
397 extern int mnt_optstr_append_option(char **optstr, const char *name,
398 const char *value);
399 extern int mnt_optstr_prepend_option(char **optstr, const char *name,
400 const char *value);
401
402 extern int mnt_optstr_get_option(const char *optstr, const char *name,
403 char **value, size_t *valsz);
404 extern int mnt_optstr_set_option(char **optstr, const char *name,
405 const char *value);
406 extern int mnt_optstr_remove_option(char **optstr, const char *name);
407 extern int mnt_optstr_deduplicate_option(char **optstr, const char *name);
408
409 extern int mnt_split_optstr(const char *optstr,
410 char **user, char **vfs, char **fs,
411 int ignore_user, int ignore_vfs);
412
413 extern int mnt_optstr_get_options(const char *optstr, char **subset,
414 const struct libmnt_optmap *map, int ignore);
415
416 extern int mnt_optstr_get_flags(const char *optstr, unsigned long *flags,
417 const struct libmnt_optmap *map);
418
419 extern int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
420 const struct libmnt_optmap *map);
421
422 /* iter.c */
423 enum {
424
425 MNT_ITER_FORWARD = 0,
426 MNT_ITER_BACKWARD
427 };
428 extern struct libmnt_iter *mnt_new_iter(int direction)
429 __ul_attribute__((warn_unused_result));
430 extern void mnt_free_iter(struct libmnt_iter *itr);
431
432 extern void mnt_reset_iter(struct libmnt_iter *itr, int direction)
433 __ul_attribute__((nonnull));
434 extern int mnt_iter_get_direction(struct libmnt_iter *itr)
435 __ul_attribute__((nonnull));
436
437 /* optmap.c */
438 enum {
439 MNT_LINUX_MAP = 1,
440 MNT_USERSPACE_MAP
441 };
442 extern const struct libmnt_optmap *mnt_get_builtin_optmap(int id);
443
444 /* lock.c */
445 extern struct libmnt_lock *mnt_new_lock(const char *datafile, pid_t id)
446 __ul_attribute__((warn_unused_result));
447 extern void mnt_ref_lock(struct libmnt_lock *ml);
448 extern void mnt_unref_lock(struct libmnt_lock *ml);
449 extern void mnt_free_lock(struct libmnt_lock *ml);
450
451 extern void mnt_unlock_file(struct libmnt_lock *ml);
452 extern int mnt_lock_file(struct libmnt_lock *ml);
453 extern int mnt_lock_block_signals(struct libmnt_lock *ml, int enable);
454
455 /* fs.c */
456 extern struct libmnt_fs *mnt_new_fs(void)
457 __ul_attribute__((warn_unused_result));
458 extern void mnt_free_fs(struct libmnt_fs *fs);
459 extern void mnt_ref_fs(struct libmnt_fs *fs);
460 extern void mnt_unref_fs(struct libmnt_fs *fs);
461
462 extern void mnt_reset_fs(struct libmnt_fs *fs);
463 extern struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
464 const struct libmnt_fs *src)
465 __ul_attribute__((warn_unused_result));
466 extern void *mnt_fs_get_userdata(struct libmnt_fs *fs);
467 extern int mnt_fs_set_userdata(struct libmnt_fs *fs, void *data);
468 extern const char *mnt_fs_get_source(struct libmnt_fs *fs);
469 extern int mnt_fs_set_source(struct libmnt_fs *fs, const char *source);
470 extern const char *mnt_fs_get_srcpath(struct libmnt_fs *fs);
471 extern int mnt_fs_get_table(struct libmnt_fs *fs, struct libmnt_table **tb);
472
473 extern int mnt_fs_get_tag(struct libmnt_fs *fs, const char **name,
474 const char **value);
475 extern const char *mnt_fs_get_target(struct libmnt_fs *fs);
476 extern int mnt_fs_set_target(struct libmnt_fs *fs, const char *tgt);
477 extern const char *mnt_fs_get_fstype(struct libmnt_fs *fs);
478 extern int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype);
479
480 extern int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
481 __ul_attribute__((warn_unused_result));
482 extern int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path)
483 __ul_attribute__((warn_unused_result));
484
485 extern char *mnt_fs_strdup_options(struct libmnt_fs *fs)
486 __ul_attribute__((warn_unused_result));
487 extern const char *mnt_fs_get_options(struct libmnt_fs *fs)
488 __ul_attribute__((warn_unused_result));
489 extern const char *mnt_fs_get_optional_fields(struct libmnt_fs *fs)
490 __ul_attribute__((warn_unused_result));
491 extern int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags);
492
493 extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr);
494 extern int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr);
495 extern int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr);
496
497 extern int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
498 char **value, size_t *valsz);
499
500 extern const char *mnt_fs_get_fs_options(struct libmnt_fs *fs);
501 extern const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs);
502 extern const char *mnt_fs_get_user_options(struct libmnt_fs *fs);
503 extern char *mnt_fs_get_vfs_options_all(struct libmnt_fs *fs);
504
505 extern const char *mnt_fs_get_attributes(struct libmnt_fs *fs);
506 extern int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr);
507 extern int mnt_fs_get_attribute(struct libmnt_fs *fs, const char *name,
508 char **value, size_t *valsz);
509 extern int mnt_fs_append_attributes(struct libmnt_fs *fs, const char *optstr);
510 extern int mnt_fs_prepend_attributes(struct libmnt_fs *fs, const char *optstr);
511
512 extern int mnt_fs_get_freq(struct libmnt_fs *fs);
513 extern int mnt_fs_set_freq(struct libmnt_fs *fs, int freq);
514 extern int mnt_fs_get_passno(struct libmnt_fs *fs);
515 extern int mnt_fs_set_passno(struct libmnt_fs *fs, int passno);
516 extern const char *mnt_fs_get_root(struct libmnt_fs *fs);
517 extern int mnt_fs_set_root(struct libmnt_fs *fs, const char *path);
518 extern const char *mnt_fs_get_bindsrc(struct libmnt_fs *fs);
519 extern int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src);
520 extern int mnt_fs_get_id(struct libmnt_fs *fs);
521 extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
522 extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
523 extern pid_t mnt_fs_get_tid(struct libmnt_fs *fs);
524
525 extern const char *mnt_fs_get_swaptype(struct libmnt_fs *fs);
526 extern off_t mnt_fs_get_size(struct libmnt_fs *fs);
527 extern off_t mnt_fs_get_usedsize(struct libmnt_fs *fs);
528 extern int mnt_fs_get_priority(struct libmnt_fs *fs);
529 extern int mnt_fs_set_priority(struct libmnt_fs *fs, int prio);
530
531 extern const char *mnt_fs_get_comment(struct libmnt_fs *fs);
532 extern int mnt_fs_set_comment(struct libmnt_fs *fs, const char *comm);
533 extern int mnt_fs_append_comment(struct libmnt_fs *fs, const char *comm);
534
535 extern int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
536 struct libmnt_cache *cache);
537 extern int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
538 struct libmnt_cache *cache);
539 extern int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types);
540 extern int mnt_fs_match_options(struct libmnt_fs *fs, const char *options);
541 extern int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file);
542
543 extern int mnt_fs_is_kernel(struct libmnt_fs *fs);
544 extern int mnt_fs_is_swaparea(struct libmnt_fs *fs);
545 extern int mnt_fs_is_netfs(struct libmnt_fs *fs);
546 extern int mnt_fs_is_pseudofs(struct libmnt_fs *fs);
547 extern int mnt_fs_is_regularfs(struct libmnt_fs *fs);
548
549 extern void mnt_free_mntent(struct mntent *mnt);
550 extern int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt);
551
552 /* tab-parse.c */
553 extern struct libmnt_table *mnt_new_table_from_file(const char *filename)
554 __ul_attribute__((warn_unused_result));
555 extern struct libmnt_table *mnt_new_table_from_dir(const char *dirname)
556 __ul_attribute__((warn_unused_result));
557 extern int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f,
558 const char *filename);
559 extern int mnt_table_parse_file(struct libmnt_table *tb, const char *filename);
560 extern int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname);
561
562 extern int mnt_table_parse_fstab(struct libmnt_table *tb, const char *filename);
563 extern int mnt_table_parse_swaps(struct libmnt_table *tb, const char *filename);
564 extern int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename);
565 extern int mnt_table_set_parser_errcb(struct libmnt_table *tb,
566 int (*cb)(struct libmnt_table *tb, const char *filename, int line));
567
568 /* tab.c */
569 extern struct libmnt_table *mnt_new_table(void)
570 __ul_attribute__((warn_unused_result));
571 extern void mnt_free_table(struct libmnt_table *tb);
572
573 extern void mnt_ref_table(struct libmnt_table *tb);
574 extern void mnt_unref_table(struct libmnt_table *tb);
575
576 extern int mnt_reset_table(struct libmnt_table *tb);
577 extern int mnt_table_get_nents(struct libmnt_table *tb);
578 extern int mnt_table_is_empty(struct libmnt_table *tb);
579
580 extern int mnt_table_set_userdata(struct libmnt_table *tb, void *data);
581 extern void *mnt_table_get_userdata(struct libmnt_table *tb);
582
583 extern void mnt_table_enable_comments(struct libmnt_table *tb, int enable);
584 extern int mnt_table_with_comments(struct libmnt_table *tb);
585 extern const char *mnt_table_get_intro_comment(struct libmnt_table *tb);
586 extern int mnt_table_set_intro_comment(struct libmnt_table *tb, const char *comm);
587 extern int mnt_table_append_intro_comment(struct libmnt_table *tb, const char *comm);
588 extern int mnt_table_set_trailing_comment(struct libmnt_table *tb, const char *comm);
589 extern const char *mnt_table_get_trailing_comment(struct libmnt_table *tb);
590 extern int mnt_table_append_trailing_comment(struct libmnt_table *tb, const char *comm);
591
592 extern int mnt_table_set_cache(struct libmnt_table *tb, struct libmnt_cache *mpc);
593 extern struct libmnt_cache *mnt_table_get_cache(struct libmnt_table *tb);
594 extern int mnt_table_add_fs(struct libmnt_table *tb, struct libmnt_fs *fs);
595 extern int mnt_table_find_fs(struct libmnt_table *tb, struct libmnt_fs *fs);
596 extern int mnt_table_insert_fs(struct libmnt_table *tb, int before,
597 struct libmnt_fs *pos, struct libmnt_fs *fs);
598 extern int mnt_table_move_fs(struct libmnt_table *src, struct libmnt_table *dst,
599 int before, struct libmnt_fs *pos, struct libmnt_fs *fs);
600 extern int mnt_table_remove_fs(struct libmnt_table *tb, struct libmnt_fs *fs);
601 extern int mnt_table_first_fs(struct libmnt_table *tb, struct libmnt_fs **fs);
602 extern int mnt_table_last_fs(struct libmnt_table *tb, struct libmnt_fs **fs);
603 extern int mnt_table_over_fs(struct libmnt_table *tb, struct libmnt_fs *parent,
604 struct libmnt_fs **child);
605 extern int mnt_table_next_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
606 struct libmnt_fs **fs);
607 extern int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
608 struct libmnt_fs *parent, struct libmnt_fs **chld);
609 extern int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root);
610 extern int mnt_table_set_iter(struct libmnt_table *tb, struct libmnt_iter *itr,
611 struct libmnt_fs *fs);
612
613 enum {
614 MNT_UNIQ_FORWARD = (1 << 1), /* default is backward */
615 MNT_UNIQ_KEEPTREE = (1 << 2)
616 };
617 extern int mnt_table_uniq_fs(struct libmnt_table *tb, int flags,
618 int (*cmp)(struct libmnt_table *,
619 struct libmnt_fs *,
620 struct libmnt_fs *));
621
622 extern struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
623 const char *path, int direction);
624 extern struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb,
625 const char *path, int direction);
626 extern struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb,
627 const char *path, int direction);
628 extern struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
629 const char *val, int direction);
630 extern struct libmnt_fs *mnt_table_find_target_with_option(struct libmnt_table *tb, const char *path,
631 const char *option, const char *val, int direction);
632 extern struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
633 const char *source, int direction);
634 extern struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb,
635 const char *source,
636 const char *target, int direction);
637 extern struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb,
638 dev_t devno, int direction);
639
640 extern int mnt_table_find_next_fs(struct libmnt_table *tb,
641 struct libmnt_iter *itr,
642 int (*match_func)(struct libmnt_fs *, void *),
643 void *userdata,
644 struct libmnt_fs **fs);
645
646 extern int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs);
647
648 /* tab_update.c */
649 extern struct libmnt_update *mnt_new_update(void)
650 __ul_attribute__((warn_unused_result));
651 extern void mnt_free_update(struct libmnt_update *upd);
652
653 extern int mnt_table_replace_file(struct libmnt_table *tb, const char *filename);
654 extern int mnt_table_write_file(struct libmnt_table *tb, FILE *file);
655
656 extern int mnt_update_is_ready(struct libmnt_update *upd);
657 extern int mnt_update_set_fs(struct libmnt_update *upd, unsigned long mountflags,
658 const char *target, struct libmnt_fs *fs);
659 extern int mnt_update_table(struct libmnt_update *upd, struct libmnt_lock *lc);
660 extern unsigned long mnt_update_get_mflags(struct libmnt_update *upd);
661 extern int mnt_update_force_rdonly(struct libmnt_update *upd, int rdonly);
662 extern const char *mnt_update_get_filename(struct libmnt_update *upd);
663 extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
664
665 /* tab_diff.c */
666 enum {
667 MNT_TABDIFF_MOUNT = 1,
668 MNT_TABDIFF_UMOUNT,
669 MNT_TABDIFF_MOVE,
670 MNT_TABDIFF_REMOUNT,
671 MNT_TABDIFF_PROPAGATION, /* not implemented yet (TODO) */
672 };
673
674 extern struct libmnt_tabdiff *mnt_new_tabdiff(void)
675 __ul_attribute__((warn_unused_result));
676 extern void mnt_free_tabdiff(struct libmnt_tabdiff *df);
677
678 extern int mnt_diff_tables(struct libmnt_tabdiff *df,
679 struct libmnt_table *old_tab,
680 struct libmnt_table *new_tab);
681
682 extern int mnt_tabdiff_next_change(struct libmnt_tabdiff *df,
683 struct libmnt_iter *itr,
684 struct libmnt_fs **old_fs,
685 struct libmnt_fs **new_fs,
686 int *oper);
687
688 /* monitor.c */
689 enum {
690 MNT_MONITOR_TYPE_USERSPACE = 1, /* userspace mount options */
691 MNT_MONITOR_TYPE_KERNEL /* kernel mount table */
692 };
693
694 extern struct libmnt_monitor *mnt_new_monitor(void);
695 extern void mnt_ref_monitor(struct libmnt_monitor *mn);
696 extern void mnt_unref_monitor(struct libmnt_monitor *mn);
697
698 extern int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable);
699 extern int mnt_monitor_enable_userspace(struct libmnt_monitor *mn,
700 int enable, const char *filename);
701
702 extern int mnt_monitor_veil_kernel(struct libmnt_monitor *mn, int enable);
703
704 extern int mnt_monitor_get_fd(struct libmnt_monitor *mn);
705 extern int mnt_monitor_close_fd(struct libmnt_monitor *mn);
706 extern int mnt_monitor_wait(struct libmnt_monitor *mn, int timeout);
707
708 extern int mnt_monitor_next_change(struct libmnt_monitor *mn,
709 const char **filename, int *type);
710 extern int mnt_monitor_event_cleanup(struct libmnt_monitor *mn);
711
712
713 /* context.c */
714
715 /*
716 * Mode for mount options from fstab), see mnt_context_set_optsmode().
717 */
718 enum {
719 MNT_OMODE_IGNORE = (1 << 1), /* ignore fstab options */
720 MNT_OMODE_APPEND = (1 << 2), /* append fstab options to existing options */
721 MNT_OMODE_PREPEND = (1 << 3), /* prepend fstab options to existing options */
722 MNT_OMODE_REPLACE = (1 << 4), /* replace existing options with options from mtab/fstab */
723
724 MNT_OMODE_FORCE = (1 << 5), /* always read fstab options */
725
726 MNT_OMODE_FSTAB = (1 << 10), /* read from fstab */
727 MNT_OMODE_MTAB = (1 << 11), /* read from mountinfo if fstab not enabled or failed */
728 MNT_OMODE_NOTAB = (1 << 12), /* do not read fstab at all */
729
730 /* default */
731 MNT_OMODE_AUTO = (MNT_OMODE_PREPEND | MNT_OMODE_FSTAB | MNT_OMODE_MTAB),
732 /* non-root users */
733 MNT_OMODE_USER = (MNT_OMODE_REPLACE | MNT_OMODE_FORCE | MNT_OMODE_FSTAB)
734 };
735
736 extern struct libmnt_context *mnt_new_context(void)
737 __ul_attribute__((warn_unused_result));
738 extern void mnt_free_context(struct libmnt_context *cxt);
739
740 extern int mnt_reset_context(struct libmnt_context *cxt);
741 extern int mnt_context_is_restricted(struct libmnt_context *cxt)
742 __ul_attribute__((nonnull));
743 extern int mnt_context_force_unrestricted(struct libmnt_context *cxt);
744
745 extern int mnt_context_init_helper(struct libmnt_context *cxt,
746 int action, int flags);
747 extern int mnt_context_helper_setopt(struct libmnt_context *cxt, int c, char *arg);
748
749 extern int mnt_context_set_optsmode(struct libmnt_context *cxt, int mode);
750 extern int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable);
751 extern int mnt_context_enable_onlyonce(struct libmnt_context *cxt, int enable);
752 extern int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable);
753 extern int mnt_context_enable_rdonly_umount(struct libmnt_context *cxt, int enable);
754 extern int mnt_context_enable_rwonly_mount(struct libmnt_context *cxt, int enable);
755 extern int mnt_context_disable_helpers(struct libmnt_context *cxt, int disable);
756 extern int mnt_context_enable_sloppy(struct libmnt_context *cxt, int enable);
757 extern int mnt_context_enable_fake(struct libmnt_context *cxt, int enable);
758 extern int mnt_context_disable_mtab(struct libmnt_context *cxt, int disable);
759 extern int mnt_context_enable_force(struct libmnt_context *cxt, int enable);
760 extern int mnt_context_enable_verbose(struct libmnt_context *cxt, int enable);
761 extern int mnt_context_enable_loopdel(struct libmnt_context *cxt, int enable);
762 extern int mnt_context_enable_fork(struct libmnt_context *cxt, int enable);
763 extern int mnt_context_disable_swapmatch(struct libmnt_context *cxt, int disable);
764
765 extern int mnt_context_get_optsmode(struct libmnt_context *cxt);
766
767 extern int mnt_context_is_onlyonce(struct libmnt_context *cxt)
768 __ul_attribute__((nonnull));
769 extern int mnt_context_is_lazy(struct libmnt_context *cxt)
770 __ul_attribute__((nonnull));
771 extern int mnt_context_is_rdonly_umount(struct libmnt_context *cxt)
772 __ul_attribute__((nonnull));
773 extern int mnt_context_is_rwonly_mount(struct libmnt_context *cxt)
774 __ul_attribute__((nonnull));
775 extern int mnt_context_is_sloppy(struct libmnt_context *cxt)
776 __ul_attribute__((nonnull));
777 extern int mnt_context_is_fake(struct libmnt_context *cxt)
778 __ul_attribute__((nonnull));
779 extern int mnt_context_is_nomtab(struct libmnt_context *cxt)
780 __ul_attribute__((nonnull));
781 extern int mnt_context_is_force(struct libmnt_context *cxt)
782 __ul_attribute__((nonnull));
783 extern int mnt_context_is_verbose(struct libmnt_context *cxt)
784 __ul_attribute__((nonnull));
785 extern int mnt_context_is_loopdel(struct libmnt_context *cxt)
786 __ul_attribute__((nonnull));
787 extern int mnt_context_is_nohelpers(struct libmnt_context *cxt)
788 __ul_attribute__((nonnull));
789 extern int mnt_context_is_nocanonicalize(struct libmnt_context *cxt)
790 __ul_attribute__((nonnull));
791 extern int mnt_context_is_swapmatch(struct libmnt_context *cxt)
792 __ul_attribute__((nonnull));
793 extern int mnt_context_forced_rdonly(struct libmnt_context *cxt)
794 __ul_attribute__((nonnull));
795
796 extern int mnt_context_is_fork(struct libmnt_context *cxt)
797 __ul_attribute__((nonnull));
798 extern int mnt_context_is_parent(struct libmnt_context *cxt)
799 __ul_attribute__((nonnull));
800 extern int mnt_context_is_child(struct libmnt_context *cxt)
801 __ul_attribute__((nonnull));
802
803 extern int mnt_context_wait_for_children(struct libmnt_context *cxt,
804 int *nchildren, int *nerrs);
805
806 extern int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
807 struct libmnt_fs *fs, int *mounted);
808 extern int mnt_context_set_fs(struct libmnt_context *cxt, struct libmnt_fs *fs);
809 extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
810
811 extern int mnt_context_set_source(struct libmnt_context *cxt, const char *source);
812 extern int mnt_context_set_target(struct libmnt_context *cxt, const char *target);
813 extern int mnt_context_set_fstype(struct libmnt_context *cxt, const char *fstype);
814 extern int mnt_context_set_target_prefix(struct libmnt_context *cxt, const char *path);
815
816 extern const char *mnt_context_get_source(struct libmnt_context *cxt);
817 extern const char *mnt_context_get_target(struct libmnt_context *cxt);
818 extern const char *mnt_context_get_fstype(struct libmnt_context *cxt);
819 extern const char *mnt_context_get_target_prefix(struct libmnt_context *cxt);
820
821 extern void *mnt_context_get_mtab_userdata(struct libmnt_context *cxt);
822 extern void *mnt_context_get_fstab_userdata(struct libmnt_context *cxt);
823 extern void *mnt_context_get_fs_userdata(struct libmnt_context *cxt);
824
825 extern int mnt_context_set_options(struct libmnt_context *cxt, const char *optstr);
826 extern int mnt_context_append_options(struct libmnt_context *cxt, const char *optstr);
827
828 extern const char *mnt_context_get_options(struct libmnt_context *cxt);
829
830 extern int mnt_context_set_fstype_pattern(struct libmnt_context *cxt, const char *pattern);
831 extern int mnt_context_set_options_pattern(struct libmnt_context *cxt, const char *pattern);
832
833 extern int mnt_context_set_passwd_cb(struct libmnt_context *cxt,
834 char *(*get)(struct libmnt_context *),
835 void (*release)(struct libmnt_context *, char *))
836 __ul_attribute__((deprecated));
837
838 extern int mnt_context_set_tables_errcb(struct libmnt_context *cxt,
839 int (*cb)(struct libmnt_table *tb, const char *filename, int line));
840 extern int mnt_context_set_fstab(struct libmnt_context *cxt,
841 struct libmnt_table *tb);
842 extern int mnt_context_get_fstab(struct libmnt_context *cxt,
843 struct libmnt_table **tb);
844
845 extern int mnt_context_get_mtab(struct libmnt_context *cxt,
846 struct libmnt_table **tb);
847 extern int mnt_context_get_table(struct libmnt_context *cxt,
848 const char *filename,
849 struct libmnt_table **tb);
850 extern int mnt_context_set_cache(struct libmnt_context *cxt,
851 struct libmnt_cache *cache);
852 extern struct libmnt_cache *mnt_context_get_cache(struct libmnt_context *cxt);
853 extern struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt);
854 extern int mnt_context_set_mflags(struct libmnt_context *cxt,
855 unsigned long flags);
856 extern int mnt_context_get_mflags(struct libmnt_context *cxt,
857 unsigned long *flags);
858 extern int mnt_context_set_user_mflags(struct libmnt_context *cxt,
859 unsigned long flags);
860 extern int mnt_context_get_user_mflags(struct libmnt_context *cxt,
861 unsigned long *flags);
862
863 extern int mnt_context_set_mountdata(struct libmnt_context *cxt, void *data);
864 extern int mnt_context_apply_fstab(struct libmnt_context *cxt);
865
866 extern int mnt_context_reset_status(struct libmnt_context *cxt);
867 extern int mnt_context_get_status(struct libmnt_context *cxt);
868
869 extern int mnt_context_helper_executed(struct libmnt_context *cxt);
870 extern int mnt_context_get_helper_status(struct libmnt_context *cxt);
871
872 extern int mnt_context_syscall_called(struct libmnt_context *cxt);
873
874 extern int mnt_context_get_syscall_errno(struct libmnt_context *cxt);
875
876 extern int mnt_context_strerror(struct libmnt_context *cxt, char *buf,
877 size_t bufsiz)
878 __ul_attribute__((deprecated));
879
880 extern int mnt_context_enable_noautofs(struct libmnt_context *cxt, int ignore);
881
882 extern int mnt_context_get_excode(struct libmnt_context *cxt,
883 int rc, char *buf, size_t bufsz);
884
885 extern int mnt_context_set_target_ns(struct libmnt_context *cxt, const char *path);
886 extern struct libmnt_ns *mnt_context_get_target_ns(struct libmnt_context *cxt);
887 extern struct libmnt_ns *mnt_context_get_origin_ns(struct libmnt_context *cxt);
888 extern struct libmnt_ns *mnt_context_switch_ns(struct libmnt_context *cxt, struct libmnt_ns *ns);
889 extern struct libmnt_ns *mnt_context_switch_origin_ns(struct libmnt_context *cxt);
890 extern struct libmnt_ns *mnt_context_switch_target_ns(struct libmnt_context *cxt);
891
892
893 /* context_mount.c */
894 extern int mnt_context_mount(struct libmnt_context *cxt);
895 extern int mnt_context_umount(struct libmnt_context *cxt);
896 extern int mnt_context_next_mount(struct libmnt_context *cxt,
897 struct libmnt_iter *itr,
898 struct libmnt_fs **fs,
899 int *mntrc, int *ignored);
900
901 extern int mnt_context_next_remount(struct libmnt_context *cxt,
902 struct libmnt_iter *itr,
903 struct libmnt_fs **fs,
904 int *mntrc,
905 int *ignored);
906
907 extern int mnt_context_prepare_mount(struct libmnt_context *cxt)
908 __ul_attribute__((warn_unused_result));
909 extern int mnt_context_do_mount(struct libmnt_context *cxt);
910 extern int mnt_context_finalize_mount(struct libmnt_context *cxt);
911
912 /* context_umount.c */
913 extern int mnt_context_find_umount_fs(struct libmnt_context *cxt,
914 const char *tgt,
915 struct libmnt_fs **pfs);
916 extern int mnt_context_next_umount(struct libmnt_context *cxt,
917 struct libmnt_iter *itr,
918 struct libmnt_fs **fs,
919 int *mntrc, int *ignored);
920
921 extern int mnt_context_prepare_umount(struct libmnt_context *cxt)
922 __ul_attribute__((warn_unused_result));
923 extern int mnt_context_do_umount(struct libmnt_context *cxt);
924 extern int mnt_context_finalize_umount(struct libmnt_context *cxt);
925
926 extern int mnt_context_tab_applied(struct libmnt_context *cxt);
927 extern int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status);
928
929 /*
930 * mount(8) userspace options masks (MNT_MAP_USERSPACE map)
931 */
932 #define MNT_MS_NOAUTO (1 << 2)
933 #define MNT_MS_USER (1 << 3)
934 #define MNT_MS_USERS (1 << 4)
935 #define MNT_MS_OWNER (1 << 5)
936 #define MNT_MS_GROUP (1 << 6)
937 #define MNT_MS_NETDEV (1 << 7)
938 #define MNT_MS_COMMENT (1 << 8)
939 #define MNT_MS_LOOP (1 << 9)
940 #define MNT_MS_NOFAIL (1 << 10)
941 #define MNT_MS_UHELPER (1 << 11)
942 #define MNT_MS_HELPER (1 << 12)
943 #define MNT_MS_XCOMMENT (1 << 13)
944 #define MNT_MS_OFFSET (1 << 14)
945 #define MNT_MS_SIZELIMIT (1 << 15)
946 #define MNT_MS_ENCRYPTION (1 << 16)
947 #define MNT_MS_XFSTABCOMM (1 << 17)
948 #define MNT_MS_HASH_DEVICE (1 << 18)
949 #define MNT_MS_ROOT_HASH (1 << 19)
950 #define MNT_MS_HASH_OFFSET (1 << 20)
951 #define MNT_MS_ROOT_HASH_FILE (1 << 21)
952 #define MNT_MS_FEC_DEVICE (1 << 22)
953 #define MNT_MS_FEC_OFFSET (1 << 23)
954 #define MNT_MS_FEC_ROOTS (1 << 24)
955 #define MNT_MS_ROOT_HASH_SIG (1 << 25)
956 #define MNT_MS_VERITY_ON_CORRUPTION (1 << 26)
957
958 /*
959 * mount(2) MS_* masks (MNT_MAP_LINUX map)
960 */
961 #ifndef MS_RDONLY
962 #define MS_RDONLY 1 /* Mount read-only */
963 #endif
964 #ifndef MS_NOSUID
965 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
966 #endif
967 #ifndef MS_NODEV
968 #define MS_NODEV 4 /* Disallow access to device special files */
969 #endif
970 #ifndef MS_NOEXEC
971 #define MS_NOEXEC 8 /* Disallow program execution */
972 #endif
973 #ifndef MS_SYNCHRONOUS
974 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
975 #endif
976 #ifndef MS_REMOUNT
977 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
978 #endif
979 #ifndef MS_MANDLOCK
980 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
981 #endif
982 #ifndef MS_DIRSYNC
983 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
984 #endif
985 #ifndef MS_NOSYMFOLLOW
986 #define MS_NOSYMFOLLOW 256 /* Don't follow symlinks */
987 #endif
988 #ifndef MS_NOATIME
989 #define MS_NOATIME 0x400 /* 1024: Do not update access times. */
990 #endif
991 #ifndef MS_NODIRATIME
992 #define MS_NODIRATIME 0x800 /* 2048: Don't update directory access times */
993 #endif
994 #ifndef MS_BIND
995 #define MS_BIND 0x1000 /* 4096: Mount existing tree elsewhere as well */
996 #endif
997 #ifndef MS_MOVE
998 #define MS_MOVE 0x2000 /* 8192: Atomically move the tree */
999 #endif
1000 #ifndef MS_REC
1001 #define MS_REC 0x4000 /* 16384: Recursive loopback */
1002 #endif
1003 #ifndef MS_SILENT
1004 #define MS_SILENT 0x8000 /* 32768: Don't emit certain kernel messages */
1005 #endif
1006 #ifndef MS_UNBINDABLE
1007 #define MS_UNBINDABLE (1<<17) /* 131072: Make unbindable */
1008 #endif
1009 #ifndef MS_PRIVATE
1010 #define MS_PRIVATE (1<<18) /* 262144: Make private */
1011 #endif
1012 #ifndef MS_SLAVE
1013 #define MS_SLAVE (1<<19) /* 524288: Make slave */
1014 #endif
1015 #ifndef MS_SHARED
1016 #define MS_SHARED (1<<20) /* 1048576: Make shared */
1017 #endif
1018 #ifndef MS_RELATIME
1019 #define MS_RELATIME (1<<21) /* 2097152: Update atime relative to mtime/ctime */
1020 #endif
1021 #ifndef MS_I_VERSION
1022 #define MS_I_VERSION (1<<23) /* Update the inode I_version field */
1023 #endif
1024 #ifndef MS_STRICTATIME
1025 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
1026 #endif
1027 #ifndef MS_LAZYTIME
1028 #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
1029 #endif
1030
1031
1032 /*
1033 * Magic mount flag number. Had to be or-ed to the flag values. Deprecated and
1034 * no more used since libmount v2.33; required for Linux <= 2.4.
1035 */
1036 #ifndef MS_MGC_VAL
1037 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
1038 #endif
1039 #ifndef MS_MGC_MSK
1040 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
1041 #endif
1042
1043
1044 /* Shared-subtree options */
1045 #define MS_PROPAGATION (MS_SHARED|MS_SLAVE|MS_UNBINDABLE|MS_PRIVATE)
1046
1047 /* Options that we make ordinary users have by default. */
1048 #define MS_SECURE (MS_NOEXEC|MS_NOSUID|MS_NODEV)
1049
1050 /* Options that we make owner-mounted devices have by default */
1051 #define MS_OWNERSECURE (MS_NOSUID|MS_NODEV)
1052
1053 #ifdef __cplusplus
1054 }
1055 #endif
1056
1057 #endif /* _LIBMOUNT_MOUNT_H */