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 (e.g. /etc/mtab)
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 */
95 * Parsed fstab/mtab/mountinfo entry
102 * List of struct libmnt_fs entries (parsed fstab/mtab/mountinfo)
109 * /etc/mtab or utab update description
111 struct libmnt_update
;
116 * Mount/umount status
118 struct libmnt_context
;
123 * Mount tables monitor
125 struct libmnt_monitor
;
130 * Stores mountinfo state
132 struct libmnt_tabdiff
;
137 * Describes mount namespace
150 * Errors -- by default libmount returns -errno for generic errors (ENOMEM,
151 * EINVAL, ...) and for mount(2) errors, but for some specific operations it
152 * returns private error codes. Note that maximum system errno value should be
155 * See also mnt_context_get_syscall_errno() and mnt_context_get_helper_status().
160 * not found required entry in fstab
162 #define MNT_ERR_NOFSTAB 5000
166 * failed to detect filesystem type
168 #define MNT_ERR_NOFSTYPE 5001
172 * required mount source undefined
174 #define MNT_ERR_NOSOURCE 5002
178 * loopdev setup failed, errno set by libc
180 #define MNT_ERR_LOOPDEV 5003
184 * failed to parse/use userspace mount options
186 #define MNT_ERR_MOUNTOPT 5004
188 * MNT_ERR_APPLYFLAGS:
190 * failed to apply MS_PROPAGATION flags
192 #define MNT_ERR_APPLYFLAGS 5005
196 * libblkid detected more filesystems on the device
198 #define MNT_ERR_AMBIFS 5006
200 * MNT_ERR_LOOPOVERLAP:
202 * detected overlapping loop device that cannot be re-used
204 #define MNT_ERR_LOOPOVERLAP 5007
208 * failed to lock mtab/utab or so.
210 #define MNT_ERR_LOCK 5008
214 * failed to switch namespace
216 #define MNT_ERR_NAMESPACE 5009
220 * Overall return codes -- based on mount(8) and umount(8) return codes.
221 * See mnt_context_get_excode() for more details.
227 * [u]mount(8) exit code: no errors
229 #define MNT_EX_SUCCESS 0
234 * [u]mount(8) exit code: incorrect invocation or permission
236 #define MNT_EX_USAGE 1
241 * [u]mount(8) exit code: out of memory, cannot fork, ...
244 #define MNT_EX_SYSERR 2
249 * [u]mount(8) exit code: internal mount bug or wrong version
251 #define MNT_EX_SOFTWARE 4
256 * [u]mount(8) exit code: user interrupt
258 #define MNT_EX_USER 8
263 * [u]mount(8) exit code: problems writing, locking, ... mtab/utab
265 #define MNT_EX_FILEIO 16
270 * [u]mount(8) exit code: mount failure
272 #define MNT_EX_FAIL 32
277 * [u]mount(8) exit code: some mount succeeded; usually when executed with
278 * --all options. Never returned by libmount.
280 #define MNT_EX_SOMEOK 64
284 #ifndef __GNUC_PREREQ
285 # if defined __GNUC__ && defined __GNUC_MINOR__
286 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
288 # define __GNUC_PREREQ(maj, min) 0
292 #ifndef __ul_attribute__
293 # if __GNUC_PREREQ (3, 4)
294 # define __ul_attribute__(_a_) __attribute__(_a_)
296 # define __ul_attribute__(_a_)
302 extern void mnt_init_debug(int mask
);
305 extern int mnt_parse_version_string(const char *ver_string
);
306 extern int mnt_get_library_version(const char **ver_string
);
307 extern int mnt_get_library_features(const char ***features
);
310 extern char *mnt_mangle(const char *str
)
311 __ul_attribute__((warn_unused_result
));
312 extern char *mnt_unmangle(const char *str
)
313 __ul_attribute__((warn_unused_result
));
315 extern int mnt_tag_is_valid(const char *tag
);
316 extern int mnt_fstype_is_netfs(const char *type
);
317 extern int mnt_fstype_is_pseudofs(const char *type
);
319 extern int mnt_match_fstype(const char *type
, const char *pattern
)
320 __ul_attribute__((warn_unused_result
));
321 extern int mnt_match_options(const char *optstr
, const char *pattern
)
322 __ul_attribute__((warn_unused_result
));
323 extern const char *mnt_get_fstab_path(void);
324 extern const char *mnt_get_swaps_path(void);
325 extern const char *mnt_get_mtab_path(void);
326 extern int mnt_has_regular_mtab(const char **mtab
, int *writable
);
327 extern char *mnt_get_mountpoint(const char *path
)
328 __ul_attribute__((warn_unused_result
));
329 extern int mnt_guess_system_root(dev_t devno
, struct libmnt_cache
*cache
, char **path
)
330 __ul_attribute__((nonnull(3)));
333 extern struct libmnt_cache
*mnt_new_cache(void)
334 __ul_attribute__((warn_unused_result
));
335 extern void mnt_free_cache(struct libmnt_cache
*cache
);
337 extern void mnt_ref_cache(struct libmnt_cache
*cache
);
338 extern void mnt_unref_cache(struct libmnt_cache
*cache
);
340 extern int mnt_cache_set_targets(struct libmnt_cache
*cache
,
341 struct libmnt_table
*mtab
);
342 extern int mnt_cache_read_tags(struct libmnt_cache
*cache
, const char *devname
);
344 extern int mnt_cache_device_has_tag(struct libmnt_cache
*cache
,
349 extern char *mnt_cache_find_tag_value(struct libmnt_cache
*cache
,
350 const char *devname
, const char *token
);
352 extern char *mnt_get_fstype(const char *devname
, int *ambi
,
353 struct libmnt_cache
*cache
)
354 __ul_attribute__((warn_unused_result
));
355 extern char *mnt_resolve_path(const char *path
, struct libmnt_cache
*cache
)
356 __ul_attribute__((warn_unused_result
));
357 extern char *mnt_resolve_target(const char *path
, struct libmnt_cache
*cache
)
358 __ul_attribute__((warn_unused_result
));
359 extern char *mnt_resolve_tag(const char *token
, const char *value
,
360 struct libmnt_cache
*cache
)
361 __ul_attribute__((warn_unused_result
));
362 extern char *mnt_resolve_spec(const char *spec
, struct libmnt_cache
*cache
)
363 __ul_attribute__((warn_unused_result
));
364 extern char *mnt_pretty_path(const char *path
, struct libmnt_cache
*cache
)
365 __ul_attribute__((warn_unused_result
));
368 extern int mnt_optstr_next_option(char **optstr
, char **name
, size_t *namesz
,
369 char **value
, size_t *valuesz
);
370 extern int mnt_optstr_append_option(char **optstr
, const char *name
,
372 extern int mnt_optstr_prepend_option(char **optstr
, const char *name
,
375 extern int mnt_optstr_get_option(const char *optstr
, const char *name
,
376 char **value
, size_t *valsz
);
377 extern int mnt_optstr_set_option(char **optstr
, const char *name
,
379 extern int mnt_optstr_remove_option(char **optstr
, const char *name
);
380 extern int mnt_optstr_deduplicate_option(char **optstr
, const char *name
);
382 extern int mnt_split_optstr(const char *optstr
,
383 char **user
, char **vfs
, char **fs
,
384 int ignore_user
, int ignore_vfs
);
386 extern int mnt_optstr_get_options(const char *optstr
, char **subset
,
387 const struct libmnt_optmap
*map
, int ignore
);
389 extern int mnt_optstr_get_flags(const char *optstr
, unsigned long *flags
,
390 const struct libmnt_optmap
*map
);
392 extern int mnt_optstr_apply_flags(char **optstr
, unsigned long flags
,
393 const struct libmnt_optmap
*map
);
398 MNT_ITER_FORWARD
= 0,
401 extern struct libmnt_iter
*mnt_new_iter(int direction
)
402 __ul_attribute__((warn_unused_result
));
403 extern void mnt_free_iter(struct libmnt_iter
*itr
);
405 extern void mnt_reset_iter(struct libmnt_iter
*itr
, int direction
)
406 __ul_attribute__((nonnull
));
407 extern int mnt_iter_get_direction(struct libmnt_iter
*itr
)
408 __ul_attribute__((nonnull
));
415 extern const struct libmnt_optmap
*mnt_get_builtin_optmap(int id
);
418 extern struct libmnt_lock
*mnt_new_lock(const char *datafile
, pid_t id
)
419 __ul_attribute__((warn_unused_result
));
420 extern void mnt_free_lock(struct libmnt_lock
*ml
);
422 extern void mnt_unlock_file(struct libmnt_lock
*ml
);
423 extern int mnt_lock_file(struct libmnt_lock
*ml
);
424 extern int mnt_lock_block_signals(struct libmnt_lock
*ml
, int enable
);
427 extern struct libmnt_fs
*mnt_new_fs(void)
428 __ul_attribute__((warn_unused_result
));
429 extern void mnt_free_fs(struct libmnt_fs
*fs
);
430 extern void mnt_ref_fs(struct libmnt_fs
*fs
);
431 extern void mnt_unref_fs(struct libmnt_fs
*fs
);
433 extern void mnt_reset_fs(struct libmnt_fs
*fs
);
434 extern struct libmnt_fs
*mnt_copy_fs(struct libmnt_fs
*dest
,
435 const struct libmnt_fs
*src
)
436 __ul_attribute__((warn_unused_result
));
437 extern void *mnt_fs_get_userdata(struct libmnt_fs
*fs
);
438 extern int mnt_fs_set_userdata(struct libmnt_fs
*fs
, void *data
);
439 extern const char *mnt_fs_get_source(struct libmnt_fs
*fs
);
440 extern int mnt_fs_set_source(struct libmnt_fs
*fs
, const char *source
);
441 extern const char *mnt_fs_get_srcpath(struct libmnt_fs
*fs
);
442 extern int mnt_fs_get_table(struct libmnt_fs
*fs
, struct libmnt_table
**tb
);
444 extern int mnt_fs_get_tag(struct libmnt_fs
*fs
, const char **name
,
446 extern const char *mnt_fs_get_target(struct libmnt_fs
*fs
);
447 extern int mnt_fs_set_target(struct libmnt_fs
*fs
, const char *tgt
);
448 extern const char *mnt_fs_get_fstype(struct libmnt_fs
*fs
);
449 extern int mnt_fs_set_fstype(struct libmnt_fs
*fs
, const char *fstype
);
451 extern int mnt_fs_streq_srcpath(struct libmnt_fs
*fs
, const char *path
)
452 __ul_attribute__((warn_unused_result
));
453 extern int mnt_fs_streq_target(struct libmnt_fs
*fs
, const char *path
)
454 __ul_attribute__((warn_unused_result
));
456 extern char *mnt_fs_strdup_options(struct libmnt_fs
*fs
)
457 __ul_attribute__((warn_unused_result
));
458 extern const char *mnt_fs_get_options(struct libmnt_fs
*fs
)
459 __ul_attribute__((warn_unused_result
));
460 extern const char *mnt_fs_get_optional_fields(struct libmnt_fs
*fs
)
461 __ul_attribute__((warn_unused_result
));
462 extern int mnt_fs_get_propagation(struct libmnt_fs
*fs
, unsigned long *flags
);
464 extern int mnt_fs_set_options(struct libmnt_fs
*fs
, const char *optstr
);
465 extern int mnt_fs_append_options(struct libmnt_fs
*fs
, const char *optstr
);
466 extern int mnt_fs_prepend_options(struct libmnt_fs
*fs
, const char *optstr
);
468 extern int mnt_fs_get_option(struct libmnt_fs
*fs
, const char *name
,
469 char **value
, size_t *valsz
);
471 extern const char *mnt_fs_get_fs_options(struct libmnt_fs
*fs
);
472 extern const char *mnt_fs_get_vfs_options(struct libmnt_fs
*fs
);
473 extern const char *mnt_fs_get_user_options(struct libmnt_fs
*fs
);
475 extern const char *mnt_fs_get_attributes(struct libmnt_fs
*fs
);
476 extern int mnt_fs_set_attributes(struct libmnt_fs
*fs
, const char *optstr
);
477 extern int mnt_fs_get_attribute(struct libmnt_fs
*fs
, const char *name
,
478 char **value
, size_t *valsz
);
479 extern int mnt_fs_append_attributes(struct libmnt_fs
*fs
, const char *optstr
);
480 extern int mnt_fs_prepend_attributes(struct libmnt_fs
*fs
, const char *optstr
);
482 extern int mnt_fs_get_freq(struct libmnt_fs
*fs
);
483 extern int mnt_fs_set_freq(struct libmnt_fs
*fs
, int freq
);
484 extern int mnt_fs_get_passno(struct libmnt_fs
*fs
);
485 extern int mnt_fs_set_passno(struct libmnt_fs
*fs
, int passno
);
486 extern const char *mnt_fs_get_root(struct libmnt_fs
*fs
);
487 extern int mnt_fs_set_root(struct libmnt_fs
*fs
, const char *path
);
488 extern const char *mnt_fs_get_bindsrc(struct libmnt_fs
*fs
);
489 extern int mnt_fs_set_bindsrc(struct libmnt_fs
*fs
, const char *src
);
490 extern int mnt_fs_get_id(struct libmnt_fs
*fs
);
491 extern int mnt_fs_get_parent_id(struct libmnt_fs
*fs
);
492 extern dev_t
mnt_fs_get_devno(struct libmnt_fs
*fs
);
493 extern pid_t
mnt_fs_get_tid(struct libmnt_fs
*fs
);
495 extern const char *mnt_fs_get_swaptype(struct libmnt_fs
*fs
);
496 extern off_t
mnt_fs_get_size(struct libmnt_fs
*fs
);
497 extern off_t
mnt_fs_get_usedsize(struct libmnt_fs
*fs
);
498 extern int mnt_fs_get_priority(struct libmnt_fs
*fs
);
499 extern int mnt_fs_set_priority(struct libmnt_fs
*fs
, int prio
);
501 extern const char *mnt_fs_get_comment(struct libmnt_fs
*fs
);
502 extern int mnt_fs_set_comment(struct libmnt_fs
*fs
, const char *comm
);
503 extern int mnt_fs_append_comment(struct libmnt_fs
*fs
, const char *comm
);
505 extern int mnt_fs_match_target(struct libmnt_fs
*fs
, const char *target
,
506 struct libmnt_cache
*cache
);
507 extern int mnt_fs_match_source(struct libmnt_fs
*fs
, const char *source
,
508 struct libmnt_cache
*cache
);
509 extern int mnt_fs_match_fstype(struct libmnt_fs
*fs
, const char *types
);
510 extern int mnt_fs_match_options(struct libmnt_fs
*fs
, const char *options
);
511 extern int mnt_fs_print_debug(struct libmnt_fs
*fs
, FILE *file
);
513 extern int mnt_fs_is_kernel(struct libmnt_fs
*fs
);
514 extern int mnt_fs_is_swaparea(struct libmnt_fs
*fs
);
515 extern int mnt_fs_is_netfs(struct libmnt_fs
*fs
);
516 extern int mnt_fs_is_pseudofs(struct libmnt_fs
*fs
);
518 extern void mnt_free_mntent(struct mntent
*mnt
);
519 extern int mnt_fs_to_mntent(struct libmnt_fs
*fs
, struct mntent
**mnt
);
522 extern struct libmnt_table
*mnt_new_table_from_file(const char *filename
)
523 __ul_attribute__((warn_unused_result
));
524 extern struct libmnt_table
*mnt_new_table_from_dir(const char *dirname
)
525 __ul_attribute__((warn_unused_result
));
526 extern int mnt_table_parse_stream(struct libmnt_table
*tb
, FILE *f
,
527 const char *filename
);
528 extern int mnt_table_parse_file(struct libmnt_table
*tb
, const char *filename
);
529 extern int mnt_table_parse_dir(struct libmnt_table
*tb
, const char *dirname
);
531 extern int mnt_table_parse_fstab(struct libmnt_table
*tb
, const char *filename
);
532 extern int mnt_table_parse_swaps(struct libmnt_table
*tb
, const char *filename
);
533 extern int mnt_table_parse_mtab(struct libmnt_table
*tb
, const char *filename
);
534 extern int mnt_table_set_parser_errcb(struct libmnt_table
*tb
,
535 int (*cb
)(struct libmnt_table
*tb
, const char *filename
, int line
));
538 extern struct libmnt_table
*mnt_new_table(void)
539 __ul_attribute__((warn_unused_result
));
540 extern void mnt_free_table(struct libmnt_table
*tb
);
542 extern void mnt_ref_table(struct libmnt_table
*tb
);
543 extern void mnt_unref_table(struct libmnt_table
*tb
);
545 extern int mnt_reset_table(struct libmnt_table
*tb
);
546 extern int mnt_table_get_nents(struct libmnt_table
*tb
);
547 extern int mnt_table_is_empty(struct libmnt_table
*tb
);
549 extern int mnt_table_set_userdata(struct libmnt_table
*tb
, void *data
);
550 extern void *mnt_table_get_userdata(struct libmnt_table
*tb
);
552 extern void mnt_table_enable_comments(struct libmnt_table
*tb
, int enable
);
553 extern int mnt_table_with_comments(struct libmnt_table
*tb
);
554 extern const char *mnt_table_get_intro_comment(struct libmnt_table
*tb
);
555 extern int mnt_table_set_intro_comment(struct libmnt_table
*tb
, const char *comm
);
556 extern int mnt_table_append_intro_comment(struct libmnt_table
*tb
, const char *comm
);
557 extern int mnt_table_set_trailing_comment(struct libmnt_table
*tb
, const char *comm
);
558 extern const char *mnt_table_get_trailing_comment(struct libmnt_table
*tb
);
559 extern int mnt_table_append_trailing_comment(struct libmnt_table
*tb
, const char *comm
);
561 extern int mnt_table_set_cache(struct libmnt_table
*tb
, struct libmnt_cache
*mpc
);
562 extern struct libmnt_cache
*mnt_table_get_cache(struct libmnt_table
*tb
);
563 extern int mnt_table_add_fs(struct libmnt_table
*tb
, struct libmnt_fs
*fs
);
564 extern int mnt_table_find_fs(struct libmnt_table
*tb
, struct libmnt_fs
*fs
);
565 extern int mnt_table_insert_fs(struct libmnt_table
*tb
, int before
,
566 struct libmnt_fs
*pos
, struct libmnt_fs
*fs
);
567 extern int mnt_table_move_fs(struct libmnt_table
*src
, struct libmnt_table
*dst
,
568 int before
, struct libmnt_fs
*pos
, struct libmnt_fs
*fs
);
569 extern int mnt_table_remove_fs(struct libmnt_table
*tb
, struct libmnt_fs
*fs
);
570 extern int mnt_table_first_fs(struct libmnt_table
*tb
, struct libmnt_fs
**fs
);
571 extern int mnt_table_last_fs(struct libmnt_table
*tb
, struct libmnt_fs
**fs
);
572 extern int mnt_table_next_fs(struct libmnt_table
*tb
, struct libmnt_iter
*itr
,
573 struct libmnt_fs
**fs
);
574 extern int mnt_table_next_child_fs(struct libmnt_table
*tb
, struct libmnt_iter
*itr
,
575 struct libmnt_fs
*parent
, struct libmnt_fs
**chld
);
576 extern int mnt_table_get_root_fs(struct libmnt_table
*tb
, struct libmnt_fs
**root
);
577 extern int mnt_table_set_iter(struct libmnt_table
*tb
, struct libmnt_iter
*itr
,
578 struct libmnt_fs
*fs
);
581 MNT_UNIQ_FORWARD
= (1 << 1), /* default is backward */
582 MNT_UNIQ_KEEPTREE
= (1 << 2)
584 extern int mnt_table_uniq_fs(struct libmnt_table
*tb
, int flags
,
585 int (*cmp
)(struct libmnt_table
*,
587 struct libmnt_fs
*));
589 extern struct libmnt_fs
*mnt_table_find_mountpoint(struct libmnt_table
*tb
,
590 const char *path
, int direction
);
591 extern struct libmnt_fs
*mnt_table_find_target(struct libmnt_table
*tb
,
592 const char *path
, int direction
);
593 extern struct libmnt_fs
*mnt_table_find_srcpath(struct libmnt_table
*tb
,
594 const char *path
, int direction
);
595 extern struct libmnt_fs
*mnt_table_find_tag(struct libmnt_table
*tb
, const char *tag
,
596 const char *val
, int direction
);
597 extern struct libmnt_fs
*mnt_table_find_target_with_option(struct libmnt_table
*tb
, const char *path
,
598 const char *option
, const char *val
, int direction
);
599 extern struct libmnt_fs
*mnt_table_find_source(struct libmnt_table
*tb
,
600 const char *source
, int direction
);
601 extern struct libmnt_fs
*mnt_table_find_pair(struct libmnt_table
*tb
,
603 const char *target
, int direction
);
604 extern struct libmnt_fs
*mnt_table_find_devno(struct libmnt_table
*tb
,
605 dev_t devno
, int direction
);
607 extern int mnt_table_find_next_fs(struct libmnt_table
*tb
,
608 struct libmnt_iter
*itr
,
609 int (*match_func
)(struct libmnt_fs
*, void *),
611 struct libmnt_fs
**fs
);
613 extern int mnt_table_is_fs_mounted(struct libmnt_table
*tb
, struct libmnt_fs
*fstab_fs
);
616 extern struct libmnt_update
*mnt_new_update(void)
617 __ul_attribute__((warn_unused_result
));
618 extern void mnt_free_update(struct libmnt_update
*upd
);
620 extern int mnt_table_replace_file(struct libmnt_table
*tb
, const char *filename
);
621 extern int mnt_table_write_file(struct libmnt_table
*tb
, FILE *file
);
623 extern int mnt_update_is_ready(struct libmnt_update
*upd
);
624 extern int mnt_update_set_fs(struct libmnt_update
*upd
, unsigned long mountflags
,
625 const char *target
, struct libmnt_fs
*fs
);
626 extern int mnt_update_table(struct libmnt_update
*upd
, struct libmnt_lock
*lc
);
627 extern unsigned long mnt_update_get_mflags(struct libmnt_update
*upd
);
628 extern int mnt_update_force_rdonly(struct libmnt_update
*upd
, int rdonly
);
629 extern const char *mnt_update_get_filename(struct libmnt_update
*upd
);
630 extern struct libmnt_fs
*mnt_update_get_fs(struct libmnt_update
*upd
);
634 MNT_TABDIFF_MOUNT
= 1,
638 MNT_TABDIFF_PROPAGATION
, /* not implemented yet (TODO) */
641 extern struct libmnt_tabdiff
*mnt_new_tabdiff(void)
642 __ul_attribute__((warn_unused_result
));
643 extern void mnt_free_tabdiff(struct libmnt_tabdiff
*df
);
645 extern int mnt_diff_tables(struct libmnt_tabdiff
*df
,
646 struct libmnt_table
*old_tab
,
647 struct libmnt_table
*new_tab
);
649 extern int mnt_tabdiff_next_change(struct libmnt_tabdiff
*df
,
650 struct libmnt_iter
*itr
,
651 struct libmnt_fs
**old_fs
,
652 struct libmnt_fs
**new_fs
,
657 MNT_MONITOR_TYPE_USERSPACE
= 1, /* userspace mount options */
658 MNT_MONITOR_TYPE_KERNEL
/* kernel mount table */
661 extern struct libmnt_monitor
*mnt_new_monitor(void);
662 extern void mnt_ref_monitor(struct libmnt_monitor
*mn
);
663 extern void mnt_unref_monitor(struct libmnt_monitor
*mn
);
665 extern int mnt_monitor_enable_kernel(struct libmnt_monitor
*mn
, int enable
);
666 extern int mnt_monitor_enable_userspace(struct libmnt_monitor
*mn
,
667 int enable
, const char *filename
);
669 extern int mnt_monitor_get_fd(struct libmnt_monitor
*mn
);
670 extern int mnt_monitor_close_fd(struct libmnt_monitor
*mn
);
671 extern int mnt_monitor_wait(struct libmnt_monitor
*mn
, int timeout
);
673 extern int mnt_monitor_next_change(struct libmnt_monitor
*mn
,
674 const char **filename
, int *type
);
675 extern int mnt_monitor_event_cleanup(struct libmnt_monitor
*mn
);
681 * Mode for mount options from fstab (or mtab), see mnt_context_set_optsmode().
684 MNT_OMODE_IGNORE
= (1 << 1), /* ignore mtab/fstab options */
685 MNT_OMODE_APPEND
= (1 << 2), /* append mtab/fstab options to existing options */
686 MNT_OMODE_PREPEND
= (1 << 3), /* prepend mtab/fstab options to existing options */
687 MNT_OMODE_REPLACE
= (1 << 4), /* replace existing options with options from mtab/fstab */
689 MNT_OMODE_FORCE
= (1 << 5), /* always read mtab/fstab options */
691 MNT_OMODE_FSTAB
= (1 << 10), /* read from fstab */
692 MNT_OMODE_MTAB
= (1 << 11), /* read from mtab if fstab not enabled or failed */
693 MNT_OMODE_NOTAB
= (1 << 12), /* do not read fstab/mtab at all */
696 MNT_OMODE_AUTO
= (MNT_OMODE_PREPEND
| MNT_OMODE_FSTAB
| MNT_OMODE_MTAB
),
698 MNT_OMODE_USER
= (MNT_OMODE_REPLACE
| MNT_OMODE_FORCE
| MNT_OMODE_FSTAB
)
701 extern struct libmnt_context
*mnt_new_context(void)
702 __ul_attribute__((warn_unused_result
));
703 extern void mnt_free_context(struct libmnt_context
*cxt
);
705 extern int mnt_reset_context(struct libmnt_context
*cxt
);
706 extern int mnt_context_is_restricted(struct libmnt_context
*cxt
)
707 __ul_attribute__((nonnull
));
708 extern int mnt_context_force_unrestricted(struct libmnt_context
*cxt
);
710 extern int mnt_context_init_helper(struct libmnt_context
*cxt
,
711 int action
, int flags
);
712 extern int mnt_context_helper_setopt(struct libmnt_context
*cxt
, int c
, char *arg
);
714 extern int mnt_context_set_optsmode(struct libmnt_context
*cxt
, int mode
);
715 extern int mnt_context_disable_canonicalize(struct libmnt_context
*cxt
, int disable
);
716 extern int mnt_context_enable_lazy(struct libmnt_context
*cxt
, int enable
);
717 extern int mnt_context_enable_rdonly_umount(struct libmnt_context
*cxt
, int enable
);
718 extern int mnt_context_enable_rwonly_mount(struct libmnt_context
*cxt
, int enable
);
719 extern int mnt_context_disable_helpers(struct libmnt_context
*cxt
, int disable
);
720 extern int mnt_context_enable_sloppy(struct libmnt_context
*cxt
, int enable
);
721 extern int mnt_context_enable_fake(struct libmnt_context
*cxt
, int enable
);
722 extern int mnt_context_disable_mtab(struct libmnt_context
*cxt
, int disable
);
723 extern int mnt_context_enable_force(struct libmnt_context
*cxt
, int enable
);
724 extern int mnt_context_enable_verbose(struct libmnt_context
*cxt
, int enable
);
725 extern int mnt_context_enable_loopdel(struct libmnt_context
*cxt
, int enable
);
726 extern int mnt_context_enable_fork(struct libmnt_context
*cxt
, int enable
);
727 extern int mnt_context_disable_swapmatch(struct libmnt_context
*cxt
, int disable
);
729 extern int mnt_context_get_optsmode(struct libmnt_context
*cxt
);
731 extern int mnt_context_is_lazy(struct libmnt_context
*cxt
)
732 __ul_attribute__((nonnull
));
733 extern int mnt_context_is_rdonly_umount(struct libmnt_context
*cxt
)
734 __ul_attribute__((nonnull
));
735 extern int mnt_context_is_rwonly_mount(struct libmnt_context
*cxt
)
736 __ul_attribute__((nonnull
));
737 extern int mnt_context_is_sloppy(struct libmnt_context
*cxt
)
738 __ul_attribute__((nonnull
));
739 extern int mnt_context_is_fake(struct libmnt_context
*cxt
)
740 __ul_attribute__((nonnull
));
741 extern int mnt_context_is_nomtab(struct libmnt_context
*cxt
)
742 __ul_attribute__((nonnull
));
743 extern int mnt_context_is_force(struct libmnt_context
*cxt
)
744 __ul_attribute__((nonnull
));
745 extern int mnt_context_is_verbose(struct libmnt_context
*cxt
)
746 __ul_attribute__((nonnull
));
747 extern int mnt_context_is_loopdel(struct libmnt_context
*cxt
)
748 __ul_attribute__((nonnull
));
749 extern int mnt_context_is_nohelpers(struct libmnt_context
*cxt
)
750 __ul_attribute__((nonnull
));
751 extern int mnt_context_is_nocanonicalize(struct libmnt_context
*cxt
)
752 __ul_attribute__((nonnull
));
753 extern int mnt_context_is_swapmatch(struct libmnt_context
*cxt
)
754 __ul_attribute__((nonnull
));
755 extern int mnt_context_forced_rdonly(struct libmnt_context
*cxt
)
756 __ul_attribute__((nonnull
));
758 extern int mnt_context_is_fork(struct libmnt_context
*cxt
)
759 __ul_attribute__((nonnull
));
760 extern int mnt_context_is_parent(struct libmnt_context
*cxt
)
761 __ul_attribute__((nonnull
));
762 extern int mnt_context_is_child(struct libmnt_context
*cxt
)
763 __ul_attribute__((nonnull
));
765 extern int mnt_context_wait_for_children(struct libmnt_context
*cxt
,
766 int *nchildren
, int *nerrs
);
768 extern int mnt_context_is_fs_mounted(struct libmnt_context
*cxt
,
769 struct libmnt_fs
*fs
, int *mounted
);
770 extern int mnt_context_set_fs(struct libmnt_context
*cxt
, struct libmnt_fs
*fs
);
771 extern struct libmnt_fs
*mnt_context_get_fs(struct libmnt_context
*cxt
);
773 extern int mnt_context_set_source(struct libmnt_context
*cxt
, const char *source
);
774 extern int mnt_context_set_target(struct libmnt_context
*cxt
, const char *target
);
775 extern int mnt_context_set_fstype(struct libmnt_context
*cxt
, const char *fstype
);
776 extern int mnt_context_set_target_prefix(struct libmnt_context
*cxt
, const char *path
);
778 extern const char *mnt_context_get_source(struct libmnt_context
*cxt
);
779 extern const char *mnt_context_get_target(struct libmnt_context
*cxt
);
780 extern const char *mnt_context_get_fstype(struct libmnt_context
*cxt
);
781 extern const char *mnt_context_get_target_prefix(struct libmnt_context
*cxt
);
783 extern void *mnt_context_get_mtab_userdata(struct libmnt_context
*cxt
);
784 extern void *mnt_context_get_fstab_userdata(struct libmnt_context
*cxt
);
785 extern void *mnt_context_get_fs_userdata(struct libmnt_context
*cxt
);
787 extern int mnt_context_set_options(struct libmnt_context
*cxt
, const char *optstr
);
788 extern int mnt_context_append_options(struct libmnt_context
*cxt
, const char *optstr
);
790 extern const char *mnt_context_get_options(struct libmnt_context
*cxt
);
792 extern int mnt_context_set_fstype_pattern(struct libmnt_context
*cxt
, const char *pattern
);
793 extern int mnt_context_set_options_pattern(struct libmnt_context
*cxt
, const char *pattern
);
795 extern int mnt_context_set_passwd_cb(struct libmnt_context
*cxt
,
796 char *(*get
)(struct libmnt_context
*),
797 void (*release
)(struct libmnt_context
*, char *))
798 __ul_attribute__((deprecated
));
800 extern int mnt_context_set_tables_errcb(struct libmnt_context
*cxt
,
801 int (*cb
)(struct libmnt_table
*tb
, const char *filename
, int line
));
802 extern int mnt_context_set_fstab(struct libmnt_context
*cxt
,
803 struct libmnt_table
*tb
);
804 extern int mnt_context_get_fstab(struct libmnt_context
*cxt
,
805 struct libmnt_table
**tb
);
807 extern int mnt_context_get_mtab(struct libmnt_context
*cxt
,
808 struct libmnt_table
**tb
);
809 extern int mnt_context_get_table(struct libmnt_context
*cxt
,
810 const char *filename
,
811 struct libmnt_table
**tb
);
812 extern int mnt_context_set_cache(struct libmnt_context
*cxt
,
813 struct libmnt_cache
*cache
);
814 extern struct libmnt_cache
*mnt_context_get_cache(struct libmnt_context
*cxt
);
815 extern struct libmnt_lock
*mnt_context_get_lock(struct libmnt_context
*cxt
);
816 extern int mnt_context_set_mflags(struct libmnt_context
*cxt
,
817 unsigned long flags
);
818 extern int mnt_context_get_mflags(struct libmnt_context
*cxt
,
819 unsigned long *flags
);
820 extern int mnt_context_set_user_mflags(struct libmnt_context
*cxt
,
821 unsigned long flags
);
822 extern int mnt_context_get_user_mflags(struct libmnt_context
*cxt
,
823 unsigned long *flags
);
825 extern int mnt_context_set_mountdata(struct libmnt_context
*cxt
, void *data
);
826 extern int mnt_context_apply_fstab(struct libmnt_context
*cxt
);
828 extern int mnt_context_reset_status(struct libmnt_context
*cxt
);
829 extern int mnt_context_get_status(struct libmnt_context
*cxt
);
831 extern int mnt_context_helper_executed(struct libmnt_context
*cxt
);
832 extern int mnt_context_get_helper_status(struct libmnt_context
*cxt
);
834 extern int mnt_context_syscall_called(struct libmnt_context
*cxt
);
836 extern int mnt_context_get_syscall_errno(struct libmnt_context
*cxt
);
838 extern int mnt_context_strerror(struct libmnt_context
*cxt
, char *buf
,
840 __ul_attribute__((deprecated
));
842 extern int mnt_context_get_excode(struct libmnt_context
*cxt
,
843 int rc
, char *buf
, size_t bufsz
);
845 extern int mnt_context_set_target_ns(struct libmnt_context
*cxt
, const char *path
);
846 extern struct libmnt_ns
*mnt_context_get_target_ns(struct libmnt_context
*cxt
);
847 extern struct libmnt_ns
*mnt_context_get_origin_ns(struct libmnt_context
*cxt
);
848 extern struct libmnt_ns
*mnt_context_switch_ns(struct libmnt_context
*cxt
, struct libmnt_ns
*ns
);
849 extern struct libmnt_ns
*mnt_context_switch_origin_ns(struct libmnt_context
*cxt
);
850 extern struct libmnt_ns
*mnt_context_switch_target_ns(struct libmnt_context
*cxt
);
853 /* context_mount.c */
854 extern int mnt_context_mount(struct libmnt_context
*cxt
);
855 extern int mnt_context_umount(struct libmnt_context
*cxt
);
856 extern int mnt_context_next_mount(struct libmnt_context
*cxt
,
857 struct libmnt_iter
*itr
,
858 struct libmnt_fs
**fs
,
859 int *mntrc
, int *ignored
);
861 extern int mnt_context_next_remount(struct libmnt_context
*cxt
,
862 struct libmnt_iter
*itr
,
863 struct libmnt_fs
**fs
,
867 extern int mnt_context_prepare_mount(struct libmnt_context
*cxt
)
868 __ul_attribute__((warn_unused_result
));
869 extern int mnt_context_do_mount(struct libmnt_context
*cxt
);
870 extern int mnt_context_finalize_mount(struct libmnt_context
*cxt
);
872 /* context_umount.c */
873 extern int mnt_context_find_umount_fs(struct libmnt_context
*cxt
,
875 struct libmnt_fs
**pfs
);
876 extern int mnt_context_next_umount(struct libmnt_context
*cxt
,
877 struct libmnt_iter
*itr
,
878 struct libmnt_fs
**fs
,
879 int *mntrc
, int *ignored
);
881 extern int mnt_context_prepare_umount(struct libmnt_context
*cxt
)
882 __ul_attribute__((warn_unused_result
));
883 extern int mnt_context_do_umount(struct libmnt_context
*cxt
);
884 extern int mnt_context_finalize_umount(struct libmnt_context
*cxt
);
886 extern int mnt_context_tab_applied(struct libmnt_context
*cxt
);
887 extern int mnt_context_set_syscall_status(struct libmnt_context
*cxt
, int status
);
890 * mount(8) userspace options masks (MNT_MAP_USERSPACE map)
892 #define MNT_MS_NOAUTO (1 << 2)
893 #define MNT_MS_USER (1 << 3)
894 #define MNT_MS_USERS (1 << 4)
895 #define MNT_MS_OWNER (1 << 5)
896 #define MNT_MS_GROUP (1 << 6)
897 #define MNT_MS_NETDEV (1 << 7)
898 #define MNT_MS_COMMENT (1 << 8)
899 #define MNT_MS_LOOP (1 << 9)
900 #define MNT_MS_NOFAIL (1 << 10)
901 #define MNT_MS_UHELPER (1 << 11)
902 #define MNT_MS_HELPER (1 << 12)
903 #define MNT_MS_XCOMMENT (1 << 13)
904 #define MNT_MS_OFFSET (1 << 14)
905 #define MNT_MS_SIZELIMIT (1 << 15)
906 #define MNT_MS_ENCRYPTION (1 << 16)
907 #define MNT_MS_XFSTABCOMM (1 << 17)
910 * mount(2) MS_* masks (MNT_MAP_LINUX map)
913 #define MS_RDONLY 1 /* Mount read-only */
916 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
919 #define MS_NODEV 4 /* Disallow access to device special files */
922 #define MS_NOEXEC 8 /* Disallow program execution */
924 #ifndef MS_SYNCHRONOUS
925 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
928 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
931 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
934 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
937 #define MS_NOATIME 0x400 /* 1024: Do not update access times. */
939 #ifndef MS_NODIRATIME
940 #define MS_NODIRATIME 0x800 /* 2048: Don't update directory access times */
943 #define MS_BIND 0x1000 /* 4096: Mount existing tree elsewhere as well */
946 #define MS_MOVE 0x2000 /* 8192: Atomically move the tree */
949 #define MS_REC 0x4000 /* 16384: Recursive loopback */
952 #define MS_SILENT 0x8000 /* 32768: Don't emit certain kernel messages */
954 #ifndef MS_UNBINDABLE
955 #define MS_UNBINDABLE (1<<17) /* 131072: Make unbindable */
958 #define MS_PRIVATE (1<<18) /* 262144: Make private */
961 #define MS_SLAVE (1<<19) /* 524288: Make slave */
964 #define MS_SHARED (1<<20) /* 1048576: Make shared */
967 #define MS_RELATIME (1<<21) /* 2097152: Update atime relative to mtime/ctime */
970 #define MS_I_VERSION (1<<23) /* Update the inode I_version field */
972 #ifndef MS_STRICTATIME
973 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
976 #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
981 * Magic mount flag number. Had to be or-ed to the flag values. Deprecated and
982 * no more used since libmount v2.33; required for Linux <= 2.4.
985 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
988 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
992 /* Shared-subtree options */
993 #define MS_PROPAGATION (MS_SHARED|MS_SLAVE|MS_UNBINDABLE|MS_PRIVATE)
995 /* Options that we make ordinary users have by default. */
996 #define MS_SECURE (MS_NOEXEC|MS_NOSUID|MS_NODEV)
998 /* Options that we make owner-mounted devices have by default */
999 #define MS_OWNERSECURE (MS_NOSUID|MS_NODEV)
1005 #endif /* _LIBMOUNT_MOUNT_H */