1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * libmount.h - libmount API
5 * This file is part of libmount from util-linux project.
7 * Copyright (C) 2008-2018 Karel Zak <kzak@redhat.com>
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.
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.
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.
24 #ifndef _LIBMOUNT_MOUNT_H
25 #define _LIBMOUNT_MOUNT_H
33 #include <sys/types.h>
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.
39 #if defined(__linux__) && !defined(MS_RDONLY)
40 # include <sys/mount.h>
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@
51 * Stores canonicalized paths and evaluated tags
58 * Stores information about the locked file
65 * Generic iterator (stores state about lists)
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
75 * Mount options description (map)
85 * mount options map masks
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() */
97 * Parsed fstab or mountinfo entry
104 * List of struct libmnt_fs entries (parsed fstab or mountinfo)
111 * utab update description
113 struct libmnt_update
;
118 * Mount/umount status
120 struct libmnt_context
;
125 * Mount tables monitor
127 struct libmnt_monitor
;
132 * Stores mountinfo state
134 struct libmnt_tabdiff
;
139 * Describes mount namespace
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
157 * See also mnt_context_get_syscall_errno() and mnt_context_get_helper_status().
162 * not found required entry in fstab
164 #define MNT_ERR_NOFSTAB 5000
168 * failed to detect filesystem type
170 #define MNT_ERR_NOFSTYPE 5001
174 * required mount source undefined
176 #define MNT_ERR_NOSOURCE 5002
180 * loopdev setup failed, errno set by libc
182 #define MNT_ERR_LOOPDEV 5003
186 * failed to parse/use userspace mount options
188 #define MNT_ERR_MOUNTOPT 5004
190 * MNT_ERR_APPLYFLAGS:
192 * failed to apply MS_PROPAGATION flags, and MOUNT_ATTR_* attributes for
195 #define MNT_ERR_APPLYFLAGS 5005
199 * libblkid detected more filesystems on the device
201 #define MNT_ERR_AMBIFS 5006
203 * MNT_ERR_LOOPOVERLAP:
205 * detected overlapping loop device that cannot be re-used
207 #define MNT_ERR_LOOPOVERLAP 5007
211 * failed to lock utab or so.
213 #define MNT_ERR_LOCK 5008
217 * failed to switch namespace
219 #define MNT_ERR_NAMESPACE 5009
223 * filesystem mounted, but --onlyonce specified
225 #define MNT_ERR_ONLYONCE 5010
229 * filesystem mounted, but subsequent X-mount.owner=/X-mount.group= lchown(2) failed
231 #define MNT_ERR_CHOWN 5011
235 * filesystem mounted, but subsequent X-mount.mode= chmod(2) failed
237 #define MNT_ERR_CHMOD 5012
241 * filesystem mounted, but subsequent X-mount.idmap= failed
243 #define MNT_ERR_IDMAP 5013
247 * Overall return codes -- based on mount(8) and umount(8) return codes.
248 * See mnt_context_get_excode() for more details.
254 * [u]mount(8) exit code: no errors
256 #define MNT_EX_SUCCESS 0
261 * [u]mount(8) exit code: incorrect invocation or permission
263 #define MNT_EX_USAGE 1
268 * [u]mount(8) exit code: out of memory, cannot fork, ...
270 #define MNT_EX_SYSERR 2
275 * [u]mount(8) exit code: internal mount bug or wrong version
277 #define MNT_EX_SOFTWARE 4
282 * [u]mount(8) exit code: user interrupt
284 #define MNT_EX_USER 8
289 * [u]mount(8) exit code: problems writing, locking, ... utab
291 #define MNT_EX_FILEIO 16
296 * [u]mount(8) exit code: mount failure
298 #define MNT_EX_FAIL 32
303 * [u]mount(8) exit code: some mount succeeded; usually when executed with
304 * --all options. Never returned by libmount.
306 #define MNT_EX_SOMEOK 64
310 #ifndef __GNUC_PREREQ
311 # if defined __GNUC__ && defined __GNUC_MINOR__
312 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
314 # define __GNUC_PREREQ(maj, min) 0
318 #ifndef __ul_attribute__
319 # if __GNUC_PREREQ (3, 4)
320 # define __ul_attribute__(_a_) __attribute__(_a_)
322 # define __ul_attribute__(_a_)
328 extern void mnt_init_debug(int mask
);
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
);
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
));
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
);
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)));
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
);
363 extern void mnt_ref_cache(struct libmnt_cache
*cache
);
364 extern void mnt_unref_cache(struct libmnt_cache
*cache
);
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
);
371 extern int mnt_cache_device_has_tag(struct libmnt_cache
*cache
,
376 extern char *mnt_cache_find_tag_value(struct libmnt_cache
*cache
,
377 const char *devname
, const char *token
);
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
));
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
,
399 extern int mnt_optstr_prepend_option(char **optstr
, const char *name
,
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
,
406 extern int mnt_optstr_remove_option(char **optstr
, const char *name
);
407 extern int mnt_optstr_deduplicate_option(char **optstr
, const char *name
);
409 extern int mnt_split_optstr(const char *optstr
,
410 char **user
, char **vfs
, char **fs
,
411 int ignore_user
, int ignore_vfs
);
413 extern int mnt_optstr_get_options(const char *optstr
, char **subset
,
414 const struct libmnt_optmap
*map
, int ignore
);
416 extern int mnt_optstr_get_flags(const char *optstr
, unsigned long *flags
,
417 const struct libmnt_optmap
*map
);
419 extern int mnt_optstr_apply_flags(char **optstr
, unsigned long flags
,
420 const struct libmnt_optmap
*map
);
425 MNT_ITER_FORWARD
= 0,
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
);
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
));
442 extern const struct libmnt_optmap
*mnt_get_builtin_optmap(int id
);
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
);
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
);
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
);
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
);
473 extern int mnt_fs_get_tag(struct libmnt_fs
*fs
, const char **name
,
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
);
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
));
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
);
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
);
497 extern int mnt_fs_get_option(struct libmnt_fs
*fs
, const char *name
,
498 char **value
, size_t *valsz
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
549 extern void mnt_free_mntent(struct mntent
*mnt
);
550 extern int mnt_fs_to_mntent(struct libmnt_fs
*fs
, struct mntent
**mnt
);
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
);
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
));
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
);
573 extern void mnt_ref_table(struct libmnt_table
*tb
);
574 extern void mnt_unref_table(struct libmnt_table
*tb
);
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
);
580 extern int mnt_table_set_userdata(struct libmnt_table
*tb
, void *data
);
581 extern void *mnt_table_get_userdata(struct libmnt_table
*tb
);
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
);
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
);
614 MNT_UNIQ_FORWARD
= (1 << 1), /* default is backward */
615 MNT_UNIQ_KEEPTREE
= (1 << 2)
617 extern int mnt_table_uniq_fs(struct libmnt_table
*tb
, int flags
,
618 int (*cmp
)(struct libmnt_table
*,
620 struct libmnt_fs
*));
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
,
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
);
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 *),
644 struct libmnt_fs
**fs
);
646 extern int mnt_table_is_fs_mounted(struct libmnt_table
*tb
, struct libmnt_fs
*fstab_fs
);
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
);
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
);
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
);
667 MNT_TABDIFF_MOUNT
= 1,
671 MNT_TABDIFF_PROPAGATION
, /* not implemented yet (TODO) */
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
);
678 extern int mnt_diff_tables(struct libmnt_tabdiff
*df
,
679 struct libmnt_table
*old_tab
,
680 struct libmnt_table
*new_tab
);
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
,
690 MNT_MONITOR_TYPE_USERSPACE
= 1, /* userspace mount options */
691 MNT_MONITOR_TYPE_KERNEL
/* kernel mount table */
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
);
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
);
702 extern int mnt_monitor_veil_kernel(struct libmnt_monitor
*mn
, int enable
);
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
);
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
);
716 * Mode for mount options from fstab), see mnt_context_set_optsmode().
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 */
724 MNT_OMODE_FORCE
= (1 << 5), /* always read fstab options */
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 */
731 MNT_OMODE_AUTO
= (MNT_OMODE_PREPEND
| MNT_OMODE_FSTAB
| MNT_OMODE_MTAB
),
733 MNT_OMODE_USER
= (MNT_OMODE_REPLACE
| MNT_OMODE_FORCE
| MNT_OMODE_FSTAB
)
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
);
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
);
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
);
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
);
765 extern int mnt_context_get_optsmode(struct libmnt_context
*cxt
);
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
));
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
));
803 extern int mnt_context_wait_for_children(struct libmnt_context
*cxt
,
804 int *nchildren
, int *nerrs
);
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
);
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
);
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
);
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
);
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
);
828 extern const char *mnt_context_get_options(struct libmnt_context
*cxt
);
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
);
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
));
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
);
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
);
863 extern int mnt_context_set_mountdata(struct libmnt_context
*cxt
, void *data
);
864 extern int mnt_context_apply_fstab(struct libmnt_context
*cxt
);
866 extern int mnt_context_reset_status(struct libmnt_context
*cxt
);
867 extern int mnt_context_get_status(struct libmnt_context
*cxt
);
869 extern int mnt_context_helper_executed(struct libmnt_context
*cxt
);
870 extern int mnt_context_get_helper_status(struct libmnt_context
*cxt
);
872 extern int mnt_context_syscall_called(struct libmnt_context
*cxt
);
874 extern int mnt_context_get_syscall_errno(struct libmnt_context
*cxt
);
876 extern int mnt_context_strerror(struct libmnt_context
*cxt
, char *buf
,
878 __ul_attribute__((deprecated
));
880 extern int mnt_context_enable_noautofs(struct libmnt_context
*cxt
, int ignore
);
882 extern int mnt_context_get_excode(struct libmnt_context
*cxt
,
883 int rc
, char *buf
, size_t bufsz
);
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
);
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
);
901 extern int mnt_context_next_remount(struct libmnt_context
*cxt
,
902 struct libmnt_iter
*itr
,
903 struct libmnt_fs
**fs
,
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
);
912 /* context_umount.c */
913 extern int mnt_context_find_umount_fs(struct libmnt_context
*cxt
,
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
);
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
);
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
);
930 * mount(8) userspace options masks (MNT_MAP_USERSPACE map)
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)
959 * mount(2) MS_* masks (MNT_MAP_LINUX map)
962 #define MS_RDONLY 1 /* Mount read-only */
965 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
968 #define MS_NODEV 4 /* Disallow access to device special files */
971 #define MS_NOEXEC 8 /* Disallow program execution */
973 #ifndef MS_SYNCHRONOUS
974 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
977 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
980 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
983 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
985 #ifndef MS_NOSYMFOLLOW
986 #define MS_NOSYMFOLLOW 256 /* Don't follow symlinks */
989 #define MS_NOATIME 0x400 /* 1024: Do not update access times. */
991 #ifndef MS_NODIRATIME
992 #define MS_NODIRATIME 0x800 /* 2048: Don't update directory access times */
995 #define MS_BIND 0x1000 /* 4096: Mount existing tree elsewhere as well */
998 #define MS_MOVE 0x2000 /* 8192: Atomically move the tree */
1001 #define MS_REC 0x4000 /* 16384: Recursive loopback */
1004 #define MS_SILENT 0x8000 /* 32768: Don't emit certain kernel messages */
1006 #ifndef MS_UNBINDABLE
1007 #define MS_UNBINDABLE (1<<17) /* 131072: Make unbindable */
1010 #define MS_PRIVATE (1<<18) /* 262144: Make private */
1013 #define MS_SLAVE (1<<19) /* 524288: Make slave */
1016 #define MS_SHARED (1<<20) /* 1048576: Make shared */
1019 #define MS_RELATIME (1<<21) /* 2097152: Update atime relative to mtime/ctime */
1021 #ifndef MS_I_VERSION
1022 #define MS_I_VERSION (1<<23) /* Update the inode I_version field */
1024 #ifndef MS_STRICTATIME
1025 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
1028 #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
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.
1037 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
1040 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
1044 /* Shared-subtree options */
1045 #define MS_PROPAGATION (MS_SHARED|MS_SLAVE|MS_UNBINDABLE|MS_PRIVATE)
1047 /* Options that we make ordinary users have by default. */
1048 #define MS_SECURE (MS_NOEXEC|MS_NOSUID|MS_NODEV)
1050 /* Options that we make owner-mounted devices have by default */
1051 #define MS_OWNERSECURE (MS_NOSUID|MS_NODEV)
1057 #endif /* _LIBMOUNT_MOUNT_H */