}
/*
- * Merges @vfs and @fs options strings into a new string.
- * This function cares about 'ro/rw' options. The 'ro' is
- * always used if @vfs or @fs is read-only.
- * For example:
- *
- * mnt_merge_optstr("rw,noexec", "ro,journal=update")
- *
- * returns: "ro,noexec,journal=update"
- *
- * mnt_merge_optstr("rw,noexec", "rw,journal=update")
- *
- * returns: "rw,noexec,journal=update"
+ * Merges @vfs and @fs options strings into a new string. This function cares
+ * about 'ro/rw' options. The 'ro' is always used if @vfs or @fs is read-only.
*/
static char *merge_optstr(const char *vfs, const char *fs)
{
return res;
}
+static char *fs_strdup_options(struct libmnt_fs *fs)
+{
+ char *res;
+
+ errno = 0;
+ if (fs->optstr)
+ return strdup(fs->optstr);
+
+ res = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
+ if (!res && errno)
+ return NULL;
+ if (fs->user_optstr &&
+ mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
+ free(res);
+ res = NULL;
+ }
+ return res;
+}
+
/**
* mnt_fs_strdup_options:
* @fs: fstab/mtab/mountinfo entry pointer
*/
char *mnt_fs_strdup_options(struct libmnt_fs *fs)
{
- char *res;
-
if (!fs)
return NULL;
if (fs->optlist)
sync_opts_from_optlist(fs, fs->optlist);
#ifdef HAVE_STATMOUNT_API
else
- mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
+ mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC
+ | STATMOUNT_MNT_BASIC | STATMOUNT_MNT_OPTS);
#endif
- errno = 0;
- if (fs->optstr)
- return strdup(fs->optstr);
+ return fs_strdup_options(fs);
- res = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
- if (!res && errno)
- return NULL;
- if (fs->user_optstr &&
- mnt_optstr_append_option(&res, fs->user_optstr, NULL)) {
- free(res);
- res = NULL;
- }
- return res;
}
/**
if (fs->optlist)
sync_opts_from_optlist(fs, fs->optlist);
#ifdef HAVE_STATMOUNT_API
- else
- mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC);
+ else {
+ mnt_fs_try_statmount(fs, optstr, STATMOUNT_SB_BASIC
+ | STATMOUNT_MNT_BASIC | STATMOUNT_MNT_OPTS);
+ if (!fs->optstr)
+ fs->optstr = fs_strdup_options(fs);
+ }
#endif
return fs->optstr;
}
sync_opts_from_optlist(fs, fs->optlist);
#ifdef HAVE_STATMOUNT_API
else
- mnt_fs_try_statmount(fs, fs_optstr, STATMOUNT_SB_BASIC);
+ mnt_fs_try_statmount(fs, fs_optstr, STATMOUNT_SB_BASIC | STATMOUNT_MNT_OPTS);
#endif
return fs->fs_optstr;
}
old = sm->disabled;
sm->disabled = disable ? 1 : 0;
+ /*
DBG(STATMNT, ul_debugobj(sm, "statmount() %s",
sm->disabled ? "off" : "on"));
+ */
return old;
}
static int apply_statmount(struct libmnt_fs *fs, struct ul_statmount *sm)
{
- int rc = 0, merge = 0;
+ int rc = 0;
if (!sm || !sm->size || !fs)
return -EINVAL;
- merge = !fs->vfs_optstr || fs->fs_optstr;
-
if ((sm->mask & STATMOUNT_FS_TYPE) && !fs->fstype)
rc = mnt_fs_set_fstype(fs, sm_str(sm, sm->fs_type));
rc = mnt_optstr_append_option(&fs->vfs_optstr, "relatime", NULL);
break;
}
-
+ free(fs->optstr);
+ fs->optstr = NULL;
}
}
if (!rc && (sm->mask & STATMOUNT_MNT_NS_ID) && !fs->ns_id)
fs->ns_id = sm->mnt_ns_id;
- if (!rc && (sm->mask & STATMOUNT_MNT_OPTS) && !fs->fs_optstr)
+ if (!rc && (sm->mask & STATMOUNT_MNT_OPTS) && !fs->fs_optstr) {
fs->fs_optstr = unmangle(sm_str(sm, sm->mnt_opts), NULL);
+ free(fs->optstr);
+ fs->optstr = NULL;
+ }
if (!rc && (sm->mask & STATMOUNT_SB_BASIC)) {
if (!fs->devno)
rc = mnt_optstr_append_option(&fs->fs_optstr, "dirsync", NULL);
if (!rc && (sm->sb_flags & SB_LAZYTIME))
rc = mnt_optstr_append_option(&fs->fs_optstr, "lazytime", NULL);
+ free(fs->optstr);
+ fs->optstr = NULL;
}
}
- if (!rc && merge) {
- free(fs->optstr);
-
- /* merge VFS and FS options to one string (we do the same in mountinfo parser) */
- fs->optstr = mnt_fs_strdup_options(fs);
- }
-
fs->flags |= MNT_FS_KERNEL;
return rc;