Filesystem

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

Synopsis

struct              libmnt_fs;
struct libmnt_fs *  mnt_copy_fs                         (struct libmnt_fs *dest,
                                                         const struct libmnt_fs *src);
void                mnt_free_fs                         (struct libmnt_fs *fs);
void                mnt_free_mntent                     (struct mntent *mnt);
int                 mnt_fs_append_attributes            (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_append_options               (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_get_attribute                (struct libmnt_fs *fs,
                                                         const char *name,
                                                         char **value,
                                                         size_t *valsz);
const char *        mnt_fs_get_attributes               (struct libmnt_fs *fs);
const char *        mnt_fs_get_bindsrc                  (struct libmnt_fs *fs);
dev_t               mnt_fs_get_devno                    (struct libmnt_fs *fs);
int                 mnt_fs_get_freq                     (struct libmnt_fs *fs);
const char *        mnt_fs_get_fs_options               (struct libmnt_fs *fs);
const char *        mnt_fs_get_fstype                   (struct libmnt_fs *fs);
int                 mnt_fs_get_id                       (struct libmnt_fs *fs);
int                 mnt_fs_get_option                   (struct libmnt_fs *fs,
                                                         const char *name,
                                                         char **value,
                                                         size_t *valsz);
const char *        mnt_fs_get_options                  (struct libmnt_fs *fs);
int                 mnt_fs_get_parent_id                (struct libmnt_fs *fs);
int                 mnt_fs_get_passno                   (struct libmnt_fs *fs);
int                 mnt_fs_get_priority                 (struct libmnt_fs *fs);
const char *        mnt_fs_get_root                     (struct libmnt_fs *fs);
off_t               mnt_fs_get_size                     (struct libmnt_fs *fs);
const char *        mnt_fs_get_source                   (struct libmnt_fs *fs);
const char *        mnt_fs_get_srcpath                  (struct libmnt_fs *fs);
const char *        mnt_fs_get_swaptype                 (struct libmnt_fs *fs);
int                 mnt_fs_get_tag                      (struct libmnt_fs *fs,
                                                         const char **name,
                                                         const char **value);
const char *        mnt_fs_get_target                   (struct libmnt_fs *fs);
off_t               mnt_fs_get_usedsize                 (struct libmnt_fs *fs);
void *              mnt_fs_get_userdata                 (struct libmnt_fs *fs);
const char *        mnt_fs_get_user_options             (struct libmnt_fs *fs);
const char *        mnt_fs_get_vfs_options              (struct libmnt_fs *fs);
int                 mnt_fs_is_kernel                    (struct libmnt_fs *fs);
int                 mnt_fs_is_netfs                     (struct libmnt_fs *fs);
int                 mnt_fs_is_pseudofs                  (struct libmnt_fs *fs);
int                 mnt_fs_is_swaparea                  (struct libmnt_fs *fs);
int                 mnt_fs_match_fstype                 (struct libmnt_fs *fs,
                                                         const char *types);
int                 mnt_fs_match_options                (struct libmnt_fs *fs,
                                                         const char *options);
int                 mnt_fs_match_source                 (struct libmnt_fs *fs,
                                                         const char *source,
                                                         struct libmnt_cache *cache);
int                 mnt_fs_match_target                 (struct libmnt_fs *fs,
                                                         const char *target,
                                                         struct libmnt_cache *cache);
int                 mnt_fs_prepend_attributes           (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_prepend_options              (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_print_debug                  (struct libmnt_fs *fs,
                                                         FILE *file);
int                 mnt_fs_set_attributes               (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_set_bindsrc                  (struct libmnt_fs *fs,
                                                         const char *src);
int                 mnt_fs_set_freq                     (struct libmnt_fs *fs,
                                                         int freq);
int                 mnt_fs_set_fstype                   (struct libmnt_fs *fs,
                                                         const char *fstype);
int                 mnt_fs_set_options                  (struct libmnt_fs *fs,
                                                         const char *optstr);
int                 mnt_fs_set_passno                   (struct libmnt_fs *fs,
                                                         int passno);
int                 mnt_fs_set_root                     (struct libmnt_fs *fs,
                                                         const char *root);
int                 mnt_fs_set_source                   (struct libmnt_fs *fs,
                                                         const char *source);
int                 mnt_fs_set_target                   (struct libmnt_fs *fs,
                                                         const char *target);
int                 mnt_fs_set_userdata                 (struct libmnt_fs *fs,
                                                         void *data);
char *              mnt_fs_strdup_options               (struct libmnt_fs *fs);
int                 mnt_fs_streq_srcpath                (struct libmnt_fs *fs,
                                                         const char *path);
int                 mnt_fs_streq_target                 (struct libmnt_fs *fs,
                                                         const char *path);
int                 mnt_fs_to_mntent                    (struct libmnt_fs *fs,
                                                         struct mntent **mnt);
struct libmnt_fs *  mnt_new_fs                          (void);
void                mnt_reset_fs                        (struct libmnt_fs *fs);

Description

Details

struct libmnt_fs

struct libmnt_fs;

Parsed fstab/mtab/mountinfo entry


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 overwrited.

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

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.

fs :

fs pointer

mnt_free_mntent ()

void                mnt_free_mntent                     (struct mntent *mnt);

Deallocates "mntent.h" mount entry.

mnt :

mount entry

mnt_fs_append_attributes ()

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

Appends mount attributes. (See mnt_fs_set_attributes()).

fs :

fstab/mtab/mountinfo entry

optstr :

options string

Returns :

0 on success or negative number 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.

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);

fs :

fstab/mtab/mountinfo entry pointer

name :

option name

value :

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

valsz :

returns size of options value or 0

Returns :

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

mnt_fs_get_attributes ()

const char *        mnt_fs_get_attributes               (struct libmnt_fs *fs);

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);

fs :

/run/mount/utab entry

Returns :

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

mnt_fs_get_devno ()

dev_t               mnt_fs_get_devno                    (struct libmnt_fs *fs);

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);

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);

fs :

fstab/mtab/mountinfo entry pointer

Returns :

pointer to filesystem type.

mnt_fs_get_id ()

int                 mnt_fs_get_id                       (struct libmnt_fs *fs);

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);

