diff options
author | Karel Zak | 2012-01-02 15:00:27 +0100 |
---|---|---|
committer | Karel Zak | 2012-01-02 15:00:27 +0100 |
commit | c70d9d768bbe291ad29f29200340d1f4d8bbf30f (patch) | |
tree | 0878a5b06223146a9bbe6a48109cf348df75218d /libmount | |
parent | mount: don't canonicalize the source of a pseudofs (diff) | |
download | kernel-qcow2-util-linux-c70d9d768bbe291ad29f29200340d1f4d8bbf30f.tar.gz kernel-qcow2-util-linux-c70d9d768bbe291ad29f29200340d1f4d8bbf30f.tar.xz kernel-qcow2-util-linux-c70d9d768bbe291ad29f29200340d1f4d8bbf30f.zip |
libmount: consolidate MNT_FS_* code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount')
-rw-r--r-- | libmount/src/context.c | 8 | ||||
-rw-r--r-- | libmount/src/context_loopdev.c | 4 | ||||
-rw-r--r-- | libmount/src/context_mount.c | 6 | ||||
-rw-r--r-- | libmount/src/context_umount.c | 2 | ||||
-rw-r--r-- | libmount/src/fs.c | 46 | ||||
-rw-r--r-- | libmount/src/libmount.h.in | 3 | ||||
-rw-r--r-- | libmount/src/libmount.sym | 3 | ||||
-rw-r--r-- | libmount/src/mountP.h | 6 | ||||
-rw-r--r-- | libmount/src/tab.c | 8 |
9 files changed, 57 insertions, 29 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c index 7dc473184..19954096b 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -1085,7 +1085,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt) /* ignore filesystems without source or filesystems * where the source is quasi-path (//foo/bar) */ - if (!src || (cxt->fs->flags & MNT_FS_NET)) + if (!src || mnt_fs_is_netfs(cxt->fs)) return 0; DBG(CXT, mnt_debug_h(cxt, "srcpath '%s'", src)); @@ -1101,7 +1101,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt) rc = path ? mnt_fs_set_source(cxt->fs, path) : -EINVAL; - } else if (cache && !(cxt->fs->flags & MNT_FS_PSEUDO)) { + } else if (cache && !mnt_fs_is_pseudofs(cxt->fs)) { /* * Source is PATH (canonicalize) */ @@ -1119,7 +1119,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt) path = src; if ((cxt->mountflags & (MS_BIND | MS_MOVE | MS_PROPAGATION)) || - (cxt->fs->flags & MNT_FS_PSEUDO)) { + mnt_fs_is_pseudofs(cxt->fs)) { DBG(CXT, mnt_debug_h(cxt, "PROPAGATION/pseudo FS source: %s", path)); return rc; } @@ -1254,7 +1254,7 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name, type = mnt_fs_get_fstype(cxt->fs); if ((cxt->flags & MNT_FL_NOHELPERS) || !type || - !strcmp(type, "none") || (cxt->fs->flags & MNT_FS_SWAP)) + !strcmp(type, "none") || mnt_fs_is_swaparea(cxt->fs)) return 0; path = strtok_r(search_path, ":", &p); diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c index 561ab397d..6221166ff 100644 --- a/libmount/src/context_loopdev.c +++ b/libmount/src/context_loopdev.c @@ -20,7 +20,6 @@ int mnt_context_is_loopdev(struct libmnt_context *cxt) { const char *type, *src; - int fl; assert(cxt); /* The mount flags have to be merged, otherwise we have to use @@ -50,9 +49,8 @@ int mnt_context_is_loopdev(struct libmnt_context *cxt) * regular files could be implemented. */ type = mnt_fs_get_fstype(cxt->fs); - fl = __mnt_fs_get_flags(cxt->fs); - if (!(fl & (MNT_FS_PSEUDO | MNT_FS_NET | MNT_FS_SWAP)) && + if (mnt_fs_is_regular(cxt->fs) && (!type || strcmp(type, "auto") == 0 || blkid_known_fstype(type))) { struct stat st; diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 8fba9c6be..f86b3f761 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -515,7 +515,7 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt) assert(cxt->helper_exec_status == 1); assert(cxt->syscall_status == 1); - if (!cxt || !cxt->fs || (cxt->fs->flags & MNT_FS_SWAP)) + if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs)) return -EINVAL; if (!mnt_fs_get_source(cxt->fs) && !mnt_fs_get_target(cxt->fs)) return -EINVAL; @@ -726,10 +726,10 @@ int mnt_context_next_mount(struct libmnt_context *cxt, DBG(CXT, mnt_debug_h(cxt, "next-mount: trying %s", tgt)); /* ignore swap */ - if (((*fs)->flags & MNT_FS_SWAP) || + if (mnt_fs_is_swaparea(*fs) || /* ignore root filesystem */ - (tgt && (strcmp(tgt, "/") == 0 || strcmp(tgt, "root") == 0)) || + (tgt && (strcmp(tgt, "/") == 0 || strcmp(tgt, "root") == 0)) || /* ignore noauto filesystems */ (o && mnt_optstr_get_option(o, "noauto", NULL, NULL) == 0) || diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 5474da01d..568cf505b 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -557,7 +557,7 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt) assert(cxt->helper_exec_status == 1); assert(cxt->syscall_status == 1); - if (!cxt || !cxt->fs || (cxt->fs->flags & MNT_FS_SWAP)) + if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs)) return -EINVAL; if (!mnt_context_get_source(cxt) && !mnt_context_get_target(cxt)) return -EINVAL; diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 90f484bec..43faa0511 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -437,20 +437,11 @@ int mnt_fs_set_target(struct libmnt_fs *fs, const char *target) return 0; } -int __mnt_fs_get_flags(struct libmnt_fs *fs) +static int mnt_fs_get_flags(struct libmnt_fs *fs) { return fs ? fs->flags : 0; } -int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags) -{ - if (fs) { - fs->flags = flags; - return 0; - } - return -EINVAL; -} - /** * mnt_fs_is_kernel: * @fs: filesystem @@ -459,7 +450,40 @@ int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags) */ int mnt_fs_is_kernel(struct libmnt_fs *fs) { - return __mnt_fs_get_flags(fs) & MNT_FS_KERNEL; + return mnt_fs_get_flags(fs) & MNT_FS_KERNEL; +} + +/** + * mnt_fs_is_swaparea: + * @fs: filesystem + * + * Returns: 1 if the filesystem uses "swap" as a type + */ +int mnt_fs_is_swaparea(struct libmnt_fs *fs) +{ + return mnt_fs_get_flags(fs) & MNT_FS_SWAP; +} + +/** + * mnt_fs_is_pseudofs: + * @fs: filesystem + * + * Returns: 1 if the filesystem is a pseudo fs type (proc, cgroups) + */ +int mnt_fs_is_pseudo(struct libmnt_fs *fs) +{ + return mnt_fs_get_flags(fs) & MNT_FS_PSEUDO; +} + +/** + * mnt_fs_is_netfs: + * @fs: filesystem + * + * Returns: 1 if the filesystem is a network filesystem + */ +int mnt_fs_is_netfs(struct libmnt_fs *fs) +{ + return mnt_fs_get_flags(fs) & MNT_FS_NET; } /** diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 7cc6cb607..9e1a65fca 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -263,6 +263,9 @@ extern int mnt_fs_match_options(struct libmnt_fs *fs, const char *options); extern int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file); extern int mnt_fs_is_kernel(struct libmnt_fs *fs); +extern int mnt_fs_is_swaparea(struct libmnt_fs *fs); +extern int mnt_fs_is_netfs(struct libmnt_fs *fs); +extern int mnt_fs_is_pseudofs(struct libmnt_fs *fs); extern void mnt_free_mntent(struct mntent *mnt); extern int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt); diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index 6f4d1c02b..0740db8e1 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -214,4 +214,7 @@ global: mnt_context_is_parent; mnt_context_next_umount; mnt_context_wait_for_children; + mnt_fs_is_netfs; + mnt_fs_is_pseudofs; + mnt_fs_is_swaparea; } MOUNT_2.20; diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 9be3aabed..c82a97999 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -224,9 +224,9 @@ struct libmnt_fs { #define MNT_FS_KERNEL (1 << 4) /* data from /proc/{mounts,self/mountinfo} */ #define MNT_FS_MERGED (1 << 5) /* already merged data from /run/mount/utab */ -extern int __mnt_fs_get_flags(struct libmnt_fs *fs); -extern int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags); - +#define mnt_fs_is_regular(_f) (!(mnt_fs_is_pseudofs(_f) \ + || mnt_fs_is_netfs(_f) \ + || mnt_fs_is_swaparea(_f))) /* * mtab/fstab/mountinfo file diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 15e20f8f6..6d2d44e6f 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -456,7 +456,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat while(mnt_table_next_fs(tb, &itr, &fs) == 0) { char *p; - if (!fs->target || !(fs->flags & MNT_FS_SWAP) || + if (!fs->target || !mnt_fs_is_swaparea(fs) || (*fs->target == '/' && *(fs->target + 1) == '\0')) continue; @@ -562,7 +562,7 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa if (ntags <= mnt_table_get_nents(tb)) { mnt_reset_iter(&itr, direction); while(mnt_table_next_fs(tb, &itr, &fs) == 0) { - if (fs->flags & (MNT_FS_NET | MNT_FS_PSEUDO)) + if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs)) continue; p = mnt_fs_get_srcpath(fs); if (p) @@ -837,7 +837,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) assert(tb); assert(fstab_fs); - if (fstab_fs->flags & MNT_FS_SWAP) + if (mnt_fs_is_swaparea(fstab_fs)) return 0; if (mnt_fs_get_option(fstab_fs, "bind", NULL, NULL) == 0) @@ -846,7 +846,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) src_fs = mnt_table_get_fs_root(tb, fstab_fs, flags, &root); if (src_fs) src = mnt_fs_get_srcpath(src_fs); - else if (fstab_fs->flags & MNT_FS_PSEUDO) + else if (mnt_fs_is_pseudofs(fstab_fs)) src = mnt_fs_get_source(fstab_fs); else src = xsrc = mnt_resolve_spec(mnt_fs_get_source(fstab_fs), |