diff options
-rw-r--r-- | shlibs/mount/src/context.c | 34 | ||||
-rw-r--r-- | shlibs/mount/src/context_mount.c | 8 | ||||
-rw-r--r-- | shlibs/mount/src/context_umount.c | 4 | ||||
-rw-r--r-- | shlibs/mount/src/fs.c | 244 | ||||
-rw-r--r-- | shlibs/mount/src/libmount.h.in | 16 | ||||
-rw-r--r-- | shlibs/mount/src/libmount.sym | 10 | ||||
-rw-r--r-- | shlibs/mount/src/mountP.h | 1 | ||||
-rw-r--r-- | shlibs/mount/src/tab_parse.c | 7 | ||||
-rw-r--r-- | shlibs/mount/src/tab_update.c | 13 |
9 files changed, 76 insertions, 261 deletions
diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index 487859a3f..f8db3cfd6 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -1376,36 +1376,14 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb, if (cxt->optsmode & MNT_OMODE_IGNORE) ; - else if (cxt->optsmode & MNT_OMODE_REPLACE) { - rc = mnt_fs_set_vfs_options(cxt->fs, - mnt_fs_get_vfs_options(fs)); - if (!rc) - rc = mnt_fs_set_fs_options(cxt->fs, - mnt_fs_get_fs_options(fs)); - if (!rc) - rc = mnt_fs_set_user_options(cxt->fs, - mnt_fs_get_user_options(fs)); + else if (cxt->optsmode & MNT_OMODE_REPLACE) + rc = mnt_fs_set_options(cxt->fs, mnt_fs_get_options(fs)); - } else if (cxt->optsmode & MNT_OMODE_APPEND) { - rc = mnt_fs_append_vfs_options(cxt->fs, - mnt_fs_get_vfs_options(fs)); - if (!rc) - rc = mnt_fs_append_fs_options(cxt->fs, - mnt_fs_get_fs_options(fs)); - if (!rc) - rc = mnt_fs_append_user_options(cxt->fs, - mnt_fs_get_user_options(fs)); + else if (cxt->optsmode & MNT_OMODE_APPEND) + rc = mnt_fs_append_options(cxt->fs, mnt_fs_get_options(fs)); - } else if (cxt->optsmode & MNT_OMODE_PREPEND) { - rc = mnt_fs_prepend_vfs_options(cxt->fs, - mnt_fs_get_vfs_options(fs)); - if (!rc) - rc = mnt_fs_prepend_fs_options(cxt->fs, - mnt_fs_get_fs_options(fs)); - if (!rc) - rc = mnt_fs_prepend_user_options(cxt->fs, - mnt_fs_get_user_options(fs)); - } + else if (cxt->optsmode & MNT_OMODE_PREPEND) + rc = mnt_fs_prepend_options(cxt->fs, mnt_fs_get_options(fs)); if (!rc) cxt->flags |= MNT_FL_TAB_APPLIED; diff --git a/shlibs/mount/src/context_mount.c b/shlibs/mount/src/context_mount.c index 0c6754644..647e26149 100644 --- a/shlibs/mount/src/context_mount.c +++ b/shlibs/mount/src/context_mount.c @@ -109,10 +109,14 @@ static int fix_optstr(struct libmnt_context *cxt) if (!rc && cxt->user_mountflags && MNT_MS_USER) rc = mnt_optstr_fix_user(&fs->user_optstr); + /* refresh merged optstr */ + free(fs->optstr); + fs->optstr = NULL; + fs->optstr = mnt_fs_strdup_options(fs); done: DBG(CXT, mnt_debug_h(cxt, "fixed options [rc=%d]: " - "vfs: '%s' fs: '%s' user: '%s'", rc, - fs->vfs_optstr, fs->fs_optstr, fs->user_optstr)); + "vfs: '%s' fs: '%s' user: '%s', optstr: '%s'", rc, + fs->vfs_optstr, fs->fs_optstr, fs->user_optstr, fs->optstr)); return rc; } diff --git a/shlibs/mount/src/context_umount.c b/shlibs/mount/src/context_umount.c index 1187a87cd..3bf8fc45e 100644 --- a/shlibs/mount/src/context_umount.c +++ b/shlibs/mount/src/context_umount.c @@ -591,7 +591,7 @@ int mnt_context_do_umount(struct libmnt_context *cxt) /* * fix options, remount --> read-only mount */ - const char *o = mnt_fs_get_vfs_options(cxt->fs); + const char *o = mnt_fs_get_options(cxt->fs); char *n = o ? strdup(o) : NULL; DBG(CXT, mnt_debug_h(cxt, "fix remount-on-umount update")); @@ -600,7 +600,7 @@ int mnt_context_do_umount(struct libmnt_context *cxt) mnt_optstr_remove_option(&n, "rw"); rc = mnt_optstr_prepend_option(&n, "ro", NULL); if (!rc) - rc = mnt_fs_set_vfs_options(cxt->fs, n); + rc = mnt_fs_set_options(cxt->fs, n); /* use "remount" instead of "umount" in /etc/mtab */ if (!rc && cxt->update && cxt->mtab_writable) diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index c2deff5f1..75ec4b476 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -59,6 +59,7 @@ void mnt_free_fs(struct libmnt_fs *fs) free(fs->root); free(fs->target); free(fs->fstype); + free(fs->optstr); free(fs->vfs_optstr); free(fs->fs_optstr); free(fs->user_optstr); @@ -154,6 +155,8 @@ struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest, goto err; if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, fstype))) goto err; + if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, optstr))) + goto err; if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, vfs_optstr))) goto err; if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, fs_optstr))) @@ -214,6 +217,10 @@ struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs) if (cpy_str_at_offset(n, fs, offsetof(struct libmnt_fs, fs_optstr))) goto err; + /* we cannot copy original optstr, the new optstr has to be without + * non-mtab options -- so, let's generate a new string */ + n->optstr = mnt_fs_strdup_options(n); + n->freq = fs->freq; n->passno = fs->passno; n->flags = fs->flags; @@ -583,6 +590,10 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs) assert(fs); errno = 0; + + if (fs->optstr) + return strdup(fs->optstr); + res = merge_optstr(fs->vfs_optstr, fs->fs_optstr); if (!res && errno) return NULL; @@ -596,6 +607,19 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs) } /** + * mnt_fs_get_options: + * @fs: fstab/mtab/mountinfo entry pointer + * + * Returns: pointer to string or NULL in case of error. + */ +const char *mnt_fs_get_options(struct libmnt_fs *fs) +{ + assert(fs); + return fs ? fs->optstr : NULL; +} + + +/** * mnt_fs_set_options: * @fs: fstab/mtab/mountinfo entry pointer * @optstr: options string @@ -607,7 +631,7 @@ char *mnt_fs_strdup_options(struct libmnt_fs *fs) */ int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr) { - char *v = NULL, *f = NULL, *u = NULL; + char *v = NULL, *f = NULL, *u = NULL, *n = NULL; assert(fs); @@ -617,15 +641,21 @@ int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr) int rc = mnt_split_optstr(optstr, &u, &v, &f, 0, 0); if (rc) return rc; + n = strdup(optstr); + if (!n) + return -ENOMEM; } free(fs->fs_optstr); free(fs->vfs_optstr); free(fs->user_optstr); + free(fs->optstr); fs->fs_optstr = f; fs->vfs_optstr = v; fs->user_optstr = u; + fs->optstr = n; + return 0; } @@ -657,9 +687,15 @@ int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr) if (!rc && v) rc = mnt_optstr_append_option(&fs->vfs_optstr, v, NULL); if (!rc && f) - rc = mnt_optstr_append_option(&fs->fs_optstr, f, NULL); + rc = mnt_optstr_append_option(&fs->fs_optstr, f, NULL); if (!rc && u) - rc = mnt_optstr_append_option(&fs->user_optstr, u, NULL); + rc = mnt_optstr_append_option(&fs->user_optstr, u, NULL); + if (!rc) + rc = mnt_optstr_append_option(&fs->optstr, optstr, NULL); + + free(v); + free(f); + free(u); return rc; } @@ -695,6 +731,12 @@ int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr) rc = mnt_optstr_prepend_option(&fs->fs_optstr, f, NULL); if (!rc && u) rc = mnt_optstr_prepend_option(&fs->user_optstr, u, NULL); + if (!rc) + rc = mnt_optstr_prepend_option(&fs->optstr, optstr, NULL); + + free(v); + free(f); + free(u); return rc; } @@ -712,71 +754,6 @@ const char *mnt_fs_get_fs_options(struct libmnt_fs *fs) } /** - * mnt_fs_set_fs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Sets FS specific mount options. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_set_fs_options(struct libmnt_fs *fs, const char *optstr) -{ - char *p = NULL; - - if (!fs) - return -EINVAL; - if (optstr) { - p = strdup(optstr); - if (!p) - return -ENOMEM; - } - free(fs->fs_optstr); - fs->fs_optstr = p; - - return 0; -} - -/** - * mnt_fs_append_fs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Appends FS specific mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_append_fs_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - return mnt_optstr_append_option(&fs->fs_optstr, optstr, NULL); -} - -/** - * mnt_fs_prepend_fs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Prepends FS specific mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_prepend_fs_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - return mnt_optstr_prepend_option(&fs->fs_optstr, optstr, NULL); -} - - -/** * mnt_fs_get_vfs_options: * @fs: fstab/mtab entry pointer * @@ -789,70 +766,6 @@ const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs) } /** - * mnt_fs_set_vfs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Sets VFS mount options. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_set_vfs_options(struct libmnt_fs *fs, const char *optstr) -{ - char *p = NULL; - - if (!fs) - return -EINVAL; - if (optstr) { - p = strdup(optstr); - if (!p) - return -ENOMEM; - } - free(fs->vfs_optstr); - fs->vfs_optstr = p; - - return 0; -} - -/** - * mnt_fs_append_vfs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Appends VFS mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_append_vfs_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - return mnt_optstr_append_option(&fs->vfs_optstr, optstr, NULL); -} - -/** - * mnt_fs_prepend_vfs_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Prepends VFS mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_prepend_vfs_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - return mnt_optstr_prepend_option(&fs->vfs_optstr, optstr, NULL); -} - -/** * mnt_fs_get_user_options: * @fs: fstab/mtab entry pointer * @@ -865,71 +778,6 @@ const char *mnt_fs_get_user_options(struct libmnt_fs *fs) } /** - * mnt_fs_set_user_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Sets userspace mount options. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_set_user_options(struct libmnt_fs *fs, const char *optstr) -{ - char *p = NULL; - - if (!fs) - return -EINVAL; - if (optstr) { - p = strdup(optstr); - if (!p) - return -ENOMEM; - } - free(fs->user_optstr); - fs->user_optstr = p; - - return 0; -} - -/** - * mnt_fs_append_user_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Appends userspace mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_append_user_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - return mnt_optstr_append_option(&fs->user_optstr, optstr, NULL); -} - -/** - * mnt_fs_prepend_user_options: - * @fs: fstab/mtab/mountinfo entry - * @optstr: options string - * - * Prepends userspace mount options. If @optstr is NULL then @fs is not - * modified and 0 is returned. - * - * Returns: 0 on success or negative number in case of error. - */ -int mnt_fs_prepend_user_options(struct libmnt_fs *fs, const char *optstr) -{ - if (!fs) - return -EINVAL; - if (!optstr) - return 0; - - return mnt_optstr_prepend_option(&fs->user_optstr, optstr, NULL); -} - -/** * mnt_fs_get_attributes: * @fs: fstab/mtab entry pointer * @@ -1384,6 +1232,8 @@ int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file) fprintf(file, "target: %s\n", mnt_fs_get_target(fs)); fprintf(file, "fstype: %s\n", mnt_fs_get_fstype(fs)); + if (mnt_fs_get_options(fs)) + fprintf(file, "optstr: %s\n", mnt_fs_get_options(fs)); if (mnt_fs_get_vfs_options(fs)) fprintf(file, "VFS-optstr: %s\n", mnt_fs_get_vfs_options(fs)); if (mnt_fs_get_fs_options(fs)) diff --git a/shlibs/mount/src/libmount.h.in b/shlibs/mount/src/libmount.h.in index 1831ed18a..cb0a28aee 100644 --- a/shlibs/mount/src/libmount.h.in +++ b/shlibs/mount/src/libmount.h.in @@ -215,28 +215,18 @@ extern const char *mnt_fs_get_fstype(struct libmnt_fs *fs); extern int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype); extern char *mnt_fs_strdup_options(struct libmnt_fs *fs); +extern const char *mnt_fs_get_options(struct libmnt_fs *fs); extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr); +extern int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr); +extern int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr); extern int mnt_fs_get_option(struct libmnt_fs *fs, const char *name, char **value, size_t *valsz); -extern int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr); extern const char *mnt_fs_get_fs_options(struct libmnt_fs *fs); -extern int mnt_fs_set_fs_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_append_fs_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_prepend_fs_options(struct libmnt_fs *fs, const char *optstr); - extern const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs); -extern int mnt_fs_set_vfs_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_append_vfs_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_prepend_vfs_options(struct libmnt_fs *fs, const char *optstr); - extern const char *mnt_fs_get_user_options(struct libmnt_fs *fs); -extern int mnt_fs_set_user_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_append_user_options(struct libmnt_fs *fs, const char *optstr); -extern int mnt_fs_prepend_user_options(struct libmnt_fs *fs, const char *optstr); extern const char *mnt_fs_get_attributes(struct libmnt_fs *fs); extern int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr); diff --git a/shlibs/mount/src/libmount.sym b/shlibs/mount/src/libmount.sym index d0ebfd728..f8a5345b0 100644 --- a/shlibs/mount/src/libmount.sym +++ b/shlibs/mount/src/libmount.sym @@ -75,10 +75,7 @@ global: mnt_free_table; mnt_free_update; mnt_fs_append_attributes; - mnt_fs_append_fs_options; mnt_fs_append_options; - mnt_fs_append_user_options; - mnt_fs_append_vfs_options; mnt_fs_get_attribute; mnt_fs_get_attributes; mnt_fs_get_bindsrc; @@ -88,6 +85,7 @@ global: mnt_fs_get_fstype; mnt_fs_get_id; mnt_fs_get_option; + mnt_fs_get_options; mnt_fs_get_parent_id; mnt_fs_get_passno; mnt_fs_get_root; @@ -104,15 +102,11 @@ global: mnt_fs_match_source; mnt_fs_match_target; mnt_fs_prepend_attributes; - mnt_fs_prepend_fs_options; mnt_fs_prepend_options; - mnt_fs_prepend_user_options; - mnt_fs_prepend_vfs_options; mnt_fs_print_debug; mnt_fs_set_attributes; mnt_fs_set_bindsrc; mnt_fs_set_freq; - mnt_fs_set_fs_options; mnt_fs_set_fstype; mnt_fs_set_options; mnt_fs_set_passno; @@ -120,8 +114,6 @@ global: mnt_fs_set_source; mnt_fs_set_target; mnt_fs_set_userdata; - mnt_fs_set_user_options; - mnt_fs_set_vfs_options; mnt_fs_strdup_options; mnt_fs_to_mntent; mnt_fstype_is_netfs; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index 71314a542..0d773ba0a 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -174,6 +174,7 @@ struct libmnt_fs { char *target; /* mountinfo[5], fstab[2]: mountpoint */ char *fstype; /* mountinfo[9], fstab[3]: filesystem type */ + char *optstr; /* fstab[4], merged options */ char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */ char *fs_optstr; /* mountinfo[11]: fs-depend options */ char *user_optstr; /* userspace mount options */ diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 4eb32eb63..cd4e34897 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -163,6 +163,11 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) rc = __mnt_fs_set_fstype_ptr(fs, fstype); if (!rc) rc = __mnt_fs_set_source_ptr(fs, src); + + /* merge VFS and FS options to the one string */ + fs->optstr = mnt_fs_strdup_options(fs); + if (!fs->optstr) + rc = -ENOMEM; } else { DBG(TAB, mnt_debug( "mountinfo parse error [sscanf rc=%d]: '%s'", rc, s)); @@ -651,7 +656,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct if (fs) { DBG(TAB, mnt_debug_h(tb, "found fs -- appending user optstr")); - mnt_fs_append_user_options(fs, optstr); + mnt_fs_append_options(fs, optstr); mnt_fs_append_attributes(fs, attrs); mnt_fs_set_bindsrc(fs, mnt_fs_get_bindsrc(uf)); fs->flags |= MNT_FS_MERGED; diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 5373e2fa2..47a3e5fe9 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -264,13 +264,13 @@ int mnt_update_force_rdonly(struct libmnt_update *upd, int rdonly) if (!upd->userspace_only) { /* /etc/mtab -- we care about VFS options there */ - const char *o = mnt_fs_get_vfs_options(upd->fs); + const char *o = mnt_fs_get_options(upd->fs); char *n = o ? strdup(o) : NULL; if (n) mnt_optstr_remove_option(&n, rdonly ? "rw" : "ro"); if (!mnt_optstr_prepend_option(&n, rdonly ? "ro" : "rw", NULL)) - rc = mnt_fs_set_vfs_options(upd->fs, n); + rc = mnt_fs_set_options(upd->fs, n); free(n); } @@ -330,7 +330,7 @@ static int utab_new_entry(struct libmnt_fs *fs, unsigned long mountflags, struct goto err; } - rc = mnt_fs_set_user_options(*ent, u); + rc = mnt_fs_set_options(*ent, u); if (rc) goto err; rc = mnt_fs_set_attributes(*ent, a); @@ -759,13 +759,8 @@ static int update_modify_options(struct libmnt_update *upd, struct libmnt_lock * if (cur) { if (upd->userspace_only) rc = mnt_fs_set_attributes(cur, mnt_fs_get_attributes(fs)); - if (!rc && !upd->userspace_only) - rc = mnt_fs_set_vfs_options(cur, mnt_fs_get_vfs_options(fs)); - if (!rc && !upd->userspace_only) - rc = mnt_fs_set_fs_options(cur, mnt_fs_get_fs_options(fs)); if (!rc) - rc = mnt_fs_set_user_options(cur, - mnt_fs_get_user_options(fs)); + rc = mnt_fs_set_options(cur, mnt_fs_get_options(fs)); if (!rc) rc = update_table(upd, tb); } |