2
* Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
4
* This file may be redistributed under the terms of the
5
* GNU Lesser General Public License.
11
* @short_description: represents one entry from fstab, mtab, or mountinfo file
23
* Returns: newly allocated struct libmnt_fs.
25
struct libmnt_fs *mnt_new_fs(void)
27
struct libmnt_fs *fs = calloc(1, sizeof(*fs));
31
/*DBG(FS, mnt_debug_h(fs, "alloc"));*/
32
INIT_LIST_HEAD(&fs->ents);
42
void mnt_free_fs(struct libmnt_fs *fs)
48
/*DBG(FS, mnt_debug_h(fs, "free"));*/
60
free(fs->user_optstr);
70
* Resets (zeroize) @fs.
72
void mnt_reset_fs(struct libmnt_fs *fs)
75
memset(fs, 0, sizeof(*fs));
78
static inline int update_str(char **dest, const char *src)
88
return 0; /* source (old) is empty */
92
x = realloc(*dest, sz);
96
memcpy(*dest, src, sz);
100
static inline int cpy_str_at_offset(void *new, const void *old, size_t offset)
102
char **o = (char **) (old + offset);
103
char **n = (char **) (new + offset);
106
return 0; /* already set, not overwrite */
108
return update_str(n, *o);
113
* @dest: destination FS
116
* If @dest is NULL, then a new FS is allocated, if any @dest field is already
117
* set then the field is NOT overwrited.
119
* This function does not copy userdata (se mnt_fs_set_userdata()). A new copy is
120
* not linked with any existing mnt_tab.
122
* Returns: @dest or NULL in case of error
124
struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
125
const struct libmnt_fs *src)
127
const struct libmnt_fs *org = dest;
135
/*DBG(FS, mnt_debug_h(dest, "copy from %p", src));*/
138
dest->parent = src->parent;
139
dest->devno = src->devno;
141
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, source)))
143
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, tagname)))
145
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, tagval)))
147
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, root)))
149
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, target)))
151
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, fstype)))
153
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, optstr)))
155
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, vfs_optstr)))
157
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, fs_optstr)))
159
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, user_optstr)))
161
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, attrs)))
163
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, bindsrc)))
166
dest->freq = src->freq;
167
dest->passno = src->passno;
168
dest->flags = src->flags;
178
* This function copies all @fs description except information that does not
179
* belong to /etc/mtab (e.g. VFS and userspace mount options with MNT_NOMTAB
182
* Returns: copy of @fs.
184
struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs)
186
struct libmnt_fs *n = mnt_new_fs();
191
if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, source)))
193
if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, target)))
195
if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, fstype)))
198
if (fs->vfs_optstr) {
200
mnt_optstr_get_options(fs->vfs_optstr, &p,
201
mnt_get_builtin_optmap(MNT_LINUX_MAP),
206
if (fs->user_optstr) {
208
mnt_optstr_get_options(fs->user_optstr, &p,
209
mnt_get_builtin_optmap(MNT_USERSPACE_MAP),
214
if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, fs_optstr)))
217
/* we cannot copy original optstr, the new optstr has to be without
218
* non-mtab options -- so, let's generate a new string */
219
n->optstr = mnt_fs_strdup_options(n);
222
n->passno = fs->passno;
223
n->flags = fs->flags;
233
* mnt_fs_get_userdata:
234
* @fs: struct libmnt_file instance
236
* Returns: private data set by mnt_fs_set_userdata() or NULL.
238
void *mnt_fs_get_userdata(struct libmnt_fs *fs)
240
return fs ? fs->userdata : NULL;
244
* mnt_fs_set_userdata:
245
* @fs: struct libmnt_file instance
248
* The "userdata" are library independent data.
250
* Returns: 0 or negative number in case of error (if @fs is NULL).
252
int mnt_fs_set_userdata(struct libmnt_fs *fs, void *data)
261
* mnt_fs_get_srcpath:
262
* @fs: struct libmnt_file (fstab/mtab/mountinfo) fs
264
* The mount "source path" is:
265
* - a directory for 'bind' mounts (in fstab or mtab only)
266
* - a device name for standard mounts
268
* See also mnt_fs_get_tag() and mnt_fs_get_source().
270
* Returns: mount source path or NULL in case of error or when the path
273
const char *mnt_fs_get_srcpath(struct libmnt_fs *fs)
281
return NULL; /* the source contains a "NAME=value" */
287
* @fs: struct libmnt_file (fstab/mtab/mountinfo) fs
289
* Returns: mount source. Note that the source could be unparsed TAG
290
* (LABEL/UUID). See also mnt_fs_get_srcpath() and mnt_fs_get_tag().
292
const char *mnt_fs_get_source(struct libmnt_fs *fs)
294
return fs ? fs->source : NULL;
298
* Used by parser ONLY (@source has to be allocated on error)
300
int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
302
char *t = NULL, *v = NULL;
306
if (source && !strcmp(source, "none")) {
310
} else if (source && strchr(source, '=')) {
311
if (blkid_parse_tag_string(source, &t, &v) != 0)
315
if (fs->source != source)
329
* @fs: fstab/mtab/mountinfo entry
330
* @source: new source
332
* This function creates a private copy (strdup()) of @source.
334
* Returns: 0 on success or negative number in case of error.
336
int mnt_fs_set_source(struct libmnt_fs *fs, const char *source)
349
rc = __mnt_fs_set_source_ptr(fs, p);
358
* @name: returns pointer to NAME string
359
* @value: returns pointer to VALUE string
361
* "TAG" is NAME=VALUE (e.g. LABEL=foo)
363
* The TAG is the first column in the fstab file. The TAG or "srcpath" has to
364
* be always set for all entries.
366
* See also mnt_fs_get_source().
371
* struct libmnt_fs *fs = mnt_table_find_target(tb, "/home", MNT_ITER_FORWARD);
376
* src = mnt_fs_get_srcpath(fs);
379
* if (mnt_fs_get_tag(fs, &tag, &val) == 0)
380
* printf("%s: %s\n", tag, val); // LABEL or UUID
382
* printf("device: %s\n", src); // device or bind path
386
* Returns: 0 on success or negative number in case that a TAG is not defined.
388
int mnt_fs_get_tag(struct libmnt_fs *fs, const char **name, const char **value)
390
if (fs == NULL || !fs->tagname)
401
* @fs: fstab/mtab/mountinfo entry pointer
403
* Returns: pointer to mountpoint path or NULL
405
const char *mnt_fs_get_target(struct libmnt_fs *fs)
408
return fs ? fs->target : NULL;
413
* @fs: fstab/mtab/mountinfo entry
414
* @target: mountpoint
416
* This function creates a private copy (strdup()) of @target.
418
* Returns: 0 on success or negative number in case of error.
420
int mnt_fs_set_target(struct libmnt_fs *fs, const char *target)
439
int __mnt_fs_get_flags(struct libmnt_fs *fs)
441
return fs ? fs->flags : 0;
444
int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags)
457
* Returns: 1 if the filesystem description is read from kernel e.g. /proc/mounts.
459
int mnt_fs_is_kernel(struct libmnt_fs *fs)
461
return __mnt_fs_get_flags(fs) & MNT_FS_KERNEL;
466
* @fs: fstab/mtab/mountinfo entry pointer
468
* Returns: pointer to filesystem type.
470
const char *mnt_fs_get_fstype(struct libmnt_fs *fs)
473
return fs ? fs->fstype : NULL;
476
/* Used by struct libmnt_file parser only */
477
int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype)
481
if (fstype != fs->fstype)
485
fs->flags &= ~MNT_FS_PSEUDO;
486
fs->flags &= ~MNT_FS_NET;
487
fs->flags &= ~MNT_FS_SWAP;
489
/* save info about pseudo filesystems */
491
if (mnt_fstype_is_pseudofs(fs->fstype))
492
fs->flags |= MNT_FS_PSEUDO;
493
else if (mnt_fstype_is_netfs(fs->fstype))
494
fs->flags |= MNT_FS_NET;
495
else if (!strcmp(fs->fstype, "swap"))
496
fs->flags |= MNT_FS_SWAP;
503
* @fs: fstab/mtab/mountinfo entry
504
* @fstype: filesystem type
506
* This function creates a private copy (strdup()) of @fstype.
508
* Returns: 0 on success or negative number in case of error.
510
int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype)
521
return __mnt_fs_set_fstype_ptr(fs, p);
525
* Merges @vfs and @fs options strings into a new string.
526
* This function cares about 'ro/rw' options. The 'ro' is
527
* always used if @vfs or @fs is read-only.
530
* mnt_merge_optstr("rw,noexec", "ro,journal=update")
532
* returns: "ro,noexec,journal=update"
534
* mnt_merge_optstr("rw,noexec", "rw,journal=update")
536
* returns: "rw,noexec,journal=update"
538
static char *merge_optstr(const char *vfs, const char *fs)
547
return strdup(fs ? fs : vfs);
548
if (!strcmp(vfs, fs))
549
return strdup(vfs); /* e.g. "aaa" and "aaa" */
551
/* leave space for leading "r[ow],", "," and trailing zero */
552
sz = strlen(vfs) + strlen(fs) + 5;
556
p = res + 3; /* make a room for rw/ro flag */
558
snprintf(p, sz - 3, "%s,%s", vfs, fs);
560
/* remove 'rw' flags */
561
rw += !mnt_optstr_remove_option(&p, "rw"); /* from vfs */
562
rw += !mnt_optstr_remove_option(&p, "rw"); /* from fs */
564
/* remove 'ro' flags if necessary */
566
ro += !mnt_optstr_remove_option(&p, "ro");
568
ro += !mnt_optstr_remove_option(&p, "ro");
572
memcpy(res, ro ? "ro" : "rw", 3);
574
memcpy(res, ro ? "ro," : "rw,", 3);
579
* mnt_fs_strdup_options:
580
* @fs: fstab/mtab/mountinfo entry pointer
582
* Merges all mount options (VFS, FS and userspace) to the one options string
583
* and returns the result. This function does not modigy @fs.
585
* Returns: pointer to string (can be freed by free(3)) or NULL in case of error.
587
char *mnt_fs_strdup_options(struct libmnt_fs *fs)
596
return strdup(fs->optstr);
598
res = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
601
if (fs->user_optstr) {
602
if (mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
611
* mnt_fs_get_options:
612
* @fs: fstab/mtab/mountinfo entry pointer
614
* Returns: pointer to string or NULL in case of error.
616
const char *mnt_fs_get_options(struct libmnt_fs *fs)
619
return fs ? fs->optstr : NULL;
624
* mnt_fs_set_options:
625
* @fs: fstab/mtab/mountinfo entry pointer
626
* @optstr: options string
628
* Splits @optstr to VFS, FS and userspace mount options and update relevat
631
* Returns: 0 on success, or negative number icase of error.
633
int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr)
635
char *v = NULL, *f = NULL, *u = NULL, *n = NULL;
642
int rc = mnt_split_optstr(optstr, &u, &v, &f, 0, 0);
651
free(fs->vfs_optstr);
652
free(fs->user_optstr);
664
* mnt_fs_append_options:
665
* @fs: fstab/mtab/mountinfo entry
666
* @optstr: mount options
668
* Parses (splits) @optstr and appends results to VFS, FS and userspace lists
671
* If @optstr is NULL then @fs is not modified and 0 is returned.
673
* Returns: 0 on success or negative number in case of error.
675
int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr)
677
char *v = NULL, *f = NULL, *u = NULL;
687
rc = mnt_split_optstr((char *) optstr, &u, &v, &f, 0, 0);
689
rc = mnt_optstr_append_option(&fs->vfs_optstr, v, NULL);
691
rc = mnt_optstr_append_option(&fs->fs_optstr, f, NULL);
693
rc = mnt_optstr_append_option(&fs->user_optstr, u, NULL);
695
rc = mnt_optstr_append_option(&fs->optstr, optstr, NULL);
705
* mnt_fs_prepend_options:
706
* @fs: fstab/mtab/mountinfo entry
707
* @optstr: mount options
709
* Parses (splits) @optstr and prepands results to VFS, FS and userspace lists
712
* If @optstr is NULL then @fs is not modified and 0 is returned.
714
* Returns: 0 on success or negative number in case of error.
716
int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr)
718
char *v = NULL, *f = NULL, *u = NULL;
728
rc = mnt_split_optstr((char *) optstr, &u, &v, &f, 0, 0);
730
rc = mnt_optstr_prepend_option(&fs->vfs_optstr, v, NULL);
732
rc = mnt_optstr_prepend_option(&fs->fs_optstr, f, NULL);
734
rc = mnt_optstr_prepend_option(&fs->user_optstr, u, NULL);
736
rc = mnt_optstr_prepend_option(&fs->optstr, optstr, NULL);
746
* mnt_fs_get_fs_options:
747
* @fs: fstab/mtab/mountinfo entry pointer
749
* Returns: pointer to superblock (fs-depend) mount option string or NULL.
751
const char *mnt_fs_get_fs_options(struct libmnt_fs *fs)
754
return fs ? fs->fs_optstr : NULL;
758
* mnt_fs_get_vfs_options:
759
* @fs: fstab/mtab entry pointer
761
* Returns: pointer to fs-independent (VFS) mount option string or NULL.
763
const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs)
766
return fs ? fs->vfs_optstr : NULL;
770
* mnt_fs_get_user_options:
771
* @fs: fstab/mtab entry pointer
773
* Returns: pointer to userspace mount option string or NULL.
775
const char *mnt_fs_get_user_options(struct libmnt_fs *fs)
778
return fs ? fs->user_optstr : NULL;
782
* mnt_fs_get_attributes:
783
* @fs: fstab/mtab entry pointer
785
* Returns: pointer to attributes string or NULL.
787
const char *mnt_fs_get_attributes(struct libmnt_fs *fs)
790
return fs ? fs->attrs : NULL;
794
* mnt_fs_set_attributes:
795
* @fs: fstab/mtab/mountinfo entry
796
* @optstr: options string
798
* Sets mount attributes. The attributes are mount(2) and mount(8) independent
799
* options, these options are not send to kernel and are not interpreted by
800
* libmount. The attributes are stored in /run/mount/utab only.
802
* The atrtributes are managed by libmount in userspace only. It's possible
803
* that information stored in userspace will not be available for libmount
804
* after CLONE_FS unshare. Be carefull, and don't use attributes if possible.
806
* Returns: 0 on success or negative number in case of error.
808
int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr)
826
* mnt_fs_append_attributes
827
* @fs: fstab/mtab/mountinfo entry
828
* @optstr: options string
830
* Appends mount attributes. (See mnt_fs_set_attributes()).
832
* Returns: 0 on success or negative number in case of error.
834
int mnt_fs_append_attributes(struct libmnt_fs *fs, const char *optstr)
840
return mnt_optstr_append_option(&fs->attrs, optstr, NULL);
844
* mnt_fs_prepend_attributes
845
* @fs: fstab/mtab/mountinfo entry
846
* @optstr: options string
848
* Prepends mount attributes. (See mnt_fs_set_attributes()).
850
* Returns: 0 on success or negative number in case of error.
852
int mnt_fs_prepend_attributes(struct libmnt_fs *fs, const char *optstr)
858
return mnt_optstr_prepend_option(&fs->attrs, optstr, NULL);
864
* @fs: fstab/mtab/mountinfo entry pointer
866
* Returns: dump frequency in days.
868
int mnt_fs_get_freq(struct libmnt_fs *fs)
871
return fs ? fs->freq : 0;
876
* @fs: fstab/mtab entry pointer
877
* @freq: dump frequency in days
879
* Returns: 0 on success or negative number in case of error.
881
int mnt_fs_set_freq(struct libmnt_fs *fs, int freq)
892
* @fs: fstab/mtab entry pointer
894
* Returns: "pass number on parallel fsck".
896
int mnt_fs_get_passno(struct libmnt_fs *fs)
899
return fs ? fs->passno: 0;
904
* @fs: fstab/mtab entry pointer
905
* @passno: pass number
907
* Returns: 0 on success or negative number in case of error.
909
int mnt_fs_set_passno(struct libmnt_fs *fs, int passno)
920
* @fs: /proc/self/mountinfo entry
922
* Returns: root of the mount within the filesystem or NULL
924
const char *mnt_fs_get_root(struct libmnt_fs *fs)
927
return fs ? fs->root : NULL;
932
* @fs: mountinfo entry
935
* Returns: 0 on success or negative number in case of error.
937
int mnt_fs_set_root(struct libmnt_fs *fs, const char *root)
955
* mnt_fs_get_bindsrc:
956
* @fs: /run/mount/utab entry
958
* Returns: full path that was used for mount(2) on MS_BIND
960
const char *mnt_fs_get_bindsrc(struct libmnt_fs *fs)
963
return fs ? fs->bindsrc : NULL;
967
* mnt_fs_set_bindsrc:
971
* Returns: 0 on success or negative number in case of error.
973
int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src)
992
* @fs: /proc/self/mountinfo entry
994
* Returns: mount ID (unique identifier of the mount) or negative number in case of error.
996
int mnt_fs_get_id(struct libmnt_fs *fs)
999
return fs ? fs->id : -EINVAL;
1003
* mnt_fs_get_parent_id:
1004
* @fs: /proc/self/mountinfo entry
1006
* Returns: parent mount ID or negative number in case of error.
1008
int mnt_fs_get_parent_id(struct libmnt_fs *fs)
1011
return fs ? fs->parent : -EINVAL;
1016
* @fs: /proc/self/mountinfo entry
1018
* Returns: value of st_dev for files on filesystem or 0 in case of error.
1020
dev_t mnt_fs_get_devno(struct libmnt_fs *fs)
1023
return fs ? fs->devno : 0;
1027
* mnt_fs_get_option:
1028
* @fs: fstab/mtab/mountinfo entry pointer
1029
* @name: option name
1030
* @value: returns pointer to the begin of the value (e.g. name=VALUE) or NULL
1031
* @valsz: returns size of options value or 0
1033
* Returns: 0 on success, 1 when not found the @name or negative number in case of error.
1035
int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
1036
char **value, size_t *valsz)
1041
rc = mnt_optstr_get_option(fs->fs_optstr, name, value, valsz);
1042
if (rc == 1 && fs->vfs_optstr)
1043
rc = mnt_optstr_get_option(fs->vfs_optstr, name, value, valsz);
1044
if (rc == 1 && fs->user_optstr)
1045
rc = mnt_optstr_get_option(fs->user_optstr, name, value, valsz);
1050
* mnt_fs_get_attribute:
1051
* @fs: fstab/mtab/mountinfo entry pointer
1052
* @name: option name
1053
* @value: returns pointer to the begin of the value (e.g. name=VALUE) or NULL
1054
* @valsz: returns size of options value or 0
1056
* Returns: 0 on success, 1 when not found the @name or negative number in case of error.
1058
int mnt_fs_get_attribute(struct libmnt_fs *fs, const char *name,
1059
char **value, size_t *valsz)
1064
rc = mnt_optstr_get_option(fs->attrs, name, value, valsz);
1069
* mnt_fs_match_target:
1071
* @target: mountpoint path
1072
* @cache: tags/paths cache or NULL
1074
* Possible are three attempts:
1075
* 1) compare @target with @fs->target
1076
* 2) realpath(@target) with @fs->target
1077
* 3) realpath(@target) with realpath(@fs->target).
1079
* The 2nd and 3rd attempts are not performed when @cache is NULL.
1081
* Returns: 1 if @fs target is equal to @target else 0.
1083
int mnt_fs_match_target(struct libmnt_fs *fs, const char *target, struct libmnt_cache *cache)
1087
if (!fs || !target || !fs->target)
1090
/* 1) native paths */
1091
rc = !strcmp(target, fs->target);
1094
/* 2) - canonicalized and non-canonicalized */
1095
char *cn = mnt_resolve_path(target, cache);
1096
rc = (cn && strcmp(cn, fs->target) == 0);
1098
/* 3) - canonicalized and canonicalized */
1100
char *tcn = mnt_resolve_path(fs->target, cache);
1101
rc = (tcn && strcmp(cn, tcn) == 0);
1109
* mnt_fs_match_source:
1111
* @source: tag or path (device or so) or NULL
1112
* @cache: tags/paths cache or NULL
1114
* Possible are four attempts:
1115
* 1) compare @source with @fs->source
1116
* 2) compare realpath(@source) with @fs->source
1117
* 3) compare realpath(@source) with realpath(@fs->source)
1118
* 4) compare realpath(@source) with evaluated tag from @fs->source
1120
* The 2nd, 3rd and 4th attempts are not performed when @cache is NULL. The
1121
* 2nd and 3rd attempts are not performed if @fs->source is tag.
1123
* Note that valid source path is NULL; the libmount uses NULL instead of
1124
* "none". The "none" is used in /proc/{mounts,self/mountninfo} for pseudo
1127
* Returns: 1 if @fs source is equal to @source else 0.
1129
int mnt_fs_match_source(struct libmnt_fs *fs, const char *source, struct libmnt_cache *cache)
1132
const char *src, *t, *v;
1137
/* undefined source -- "none" in /proc */
1138
if (source == NULL && fs->source == NULL)
1141
if (source == NULL || fs->source == NULL)
1144
/* 1) native paths/tags */
1145
if (!strcmp(source, fs->source))
1150
if (fs->flags & (MNT_FS_NET | MNT_FS_PSEUDO))
1153
cn = mnt_resolve_spec(source, cache);
1157
/* 2) canonicalized and native */
1158
src = mnt_fs_get_srcpath(fs);
1159
if (src && !strcmp(cn, src))
1162
/* 3) canonicalized and canonicalized */
1164
src = mnt_resolve_path(src, cache);
1165
if (src && !strcmp(cn, src))
1168
if (src || mnt_fs_get_tag(fs, &t, &v))
1169
/* src path does not match and tag is not defined */
1172
/* read @source's tags to the cache */
1173
if (mnt_cache_read_tags(cache, cn) < 0) {
1174
if (errno == EACCES) {
1175
/* we don't have permissions to read TAGs from
1176
* @source, but can translate @fs tag to devname.
1178
* (because libblkid uses udev symlinks and this is
1179
* accessible for non-root uses)
1181
char *x = mnt_resolve_tag(t, v, cache);
1182
if (x && !strcmp(x, cn))
1188
/* 4) has the @source a tag that matches with tag from @fs ? */
1189
if (mnt_cache_device_has_tag(cache, cn, t, v))
1196
* mnt_fs_match_fstype:
1198
* @types: filesystem name or comma delimited list of filesystems
1200
* For more details see mnt_match_fstype().
1202
* Returns: 1 if @fs type is matching to @types else 0. The function returns
1203
* 0 when types is NULL.
1205
int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types)
1207
return mnt_match_fstype(fs->fstype, types);
1211
* mnt_fs_match_options:
1213
* @options: comma delimited list of options (and nooptions)
1215
* For more details see mnt_match_options().
1217
* Returns: 1 if @fs type is matching to @options else 0. The function returns
1218
* 0 when types is NULL.
1220
int mnt_fs_match_options(struct libmnt_fs *fs, const char *options)
1222
return mnt_match_options(mnt_fs_get_options(fs), options);
1226
* mnt_fs_print_debug
1227
* @fs: fstab/mtab/mountinfo entry
1228
* @file: file stream
1230
* Returns: 0 on success or negative number in case of error.
1232
int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file)
1236
fprintf(file, "------ fs: %p\n", fs);
1237
fprintf(file, "source: %s\n", mnt_fs_get_source(fs));
1238
fprintf(file, "target: %s\n", mnt_fs_get_target(fs));
1239
fprintf(file, "fstype: %s\n", mnt_fs_get_fstype(fs));
1241
if (mnt_fs_get_options(fs))
1242
fprintf(file, "optstr: %s\n", mnt_fs_get_options(fs));
1243
if (mnt_fs_get_vfs_options(fs))
1244
fprintf(file, "VFS-optstr: %s\n", mnt_fs_get_vfs_options(fs));
1245
if (mnt_fs_get_fs_options(fs))
1246
fprintf(file, "FS-opstr: %s\n", mnt_fs_get_fs_options(fs));
1247
if (mnt_fs_get_user_options(fs))
1248
fprintf(file, "user-optstr: %s\n", mnt_fs_get_user_options(fs));
1249
if (mnt_fs_get_attributes(fs))
1250
fprintf(file, "attributes: %s\n", mnt_fs_get_attributes(fs));
1252
if (mnt_fs_get_root(fs))
1253
fprintf(file, "root: %s\n", mnt_fs_get_root(fs));
1254
if (mnt_fs_get_bindsrc(fs))
1255
fprintf(file, "bindsrc: %s\n", mnt_fs_get_bindsrc(fs));
1256
if (mnt_fs_get_freq(fs))
1257
fprintf(file, "freq: %d\n", mnt_fs_get_freq(fs));
1258
if (mnt_fs_get_passno(fs))
1259
fprintf(file, "pass: %d\n", mnt_fs_get_passno(fs));
1260
if (mnt_fs_get_id(fs))
1261
fprintf(file, "id: %d\n", mnt_fs_get_id(fs));
1262
if (mnt_fs_get_parent_id(fs))
1263
fprintf(file, "parent: %d\n", mnt_fs_get_parent_id(fs));
1264
if (mnt_fs_get_devno(fs))
1265
fprintf(file, "devno: %d:%d\n", major(mnt_fs_get_devno(fs)),
1266
minor(mnt_fs_get_devno(fs)));
1274
* Deallocates "mntent.h" mount entry.
1276
void mnt_free_mntent(struct mntent *mnt)
1279
free(mnt->mnt_fsname);
1281
free(mnt->mnt_type);
1282
free(mnt->mnt_opts);
1290
* @mnt: mount description (as described in mntent.h)
1292
* Copies information from @fs to struct mntent @mnt. If @mnt is already set
1293
* then the struct mntent items are reallocated and updated. See also
1294
* mnt_free_mntent().
1296
* Returns: 0 on success and negative number in case of error.
1298
int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt)
1308
m = calloc(1, sizeof(*m));
1313
if ((rc = update_str(&m->mnt_fsname, mnt_fs_get_source(fs))))
1315
if ((rc = update_str(&m->mnt_dir, mnt_fs_get_target(fs))))
1317
if ((rc = update_str(&m->mnt_type, mnt_fs_get_fstype(fs))))
1321
m->mnt_opts = mnt_fs_strdup_options(fs);
1322
if (!m->mnt_opts && errno) {
1327
m->mnt_freq = mnt_fs_get_freq(fs);
1328
m->mnt_passno = mnt_fs_get_passno(fs);
1330
if (!m->mnt_fsname) {
1331
m->mnt_fsname = strdup("none");