Welcome to NYCU CSIT Mirror site

Mount context: libmount Reference Manual

Mount context

Mount context — high-level API to mount operation.

Types and Values

#define MNT_MS_COMMENT
#define MNT_MS_GROUP
#define MNT_MS_HELPER
#define MNT_MS_LOOP
#define MNT_MS_NETDEV
#define MNT_MS_NOAUTO
#define MNT_MS_NOFAIL
#define MNT_MS_OFFSET
#define MNT_MS_OWNER
#define MNT_MS_SIZELIMIT
#define MNT_MS_ENCRYPTION
#define MNT_MS_UHELPER
#define MNT_MS_USER
#define MNT_MS_USERS
#define MNT_MS_XCOMMENT
#define MNT_MS_XFSTABCOMM
#define MNT_MS_HASH_DEVICE
#define MNT_MS_ROOT_HASH
#define MNT_MS_HASH_OFFSET
#define MNT_MS_ROOT_HASH_FILE
#define MNT_MS_FEC_DEVICE
#define MNT_MS_FEC_OFFSET
#define MNT_MS_FEC_ROOTS
#define MNT_MS_ROOT_HASH_SIG
#define MS_BIND
#define MS_DIRSYNC
#define MS_I_VERSION
#define MS_MANDLOCK
#define MS_MGC_MSK
#define MS_MGC_VAL
#define MS_MOVE
#define MS_NOATIME
#define MS_NODEV
#define MS_NODIRATIME
#define MS_NOEXEC
#define MS_NOSUID
#define MS_OWNERSECURE
#define MS_PRIVATE
#define MS_PROPAGATION
#define MS_RDONLY
#define MS_REC
#define MS_RELATIME
#define MS_REMOUNT
#define MS_SECURE
#define MS_SHARED
#define MS_SILENT
#define MS_SLAVE
#define MS_STRICTATIME
#define MS_SYNCHRONOUS
#define MS_UNBINDABLE
#define MS_LAZYTIME

Description

Functions

mnt_context_do_mount ()

int
mnt_context_do_mount (struct libmnt_context *cxt);

Call mount(2) or mount.type helper. Unnecessary for mnt_context_mount().

Note that this function could be called only once. If you want to mount another source or target, then you have to call mnt_reset_context().

If you want to call mount(2) for the same source and target with different mount flags or fstype, then call mnt_context_reset_status() and then try again mnt_context_do_mount().

WARNING: non-zero return code does not mean that mount(2) syscall or mount.type helper wasn't successfully called.

Check mnt_context_get_status() after error! See mnt_context_mount() for more details about errors and warnings.

Parameters

cxt

context

 

Returns

0 on success; >0 in case of mount(2) error (returns syscall errno), <0 in case of other errors.


mnt_context_finalize_mount ()

int
mnt_context_finalize_mount (struct libmnt_context *cxt);

Mtab update, etc. Unnecessary for mnt_context_mount(), but should be called after mnt_context_do_mount(). See also mnt_context_set_syscall_status().

Parameters

cxt

context

 

Returns

negative number on error, 0 on success.


mnt_context_mount ()

int
mnt_context_mount (struct libmnt_context *cxt);

High-level, mounts the filesystem by mount(2) or fork()+exec(/sbin/mount.type).

This is similar to:

mnt_context_prepare_mount(cxt); mnt_context_do_mount(cxt); mnt_context_finalize_mount(cxt);

See also mnt_context_disable_helpers().

Note that this function should be called only once. If you want to mount with different settings, then you have to call mnt_reset_context(). It's NOT enough to call mnt_context_reset_status(). If you want to call this function more than once, the whole context has to be reset.

WARNING: non-zero return code does not mean that mount(2) syscall or mount.type helper wasn't successfully called.

Always use mnt_context_get_status():

1
2
3
4
5
6
7
rc = mnt_context_mount(cxt);

if (mnt_context_helper_executed(cxt))
        return mnt_context_get_helper_status(cxt);
if (rc == 0 && mnt_context_get_status(cxt) == 1)
        return MNT_EX_SUCCESS;
return MNT_EX_FAIL;

or mnt_context_get_excode() to generate mount(8) compatible error or warning message:

