Welcome to NYCU CSIT Mirror site

Mount context

Mount context

Mount context — high-level API to mount operation.

Synopsis

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

#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             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

Description

Details

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!

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().

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.

Check mnt_context_get_status() after error!

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.

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_prepare_mount ()

int                 mnt_context_prepare_mount           (struct libmnt_context *cxt);

Prepare context for mounting, unnecessary for mnt_context_mount().

cxt :

context

Returns :

negative number on error, zero on success

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)

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 */