From 58a19f1ea7a6d19e03500faf444a6d46defc0bdb Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 18 Jan 2018 15:38:45 +0800 Subject: [PATCH] btrfs-progs: check: Move imode_to_type function to check/common.h This function is shared between original and lowmem mode, and it's small enough, so move it to check/common.h. Reviewed-by: Su Yue Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- check/common.h | 19 +++++++++++++++++++ check/main.c | 17 ----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/check/common.h b/check/common.h index 8d93ddbf..3e0a5ebe 100644 --- a/check/common.h +++ b/check/common.h @@ -20,6 +20,8 @@ */ #ifndef __BTRFS_CHECK_COMMON_H__ #define __BTRFS_CHECK_COMMON_H__ + +#include #include "ctree.h" /* @@ -53,4 +55,21 @@ extern struct btrfs_fs_info *global_info; extern struct task_ctx ctx; extern struct cache_tree *roots_info_cache; +static inline u8 imode_to_type(u32 imode) +{ +#define S_SHIFT 12 + static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { + [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, + [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, + [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, + [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, + [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, + [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, + [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, + }; + + return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT]; +#undef S_SHIFT +} + #endif diff --git a/check/main.c b/check/main.c index e87cd159..79a2d595 100644 --- a/check/main.c +++ b/check/main.c @@ -425,23 +425,6 @@ static void record_root_in_trans(struct btrfs_trans_handle *trans, } } -static u8 imode_to_type(u32 imode) -{ -#define S_SHIFT 12 - static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, - }; - - return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT]; -#undef S_SHIFT -} - static int device_record_compare(struct rb_node *node1, struct rb_node *node2) { struct device_record *rec1;