summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src
diff options
context:
space:
mode:
authorKarel Zak2010-09-14 10:50:49 +0200
committerKarel Zak2011-01-03 12:28:42 +0100
commitc83fd489e6a8b43339e39bbc3528b9771746ae32 (patch)
tree5766fe34a4a8917edfe9e4a7133e41da65db5457 /shlibs/mount/src
parentlibmount: add mnt_optstr_prepend_option() (diff)
downloadkernel-qcow2-util-linux-c83fd489e6a8b43339e39bbc3528b9771746ae32.tar.gz
kernel-qcow2-util-linux-c83fd489e6a8b43339e39bbc3528b9771746ae32.tar.xz
kernel-qcow2-util-linux-c83fd489e6a8b43339e39bbc3528b9771746ae32.zip
libmount: add mnt_fs_prepend_optstr()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src')
-rw-r--r--shlibs/mount/src/fs.c34
-rw-r--r--shlibs/mount/src/mount.h.in1
-rw-r--r--shlibs/mount/src/mount.sym1
-rw-r--r--shlibs/mount/src/tab_parse.c6
-rw-r--r--shlibs/mount/src/tab_update.c4
5 files changed, 38 insertions, 8 deletions
diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c
index 11dbf6457..fad5da890 100644
--- a/shlibs/mount/src/fs.c
+++ b/shlibs/mount/src/fs.c
@@ -484,11 +484,39 @@ int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr)
}
/**
+ * 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)
@@ -501,8 +529,6 @@ 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)
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in
index 559f59a41..b35d64524 100644
--- a/shlibs/mount/src/mount.h.in
+++ b/shlibs/mount/src/mount.h.in
@@ -209,6 +209,7 @@ extern int mnt_fs_set_fstype(mnt_fs *ent, const char *fstype);
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);
diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym
index af0cc88fb..d0fa3085b 100644
--- a/shlibs/mount/src/mount.sym
+++ b/shlibs/mount/src/mount.sym
@@ -19,6 +19,7 @@ global:
mnt_free_optls;
mnt_free_tab;
mnt_fs_append_optstr;
+ mnt_fs_prepend_optstr;
mnt_fs_append_userspace_optstr;
mnt_fs_get_devno;
mnt_fs_get_freq;
diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c
index 9c65c57ed..e782b2781 100644
--- a/shlibs/mount/src/tab_parse.c
+++ b/shlibs/mount/src/tab_parse.c
@@ -116,6 +116,7 @@ static int next_number(char **s, int *num)
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));
@@ -133,8 +134,8 @@ static int mnt_tab_parse_file_line(mnt_fs *fs, char *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 */
@@ -151,6 +152,7 @@ static int mnt_tab_parse_file_line(mnt_fs *fs, char *s)
return 0;
err:
+ free(p);
if (rc)
return rc;
return errno == ENOMEM ? -ENOMEM : -EINVAL;
diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c
index c023777cb..3d60f46b4 100644
--- a/shlibs/mount/src/tab_update.c
+++ b/shlibs/mount/src/tab_update.c
@@ -585,16 +585,16 @@ int mnt_prepare_update(mnt_update *upd)
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))