From 569f95b7e8d457e11ce1ca114128bdf7f732208f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 24 Aug 2010 16:03:50 +0200 Subject: libmount: clean up mnt_fs_set_optstr() Signed-off-by: Karel Zak --- shlibs/mount/src/fs.c | 72 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 17 deletions(-) (limited to 'shlibs/mount/src/fs.c') diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 4931d0785..2151d5449 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 -- cgit v1.2.3-55-g7522