libmount Reference Manual | ||||
---|---|---|---|---|
Top | Description |
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
); void mnt_ref_fs (struct libmnt_fs *fs
); void mnt_unref_fs (struct libmnt_fs *fs
); int mnt_fs_append_attributes (struct libmnt_fs *fs
,const char *optstr
); int mnt_fs_append_comment (struct libmnt_fs *fs
,const char *comm
); 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
); const char * mnt_fs_get_comment (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_optional_fields (struct libmnt_fs *fs
); 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
); int mnt_fs_get_propagation (struct libmnt_fs *fs
,unsigned long *flags
); 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
); pid_t mnt_fs_get_tid (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_comment (struct libmnt_fs *fs
,const char *comm
); 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
);
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.
|
destination FS |
|
source FS |
Returns : |
dest or NULL in case of error |
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.
|
fs pointer |
void mnt_free_mntent (struct mntent *mnt
);
Deallocates the "mntent.h" mount entry.
|
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()
.
|
fs pointer |
int mnt_fs_append_attributes (struct libmnt_fs *fs
,const char *optstr
);
Appends mount attributes. (See mnt_fs_set_attributes()
).
|
fstab/mtab/mountinfo entry |
|
options string |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_append_comment (struct libmnt_fs *fs
,const char *comm
);
See also mnt_fs_set_comment()
.
|
fstab entry pointer |
|
comment string |
Returns : |
0 on success or <0 in case of error. |
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.
|
fstab/mtab/mountinfo entry |
|
mount options |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_get_attribute (struct libmnt_fs *fs
,const char *name
,char **value
,size_t *valsz
);
|
fstab/mtab/mountinfo entry pointer |
|
option name |
|
returns pointer to the beginning of the value (e.g. name=VALUE) or NULL |
|
returns size of options value or 0 |
Returns : |
0 on success, 1 when name not found or negative number in case of error. |
const char * mnt_fs_get_attributes (struct libmnt_fs *fs
);
|
fstab/mtab entry pointer |
Returns : |
pointer to attributes string or NULL. |
const char * mnt_fs_get_bindsrc (struct libmnt_fs *fs
);
|
/run/mount/utab entry |
Returns : |
full path that was used for mount(2) on MS_BIND |
const char * mnt_fs_get_comment (struct libmnt_fs *fs
);
|
fstab/mtab/mountinfo entry pointer |
Returns : |
0 on success, 1 when not found the name or negative number in case of error. |
dev_t mnt_fs_get_devno (struct libmnt_fs *fs
);
|
/proc/self/mountinfo entry |
Returns : |
value of st_dev for files on filesystem or 0 in case of error. |
int mnt_fs_get_freq (struct libmnt_fs *fs
);
|
fstab/mtab/mountinfo entry pointer |
Returns : |
dump frequency in days. |
const char * mnt_fs_get_fstype (struct libmnt_fs *fs
);
|
fstab/mtab/mountinfo entry pointer |
Returns : |
pointer to filesystem type. |
int mnt_fs_get_id (struct libmnt_fs *fs
);
|
/proc/self/mountinfo entry |
Returns : |
mount ID (unique identifier of the mount) or negative number in case of error. |
int mnt_fs_get_option (struct libmnt_fs *fs
,const char *name
,char **value
,size_t *valsz
);
|
fstab/mtab/mountinfo entry pointer |
|
option name |
|
returns pointer to the beginning of the value (e.g. name=VALUE) or NULL |
|
returns size of options value or 0 |
Returns : |
0 on success, 1 when name not found or negative number in case of error. |
const char * mnt_fs_get_optional_fields (struct libmnt_fs *fs
);
|
mountinfo entry pointer |
Returns : |
pointer to string with mountinfo optional fields or NULL in case of error. |
const char * mnt_fs_get_options (struct libmnt_fs *fs
);
|
fstab/mtab/mountinfo entry pointer |
Returns : |
pointer to string or NULL in case of error. |
int mnt_fs_get_parent_id (struct libmnt_fs *fs
);
|
/proc/self/mountinfo entry |
Returns : |
parent mount ID or negative number in case of error. |
int mnt_fs_get_passno (struct libmnt_fs *fs
);
|
fstab/mtab entry pointer |
Returns : |
"pass number on parallel fsck". |
int mnt_fs_get_priority (struct libmnt_fs *fs
);
|
/proc/swaps entry |
Returns : |
priority |
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.
|
mountinfo entry |
|
returns propagation MS_* flags as present in the mountinfo file |
Returns : |
0 on success or negative number in case of error. |
const char * mnt_fs_get_root (struct libmnt_fs *fs
);
|
/proc/self/mountinfo entry |
Returns : |
root of the mount within the filesystem or NULL |
off_t mnt_fs_get_size (struct libmnt_fs *fs
);
|
/proc/swaps entry |
Returns : |
size |
const char * mnt_fs_get_source (struct libmnt_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() . |
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()
.
|
struct libmnt_file (fstab/mtab/mountinfo) fs |
Returns : |
mount source path or NULL in case of error or when the path is not defined. |
const char * mnt_fs_get_swaptype (struct libmnt_fs *fs
);
|
/proc/swaps entry |
Returns : |
swap type or NULL |
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 |
|
fs |
|
returns pointer to NAME string |
|
returns pointer to VALUE string |
Returns : |
0 on success or negative number in case a TAG is not defined. |
const char * mnt_fs_get_target (struct libmnt_fs *fs
);
|
fstab/mtab/mountinfo entry pointer |
Returns : |
pointer to mountpoint path or NULL |
pid_t mnt_fs_get_tid (struct libmnt_fs *fs
);
|
/proc/tid/mountinfo entry |
Returns : |
TID (task ID) for filesystems read from the mountinfo file |
off_t mnt_fs_get_usedsize (struct libmnt_fs *fs
);
|
/proc/swaps entry |
Returns : |
used size |
void * mnt_fs_get_userdata (struct libmnt_fs *fs
);
|
struct libmnt_file instance |
Returns : |
private data set by mnt_fs_set_userdata() or NULL. |
const char * mnt_fs_get_user_options (struct libmnt_fs *fs
);
|
fstab/mtab entry pointer |
Returns : |
pointer to userspace mount option string or NULL. |
const char * mnt_fs_get_vfs_options (struct libmnt_fs *fs
);
|
fstab/mtab entry pointer |
Returns : |
pointer to fs-independent (VFS) mount option string or NULL. |
int mnt_fs_is_kernel (struct libmnt_fs *fs
);
|
filesystem |
Returns : |
1 if the filesystem description is read from kernel e.g. /proc/mounts. |
int mnt_fs_is_netfs (struct libmnt_fs *fs
);
|
filesystem |
Returns : |
1 if the filesystem is a network filesystem |
int mnt_fs_is_pseudofs (struct libmnt_fs *fs
);
|
filesystem |
Returns : |
1 if the filesystem is a pseudo fs type (proc, cgroups) |
int mnt_fs_is_swaparea (struct libmnt_fs *fs
);
|
filesystem |
Returns : |
1 if the filesystem uses "swap" as a type |
int mnt_fs_match_fstype (struct libmnt_fs *fs
,const char *types
);
For more details see mnt_match_fstype()
.
|
filesystem |
|
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. |
int mnt_fs_match_options (struct libmnt_fs *fs
,const char *options
);
For more details see mnt_match_options()
.
|
filesystem |
|
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. |
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.
|
filesystem |
|
tag or path (device or so) or NULL |
|
tags/paths cache or NULL |
Returns : |
1 if fs source is equal to source , else 0. |
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.
|
filesystem |
|
mountpoint path |
|
tags/paths cache or NULL |
Returns : |
1 if fs target is equal to target , else 0. |
int mnt_fs_prepend_attributes (struct libmnt_fs *fs
,const char *optstr
);
Prepends mount attributes. (See mnt_fs_set_attributes()
).
|
fstab/mtab/mountinfo entry |
|
options string |
Returns : |
0 on success or negative number in case of error. |
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.
|
fstab/mtab/mountinfo entry |
|
mount options |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_print_debug (struct libmnt_fs *fs
,FILE *file
);
|
fstab/mtab/mountinfo entry |
|
file stream |
Returns : |
0 on success or negative number in case of error. |
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.
|
fstab/mtab/mountinfo entry |
|
options string |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_bindsrc (struct libmnt_fs *fs
,const char *src
);
|
filesystem |
|
path |
Returns : |
0 on success or negative number in case of error. |
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).
|
fstab entry pointer |
|
comment string |
Returns : |
0 on success or <0 in case of error. |
int mnt_fs_set_freq (struct libmnt_fs *fs
,int freq
);
|
fstab/mtab entry pointer |
|
dump frequency in days |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_fstype (struct libmnt_fs *fs
,const char *fstype
);
This function creates a private copy (strdup()
) of fstype
.
|
fstab/mtab/mountinfo entry |
|
filesystem type |
Returns : |
0 on success or negative number in case of error. |
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
.
|
fstab/mtab/mountinfo entry pointer |
|
options string |
Returns : |
0 on success, or negative number in case of error. |
int mnt_fs_set_passno (struct libmnt_fs *fs
,int passno
);
|
fstab/mtab entry pointer |
|
pass number |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_root (struct libmnt_fs *fs
,const char *root
);
|
mountinfo entry |
|
path |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_source (struct libmnt_fs *fs
,const char *source
);
This function creates a private copy (strdup()
) of source
.
|
fstab/mtab/mountinfo entry |
|
new source |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_target (struct libmnt_fs *fs
,const char *target
);
This function creates a private copy (strdup()
) of target
.
|
fstab/mtab/mountinfo entry |
|
mountpoint |
Returns : |
0 on success or negative number in case of error. |
int mnt_fs_set_userdata (struct libmnt_fs *fs
,void *data
);
The "userdata" are library independent data.
|
struct libmnt_file instance |
|
user data |
Returns : |
0 or negative number in case of error (if fs is NULL). |
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 modigy fs
.
|
fstab/mtab/mountinfo entry pointer |
Returns : |
pointer to string (can be freed by free(3)) or NULL in case of error. |
int mnt_fs_streq_srcpath (struct libmnt_fs *fs
,const char *path
);
Compares fs
source path with path
. The trailing slash is ignored.
See also mnt_fs_match_source()
.
|
fs |
|
source path |
Returns : |
1 if fs source path equal to path , otherwise 0. |
int mnt_fs_streq_target (struct libmnt_fs *fs
,const char *path
);
Compares fs
target path with path
. The trailing slash is ignored.
See also mnt_fs_match_target()
.
|
fs |
|
mount point |
Returns : |
1 if fs target path equal to path , otherwise 0. |
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()
.
|
filesystem |
|
mount description (as described in mntent.h) |
Returns : |
0 on success and a negative number in case of error. |
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. |