1
2
3
4
5
rc = mnt_context_mount(cxt);
rc = mnt_context_get_excode(cxt, rc, buf, sizeof(buf));
if (buf)
        warnx(_("%s: %s"), mnt_context_get_target(cxt), buf);
 return rc;   // MNT_EX_*

Parameters

cxt

mount context

 

Returns

0 on success; >0 in case of mount(2) error (returns syscall errno), <0 in case of other errors.


mnt_context_next_mount ()

int
mnt_context_next_mount (struct libmnt_context *cxt,
                        struct libmnt_iter *itr,
                        struct libmnt_fs **fs,
                        int *mntrc,
                        int *ignored);

This function tries to mount the next filesystem from fstab (as returned by mnt_context_get_fstab()). See also mnt_context_set_fstab().

You can filter out filesystems by: mnt_context_set_options_pattern() to simulate mount -a -O pattern mnt_context_set_fstype_pattern() to simulate mount -a -t pattern

If the filesystem is already mounted or does not match defined criteria, then the mnt_context_next_mount() function returns zero, but the ignored is non-zero. Note that the root filesystem and filesystems with "noauto" option are always ignored.

If mount(2) syscall or mount.type helper failed, then the mnt_context_next_mount() function returns zero, but the mntrc is non-zero. Use also mnt_context_get_status() to check if the filesystem was successfully mounted.

See mnt_context_mount() for more details about errors and warnings.

Parameters

cxt

context

 

itr

iterator

 

fs

returns the current filesystem

 

mntrc

returns the return code from mnt_context_mount()

 

ignored

returns 1 for non-matching and 2 for already mounted filesystems

 

Returns

0 on success, <0 in case of error (!= mount(2) errors) 1 at the end of the list.


mnt_context_next_remount ()

int
mnt_context_next_remount (struct libmnt_context *cxt,
                          struct libmnt_iter *itr,
                          struct libmnt_fs **fs,
                          int *mntrc,
                          int *ignored);

This function tries to remount the next mounted filesystem (as returned by mnt_context_get_mtab()).

You can filter out filesystems by: mnt_context_set_options_pattern() to simulate mount -a -O pattern mnt_context_set_fstype_pattern() to simulate mount -a -t pattern

If the filesystem does not match defined criteria, then the mnt_context_next_remount() function returns zero, but the ignored is non-zero.

IMPORTANT -- the mount operation is performed in the current context. The context is reset before the next mount (see mnt_reset_context()). The context setting related to the filesystem (e.g. mount options, etc.) are protected.

If mount(2) syscall or mount.type helper failed, then the mnt_context_next_mount() function returns zero, but the mntrc is non-zero. Use also mnt_context_get_status() to check if the filesystem was successfully mounted.

See mnt_context_mount() for more details about errors and warnings.

Parameters

cxt

context

 

itr

iterator

 

fs

returns the current filesystem

 

mntrc

returns the return code from mnt_context_mount()

 

ignored

returns 1 for non-matching

 

Returns

0 on success, <0 in case of error (!= mount(2) errors) 1 at the end of the list.

Since: 2.34


mnt_context_prepare_mount ()

int
mnt_context_prepare_mount (struct libmnt_context *cxt);

Prepare context for mounting, unnecessary for mnt_context_mount().

Parameters

cxt

context

 

Returns

negative number on error, zero on success

Types and Values

MNT_MS_COMMENT

#define MNT_MS_COMMENT  (1 << 8)

MNT_MS_GROUP

#define MNT_MS_GROUP (1 << 6)

MNT_MS_HELPER

#define MNT_MS_HELPER   (1 << 12)

MNT_MS_LOOP

#define MNT_MS_LOOP     (1 << 9)

MNT_MS_NETDEV

#define MNT_MS_NETDEV (1 << 7)

MNT_MS_NOAUTO

#define MNT_MS_NOAUTO (1 << 2)

MNT_MS_NOFAIL

#define MNT_MS_NOFAIL   (1 << 10)

MNT_MS_OFFSET

#define MNT_MS_OFFSET   (1 << 14)

MNT_MS_OWNER

#define MNT_MS_OWNER (1 << 5)

MNT_MS_SIZELIMIT

