Welcome to NYCU CSIT Mirror site

Options string: libmount Reference Manual

Options string

Options string — low-level API for working with mount options

Description

This is a simple and low-level API to working with mount options that are stored in a string.

Functions

mnt_optstr_append_option ()

int
mnt_optstr_append_option (char **optstr,
                          const char *name,
                          const char *value);

Parameters

optstr

option string or NULL, returns a reallocated string

 

name

value name

 

value

value

 

Returns

0 on success or <0 in case of error. After an error the optstr should be unmodified.


mnt_optstr_apply_flags ()

int
mnt_optstr_apply_flags (char **optstr,
                        unsigned long  flags,
                        const struct libmnt_optmap *map);

Removes/adds options to the optstr according to flags. For example:

MS_NOATIME and "foo,bar,noexec" --returns-> "foo,bar,noatime"

Parameters

optstr

string with comma separated list of options

 

flags

returns mount flags

 

map

options map

 

Returns

0 on success or negative number in case of error.


mnt_optstr_deduplicate_option ()

int
mnt_optstr_deduplicate_option (char **optstr,
                               const char *name);

Removes all instances of name except the last one.

Parameters

optstr

string with a comma separated list of options

 

name

requested option name

 

Returns

0 on success, 1 when not found the name or negative number in case of error.


mnt_optstr_get_flags ()

int
mnt_optstr_get_flags (const char *optstr,
                      unsigned long *flags,
                      const struct libmnt_optmap *map);

Returns in flags IDs of options from optstr as defined in the map .

For example:

"bind,exec,foo,bar" --returns-> MS_BIND

"bind,noexec,foo,bar" --returns-> MS_BIND|MS_NOEXEC

Note that flags are not zeroized by this function! This function sets/unsets bits in the flags only.

Parameters

optstr

string with comma separated list of options

 

flags

returns mount flags

 

map

options map

 

Returns

0 on success or negative number in case of error


mnt_optstr_get_option ()

int
mnt_optstr_get_option (const char *optstr,
                       const char *name,
                       char **value,
                       size_t *valsz);

Parameters

optstr

string with a comma separated list of options

 

name

requested option name

 

value

returns a pointer to the beginning of the value (e.g. name=VALUE) or NULL

 

valsz

returns size of the value or 0

 

Returns

0 on success, 1 when not found the name or negative number in case of error.


mnt_optstr_get_options ()

int
mnt_optstr_get_options (const char *optstr,
                        char **subset,
                        const struct libmnt_optmap *map,
                        int ignore);

Extracts options from optstr that belong to the map , for example:

mnt_optstr_get_options(optstr, &p, mnt_get_builtin_optmap(MNT_LINUX_MAP), MNT_NOMTAB);

the 'p' returns all VFS options, the options that do not belong to mtab are ignored.

Parameters

optstr

string with a comma separated list of options

 

subset

returns newly allocated string with options

 

map

options map

 

ignore

mask of the options that should be ignored

 

Returns

0 on success, or a negative number in case of error.


mnt_optstr_next_option ()

int
mnt_optstr_next_option (char **optstr,
                        char **name,
                        size_t *namesz,
                        char **value,
                        size_t *valuesz);

Parses the first option in optstr .

Parameters

optstr

option string, returns the position of the next option

 

name

returns the option name

 

namesz

returns the option name length

 

value

returns the option value or NULL

 

valuesz

returns the option value length or zero

 

Returns

0 on success, 1 at the end of optstr or negative number in case of error.


mnt_optstr_prepend_option ()

int
mnt_optstr_prepend_option (char **optstr,
                           const char *name,
                           const char *value);

Parameters

optstr

option string or NULL, returns a reallocated string

 

name

value name

 

value

value

 

Returns

0 on success or <0 in case of error. After an error the optstr should be unmodified.


mnt_optstr_remove_option ()

int
mnt_optstr_remove_option (char **optstr,
                          const char *name);

Parameters

optstr

string with a comma separated list of options

 

name

requested option name

 

Returns

0 on success, 1 when not found the name or negative number in case of error.


mnt_optstr_set_option ()

int
mnt_optstr_set_option (char **optstr,
                       const char *name,
                       const char *value);

Set or unset the option value .

Parameters

optstr

string with a comma separated list of options

 

name

requested option

 

value

new value or NULL

 

Returns

0 on success, 1 when not found the name or negative number in case of error.


mnt_split_optstr ()

int
mnt_split_optstr (const char *optstr,
                  char **user,
                  char **vfs,
                  char **fs,
                  int ignore_user,
                  int ignore_vfs);

For example:

mnt_split_optstr(optstr, &u, NULL, NULL, MNT_NOMTAB, 0);

returns all userspace options, the options that do not belong to mtab are ignored.

Note that FS options are all options that are undefined in MNT_USERSPACE_MAP or MNT_LINUX_MAP.

Parameters

optstr

string with comma separated list of options

 

user

returns newly allocated string with userspace options

 

vfs

returns newly allocated string with VFS options

 

fs

returns newly allocated string with FS options

 

ignore_user

option mask for options that should be ignored

 

ignore_vfs

option mask for options that should be ignored

 

Returns

0 on success, or a negative number in case of error.


mnt_match_options ()

int
mnt_match_options (const char *optstr,
                   const char *pattern);

The "no" could be used for individual items in the options list. The "no" prefix does not have a global meaning.

Unlike fs type matching, nonetdev,user and nonetdev,nouser have DIFFERENT meanings; each option is matched explicitly as specified.

The "no" prefix interpretation could be disabled by the "+" prefix, for example "+noauto" matches if optstr literally contains the "noauto" string.

"xxx,yyy,zzz" : "nozzz" -> False

"xxx,yyy,zzz" : "xxx,noeee" -> True

"bar,zzz" : "nofoo" -> True (does not contain "foo")

"nofoo,bar" : "nofoo" -> True (does not contain "foo")

"nofoo,bar" : "+nofoo" -> True (contains "nofoo")

"bar,zzz" : "+nofoo" -> False (does not contain "nofoo")

Parameters

optstr

options string

 

pattern

comma delimited list of options

 

Returns

1 if pattern is matching, else 0. This function also returns 0 if pattern is NULL and optstr is non-NULL.