Top |
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.
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 use mnt_unref_fs()
.
The reference counting is supported since util-linux v2.24.
void
mnt_free_mntent (struct mntent *mnt
);
Deallocates the "mntent.h" mount entry.
void
mnt_unref_fs (struct libmnt_fs *fs
);
De-increments reference counter, on zero the fs
is automatically
deallocated by mnt_free_fs()
.
int mnt_fs_append_attributes (struct libmnt_fs *fs
,const char *optstr
);
Appends mount attributes. (See mnt_fs_set_attributes()
).
int mnt_fs_append_comment (struct libmnt_fs *fs
,const char *comm
);
See also mnt_fs_set_comment()
.
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.
int mnt_fs_get_attribute (struct libmnt_fs *fs
,const char *name
,char **value
,size_t *valsz
);
int mnt_fs_get_option (struct libmnt_fs *fs
,const char *name
,char **value
,size_t *valsz
);
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.
const char *
mnt_fs_get_source (struct libmnt_fs *fs
);
mount source. Note that the source could be unparsed TAG
(LABEL/UUID). See also mnt_fs_get_srcpath()
and mnt_fs_get_tag()
.
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()
.
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 |
int mnt_fs_match_fstype (struct libmnt_fs *fs
,const char *types
);
For more details see mnt_match_fstype()
.
int mnt_fs_match_options (struct libmnt_fs *fs
,const char *options
);
For more details see mnt_match_options()
.
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.
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.
int mnt_fs_prepend_attributes (struct libmnt_fs *fs
,const char *optstr
);
Prepends mount attributes. (See mnt_fs_set_attributes()
).
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.
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.
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).
int mnt_fs_set_fstype (struct libmnt_fs *fs
,const char *fstype
);
This function creates a private copy (strdup()
) of fstype
.
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
.
int mnt_fs_set_source (struct libmnt_fs *fs
,const char *source
);
This function creates a private copy (strdup()
) of source
.
int mnt_fs_set_target (struct libmnt_fs *fs
,const char *tgt
);
This function creates a private copy (strdup()
) of tgt
.
int mnt_fs_set_userdata (struct libmnt_fs *fs
,void *data
);
The "userdata" are library independent data.
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
.
int mnt_fs_streq_srcpath (struct libmnt_fs *fs
,const char *path
);
Compares fs
source path with path
. The redundant slashs are ignored.
This function compares strings and does not cannonicalize the paths.
See also more heavy and generic mnt_fs_match_source()
.
int mnt_fs_streq_target (struct libmnt_fs *fs
,const char *path
);
Compares fs
target path with path
. The redundant slashs are ignored.
This function compares strings and does not cannonicalize the paths.
See also more generic mnt_fs_match_target()
.
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()
.
struct libmnt_fs *
mnt_new_fs (void
);
The initial refcount is 1, and needs to be decremented to release the resources of the filesystem.