From: Karel Zak Date: Tue, 14 Sep 2010 08:50:49 +0000 (+0200) Subject: libmount: add mnt_fs_prepend_optstr() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c83fd489e6a8b43339e39bbc3528b9771746ae32;p=util-linux libmount: add mnt_fs_prepend_optstr() Signed-off-by: Karel Zak --- diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 11dbf645..fad5da89 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -483,12 +483,40 @@ int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr) 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) @@ -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 559f59a4..b35d6452 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 af0cc88f..d0fa3085 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 9c65c57e..e782b278 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 c023777c..3d60f46b 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))