Utils

Utils — misc utils.

Functions

int mnt_fstype_is_netfs ()
int mnt_fstype_is_pseudofs ()
const char * mnt_get_fstab_path ()
char * mnt_get_mountpoint ()
const char * mnt_get_mtab_path ()
const char * mnt_get_swaps_path ()
int mnt_guess_system_root ()
int mnt_has_regular_mtab ()
char * mnt_mangle ()
int mnt_match_fstype ()
int mnt_tag_is_valid ()
char * mnt_unmangle ()

Description

Functions

mnt_fstype_is_netfs ()

int
mnt_fstype_is_netfs (const char *type);

Parameters

type

filesystem name

 

Returns

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


mnt_fstype_is_pseudofs ()

int
mnt_fstype_is_pseudofs (const char *type);

Parameters

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

char *
mnt_get_mountpoint (const char *path);

This function finds the mountpoint that a given path resides in. path should be canonicalized. The returned pointer should be freed by the caller.

WARNING: the function compares st_dev of the path elements. This traditional way may be insufficient on filesystems like Linux "overlay". See also mnt_table_find_target().

Parameters

path

pathname

 

Returns

allocated string with the target of the mounted device or NULL on error


mnt_get_mtab_path ()

const char *
mnt_get_mtab_path (void);

mnt_get_mtab_path is deprecated and should not be used in newly-written code.

libmount uses /proc/self/mountinfo only.

This function returns the *default* location of the mtab file.

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

int
mnt_guess_system_root (dev_t devno,
                       struct libmnt_cache *cache,
                       char **path);

Converts devno to the real device name if devno major number is greater than zero, otherwise use root= kernel cmdline option to get device name.

The function uses /sys to convert devno to device name.

Parameters

devno

device number or zero

 

cache

paths cache or NULL

 

path

returns allocated path

 

Returns

0 = success, 1 = not found, <0 = error

Since: 2.34


mnt_has_regular_mtab ()

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

mnt_has_regular_mtab is deprecated and should not be used in newly-written code.

libmount does not use /etc/mtab at all since v2.39.

Parameters

mtab

returns NULL

 

writable

returns 0

 

Returns

0


mnt_mangle ()

char *
mnt_mangle (const char *str);

Encode str to be compatible with fstab/mtab

Parameters

str

string

 

Returns

newly 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 filesystems 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

Parameters

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

int
mnt_tag_is_valid (const char *tag);

Parameters

tag

NAME=value string

 

Returns

1 if the tag is parsable and tag NAME= is supported by libmount, or 0.


mnt_unmangle ()

char *
mnt_unmangle (const char *str);

Decode str from fstab/mtab

Parameters

str

string

 

Returns

newly allocated string or NULL in case of error.