libmount Reference Manual | ||||
---|---|---|---|---|
Top | Description |
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_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
); 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_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_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_wait_for_children (struct libmnt_context *cxt
,int *nchildren
,int *nerrs
);
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
void mnt_free_context (struct libmnt_context *cxt
);
Deallocates context struct.
|
mount context |
struct libmnt_context * mnt_new_context (void
);
Returns : |
newly allocated mount 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.
|
mount context |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_append_options (struct libmnt_context *cxt
,const char *optstr
);
|
mount context |
|
comma delimited mount options |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_apply_fstab (struct libmnt_context *cxt
);
This function is optional.
|
mount context |
Returns : |
0 on success, negative number in case of error. |
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 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).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_disable_helpers (struct libmnt_context *cxt
,int disable
);
Enable/disable /sbin/[u]mount.* helpers (see mount(8) man page, option -i).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_disable_mtab (struct libmnt_context *cxt
,int disable
);
Disable/enable mtab update (see mount(8) man page, option -n).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_fake (struct libmnt_context *cxt
,int enable
);
Enable/disable fake mounting (see mount(8) man page, option -f).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_force (struct libmnt_context *cxt
,int enable
);
Enable/disable force umounting (see umount(8) man page, option -f).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
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).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_lazy (struct libmnt_context *cxt
,int enable
);
Enable/disable lazy umount (see umount(8) man page, option -l).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_loopdel (struct libmnt_context *cxt
,int enable
);
Enable/disable loop delete (destroy) after umount (see umount(8), option -d)
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
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).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_sloppy (struct libmnt_context *cxt
,int enable
);
Set/unset sloppy mounting (see mount(8) man page, option -s).
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_enable_verbose (struct libmnt_context *cxt
,int enable
);
Enable/disable verbose output (TODO: not implemented yet)
|
mount context |
|
TRUE or FALSE |
Returns : |
0 on success, negative number in case of error. |
struct libmnt_cache * mnt_context_get_cache (struct libmnt_context *cxt
);
See also mnt_context_set_cache()
.
|
mount context |
Returns : |
pointer to cache or NULL if canonicalization is disabled. |
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.
|
mount context |
Returns : |
pointer to FS description or NULL in case of calloc() errrr. |
int mnt_context_get_fstab (struct libmnt_context *cxt
,struct libmnt_table **tb
);
See also mnt_table_parse_fstab()
for more details about fstab.
|
mount context |
|
returns fstab |
Returns : |
0 on success, negative number in case of error. |
const char * mnt_context_get_fstype (struct libmnt_context *cxt
);
|
mount context |
Returns : |
returns pointer or NULL in case of error pr if not set. |
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.
|
mount context |
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.
|
mount context |
Returns : |
pointer to lock struct or NULL. |
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()
).
|
mount context |
|
returns MS_* mount flags |
Returns : |
0 on success, negative number in case of error. |
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
).
|
mount context |
|
returns mtab |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_get_optsmode (struct libmnt_context *cxt
);
|
mount context |
Returns : |
MNT_OMASK_* mask or zero. |
const char * mnt_context_get_source (struct libmnt_context *cxt
);
|
mount context |
Returns : |
returns pointer or NULL in case of error pr if not set. |
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 sucessful.
|
mount context |
Returns : |
1 if mount.type or mount(2) syscall has been succesfully called. |
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.
|
mount context |
Returns : |
mount(2) errno if the syscall failed or 0. |
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
).
|
mount context |
|
e.g. /proc/self/mountinfo |
|
returns the table |
Returns : |
0 on success, negative number in case of error. |
const char * mnt_context_get_target (struct libmnt_context *cxt
);
|
mount context |
Returns : |
returns pointer or NULL in case of error pr if not set. |
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()
).
|
mount context |
|
returns mount flags |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_helper_executed (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if mount.type helper has been executed, or 0. |
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.
|
context |
|
getopt() result |
|
getopt() optarg |
Returns : |
negative number on error, 1 if c is unknown option, 0 on success. |
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);
|
mount context |
|
MNT_ACT_{UMOUNT,MOUNT} |
|
not used now |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_is_fake (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if fake flag is enabled or 0 |
int mnt_context_is_force (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if force umounting flag is enabled or 0 |
int mnt_context_is_fs_mounted (struct libmnt_context *cxt
,struct libmnt_fs *fs
,int *mounted
);
|
context |
|
filesystem |
|
returns 1 for mounted and 0 for non-mounted filesystems |
Returns : |
0 on success and negative number in case of error. |
int mnt_context_is_lazy (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if lazy umount is enabled or 0 |
int mnt_context_is_nomtab (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if no-mtab is enabled or 0 |
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.
|
mount context |
Returns : |
1 if read-only remount failed umount(2) is enables or 0 |
int mnt_context_is_restricted (struct libmnt_context *cxt
);
|
mount context |
Returns : |
0 for unrestricted mount (user is root), or 1 for non-root mounts |
int mnt_context_is_sloppy (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if sloppy flag is enabled or 0 |
int mnt_context_is_verbose (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if verbose flag is enabled or 0 |
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.
|
context |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
cache instance or nULL |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
filesystem description |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
fstab |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_fstype (struct libmnt_context *cxt
,const char *fstype
);
Note that the fstype
has to be the real FS type. For comma-separated list of
filesystems or for "nofs" notation use mnt_context_set_fstype_pattern()
.
|
mount context |
|
filesystem type |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_fstype_pattern (struct libmnt_context *cxt
,const char *pattern
);
See mount(8), option -t.
|
mount context |
|
FS name pattern (or NULL to reset the current setting) |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
mount(2) flags (MS_* flags) |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
mount(2) data |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_options (struct libmnt_context *cxt
,const char *optstr
);
|
mount context |
|
comma delimited mount options |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_options_pattern (struct libmnt_context *cxt
,const char *pattern
);
See mount(8), option -O.
|
mount context |
|
options pattern (or NULL to reset the current setting) |
Returns : |
0 on success, negative number in case of error. |
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}
|
mount context |
|
MNT_OMASK_* flags |
Returns : |
0 on success, negative number in case of error. |
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)
|
mount context |
|
callback to get password |
|
callback to release (delallocate) password |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_source (struct libmnt_context *cxt
,const char *source
);
|
mount context |
|
mount source (device, directory, UUID, LABEL, ...) |
Returns : |
0 on success, negative number in case of error. |
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.
|
mount context |
|
mount(2) status |
Returns : |
0 or negative number in case of error. |
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()
.
|
mount context |
|
pointer to callback function |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_set_target (struct libmnt_context *cxt
,const char *target
);
|
mount context |
|
mountpoint |
Returns : |
0 on success, negative number in case of error. |
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()
.
|
mount context |
|
mount(2) flags (MNT_MS_* flags, e.g. MNT_MS_LOOP) |
Returns : |
0 on success, negative number in case of error. |
int mnt_context_strerror (struct libmnt_context *cxt
,char *buf
,size_t bufsiz
);
Not implemented yet.
|
context |
|
buffer |
|
size of the buffer |
Returns : |
0 or negative number in case of error. |
int mnt_context_syscall_called (struct libmnt_context *cxt
);
|
mount context |
Returns : |
1 if mount(2) syscall has been called, or 0. |