fs :

fstab/mtab/mountinfo entry pointer

name :

option name

value :

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

valsz :

returns size of options value or 0

Returns :

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

mnt_fs_get_options ()

const char *        mnt_fs_get_options                  (struct libmnt_fs *fs);

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);

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);

fs :

fstab/mtab entry pointer

Returns :

"pass number on parallel fsck".

mnt_fs_get_priority ()

int                 mnt_fs_get_priority                 (struct libmnt_fs *fs);

fs :

/proc/swaps entry

Returns :

priority

mnt_fs_get_root ()

const char *        mnt_fs_get_root                     (struct libmnt_fs *fs);

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);

fs :

/proc/swaps entry

Returns :

size

mnt_fs_get_source ()

const char *        mnt_fs_get_source                   (struct libmnt_fs *fs);

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

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);

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" has to be always 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

fs :

fs

name :

returns pointer to NAME string

value :

returns pointer to VALUE string

Returns :

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

mnt_fs_get_target ()

const char *        mnt_fs_get_target                   (struct libmnt_fs *fs);

fs :

fstab/mtab/mountinfo entry pointer

Returns :

pointer to mountpoint path or NULL

mnt_fs_get_usedsize ()

off_t               mnt_fs_get_usedsize                 (struct libmnt_fs *fs);

fs :

/proc/swaps entry

Returns :

used size

mnt_fs_get_userdata ()

void *              mnt_fs_get_userdata                 (struct libmnt_fs *fs);

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);

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);

fs :

fstab/mtab entry pointer

Returns :

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

mnt_fs_is_kernel ()

int                 mnt_fs_is_kernel                    (struct libmnt_fs *fs);

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);

fs :

filesystem

Returns :

1 if the filesystem is a network filesystem

mnt_fs_is_pseudofs ()

int                 mnt_fs_is_pseudofs                  (struct libmnt_fs *fs);

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);

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

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

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);

Possible are four attempts: 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.

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.

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

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

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 prepands results to VFS, FS and userspace lists of options.

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

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);

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 send to kernel and are not interpreted by libmount. The attributes are stored in /run/mount/utab only.

The atrtributes 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.

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);

fs :

filesystem

src :

path

Returns :

0 on success or negative number in case of error.

mnt_fs_set_freq ()

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

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.

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 update relevat parts of fs.

fs :

fstab/mtab/mountinfo entry pointer

optstr :

options string

Returns :

0 on success, or negative number icase of error.

mnt_fs_set_passno ()

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

fs :

fstab/mtab entry pointer

passno :

pass number

Returns :

0 on success or negative number in case of error.

mnt_fs_set_root ()

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

fs :

mountinfo entry

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.

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 *target);

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

fs :

fstab/mtab/mountinfo entry

target :

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.

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 the one options string and returns the result. This function does not modigy fs.

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 tailing slash is ignored. See also mnt_fs_match_source().

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 tailing slash is ignored. See also mnt_fs_match_target().

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

fs :

filesystem

mnt :

mount description (as described in mntent.h)

Returns :

0 on success and negative number in case of error.

mnt_new_fs ()

struct libmnt_fs *  mnt_new_fs                          (void);

Returns :

newly allocated struct libmnt_fs.

mnt_reset_fs ()

void                mnt_reset_fs                        (struct libmnt_fs *fs);

Resets (zeroize) fs.

fs :

fs pointer