return rc;
}
+/**
+ * mnt_fs_prepend_optstr:
+ * @fs: fstab/mtab/mountinfo entry
+ * @optstr: mount options
+ *
+ * Returns: 0 on success or negative number in case of error.
+ */
+int mnt_fs_prepend_optstr(mnt_fs *fs, const char *optstr)
+{
+ char *v = NULL, *f = NULL;
+ int rc;
+
+ assert(fs);
+
+ if (!fs)
+ return -EINVAL;
+ if (!optstr)
+ return 0;
+
+ rc = mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0);
+ if (!rc)
+ rc = mnt_optstr_prepend_option(&fs->optstr, optstr, NULL);
+ if (!rc && v)
+ rc = mnt_optstr_prepend_option(&fs->vfs_optstr, v, NULL);
+ if (!rc && f)
+ rc = mnt_optstr_prepend_option(&fs->fs_optstr, f, NULL);
+
+ return rc;
+}
+
/**
* mnt_fs_get_fs_optstr:
* @fs: fstab/mtab/mountinfo entry pointer
*
- * This function works for "mountinfo" files only.
- *
* Returns: pointer to superblock (fs-depend) mount option string or NULL.
*/
const char *mnt_fs_get_fs_optstr(mnt_fs *fs)
* mnt_fs_get_vfs_optstr:
* @fs: fstab/mtab entry pointer
*
- * This function works for "mountinfo" files only.
- *
* Returns: pointer to fs-independent (VFS) mount option string or NULL.
*/
const char *mnt_fs_get_vfs_optstr(mnt_fs *fs)
extern const char *mnt_fs_get_optstr(mnt_fs *ent);
extern int mnt_fs_set_optstr(mnt_fs *ent, const char *optstr);
extern int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr);
+extern int mnt_fs_prepend_optstr(mnt_fs *fs, const char *optstr);
extern int mnt_fs_append_userspace_optstr(mnt_fs *fs, const char *optstr);
extern const char *mnt_fs_get_vfs_optstr(mnt_fs *ent);
extern const char *mnt_fs_get_fs_optstr(mnt_fs *ent);
static int mnt_tab_parse_file_line(mnt_fs *fs, char *s)
{
int rc = 0;
+ char *p = NULL;
/* SOURCE */
rc =__mnt_fs_set_source(fs, next_word(&s));
goto err;
/* OPTS */
- fs->optstr = next_word(&s);
- if (!fs->optstr)
+ p = next_word(&s);
+ if (!p || mnt_fs_set_optstr(fs, p))
goto err;
/* default */
return 0;
err:
+ free(p);
if (rc)
return rc;
return errno == ENOMEM ? -ENOMEM : -EINVAL;
return 0;
/*
- * A) classic /etc/mtab
+ * A) classic /etc/mtab or /etc/fstab update
*/
if (upd->format != MNT_FMT_MOUNTINFO)
return 0;
/*
* B) /var/run/mount/mountinfo
+ * - remove all non-userspace mount options
*/
if (upd->mountflags & MS_REMOUNT) {
- /* remount */
if (mnt_split_optstr(o, &u, NULL, NULL, MNT_NOMTAB, 0))
goto err;
if (__mnt_fs_set_optstr(upd->fs, u, FALSE))