Library high-level context

Library high-level context — high-level API to mount/umount devices.

Synopsis

struct              libmnt_context;
void                mnt_free_context                    (struct libmnt_context *cxt);
struct libmnt_context * mnt_new_context                 (void);
int                 mnt_reset_context                   (struct libmnt_context *cxt);
int                 mnt_context_append_options          (struct libmnt_context *cxt,
                                                         const char *optstr);
int                 mnt_context_apply_fstab             (struct libmnt_context *cxt);
int                 mnt_context_disable_canonicalize    (struct libmnt_context *cxt,
                                                         int disable);
int                 mnt_context_disable_helpers         (struct libmnt_context *cxt,
                                                         int disable);
int                 mnt_context_disable_mtab            (struct libmnt_context *cxt,
                                                         int disable);
int                 mnt_context_disable_swapmatch       (struct libmnt_context *cxt,
                                                         int disable);
int                 mnt_context_enable_fake             (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_force            (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_fork             (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_lazy             (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_loopdel          (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_rdonly_umount    (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_sloppy           (struct libmnt_context *cxt,
                                                         int enable);
int                 mnt_context_enable_verbose          (struct libmnt_context *cxt,
                                                         int enable);
struct libmnt_cache * mnt_context_get_cache             (struct libmnt_context *cxt);
struct libmnt_fs *  mnt_context_get_fs                  (struct libmnt_context *cxt);
int                 mnt_context_get_fstab               (struct libmnt_context *cxt,
                                                         struct libmnt_table **tb);
const char *        mnt_context_get_fstype              (struct libmnt_context *cxt);
int                 mnt_context_get_helper_status       (struct libmnt_context *cxt);
struct libmnt_lock * mnt_context_get_lock               (struct libmnt_context *cxt);
int                 mnt_context_get_mflags              (struct libmnt_context *cxt,
                                                         unsigned long *flags);
int                 mnt_context_get_mtab                (struct libmnt_context *cxt,
                                                         struct libmnt_table **tb);
const char *        mnt_context_get_options             (struct libmnt_context *cxt);
int                 mnt_context_get_optsmode            (struct libmnt_context *cxt);
const char *        mnt_context_get_source              (struct libmnt_context *cxt);
int                 mnt_context_get_status              (struct libmnt_context *cxt);
int                 mnt_context_get_syscall_errno       (struct libmnt_context *cxt);
int                 mnt_context_get_table               (struct libmnt_context *cxt,
                                                         const char *filename,
                                                         struct libmnt_table **tb);
const char *        mnt_context_get_target              (struct libmnt_context *cxt);
int                 mnt_context_get_user_mflags         (struct libmnt_context *cxt,
                                                         unsigned long *flags);
int                 mnt_context_helper_executed         (struct libmnt_context *cxt);
int                 mnt_context_helper_setopt           (struct libmnt_context *cxt,
                                                         int c,
                                                         char *arg);
int                 mnt_context_init_helper             (struct libmnt_context *cxt,
                                                         int action,
                                                         int flags);
int                 mnt_context_is_child                (struct libmnt_context *cxt);
int                 mnt_context_is_fake                 (struct libmnt_context *cxt);
int                 mnt_context_is_force                (struct libmnt_context *cxt);
int                 mnt_context_is_fork                 (struct libmnt_context *cxt);
int                 mnt_context_is_fs_mounted           (struct libmnt_context *cxt,
                                                         struct libmnt_fs *fs,
                                                         int *mounted);
int                 mnt_context_is_lazy                 (struct libmnt_context *cxt);
int                 mnt_context_is_loopdel              (struct libmnt_context *cxt);
int                 mnt_context_is_nocanonicalize       (struct libmnt_context *cxt);
int                 mnt_context_is_nohelpers            (struct libmnt_context *cxt);
int                 mnt_context_is_nomtab               (struct libmnt_context *cxt);
int                 mnt_context_is_parent               (struct libmnt_context *cxt);
int                 mnt_context_is_rdonly_umount        (struct libmnt_context *cxt);
int                 mnt_context_is_restricted           (struct libmnt_context *cxt);
int                 mnt_context_is_sloppy               (struct libmnt_context *cxt);
int                 mnt_context_is_swapmatch            (struct libmnt_context *cxt);
int                 mnt_context_is_verbose              (struct libmnt_context *cxt);
int                 mnt_context_reset_status            (struct libmnt_context *cxt);
int                 mnt_context_set_cache               (struct libmnt_context *cxt,
                                                         struct libmnt_cache *cache);
int                 mnt_context_set_fs                  (struct libmnt_context *cxt,
                                                         struct libmnt_fs *fs);
int                 mnt_context_set_fstab               (struct libmnt_context *cxt,
                                                         struct libmnt_table *tb);
int                 mnt_context_set_fstype              (struct libmnt_context *cxt,
                                                         const char *fstype);
int                 mnt_context_set_fstype_pattern      (struct libmnt_context *cxt,
                                                         const char *pattern);
int                 mnt_context_set_mflags              (struct libmnt_context *cxt,
                                                         unsigned long  flags);
int                 mnt_context_set_mountdata           (struct libmnt_context *cxt,
                                                         void *data);
int                 mnt_context_set_options             (struct libmnt_context *cxt,
                                                         const char *optstr);
int                 mnt_context_set_options_pattern     (struct libmnt_context *cxt,
                                                         const char *pattern);
int                 mnt_context_set_optsmode            (struct libmnt_context *cxt,
                                                         int mode);
int                 mnt_context_set_passwd_cb           (struct libmnt_context *cxt,
                                                         char* (*get) (struct libmnt_context *),
                                                         void (*release) (struct libmnt_context *, char *));
int                 mnt_context_set_source              (struct libmnt_context *cxt,
                                                         const char *source);
int                 mnt_context_set_syscall_status      (struct libmnt_context *cxt,
                                                         int status);
int                 mnt_context_set_tables_errcb        (struct libmnt_context *cxt,
                                                         int (*cb) (struct libmnt_table *tb, const char *filename, int line));
int                 mnt_context_set_target              (struct libmnt_context *cxt,
                                                         const char *target);
int                 mnt_context_set_user_mflags         (struct libmnt_context *cxt,
                                                         unsigned long  flags);
int                 mnt_context_strerror                (struct libmnt_context *cxt,
                                                         char *buf,
                                                         size_t bufsiz);
int                 mnt_context_syscall_called          (struct libmnt_context *cxt);
int                 mnt_context_tab_applied             (struct libmnt_context *cxt);
int                 mnt_context_wait_for_children       (struct libmnt_context *cxt,
                                                         int *nchildren,
                                                         int *nerrs);

#define             MNT_ERR_AMBIFS
#define             MNT_ERR_APPLYFLAGS
#define             MNT_ERR_LOOPDEV
#define             MNT_ERR_MOUNTOPT
#define             MNT_ERR_NOFSTAB
#define             MNT_ERR_NOFSTYPE
#define             MNT_ERR_NOSOURCE

Description

1
2
3
4
5
6
7
8
9
struct libmnt_context *cxt = mnt_new_context();

mnt_context_set_options(cxt, "aaa,bbb,ccc=CCC");
mnt_context_set_mflags(cxt, MS_NOATIME|MS_NOEXEC);
mnt_context_set_target(cxt, "/mnt/foo");

if (!mnt_context_mount(cxt))
    printf("successfully mounted\n");
mnt_free_context(cxt);

This code is similar to:

mount -o aaa,bbb,ccc=CCC,noatime,noexec /mnt/foo

Details

struct libmnt_context

struct libmnt_context;

Mount/umount status


mnt_free_context ()

void                mnt_free_context                    (struct libmnt_context *cxt);

Deallocates context struct.

cxt :

mount context

mnt_new_context ()

struct libmnt_context * mnt_new_context                 (void);

Returns :

newly allocated mount context

mnt_reset_context ()

int                 mnt_reset_context                   (struct libmnt_context *cxt);

Resets all information in the context that are directly related to the latest mount (spec, source, target, mount options, ....)

The match patters, cached fstab, cached canonicalized paths and tags and [e]uid are not reseted. You have to use

mnt_context_set_fstab(cxt, NULL); mnt_context_set_cache(cxt, NULL); mnt_context_set_fstype_pattern(cxt, NULL); mnt_context_set_options_pattern(cxt, NULL);

to reset these stuff.

cxt :

mount context

Returns :

0 on success, negative number in case of error.

mnt_context_append_options ()

int                 mnt_context_append_options          (struct libmnt_context *cxt,
                                                         const char *optstr);

cxt :

mount context

optstr :

comma delimited mount options

Returns :

0 on success, negative number in case of error.

mnt_context_apply_fstab ()

int                 mnt_context_apply_fstab             (struct libmnt_context *cxt);

This function is optional.

cxt :

mount context

Returns :

0 on success, negative number in case of error.

mnt_context_disable_canonicalize ()

int                 mnt_context_disable_canonicalize    (struct libmnt_context *cxt,
                                                         int disable);

Enable/disable paths canonicalization and tags evaluation. The libmount context canonicalies paths when search in fstab and when prepare source and target paths for mount(2) syscall.

This fuction has effect to the private (within context) fstab instance only (see mnt_context_set_fstab()). If you want to use an external fstab then you need manage your private struct libmnt_cache (see mnt_table_set_cache(fstab, NULL).

cxt :

mount context

disable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_disable_helpers ()

int                 mnt_context_disable_helpers         (struct libmnt_context *cxt,
                                                         int disable);

Enable/disable /sbin/[u]mount.* helpers (see mount(8) man page, option -i).

cxt :

mount context

disable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_disable_mtab ()

int                 mnt_context_disable_mtab            (struct libmnt_context *cxt,
                                                         int disable);

Disable/enable mtab update (see mount(8) man page, option -n).

cxt :

mount context

disable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_disable_swapmatch ()

int                 mnt_context_disable_swapmatch       (struct libmnt_context *cxt,
                                                         int disable);

Disable/enable swap between source and target for mount(8) if only one path is specified.

cxt :

mount context

disable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_fake ()

int                 mnt_context_enable_fake             (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable fake mounting (see mount(8) man page, option -f).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_force ()

int                 mnt_context_enable_force            (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable force umounting (see umount(8) man page, option -f).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_fork ()

int                 mnt_context_enable_fork             (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable fork(2) call in mnt_context_next_mount() (see mount(8) man page, option -F).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_lazy ()

int                 mnt_context_enable_lazy             (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable lazy umount (see umount(8) man page, option -l).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_loopdel ()

int                 mnt_context_enable_loopdel          (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable loop delete (destroy) after umount (see umount(8), option -d)

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_rdonly_umount ()

int                 mnt_context_enable_rdonly_umount    (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable read-only remount on failed umount(2) (see umount(8) man page, option -r).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_sloppy ()

int                 mnt_context_enable_sloppy           (struct libmnt_context *cxt,
                                                         int enable);

Set/unset sloppy mounting (see mount(8) man page, option -s).

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_enable_verbose ()

int                 mnt_context_enable_verbose          (struct libmnt_context *cxt,
                                                         int enable);

Enable/disable verbose output (TODO: not implemented yet)

cxt :

mount context

enable :

TRUE or FALSE

Returns :

0 on success, negative number in case of error.

mnt_context_get_cache ()

struct libmnt_cache * mnt_context_get_cache             (struct libmnt_context *cxt);

See also mnt_context_set_cache().

cxt :

mount context

Returns :

pointer to cache or NULL if canonicalization is disabled.

mnt_context_get_fs ()

struct libmnt_fs *  mnt_context_get_fs                  (struct libmnt_context *cxt);

The FS contains the basic description of mountpoint, fs type and so on. Note that the FS is modified by mnt_context_set_{source,target,options,fstype} functions.

cxt :

mount context

Returns :

pointer to FS description or NULL in case of calloc() errrr.

mnt_context_get_fstab ()

int                 mnt_context_get_fstab               (struct libmnt_context *cxt,
                                                         struct libmnt_table **tb);

See also mnt_table_parse_fstab() for more details about fstab.

cxt :

mount context

tb :

returns fstab

Returns :

0 on success, negative number in case of error.

mnt_context_get_fstype ()

const char *        mnt_context_get_fstype              (struct libmnt_context *cxt);

cxt :

mount context

Returns :

pointer or NULL in case of error pr if not set.

mnt_context_get_helper_status ()

int                 mnt_context_get_helper_status       (struct libmnt_context *cxt);

Return: mount.type helper exit status, result is reliable only if mnt_context_helper_executed() returns 1.

cxt :

mount context

mnt_context_get_lock ()

struct libmnt_lock * mnt_context_get_lock               (struct libmnt_context *cxt);

The libmount applications don't have to care about mtab locking, but with a small exception: the application has to be able to remove the lock file when interrupted by signal or signals have to be ignored when the lock is locked.

The default behavior is to ignore all signals (except SIGALRM and SIGTRAP for mtab udate) when the lock is locked. If this behavior is unacceptable then use:

lc = mnt_context_get_lock(cxt); if (lc) mnt_lock_block_signals(lc, FALSE);

and don't forget to call mnt_unlock_file(lc) before exit.

cxt :

mount context

Returns :

pointer to lock struct or NULL.

mnt_context_get_mflags ()

int                 mnt_context_get_mflags              (struct libmnt_context *cxt,
                                                         unsigned long *flags);

Converts mount options string to MS_* flags and bitewise-OR the result with already defined flags (see mnt_context_set_mflags()).

cxt :

mount context

flags :

returns MS_* mount flags

Returns :

0 on success, negative number in case of error.

mnt_context_get_mtab ()

int                 mnt_context_get_mtab                (struct libmnt_context *cxt,
                                                         struct libmnt_table **tb);

See also mnt_table_parse_mtab() for more details about mtab/mountinfo. The result will deallocated by mnt_free_context(cxt).

cxt :

mount context

tb :

returns mtab

Returns :

0 on success, negative number in case of error.

mnt_context_get_options ()

const char *        mnt_context_get_options             (struct libmnt_context *cxt);

This function returns mount options set by mnt_context_set_options() or mnt_context_append_options().

Note that *after* mnt_context_prepare_mount() may the mount options string also includes options set by mnt_context_set_mflags() or another options generated by this library.

cxt :

mount context

Returns :

pointer or NULL

mnt_context_get_optsmode ()

int                 mnt_context_get_optsmode            (struct libmnt_context *cxt);

cxt :

mount context

Returns :

MNT_OMASK_* mask or zero.

mnt_context_get_source ()

const char *        mnt_context_get_source              (struct libmnt_context *cxt);

cxt :

mount context

Returns :

returns pointer or NULL in case of error pr if not set.

mnt_context_get_status ()

int                 mnt_context_get_status              (struct libmnt_context *cxt);

Global libmount status.

The real exit code of the mount.type helper has to be tested by mnt_context_get_helper_status(). The mnt_context_get_status() only inform that exec() has been successful.

cxt :

mount context

Returns :

1 if mount.type or mount(2) syscall has been successfully called.

mnt_context_get_syscall_errno ()

int                 mnt_context_get_syscall_errno       (struct libmnt_context *cxt);

The result from this function is reliable only if mnt_context_syscall_called() returns 1.

cxt :

mount context

Returns :

mount(2) errno if the syscall failed or 0.

mnt_context_get_table ()

int                 mnt_context_get_table               (struct libmnt_context *cxt,
                                                         const char *filename,
                                                         struct libmnt_table **tb);

This function allocates a new table and parses the file. The parser error callback and cache for tags and paths is set according to the cxt setting. See also mnt_table_parse_file().

It's strongly recommended use mnt_context_get_mtab() and mnt_context_get_fstab() functions for mtab and fstab files. This function does not care about LIBMOUNT_* env.variables and does not merge userspace options.

The result will NOT be deallocated by mnt_free_context(cxt).

cxt :

mount context

filename :

e.g. /proc/self/mountinfo

tb :

returns the table

Returns :

0 on success, negative number in case of error.

mnt_context_get_target ()

const char *        mnt_context_get_target              (struct libmnt_context *cxt);

cxt :

mount context

Returns :

returns pointer or NULL in case of error pr if not set.

mnt_context_get_user_mflags ()

int                 mnt_context_get_user_mflags         (struct libmnt_context *cxt,
                                                         unsigned long *flags);

Converts mount options string to MNT_MS_* flags and bitewise-OR the result with already defined flags (see mnt_context_set_user_mflags()).

cxt :

mount context

flags :

returns mount flags

Returns :

0 on success, negative number in case of error.

mnt_context_helper_executed ()

int                 mnt_context_helper_executed         (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if mount.type helper has been executed, or 0.

mnt_context_helper_setopt ()

int                 mnt_context_helper_setopt           (struct libmnt_context *cxt,
                                                         int c,
                                                         char *arg);

This function applies [u]mount.type command line option (for example parsed by getopt or getopt_long) to cxt. All unknown options are ignored and then 1 is returned.

cxt :

context

c :

getopt() result

arg :

getopt() optarg

Returns :

negative number on error, 1 if c is unknown option, 0 on success.

mnt_context_init_helper ()

int                 mnt_context_init_helper             (struct libmnt_context *cxt,
                                                         int action,
                                                         int flags);

This function infors libmount that used from [u]mount.type helper.

The function also calls mnt_context_disable_helpers() to avoid recursive mount.type helpers calling. It you really want to call another mount.type helper from your helper than you have to explicitly enable this feature by:

mnt_context_disable_helpers(cxt, FALSE);

cxt :

mount context

action :

MNT_ACT_{UMOUNT,MOUNT}

flags :

not used now

Returns :

0 on success, negative number in case of error.

mnt_context_is_child ()

int                 mnt_context_is_child                (struct libmnt_context *cxt);

Return: 1 if mount -F enabled and the current context is child, or 0

cxt :

mount context

mnt_context_is_fake ()

int                 mnt_context_is_fake                 (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if fake flag is enabled or 0

mnt_context_is_force ()

int                 mnt_context_is_force                (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if force umounting flag is enabled or 0

mnt_context_is_fork ()

int                 mnt_context_is_fork                 (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if fork (mount -F) is enabled or 0

mnt_context_is_fs_mounted ()

int                 mnt_context_is_fs_mounted           (struct libmnt_context *cxt,
                                                         struct libmnt_fs *fs,
                                                         int *mounted);

Please, read mnt_table_is_fs_mounted() description!

cxt :

context

fs :

filesystem

mounted :

returns 1 for mounted and 0 for non-mounted filesystems

Returns :

0 on success and negative number in case of error.

mnt_context_is_lazy ()

int                 mnt_context_is_lazy                 (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if lazy umount is enabled or 0

mnt_context_is_loopdel ()

int                 mnt_context_is_loopdel              (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if loop device should be deleted after umount (umount -d) or 0.

mnt_context_is_nocanonicalize ()

int                 mnt_context_is_nocanonicalize       (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if no-canonicalize mode enabled or 0.

mnt_context_is_nohelpers ()

int                 mnt_context_is_nohelpers            (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if helpers are disabled (mount -i) or 0

mnt_context_is_nomtab ()

int                 mnt_context_is_nomtab               (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if no-mtab is enabled or 0

mnt_context_is_parent ()

int                 mnt_context_is_parent               (struct libmnt_context *cxt);

Return: 1 if mount -F enabled and the current context is parent, or 0

cxt :

mount context

mnt_context_is_rdonly_umount ()

int                 mnt_context_is_rdonly_umount        (struct libmnt_context *cxt);

See also mnt_context_enable_rdonly_umount() and see umount(8) man page, option -r.

cxt :

mount context

Returns :

1 if read-only remount failed umount(2) is enables or 0

mnt_context_is_restricted ()

int                 mnt_context_is_restricted           (struct libmnt_context *cxt);

cxt :

mount context

Returns :

0 for unrestricted mount (user is root), or 1 for non-root mounts

mnt_context_is_sloppy ()

int                 mnt_context_is_sloppy               (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if sloppy flag is enabled or 0

mnt_context_is_swapmatch ()

int                 mnt_context_is_swapmatch            (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if swap between source and target is allowed (default is 1) or 0.

mnt_context_is_verbose ()

int                 mnt_context_is_verbose              (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if verbose flag is enabled or 0

mnt_context_reset_status ()

int                 mnt_context_reset_status            (struct libmnt_context *cxt);

Resets mount(2) and mount.type statuses, so mnt_context_do_mount() or mnt_context_do_umount() could be again called with the same settings.

BE CAREFUL -- after this soft reset the libmount will NOT parse mount options, evaluate permissions or apply stuff from fstab.

cxt :

context

Returns :

0 on success, negative number in case of error.

mnt_context_set_cache ()

int                 mnt_context_set_cache               (struct libmnt_context *cxt,
                                                         struct libmnt_cache *cache);

The mount context maintains a private struct libmnt_cache by default. This function allows to overwrite the private cache with an external instance. Note that the external instance is not deallocated by mnt_free_context().

If the cache argument is NULL then the current private cache instance is reseted.

cxt :

mount context

cache :

cache instance or nULL

Returns :

0 on success, negative number in case of error.

mnt_context_set_fs ()

int                 mnt_context_set_fs                  (struct libmnt_context *cxt,
                                                         struct libmnt_fs *fs);

The mount context uses private fs by default. This function allows to overwrite the private fs with an external instance. Note that the external fs instance is not deallocated by mnt_free_context() or mnt_reset_context().

The fs will be modified by mnt_context_set_{source,target,options,fstype} functions, If the fs is NULL then all current FS specific setting (source, target, etc., exclude spec) is reseted.

cxt :

mount context

fs :

filesystem description

Returns :

0 on success, negative number in case of error.

mnt_context_set_fstab ()

int                 mnt_context_set_fstab               (struct libmnt_context *cxt,
                                                         struct libmnt_table *tb);

The mount context reads /etc/fstab to the the private struct libmnt_table by default. This function allows to overwrite the private fstab with an external instance. Note that the external instance is not deallocated by mnt_free_context().

The fstab is used read-only and is not modified, it should be possible to share the fstab between more mount contexts (TODO: tests it.)

If the tb argument is NULL then the current private fstab instance is reseted.

cxt :

mount context

tb :

fstab

Returns :

0 on success, negative number in case of error.

mnt_context_set_fstype ()

int                 mnt_context_set_fstype              (struct libmnt_context *cxt,
                                                         const char *fstype);

Note that the fstype has to be the real FS type. For patterns with comma-separated list of filesystems or for "nofs" notation use mnt_context_set_fstype_pattern().

cxt :

mount context

fstype :

filesystem type

Returns :

0 on success, negative number in case of error.

mnt_context_set_fstype_pattern ()

int                 mnt_context_set_fstype_pattern      (struct libmnt_context *cxt,
                                                         const char *pattern);

See mount(8), option -t.

cxt :

mount context

pattern :

FS name pattern (or NULL to reset the current setting)

Returns :

0 on success, negative number in case of error.

mnt_context_set_mflags ()

int                 mnt_context_set_mflags              (struct libmnt_context *cxt,
                                                         unsigned long  flags);

Sets mount flags (see mount(2) man page).

Note that mount context allows to define mount options by mount flags. It means you can for example use

mnt_context_set_mflags(cxt, MS_NOEXEC | MS_NOSUID);

rather than

mnt_context_set_options(cxt, "noexec,nosuid");

these both calls have the same effect.

cxt :

mount context

flags :

mount(2) flags (MS_* flags)

Returns :

0 on success, negative number in case of error.

mnt_context_set_mountdata ()

int                 mnt_context_set_mountdata           (struct libmnt_context *cxt,
                                                         void *data);

The mount context generates mountdata from mount options by default. This function allows to overwrite this behavior, and data will be used instead of mount options.

The libmount does not deallocated the data by mnt_free_context(). Note that NULL is also valid mount data.

cxt :

mount context

data :

mount(2) data

Returns :

0 on success, negative number in case of error.

mnt_context_set_options ()

int                 mnt_context_set_options             (struct libmnt_context *cxt,
                                                         const char *optstr);

cxt :

mount context

optstr :

comma delimited mount options

Returns :

0 on success, negative number in case of error.

mnt_context_set_options_pattern ()

int                 mnt_context_set_options_pattern     (struct libmnt_context *cxt,
                                                         const char *pattern);

See mount(8), option -O.

cxt :

mount context

pattern :

options pattern (or NULL to reset the current setting)

Returns :

0 on success, negative number in case of error.

mnt_context_set_optsmode ()

int                 mnt_context_set_optsmode            (struct libmnt_context *cxt,
                                                         int mode);

Controls how to use mount optionsmsource and target paths from fstab/mtab.

MNT_OMODE_IGNORE: ignore mtab/fstab options

MNT_OMODE_APPEND: append mtab/fstab options to existing options

MNT_OMODE_PREPEND: prepend mtab/fstab options to existing options

MNT_OMODE_REPLACE: replace existing options with options from mtab/fstab

MNT_OMODE_FORCE: always read mtab/fstab (although source and target is defined)

MNT_OMODE_FSTAB: read from fstab

MNT_OMODE_MTAB: read from mtab if fstab not enabled or failed

MNT_OMODE_NOTAB: do not read fstab/mtab at all

MNT_OMODE_AUTO: default mode (MNT_OMODE_PREPEND | MNT_OMODE_FSTAB | MNT_OMODE_MTAB)

MNT_OMODE_USER: default for non-root users (MNT_OMODE_REPLACE | MNT_OMODE_FORCE | MNT_OMODE_FSTAB)

Notes:

  • MNT_OMODE_USER is always used if mount context is in restricted mode

  • MNT_OMODE_AUTO is used if nothing other is defined

  • the flags are eavaluated in this order: MNT_OMODE_NOTAB, MNT_OMODE_FORCE, MNT_OMODE_FSTAB, MNT_OMODE_MTAB and then the mount options from fstab/mtab are set according to MNT_OMODE_{IGNORE,APPEND,PREPAND,REPLACE}

cxt :

mount context

mode :

MNT_OMASK_* flags

Returns :

0 on success, negative number in case of error.

mnt_context_set_passwd_cb ()

int                 mnt_context_set_passwd_cb           (struct libmnt_context *cxt,
                                                         char* (*get) (struct libmnt_context *),
                                                         void (*release) (struct libmnt_context *, char *));

Sets callbacks for encryption password (e.g encrypted loopdev). This function is deprecated (encrypted loops are no ore supported).

cxt :

mount context

get :

callback to get password

release :

callback to release (delallocate) password

Returns :

0 on success, negative number in case of error.

mnt_context_set_source ()

int                 mnt_context_set_source              (struct libmnt_context *cxt,
                                                         const char *source);

cxt :

mount context

source :

mount source (device, directory, UUID, LABEL, ...)

Returns :

0 on success, negative number in case of error.

mnt_context_set_syscall_status ()

int                 mnt_context_set_syscall_status      (struct libmnt_context *cxt,
                                                         int status);

The status should be 0 on success, or negative number on error (-errno).

This function should be used only if [u]mount(2) syscall is NOT called by libmount code.

cxt :

mount context

status :

mount(2) status

Returns :

0 or negative number in case of error.

mnt_context_set_tables_errcb ()

int                 mnt_context_set_tables_errcb        (struct libmnt_context *cxt,
                                                         int (*cb) (struct libmnt_table *tb, const char *filename, int line));

The error callback is used for all tab files (e.g. mtab, fstab) parsed within the context.

See also mnt_context_get_mtab(), mnt_context_get_fstab(), mnt_table_set_parser_errcb().

cxt :

mount context

cb :

pointer to callback function

Returns :

0 on success, negative number in case of error.

mnt_context_set_target ()

int                 mnt_context_set_target              (struct libmnt_context *cxt,
                                                         const char *target);

cxt :

mount context

target :

mountpoint

Returns :

0 on success, negative number in case of error.

mnt_context_set_user_mflags ()

int                 mnt_context_set_user_mflags         (struct libmnt_context *cxt,
                                                         unsigned long  flags);

Sets userspace mount flags.

See also notest for mnt_context_set_mflags().

cxt :

mount context

flags :

mount(2) flags (MNT_MS_* flags, e.g. MNT_MS_LOOP)

Returns :

0 on success, negative number in case of error.

mnt_context_strerror ()

int                 mnt_context_strerror                (struct libmnt_context *cxt,
                                                         char *buf,
                                                         size_t bufsiz);

Not implemented yet.

cxt :

context

buf :

buffer

bufsiz :

size of the buffer

Returns :

0 or negative number in case of error.

mnt_context_syscall_called ()

int                 mnt_context_syscall_called          (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if mount(2) syscall has been called, or 0.

mnt_context_tab_applied ()

int                 mnt_context_tab_applied             (struct libmnt_context *cxt);

cxt :

mount context

Returns :

1 if fstab (or mtab) has been applied to the context, or 0.

mnt_context_wait_for_children ()

int                 mnt_context_wait_for_children       (struct libmnt_context *cxt,
                                                         int *nchildren,
                                                         int *nerrs);

MNT_ERR_AMBIFS

#define MNT_ERR_AMBIFS       5006

libblkid detected more filesystems on the device


MNT_ERR_APPLYFLAGS

#define MNT_ERR_APPLYFLAGS   5005

failed to apply MS_PROPAGATION flags


MNT_ERR_LOOPDEV

#define MNT_ERR_LOOPDEV	     5003

loopdev setup failed, errno set by libc


MNT_ERR_MOUNTOPT

#define MNT_ERR_MOUNTOPT     5004

failed to parse/use userspace mount options


MNT_ERR_NOFSTAB

#define MNT_ERR_NOFSTAB      5000

not found required entry in fstab


MNT_ERR_NOFSTYPE

#define MNT_ERR_NOFSTYPE     5001

failed to detect filesystem type


MNT_ERR_NOSOURCE

#define MNT_ERR_NOSOURCE     5002

required mount source undefined