Filesystem

Filesystem — represents one entry from fstab, mtab, or mountinfo file

Functions

struct libmnt_fs * mnt_copy_fs ()
void mnt_free_fs ()
void mnt_free_mntent ()
void mnt_ref_fs ()
void mnt_unref_fs ()
int mnt_fs_append_attributes ()
int mnt_fs_append_comment ()
int mnt_fs_append_options ()
int mnt_fs_get_attribute ()
const char * mnt_fs_get_attributes ()
const char * mnt_fs_get_bindsrc ()
const char * mnt_fs_get_comment ()
dev_t mnt_fs_get_devno ()
int mnt_fs_get_freq ()
const char * mnt_fs_get_fs_options ()
const char * mnt_fs_get_fstype ()
int mnt_fs_get_id ()
int mnt_fs_get_option ()
const char * mnt_fs_get_optional_fields ()
const char * mnt_fs_get_options ()
int mnt_fs_get_parent_id ()
int mnt_fs_get_passno ()
int mnt_fs_get_priority ()
int mnt_fs_get_propagation ()
const char * mnt_fs_get_root ()
off_t mnt_fs_get_size ()
const char * mnt_fs_get_source ()
const char * mnt_fs_get_srcpath ()
const char * mnt_fs_get_swaptype ()
int mnt_fs_get_tag ()
int mnt_fs_get_table ()
const char * mnt_fs_get_target ()
pid_t mnt_fs_get_tid ()
off_t mnt_fs_get_usedsize ()
void * mnt_fs_get_userdata ()
const char * mnt_fs_get_user_options ()
const char * mnt_fs_get_vfs_options ()
char * mnt_fs_get_vfs_options_all ()
int mnt_fs_is_kernel ()
int mnt_fs_is_netfs ()
int mnt_fs_is_pseudofs ()
int mnt_fs_is_swaparea ()
int mnt_fs_match_fstype ()
int mnt_fs_match_options ()
int mnt_fs_match_source ()
int mnt_fs_match_target ()
int mnt_fs_prepend_attributes ()
int mnt_fs_prepend_options ()
int mnt_fs_print_debug ()
int mnt_fs_set_attributes ()
int mnt_fs_set_bindsrc ()
int mnt_fs_set_comment ()
int mnt_fs_set_freq ()
int mnt_fs_set_fstype ()
int mnt_fs_set_options ()
int mnt_fs_set_passno ()
int mnt_fs_set_priority ()
int mnt_fs_set_root ()
int mnt_fs_set_source ()
int mnt_fs_set_target ()
int mnt_fs_set_userdata ()
char * mnt_fs_strdup_options ()
int mnt_fs_streq_srcpath ()
int mnt_fs_streq_target ()
int mnt_fs_to_mntent ()
struct libmnt_fs * mnt_new_fs ()
void mnt_reset_fs ()

Types and Values

struct libmnt_fs

Description

Functions

mnt_copy_fs ()

struct libmnt_fs *
mnt_copy_fs (struct libmnt_fs *dest,
             const struct libmnt_fs *src);

If dest is NULL, then a new FS is allocated, if any dest field is already set, then the field is NOT overwritten.

This function does not copy userdata (se mnt_fs_set_userdata()). A new copy is not linked with any existing mnt_tab.

Parameters

dest

destination FS

 

src

source FS

 

Returns

dest or NULL in case of error


mnt_free_fs ()

void
mnt_free_fs (struct libmnt_fs *fs);

Deallocates the fs. This function does not care about reference count. Don't use this function directly -- it's better to use mnt_unref_fs().

The reference counting is supported since util-linux v2.24.

Parameters

fs

fs pointer

 

mnt_free_mntent ()

void
mnt_free_mntent (struct mntent *mnt);

Deallocates the "mntent.h" mount entry.

Parameters

mnt

mount entry

 

mnt_ref_fs ()

void
mnt_ref_fs (struct libmnt_fs *fs);

Increments reference counter.

Parameters

fs

fs pointer

 

mnt_unref_fs ()

void
mnt_unref_fs (struct libmnt_fs *fs);

De-increments reference counter, on zero the fs is automatically deallocated by mnt_free_fs().

Parameters

fs

fs pointer

 

mnt_fs_append_attributes ()

int
mnt_fs_append_attributes (struct libmnt_fs *fs,
                          const char *optstr);

