From 2915bdc0db7b6931c35e235879d59b6c61b4b1bc Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Sat, 18 Dec 2010 01:08:25 +0100 Subject: [PATCH] libmount: clean mnt_update_* target usage Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 19 +++++++++++-------- shlibs/mount/src/tab_update.c | 24 +++++++++++++++--------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index abe0dc9d..8fbad4a8 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -850,8 +850,10 @@ int mnt_context_prepare_srcpath(mnt_context *cxt) src = mnt_fs_get_source(cxt->fs); - /* ignore filesystems without a real source */ - if (!src || (cxt->fs->flags & (MNT_FS_PSEUDO | MNT_FS_NET))) + /* ignore filesystems without a real source or MS_PROPAGATION stuff */ + if (!src || + (cxt->fs->flags & (MNT_FS_PSEUDO | MNT_FS_NET)) || + (cxt->mountflags & (MS_BIND | MS_MOVE | MS_PROPAGATION))) return 0; DBG(CXT, mnt_debug_h(cxt, "srcpath '%s'", src)); @@ -893,9 +895,7 @@ int mnt_context_prepare_srcpath(mnt_context *cxt) /* * Initialize loop device */ - if (is_loop(cxt) && - !(cxt->mountflags & (MS_BIND | MS_MOVE | - MS_PROPAGATION | MS_REMOUNT))) { + if (is_loop(cxt)) { ; /* TODO */ } @@ -1102,9 +1102,12 @@ int mnt_context_prepare_update(mnt_context *cxt) !cxt->mtab_writable); } - rc = mnt_update_set_fs(cxt->update, cxt->mountflags, - mnt_fs_get_target(cxt->fs), - cxt->action == MNT_ACT_UMOUNT ? NULL : cxt->fs); + if (cxt->action == MNT_ACT_UMOUNT) + rc = mnt_update_set_fs(cxt->update, cxt->mountflags, + mnt_fs_get_target(cxt->fs), NULL); + else + rc = mnt_update_set_fs(cxt->update, cxt->mountflags, + NULL, cxt->fs); return rc < 0 ? rc : 0; } diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index cc0335fb..5afa0d49 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -146,8 +146,8 @@ int mnt_update_is_ready(mnt_update *upd) * mnt_update_set_fs: * @upd: update handler * @mountflags: MS_* flags - * @target: umount target or MS_MOVE source - * @fs: mount or MS_REMOUNT filesystem description, or MS_MOVE target + * @target: umount target, must be num for mount + * @fs: mount filesystem description, must be NULL for umount * * Returns: -1 in case on error, 0 on success, 1 if update is unnecessary. */ @@ -161,6 +161,10 @@ int mnt_update_set_fs(mnt_update *upd, unsigned long mountflags, if (!upd) return -EINVAL; + if ((mountflags & MS_MOVE) && (!fs || !mnt_fs_get_srcpath(fs))) + return -EINVAL; + if (target && fs) + return -EINVAL; DBG(UPDATE, mnt_debug_h(upd, "reseting FS [fs=0x%p, target=%s, flags=0x%08lx]", @@ -180,13 +184,19 @@ int mnt_update_set_fs(mnt_update *upd, unsigned long mountflags, if (mountflags & MS_PROPAGATION) return 1; + upd->mountflags = mountflags; rc = mnt_update_set_filename(upd, NULL, 0); if (rc) return rc; /* error or no file available (rc = 1) */ - if (fs) { + if (target) { + upd->target = strdup(target); + if (!upd->target) + return -ENOMEM; + + } else if (fs) { if (upd->userspace_only && !(mountflags & MS_MOVE)) { int rc = utab_new_entry(fs, mountflags, &upd->fs); if (rc) @@ -198,11 +208,6 @@ int mnt_update_set_fs(mnt_update *upd, unsigned long mountflags, } } - if (target) { - upd->target = strdup(target); - if (!upd->target) - return -ENOMEM; - } DBG(UPDATE, mnt_debug_h(upd, "ready")); upd->ready = TRUE; @@ -675,7 +680,8 @@ static int update_modify_target(mnt_update *upd, mnt_lock *lc) tb = __mnt_new_tab_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); if (tb) { - mnt_fs *cur = mnt_tab_find_target(tb, upd->target, MNT_ITER_BACKWARD); + mnt_fs *cur = mnt_tab_find_target(tb, + mnt_fs_get_srcpath(upd->fs), MNT_ITER_BACKWARD); if (cur) { rc = mnt_fs_set_target(cur, mnt_fs_get_target(upd->fs)); if (!rc) -- 2.39.5