From: Karel Zak Date: Tue, 24 Aug 2010 14:03:50 +0000 (+0200) Subject: libmount: clean up mnt_fs_set_optstr() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=569f95b7e8d457e11ce1ca114128bdf7f732208f;p=util-linux libmount: clean up mnt_fs_set_optstr() Signed-off-by: Karel Zak --- diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 4931d078..2151d544 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -390,16 +390,7 @@ const char *mnt_fs_get_optstr(mnt_fs *fs) return fs ? fs->optstr : NULL; } -/** - * mnt_fs_set_optstr: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * This function creates a private copy of @optstr. - * - * Returns: 0 on success or -1 in case of error. - */ -int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) +int __mnt_fs_set_optstr(mnt_fs *fs, const char *optstr, int split) { char *p = NULL, *v = NULL, *f = NULL; @@ -409,7 +400,8 @@ int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) return -1; if (optstr) { - if (mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) + if (split && + mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) return -1; p = strdup(optstr); @@ -431,17 +423,31 @@ int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) } /** - * mnt_fs_append_optstr: + * mnt_fs_set_optstr: * @fs: fstab/mtab/mountinfo entry - * @optstr: options string (usually userspace specific options) + * @optstr: options string * - * This function appends @optstr to the current list of the mount options. The - * VFS and FS specific lists are not modified -- so then the - * mnt_fs_get_optstr() function returns VFS + FS + userspace mount options. + * This function creates a private copy of @optstr. The function also updates + * VFS and FS mount options. * * Returns: 0 on success or -1 in case of error. */ -int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr) +int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) +{ + return __mnt_fs_set_optstr(fs, optstr, TRUE); +} + +/** + * mnt_fs_append_userspace_optstr: + * @fs: fstab/mtab/mountinfo entry + * @optstr: options string + * + * This function appends @optstr to the current list of the mount options. The VFS and + * FS mount options are not modified. + * + * Returns: 0 on success or -1 in case of error. + */ +int mnt_fs_append_userspace_optstr(mnt_fs *fs, const char *optstr) { assert(fs); @@ -451,6 +457,38 @@ int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr) return mnt_optstr_append_option(&fs->optstr, optstr, NULL); } +/** + * mnt_fs_append_optstr: + * @fs: fstab/mtab/mountinfo entry + * @optstr: mount options + * + * Returns: 0 on success or -1 in case of error. + */ +int mnt_fs_append_optstr(mnt_fs *fs, const char *optstr) +{ + char *v = NULL, *f = NULL; + + assert(fs); + + if (!fs) + return -1; + if (!optstr) + return 0; + + if (mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) + return -1; + + if (mnt_optstr_append_option(&fs->optstr, optstr, NULL)) + return -1; + if (v && mnt_optstr_append_option(&fs->vfs_optstr, v, NULL)) + return -1; + if (f && mnt_optstr_append_option(&fs->fs_optstr, f, NULL)) + return -1; + + return 0; + +} + /** * mnt_fs_get_fs_optstr: * @fs: fstab/mtab/mountinfo entry pointer diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index 5f900155..a4170b47 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -207,6 +207,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_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); extern int mnt_fs_get_freq(mnt_fs *ent); diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index 198f8285..56e20ddd 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_append_userspace_optstr; mnt_fs_get_devno; mnt_fs_get_freq; mnt_fs_get_fs_optstr; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index 9f00b613..d962b679 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -11,6 +11,7 @@ #define _LIBMOUNT_PRIVATE_H #include +#include "c.h" #define USE_UNSTABLE_LIBMOUNT_API @@ -170,5 +171,6 @@ extern int mnt_optmap_require_value(const struct mnt_optmap *mapent); /* fs.c */ extern int __mnt_fs_set_source(mnt_fs *fs, char *source); extern int __mnt_fs_set_fstype(mnt_fs *fs, char *fstype); +extern int __mnt_fs_set_optstr(mnt_fs *fs, const char *optstr, int split); #endif /* _LIBMOUNT_PRIVATE_H */ diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 6f8308e5..1d59d17a 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -613,7 +613,7 @@ done: * Note that @uf must contain only userspace specific mount options instead of * VFS options (note that FS options are ignored). * - * Returns: modified filesystem (from @tb) or NULL. + * Returns modified filesystem (from @tb) or NULL. */ static mnt_fs *mnt_tab_merge_userspace_fs(mnt_tab *tb, mnt_fs *uf) { @@ -647,7 +647,7 @@ static mnt_fs *mnt_tab_merge_userspace_fs(mnt_tab *tb, mnt_fs *uf) } if (fs) - mnt_fs_append_optstr(fs, optstr); + mnt_fs_append_userspace_optstr(fs, optstr); return fs; } diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 887ee685..7b53d63c 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -531,6 +531,7 @@ err: * - for /var/run/mount/mountinfo: * * evaluate if the update is necessary * * set fs root and devname for bind mount and btrfs subvolumes + * * removes unnecessary mount options * - allocate update_lock if necessary * * This function has to be always called before mount(2). The mnt_update_file() @@ -599,7 +600,7 @@ int mnt_prepare_update(mnt_update *upd) /* remount */ if (mnt_split_optstr(o, &u, NULL, NULL, MNT_NOMTAB, 0)) goto err; - if (mnt_fs_set_optstr(upd->fs, u)) + if (__mnt_fs_set_optstr(upd->fs, u, FALSE)) goto err; } else { @@ -611,7 +612,7 @@ int mnt_prepare_update(mnt_update *upd) goto nothing; /* no userpsace options */ if (set_fs_root(upd, upd->fs)) goto err; - mnt_fs_set_optstr(upd->fs, u); + __mnt_fs_set_optstr(upd->fs, u, FALSE); } if (!upd->nolock && !upd->lc) { @@ -765,7 +766,7 @@ static int modify_options(mnt_update *upd) mnt_tab_remove_fs(tb, fs); rem_fs = fs; } else - mnt_fs_set_optstr(fs, mnt_fs_get_optstr(upd->fs)); + __mnt_fs_set_optstr(fs, mnt_fs_get_optstr(upd->fs), FALSE); if (!update_file(upd->filename, upd->format, tb)) rc = 0;