Appends mount attributes. (See mnt_fs_set_attributes()).

Parameters

fs

fstab/mtab/mountinfo entry

 

optstr

options string

 

Returns

0 on success or negative number in case of error.


mnt_fs_append_comment ()

int
mnt_fs_append_comment (struct libmnt_fs *fs,
                       const char *comm);

See also mnt_fs_set_comment().

Parameters

fs

fstab entry pointer

 

comm

comment string

 

Returns

0 on success or <0 in case of error.


mnt_fs_append_options ()

int
mnt_fs_append_options (struct libmnt_fs *fs,
                       const char *optstr);

Parses (splits) optstr and appends results to VFS, FS and userspace lists of options.

If optstr is NULL, then fs is not modified and 0 is returned.

Parameters

fs

fstab/mtab/mountinfo entry

 

optstr

mount options

 

Returns

0 on success or negative number in case of error.


mnt_fs_get_attribute ()

int
mnt_fs_get_attribute (struct libmnt_fs *fs,
                      const char *name,
                      char **value,
                      size_t *valsz);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

name

option name

 

value

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

 

valsz

returns size of options value or 0

 

Returns

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


mnt_fs_get_attributes ()

const char *
mnt_fs_get_attributes (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab entry pointer

 

Returns

pointer to attributes string or NULL.


mnt_fs_get_bindsrc ()

const char *
mnt_fs_get_bindsrc (struct libmnt_fs *fs);

Parameters

fs

/run/mount/utab entry

 

Returns

full path that was used for mount(2) on MS_BIND


mnt_fs_get_comment ()

const char *
mnt_fs_get_comment (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

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


mnt_fs_get_devno ()

dev_t
mnt_fs_get_devno (struct libmnt_fs *fs);

Parameters

fs

/proc/self/mountinfo entry

 

Returns

value of st_dev for files on filesystem or 0 in case of error.


mnt_fs_get_freq ()

int
mnt_fs_get_freq (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

dump frequency in days.


mnt_fs_get_fs_options ()

const char *
mnt_fs_get_fs_options (struct libmnt_fs *fs);

mnt_fs_get_fstype ()

const char *
mnt_fs_get_fstype (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

pointer to filesystem type.


mnt_fs_get_id ()

int
mnt_fs_get_id (struct libmnt_fs *fs);

Parameters

fs

/proc/self/mountinfo entry

 

Returns

mount ID (unique identifier of the mount) or negative number in case of error.


mnt_fs_get_option ()

int
mnt_fs_get_option (struct libmnt_fs *fs,
                   const char *name,
                   char **value,
                   size_t *valsz);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

name

option name

 

value

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

 

valsz

returns size of options value or 0

 

Returns

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


mnt_fs_get_optional_fields ()

const char *
mnt_fs_get_optional_fields (struct libmnt_fs *fs);

Parameters

fs

mountinfo entry pointer

 

Returns

pointer to string with mountinfo optional fields or NULL in case of error.


mnt_fs_get_options ()

const char *
mnt_fs_get_options (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

pointer to string or NULL in case of error.


mnt_fs_get_parent_id ()

int
mnt_fs_get_parent_id (struct libmnt_fs *fs);

Parameters

fs

/proc/self/mountinfo entry

 

Returns

parent mount ID or negative number in case of error.


mnt_fs_get_passno ()

int
mnt_fs_get_passno (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab entry pointer

 

Returns

"pass number on parallel fsck".


mnt_fs_get_priority ()

int
mnt_fs_get_priority (struct libmnt_fs *fs);

Parameters

fs

/proc/swaps entry

 

Returns

priority


mnt_fs_get_propagation ()

int
mnt_fs_get_propagation (struct libmnt_fs *fs,
                        unsigned long *flags);

Note that this function sets flags to zero if no propagation flags are found in the mountinfo file. The kernel default is MS_PRIVATE, this flag is not stored in the mountinfo file.

Parameters

fs

mountinfo entry

 

flags

returns propagation MS_* flags as present in the mountinfo file

 

Returns

0 on success or negative number in case of error.


mnt_fs_get_root ()

const char *
mnt_fs_get_root (struct libmnt_fs *fs);

Parameters

fs

/proc/self/mountinfo entry

 

Returns

root of the mount within the filesystem or NULL


mnt_fs_get_size ()

off_t
mnt_fs_get_size (struct libmnt_fs *fs);

Parameters

fs

/proc/swaps entry

 

Returns

size


mnt_fs_get_source ()

const char *
mnt_fs_get_source (struct libmnt_fs *fs);

Parameters

fs

struct libmnt_file (fstab/mtab/mountinfo) fs

 

Returns

mount source. Note that the source could be unparsed TAG (LABEL/UUID). See also mnt_fs_get_srcpath() and mnt_fs_get_tag().


mnt_fs_get_srcpath ()

const char *
mnt_fs_get_srcpath (struct libmnt_fs *fs);

The mount "source path" is:

  • a directory for 'bind' mounts (in fstab or mtab only)

  • a device name for standard mounts

See also mnt_fs_get_tag() and mnt_fs_get_source().

Parameters

fs

struct libmnt_file (fstab/mtab/mountinfo) fs

 

Returns

mount source path or NULL in case of error or when the path is not defined.


mnt_fs_get_swaptype ()

const char *
mnt_fs_get_swaptype (struct libmnt_fs *fs);

Parameters

fs

/proc/swaps entry

 

Returns

swap type or NULL


mnt_fs_get_tag ()

int
mnt_fs_get_tag (struct libmnt_fs *fs,
                const char **name,
                const char **value);

"TAG" is NAME=VALUE (e.g. LABEL=foo)

The TAG is the first column in the fstab file. The TAG or "srcpath" always has to be set for all entries.

See also mnt_fs_get_source().

1
2
3
4
5
6
7
8
9
10
11
12
13
char *src;
struct libmnt_fs *fs = mnt_table_find_target(tb, "/home", MNT_ITER_FORWARD);

if (!fs)
	goto err;

src = mnt_fs_get_srcpath(fs);
if (!src) {
	char *tag, *val;
	if (mnt_fs_get_tag(fs, &tag, &val) == 0)
		printf("%s: %s\n", tag, val);	// LABEL or UUID
} else
	printf("device: %s\n", src);		// device or bind path

Parameters

fs

fs

 

name

returns pointer to NAME string

 

value

returns pointer to VALUE string

 

Returns

0 on success or negative number in case a TAG is not defined.


mnt_fs_get_table ()

int
mnt_fs_get_table (struct libmnt_fs *fs,
                  struct libmnt_table **tb);

Parameters

fs

table entry

 

tb

table that contains fs

 

Returns

0 or negative number on error (if fs or tb is NULL).

Since: 2.34


mnt_fs_get_target ()

const char *
mnt_fs_get_target (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

pointer to mountpoint path or NULL


mnt_fs_get_tid ()

pid_t
mnt_fs_get_tid (struct libmnt_fs *fs);

Parameters

fs

/proc/tid/mountinfo entry

 

Returns

TID (task ID) for filesystems read from the mountinfo file


mnt_fs_get_usedsize ()

off_t
mnt_fs_get_usedsize (struct libmnt_fs *fs);

Parameters

fs

/proc/swaps entry

 

Returns

used size


mnt_fs_get_userdata ()

void *
mnt_fs_get_userdata (struct libmnt_fs *fs);

Parameters

fs

struct libmnt_file instance

 

Returns

private data set by mnt_fs_set_userdata() or NULL.


mnt_fs_get_user_options ()

const char *
mnt_fs_get_user_options (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab entry pointer

 

Returns

pointer to userspace mount option string or NULL.


mnt_fs_get_vfs_options ()

const char *
mnt_fs_get_vfs_options (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab entry pointer

 

Returns

pointer to fs-independent (VFS) mount option string or NULL.


mnt_fs_get_vfs_options_all ()

char *
mnt_fs_get_vfs_options_all (struct libmnt_fs *fs);

Parameters

fs

fstab/mtab entry pointer

 

Returns

pointer to newlly allocated string (can be freed by free(3)) or NULL in case of error. The string contains all (including defaults) mount options.


mnt_fs_is_kernel ()

int
mnt_fs_is_kernel (struct libmnt_fs *fs);

Parameters

fs

filesystem

 

Returns

1 if the filesystem description is read from kernel e.g. /proc/mounts.


mnt_fs_is_netfs ()

int
mnt_fs_is_netfs (struct libmnt_fs *fs);

Parameters

fs

filesystem

 

Returns

1 if the filesystem is a network filesystem


mnt_fs_is_pseudofs ()

int
mnt_fs_is_pseudofs (struct libmnt_fs *fs);

Parameters

fs

filesystem

 

Returns

1 if the filesystem is a pseudo fs type (proc, cgroups)


mnt_fs_is_swaparea ()

int
mnt_fs_is_swaparea (struct libmnt_fs *fs);

Parameters

fs

filesystem

 

Returns

1 if the filesystem uses "swap" as a type


mnt_fs_match_fstype ()

int
mnt_fs_match_fstype (struct libmnt_fs *fs,
                     const char *types);

For more details see mnt_match_fstype().

Parameters

fs

filesystem

 

types

filesystem name or comma delimited list of filesystems

 

Returns

1 if fs type is matching to types , else 0. The function returns 0 when types is NULL.


mnt_fs_match_options ()

int
mnt_fs_match_options (struct libmnt_fs *fs,
                      const char *options);

For more details see mnt_match_options().

Parameters

fs

filesystem

 

options

comma delimited list of options (and nooptions)

 

Returns

1 if fs type is matching to options , else 0. The function returns 0 when types is NULL.


mnt_fs_match_source ()

int
mnt_fs_match_source (struct libmnt_fs *fs,
                     const char *source,
                     struct libmnt_cache *cache);

Four attempts are possible: 1) compare source with fs->source 2) compare realpath(source ) with fs->source 3) compare realpath(source ) with realpath(fs->source ) 4) compare realpath(source ) with evaluated tag from fs->source

The 2nd, 3rd and 4th attempts are not performed when cache is NULL. The 2nd and 3rd attempts are not performed if fs->source is tag.

Parameters

fs

filesystem

 

source

tag or path (device or so) or NULL

 

cache

tags/paths cache or NULL

 

Returns

1 if fs source is equal to source , else 0.


mnt_fs_match_target ()

int
mnt_fs_match_target (struct libmnt_fs *fs,
                     const char *target,
                     struct libmnt_cache *cache);

Possible are three attempts: 1) compare target with fs->target

2) realpath(target ) with fs->target

3) realpath(target ) with realpath(fs->target ) if fs is not from /proc/self/mountinfo.

However, if mnt_cache_set_targets(cache, mtab) was called, and the path target or fs->target is found in the mtab , the canonicalization is is not performed (see mnt_resolve_target()).

The 2nd and 3rd attempts are not performed when cache is NULL.

Parameters

fs

filesystem

 

target

mountpoint path

 

cache

tags/paths cache or NULL

 

Returns

1 if fs target is equal to target , else 0.


mnt_fs_prepend_attributes ()

int
mnt_fs_prepend_attributes (struct libmnt_fs *fs,
                           const char *optstr);

Prepends mount attributes. (See mnt_fs_set_attributes()).

Parameters

fs

fstab/mtab/mountinfo entry

 

optstr

options string

 

Returns

0 on success or negative number in case of error.


mnt_fs_prepend_options ()

int
mnt_fs_prepend_options (struct libmnt_fs *fs,
                        const char *optstr);

Parses (splits) optstr and prepends the results to VFS, FS and userspace lists of options.

If optstr is NULL, then fs is not modified and 0 is returned.

Parameters

fs

fstab/mtab/mountinfo entry

 

optstr

mount options

 

Returns

0 on success or negative number in case of error.


mnt_fs_print_debug ()

int
mnt_fs_print_debug (struct libmnt_fs *fs,
                    FILE *file);

Parameters

fs

fstab/mtab/mountinfo entry

 

file

file stream

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_attributes ()

int
mnt_fs_set_attributes (struct libmnt_fs *fs,
                       const char *optstr);

Sets mount attributes. The attributes are mount(2) and mount(8) independent options, these options are not sent to the kernel and are not interpreted by libmount. The attributes are stored in /run/mount/utab only.

The attributes are managed by libmount in userspace only. It's possible that information stored in userspace will not be available for libmount after CLONE_FS unshare. Be careful, and don't use attributes if possible.

Parameters

fs

fstab/mtab/mountinfo entry

 

optstr

options string

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_bindsrc ()

int
mnt_fs_set_bindsrc (struct libmnt_fs *fs,
                    const char *src);

Parameters

fs

filesystem

 

src

path

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_comment ()

int
mnt_fs_set_comment (struct libmnt_fs *fs,
                    const char *comm);

Note that the comment has to be terminated by '\n' (new line), otherwise the whole filesystem entry will be written as a comment to the tabfile (e.g. fstab).

Parameters

fs

fstab entry pointer

 

comm

comment string

 

Returns

0 on success or <0 in case of error.


mnt_fs_set_freq ()

int
mnt_fs_set_freq (struct libmnt_fs *fs,
                 int freq);

Parameters

fs

fstab/mtab entry pointer

 

freq

dump frequency in days

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_fstype ()

int
mnt_fs_set_fstype (struct libmnt_fs *fs,
                   const char *fstype);

This function creates a private copy (strdup()) of fstype .

Parameters

fs

fstab/mtab/mountinfo entry

 

fstype

filesystem type

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_options ()

int
mnt_fs_set_options (struct libmnt_fs *fs,
                    const char *optstr);

Splits optstr to VFS, FS and userspace mount options and updates relevant parts of fs .

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

optstr

options string

 

Returns

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


mnt_fs_set_passno ()

int
mnt_fs_set_passno (struct libmnt_fs *fs,
                   int passno);

Parameters

fs

fstab/mtab entry pointer

 

passno

pass number

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_priority ()

int
mnt_fs_set_priority (struct libmnt_fs *fs,
                     int prio);

Parameters

fs

/proc/swaps entry

 

prio

priority

 

Returns

0 or -1 in case of error

Since: 2.28


mnt_fs_set_root ()

int
mnt_fs_set_root (struct libmnt_fs *fs,
                 const char *path);

Parameters

fs

mountinfo entry

 

path

root path

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_source ()

int
mnt_fs_set_source (struct libmnt_fs *fs,
                   const char *source);

This function creates a private copy (strdup()) of source .

Parameters

fs

fstab/mtab/mountinfo entry

 

source

new source

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_target ()

int
mnt_fs_set_target (struct libmnt_fs *fs,
                   const char *tgt);

This function creates a private copy (strdup()) of tgt .

Parameters

fs

fstab/mtab/mountinfo entry

 

tgt

mountpoint

 

Returns

0 on success or negative number in case of error.


mnt_fs_set_userdata ()

int
mnt_fs_set_userdata (struct libmnt_fs *fs,
                     void *data);

The "userdata" are library independent data.

Parameters

fs

struct libmnt_file instance

 

data

user data

 

Returns

0 or negative number in case of error (if fs is NULL).


mnt_fs_strdup_options ()

char *
mnt_fs_strdup_options (struct libmnt_fs *fs);

Merges all mount options (VFS, FS and userspace) to one options string and returns the result. This function does not modify fs .

Parameters

fs

fstab/mtab/mountinfo entry pointer

 

Returns

pointer to string (can be freed by free(3)) or NULL in case of error.


mnt_fs_streq_srcpath ()

int
mnt_fs_streq_srcpath (struct libmnt_fs *fs,
                      const char *path);

Compares fs source path with path . The redundant slashes are ignored. This function compares strings and does not canonicalize the paths. See also more heavy and generic mnt_fs_match_source().

Parameters

fs

fs

 

path

source path

 

Returns

1 if fs source path equal to path , otherwise 0.


mnt_fs_streq_target ()

int
mnt_fs_streq_target (struct libmnt_fs *fs,
                     const char *path);

Compares fs target path with path . The redundant slashes are ignored. This function compares strings and does not canonicalize the paths. See also more generic mnt_fs_match_target().

Parameters

fs

fs

 

path

mount point

 

Returns

1 if fs target path equal to path , otherwise 0.


mnt_fs_to_mntent ()

int
mnt_fs_to_mntent (struct libmnt_fs *fs,
                  struct mntent **mnt);

Copies the information from fs to struct mntent mnt . If mnt is already set, then the struct mntent items are reallocated and updated. See also mnt_free_mntent().

Parameters

fs

filesystem

 

mnt

mount description (as described in mntent.h)

 

Returns

0 on success and a negative number in case of error.


mnt_new_fs ()

struct libmnt_fs *
mnt_new_fs (void);

The initial refcount is 1, and needs to be decremented to release the resources of the filesystem.

Returns

newly allocated struct libmnt_fs.


mnt_reset_fs ()

void
mnt_reset_fs (struct libmnt_fs *fs);

Resets (zeroize) fs .

Parameters

fs

fs pointer

 

Types and Values

struct libmnt_fs

struct libmnt_fs;

Parsed fstab/mtab/mountinfo entry