#define MNT_MS_SIZELIMIT (1 << 15)

MNT_MS_ENCRYPTION

#define MNT_MS_ENCRYPTION (1 << 16)

MNT_MS_UHELPER

#define MNT_MS_UHELPER  (1 << 11)

MNT_MS_USER

#define MNT_MS_USER (1 << 3)

MNT_MS_USERS

#define MNT_MS_USERS (1 << 4)

MNT_MS_XCOMMENT

#define MNT_MS_XCOMMENT (1 << 13)

MNT_MS_XFSTABCOMM

#define MNT_MS_XFSTABCOMM (1 << 17)

MNT_MS_HASH_DEVICE

#define MNT_MS_HASH_DEVICE (1 << 18)

MNT_MS_ROOT_HASH

#define MNT_MS_ROOT_HASH (1 << 19)

MNT_MS_HASH_OFFSET

#define MNT_MS_HASH_OFFSET (1 << 20)

MNT_MS_ROOT_HASH_FILE

#define MNT_MS_ROOT_HASH_FILE (1 << 21)

MNT_MS_FEC_DEVICE

#define MNT_MS_FEC_DEVICE (1 << 22)

MNT_MS_FEC_OFFSET

#define MNT_MS_FEC_OFFSET (1 << 23)

MNT_MS_FEC_ROOTS

#define MNT_MS_FEC_ROOTS (1 << 24)

MNT_MS_ROOT_HASH_SIG

#define MNT_MS_ROOT_HASH_SIG (1 << 25)

MS_BIND

#define MS_BIND		0x1000 /* 4096: Mount existing tree elsewhere as well */

MS_DIRSYNC

#define MS_DIRSYNC 128 /* Directory modifications are synchronous */

MS_I_VERSION

#define MS_I_VERSION (1<<23) /* Update the inode I_version field */

MS_MANDLOCK

#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */

MS_MGC_MSK

#define MS_MGC_MSK 0xffff0000 /* magic flag number mask */

MS_MGC_VAL

#define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */

MS_MOVE

#define MS_MOVE		0x2000 /* 8192: Atomically move the tree */

MS_NOATIME

#define MS_NOATIME 0x400 /* 1024: Do not update access times. */

MS_NODEV

#define MS_NODEV	 4 /* Disallow access to device special files */

MS_NODIRATIME

#define MS_NODIRATIME   0x800 /* 2048: Don't update directory access times */

MS_NOEXEC

#define MS_NOEXEC	 8 /* Disallow program execution */

MS_NOSUID

#define MS_NOSUID	 2 /* Ignore suid and sgid bits */

MS_OWNERSECURE

#define MS_OWNERSECURE (MS_NOSUID|MS_NODEV)

MS_PRIVATE

#define MS_PRIVATE (1<<18) /* 262144: Make private */

MS_PROPAGATION

#define MS_PROPAGATION  (MS_SHARED|MS_SLAVE|MS_UNBINDABLE|MS_PRIVATE)

MS_RDONLY

#define MS_RDONLY	 1 /* Mount read-only */

MS_REC

#define MS_REC		0x4000 /* 16384: Recursive loopback */

MS_RELATIME

#define MS_RELATIME (1<<21) /* 2097152: Update atime relative to mtime/ctime */

MS_REMOUNT

#define MS_REMOUNT 32 /* Alter flags of a mounted FS */

MS_SECURE

#define MS_SECURE (MS_NOEXEC|MS_NOSUID|MS_NODEV)

MS_SHARED

#define MS_SHARED (1<<20) /* 1048576: Make shared */

MS_SILENT

#define MS_SILENT 0x8000 /* 32768: Don't emit certain kernel messages */

MS_SLAVE

#define MS_SLAVE (1<<19) /* 524288: Make slave */

MS_STRICTATIME

#define MS_STRICTATIME (1<<24) /* Always perform atime updates */

MS_SYNCHRONOUS

#define MS_SYNCHRONOUS 16 /* Writes are synced at once */

MS_UNBINDABLE

#define MS_UNBINDABLE (1<<17) /* 131072: Make unbindable */

MS_LAZYTIME

#define MS_LAZYTIME     (1<<25) /* Update the on-disk [acm]times lazily */