libmount Reference Manual | ||||
---|---|---|---|---|
Top | Description |
struct libmnt_table; void mnt_free_table (struct libmnt_table *tb
); struct libmnt_table * mnt_new_table (void
); int mnt_reset_table (struct libmnt_table *tb
); struct libmnt_table * mnt_new_table_from_dir (const char *dirname
); struct libmnt_table * mnt_new_table_from_file (const char *filename
); int mnt_table_add_fs (struct libmnt_table *tb
,struct libmnt_fs *fs
); struct libmnt_fs * mnt_table_find_devno (struct libmnt_table *tb
,dev_t devno
,int direction
); int mnt_table_find_next_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,int (*match_func) (struct libmnt_fs *, void *)
,void *userdata
,struct libmnt_fs **fs
); struct libmnt_fs * mnt_table_find_pair (struct libmnt_table *tb
,const char *source
,const char *target
,int direction
); struct libmnt_fs * mnt_table_find_source (struct libmnt_table *tb
,const char *source
,int direction
); struct libmnt_fs * mnt_table_find_srcpath (struct libmnt_table *tb
,const char *path
,int direction
); struct libmnt_fs * mnt_table_find_tag (struct libmnt_table *tb
,const char *tag
,const char *val
,int direction
); struct libmnt_fs * mnt_table_find_target (struct libmnt_table *tb
,const char *path
,int direction
); struct libmnt_cache * mnt_table_get_cache (struct libmnt_table *tb
); int mnt_table_get_nents (struct libmnt_table *tb
); int mnt_table_get_root_fs (struct libmnt_table *tb
,struct libmnt_fs **root
); int mnt_table_is_fs_mounted (struct libmnt_table *tb
,struct libmnt_fs *fstab_fs
); int mnt_table_next_child_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs *parent
,struct libmnt_fs **chld
); int mnt_table_next_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs **fs
); int mnt_table_parse_dir (struct libmnt_table *tb
,const char *dirname
); int mnt_table_parse_file (struct libmnt_table *tb
,const char *filename
); int mnt_table_parse_fstab (struct libmnt_table *tb
,const char *filename
); int mnt_table_parse_mtab (struct libmnt_table *tb
,const char *filename
); int mnt_table_parse_stream (struct libmnt_table *tb
,FILE *f
,const char *filename
); int mnt_table_parse_swaps (struct libmnt_table *tb
,const char *filename
); int mnt_table_remove_fs (struct libmnt_table *tb
,struct libmnt_fs *fs
); int mnt_table_set_cache (struct libmnt_table *tb
,struct libmnt_cache *mpc
); int mnt_table_set_iter (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs *fs
); int mnt_table_set_parser_errcb (struct libmnt_table *tb
,int (*cb) (struct libmnt_table *tb, const char *filename, int line)
);
Note that mnt_table_find_* functions are mount(8) compatible. These functions try to find an entry in more iterations where the first attempt is always based on comparison with unmodified (non-canonicalized or un-evaluated) paths or tags. For example fstab with two entries:
1 2 |
LABEL=foo /foo auto rw /dev/foo /foo auto rw |
where both lines are used for the *same* device, then
1 |
mnt_table_find_source(tb, "/dev/foo", &fs); |
will returns the second line, and
1 |
mnt_table_find_source(tb, "LABEL=foo", &fs); |
will returns the first entry, and
1 |
mnt_table_find_source(tb, "UUID=anyuuid", &fs); |
will returns the first entry (if UUID matches with the device).
struct libmnt_table;
List of struct libmnt_fs entries (parsed fstab/mtab/mountinfo)
void mnt_free_table (struct libmnt_table *tb
);
Deallocates tab struct and all entries.
|
tab pointer |
struct libmnt_table * mnt_new_table (void
);
The tab is a container for struct libmnt_fs entries that usually represents a fstab, mtab or mountinfo file from your system.
See also mnt_table_parse_file()
.
Returns : |
newly allocated tab struct. |
int mnt_reset_table (struct libmnt_table *tb
);
Dealocates all entries (filesystems) from the table
|
tab pointer |
Returns : |
0 on success or negative number in case of error. |
struct libmnt_table * mnt_new_table_from_dir (const char *dirname
);
|
directory with *.fstab files |
Returns : |
newly allocated tab on success and NULL in case of error. |
struct libmnt_table * mnt_new_table_from_file (const char *filename
);
Same as mnt_new_table()
+ mnt_table_parse_file()
. Use this function for private
files only. This function does not allow to use error callback, so you
cannot provide any feedback to end-users about broken records in files (e.g.
fstab).
|
/etc/{m,fs}tab or /proc/self/mountinfo path |
Returns : |
newly allocated tab on success and NULL in case of error. |
int mnt_table_add_fs (struct libmnt_table *tb
,struct libmnt_fs *fs
);
Adds a new entry to tab.
|
tab pointer |
|
new entry |
Returns : |
0 on success or negative number in case of error. |
struct libmnt_fs * mnt_table_find_devno (struct libmnt_table *tb
,dev_t devno
,int direction
);
Note that zero could be valid device number for root pseudo filesystem (e.g. tmpfs).
|
/proc/self/mountinfo |
|
device number |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
int mnt_table_find_next_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,int (*match_func) (struct libmnt_fs *, void *)
,void *userdata
,struct libmnt_fs **fs
);
This function allows search in tb
.
|
table |
|
iterator |
|
function returns 1 or 0 |
|
extra data for match_func |
|
returns pointer to the next matching table entry |
Returns : |
negative number in case of error, 1 at end of table or 0 o success. |
struct libmnt_fs * mnt_table_find_pair (struct libmnt_table *tb
,const char *source
,const char *target
,int direction
);
This function is implemented by mnt_fs_match_source()
and
mnt_fs_match_target()
functions. It means that this is more expensive that
others mnt_table_find_* function, because every tab
entry is fully evaluated.
|
tab pointer |
|
TAG or path |
|
mountpoint |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
struct libmnt_fs * mnt_table_find_source (struct libmnt_table *tb
,const char *source
,int direction
);
This is high-level API for mnt_table_find_{srcpath,tag}. You needn't to care
about source
format (device, LABEL, UUID, ...). This function parses source
and calls mnt_table_find_tag()
or mnt_table_find_srcpath()
.
|
tab pointer |
|
TAG or path |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
struct libmnt_fs * mnt_table_find_srcpath (struct libmnt_table *tb
,const char *path
,int direction
);
Try to lookup an entry in given tab, possible are four iterations, first
with path
, second with realpath(path
), third with tags (LABEL, UUID, ..)
from path
and fourth with realpath(path
) against realpath(entry->srcpath).
The 2nd, 3rd and 4th iterations are not performed when tb
cache is not
set (see mnt_table_set_cache()
).
Note that NULL is a valid source path; it will be replaced with "none". The "none" is used in /proc/{mounts,self/mountinfo} for pseudo filesystems.
|
tab pointer |
|
source path (devname or dirname) or NULL |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
struct libmnt_fs * mnt_table_find_tag (struct libmnt_table *tb
,const char *tag
,const char *val
,int direction
);
Try to lookup an entry in given tab, first attempt is lookup by tag
and
val
, for the second attempt the tag is evaluated (converted to the device
name) and mnt_table_find_srcpath()
is preformed. The second attempt is not
performed when tb
cache is not set (see mnt_table_set_cache()
).
|
tab pointer |
|
tag name (e.g "LABEL", "UUID", ...) |
|
tag value |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
struct libmnt_fs * mnt_table_find_target (struct libmnt_table *tb
,const char *path
,int direction
);
Try to lookup an entry in given tab, possible are three iterations, first
with path
, second with realpath(path
) and third with realpath(path
)
against realpath(fs->target). The 2nd and 3rd iterations are not performed
when tb
cache is not set (see mnt_table_set_cache()
).
|
tab pointer |
|
mountpoint directory |
|
MNT_ITER_{FORWARD,BACKWARD} |
Returns : |
a tab entry or NULL. |
struct libmnt_cache * mnt_table_get_cache (struct libmnt_table *tb
);
|
pointer to tab |
Returns : |
pointer to struct libmnt_cache instance or NULL. |
int mnt_table_get_nents (struct libmnt_table *tb
);
|
pointer to tab |
Returns : |
number of valid entries in tab. |
int mnt_table_get_root_fs (struct libmnt_table *tb
,struct libmnt_fs **root
);
The function uses parent ID from mountinfo file to determine root filesystem (the filesystem with the smallest ID). The function is designed mostly for applications where is necessary to sort mountpoints by IDs to get the tree of the mountpoints (e.g. findmnt default output).
If you're not sure than use
mnt_table_find_target(tb, "/", MNT_ITER_BACKWARD);
this is more robust and usable for arbitrary tab file (including fstab).
|
mountinfo file (/proc/self/mountinfo) |
|
returns pointer to the root filesystem (/) |
Returns : |
0 on success or less then zero case of error. |
int mnt_table_is_fs_mounted (struct libmnt_table *tb
,struct libmnt_fs *fstab_fs
);
int mnt_table_next_child_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs *parent
,struct libmnt_fs **chld
);
Note that filesystems are returned in the order how was mounted (according to IDs in /proc/self/mountinfo).
|
mountinfo file (/proc/self/mountinfo) |
|
iterator |
|
parental FS |
|
returns the next child filesystem |
Returns : |
0 on success, negative number in case of error or 1 at end of list. |
int mnt_table_next_fs (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs **fs
);
|
tab pointer | ||
|
iterator | ||
|
returns the next tab entry | ||
Returns : |
0 on success, negative number in case of error or 1 at end of list.
Example:
|
int mnt_table_parse_dir (struct libmnt_table *tb
,const char *dirname
);
The directory:
files are sorted by strverscmp(3)
files that starts with "." are ignored (e.g. ".10foo.fstab")
files without the ".fstab" extension are ignored
|
mount table |
|
directory |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_parse_file (struct libmnt_table *tb
,const char *filename
);
Parses whole table (e.g. /etc/mtab) and appends new records to the tab
.
The libmount parser ignores broken (syntax error) lines, these lines are
reported to caller by errcb()
function (see mnt_table_set_parser_errcb()
).
|
tab pointer |
|
file |
Returns : |
0 on success, negative number in case of error. |
int mnt_table_parse_fstab (struct libmnt_table *tb
,const char *filename
);
This function parses /etc/fstab and appends new lines to the tab
. If the
filename
is a directory then mnt_table_parse_dir()
is called.
See also mnt_table_set_parser_errcb()
.
|
table |
|
overwrites default (/etc/fstab or $LIBMOUNT_FSTAB) or NULL |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_parse_mtab (struct libmnt_table *tb
,const char *filename
);
This function parses /etc/mtab or /proc/self/mountinfo + /run/mount/utabs or /proc/mounts.
See also mnt_table_set_parser_errcb()
.
|
table |
|
overwrites default (/etc/mtab or $LIBMOUNT_MTAB) or NULL |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_parse_stream (struct libmnt_table *tb
,FILE *f
,const char *filename
);
|
tab pointer |
|
file stream |
|
filename used for debug and error messages |
Returns : |
0 on success, negative number in case of error. |
int mnt_table_parse_swaps (struct libmnt_table *tb
,const char *filename
);
This function parses /proc/swaps and appends new lines to the tab
.
See also mnt_table_set_parser_errcb()
.
|
table |
|
overwrites default (/proc/swaps or $LIBMOUNT_SWAPS) or NULL |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_remove_fs (struct libmnt_table *tb
,struct libmnt_fs *fs
);
|
tab pointer |
|
new entry |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_set_cache (struct libmnt_table *tb
,struct libmnt_cache *mpc
);
Setups a cache for canonicalized paths and evaluated tags (LABEL/UUID). The cache is recommended for mnt_table_find_*() functions.
The cache could be shared between more tabs. Be careful when you share the same cache between more threads -- currently the cache does not provide any locking method.
See also mnt_new_cache()
.
|
pointer to tab |
|
pointer to struct libmnt_cache instance |
Returns : |
0 on success or negative number in case of error. |
int mnt_table_set_iter (struct libmnt_table *tb
,struct libmnt_iter *itr
,struct libmnt_fs *fs
);
Sets iter
to the position of fs
in the file tb
.
|
tab pointer |
|
iterator |
|
tab entry |
Returns : |
0 on success, negative number in case of error. |
int mnt_table_set_parser_errcb (struct libmnt_table *tb
,int (*cb) (struct libmnt_table *tb, const char *filename, int line)
);
The error callback function is called by table parser (mnt_table_parse_file()
)
in case of syntax error. The callback function could be used for errors
evaluation, libmount will continue/stop parsing according to callback return
codes:
<0 : fatal error (abort parsing) 0 : success (parsing continue) >0 : recoverable error (the line is ignored, parsing continue).
|
pointer to table |
|
pointer to callback function |
Returns : |
0 on success or negative number in case of error. |