Utils

Utils — misc utils.

Synopsis

int                 mnt_fstype_is_netfs                 (const char *type);
int                 mnt_fstype_is_pseudofs              (const char *type);
const char *        mnt_get_fstab_path                  (void);
const char *        mnt_get_mtab_path                   (void);
const char *        mnt_get_swaps_path                  (void);
int                 mnt_has_regular_mtab                (const char **mtab,
                                                         int *writable);
char *              mnt_mangle                          (const char *str);
int                 mnt_match_fstype                    (const char *type,
                                                         const char *pattern);
int                 mnt_match_options                   (const char *optstr,
                                                         const char *pattern);
char *              mnt_unmangle                        (const char *str);

Description

Details

mnt_fstype_is_netfs ()

int                 mnt_fstype_is_netfs                 (const char *type);

type :

filesystem name

Returns :

1 for filesystems like cifs, nfs, ... or 0.

mnt_fstype_is_pseudofs ()

int                 mnt_fstype_is_pseudofs              (const char *type);

type :

filesystem name

Returns :

1 for filesystems like proc, sysfs, ... or 0.

mnt_get_fstab_path ()

const char *        mnt_get_fstab_path                  (void);

Returns :

path to /etc/fstab or $LIBMOUNT_FSTAB.

mnt_get_mtab_path ()

const char *        mnt_get_mtab_path                   (void);

This function returns *default* location of the mtab file. The result does not have to be writable. See also mnt_has_regular_mtab().

Returns :

path to /etc/mtab or $LIBMOUNT_MTAB.

mnt_get_swaps_path ()

const char *        mnt_get_swaps_path                  (void);

Returns :

path to /proc/swaps or $LIBMOUNT_SWAPS.

mnt_has_regular_mtab ()

int                 mnt_has_regular_mtab                (const char **mtab,
                                                         int *writable);

If the file does not exist and writable argument is not NULL then it will try to create the file

mtab :

returns path to mtab

writable :

returns 1 if the file is writable

Returns :

1 if /etc/mtab is a regular file, and 0 in case of error (check errno for more details).

mnt_mangle ()

char *              mnt_mangle                          (const char *str);

Encode str to be compatible with fstab/mtab

str :

string

Returns :

new allocated string or NULL in case of error.

mnt_match_fstype ()

int                 mnt_match_fstype                    (const char *type,
                                                         const char *pattern);

The pattern list of filesystem can be prefixed with a global "no" prefix to invert matching of the whole list. The "no" could also be used for individual items in the pattern list. So, "nofoo,bar" has the same meaning as "nofoo,nobar".

"bar" : "nofoo,bar" -> False (global "no" prefix)

"bar" : "foo,bar" -> True

"bar" : "foo,nobar" -> False

type :

filesystem type

pattern :

filesystem name or comma delimited list of names

Returns :

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

mnt_match_options ()

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

The "no" could 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 disable by "+" prefix, for example "+noauto" matches if optstr literally contains "noauto" string.

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

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

"bar,zzz" : "nofoo" -> True

"nofoo,bar" : "+nofoo" -> True

"bar,zzz" : "+nofoo" -> False

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.

mnt_unmangle ()

char *              mnt_unmangle                        (const char *str);

Decode str from fstab/mtab

str :

string

Returns :

new allocated string or NULL in case of error.