linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.com>, Theodore Ts'o <tytso@mit.edu>,
	Dave Chinner <david@fromorbit.com>
Cc: "Darrick J . Wong" <darrick.wong@oracle.com>,
	Chris Mason <clm@fb.com>, Boaz Harrosh <boaz@plexistor.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
	Mark Fasheh <mfasheh@versity.com>,
	Evgeniy Dushistov <dushistov@mail.ru>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org
Subject: [RFC][PATCH 10/11] btrfs: use common file type conversion
Date: Mon, 19 Dec 2016 22:11:07 +0200	[thread overview]
Message-ID: <1482178268-22883-11-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1482178268-22883-1-git-send-email-amir73il@gmail.com>

deduplicate the btrfs file type conversion implementation.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/btrfs/btrfs_inode.h          |  2 --
 fs/btrfs/delayed-inode.c        |  2 +-
 fs/btrfs/inode.c                | 19 ++-----------------
 include/uapi/linux/btrfs_tree.h |  2 ++
 4 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 1a8fa46..1230e5b 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -198,8 +198,6 @@ struct btrfs_inode {
 	struct inode vfs_inode;
 };
 
-extern unsigned char btrfs_filetype_table[];
-
 static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
 {
 	return container_of(inode, struct btrfs_inode, vfs_inode);
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 80982a8..50260f0 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1717,7 +1717,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
 		name = (char *)(di + 1);
 		name_len = btrfs_stack_dir_name_len(di);
 
-		d_type = btrfs_filetype_table[di->type];
+		d_type = fs_dtype(di->type);
 		btrfs_disk_key_to_cpu(&location, &di->location);
 
 		over = !dir_emit(ctx, name, name_len,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f2b281a..45acb12 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -89,17 +89,6 @@ struct kmem_cache *btrfs_transaction_cachep;
 struct kmem_cache *btrfs_path_cachep;
 struct kmem_cache *btrfs_free_space_cachep;
 
-#define S_SHIFT 12
-static const 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,
-};
-
 static int btrfs_setsize(struct inode *inode, struct iattr *attr);
 static int btrfs_truncate(struct inode *inode);
 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
@@ -5814,10 +5803,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
 	return d_splice_alias(inode, dentry);
 }
 
-unsigned char btrfs_filetype_table[] = {
-	DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
-};
-
 static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
 {
 	struct inode *inode = file_inode(file);
@@ -5905,7 +5890,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
 		read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
 				   name_len);
 
-		d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
+		d_type = fs_dtype(btrfs_dir_type(leaf, di));
 		btrfs_dir_item_key_to_cpu(leaf, di, &location);
 
 		over = !dir_emit(ctx, name_ptr, name_len, location.objectid,
@@ -6301,7 +6286,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
 
 static inline u8 btrfs_inode_type(struct inode *inode)
 {
-	return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
+	return fs_umode_to_ftype(inode->i_mode);
 }
 
 /*
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index d5ad15a..1335ff1 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -303,6 +303,8 @@
  *
  * Used by:
  * struct btrfs_dir_item.type
+ *
+ * Values 0..7 should match common file type values in file_type.h.
  */
 #define BTRFS_FT_UNKNOWN	0
 #define BTRFS_FT_REG_FILE	1
-- 
2.7.4


  parent reply	other threads:[~2016-12-19 20:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 20:10 [RFC][PATCH 00/11] common implementation of dirent file types Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 01/11] fs: common implementation of file type conversions Amir Goldstein
2016-12-19 21:13   ` Darrick J. Wong
2016-12-20  5:01     ` Amir Goldstein
2016-12-20  7:37   ` [RFC][PATCH v2 " Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 02/11] ufs: use fs_umode_to_dtype() helper Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 03/11] hfsplus: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 04/11] ext2: use common file type conversion Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 05/11] exofs: " Amir Goldstein
2016-12-19 21:50   ` Boaz Harrosh
2016-12-19 20:11 ` [RFC][PATCH 06/11] ext4: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 07/11] ocfs2: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 08/11] f2fs: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 09/11] nilfs2: " Amir Goldstein
2016-12-19 20:11 ` Amir Goldstein [this message]
2016-12-19 20:11 ` [RFC][PATCH 11/11] xfs: " Amir Goldstein
2016-12-19 21:55   ` Darrick J. Wong
2016-12-20  6:17     ` Amir Goldstein
2016-12-20 14:07       ` Amir Goldstein
2016-12-20  0:28   ` Darrick J. Wong
2016-12-20  5:20     ` Amir Goldstein
2016-12-21  5:23       ` Dave Chinner
2016-12-21  6:37         ` Amir Goldstein
2016-12-21 10:12           ` [RFC][PATCH v2 " Amir Goldstein
2016-12-21 18:01             ` [PATCH v3 " Amir Goldstein
2016-12-22 21:07               ` [PATCH v4] xfs: fix the size of xfs_mode_to_ftype table Amir Goldstein
2016-12-23 21:01                 ` Darrick J. Wong
2016-12-24  7:31                   ` Amir Goldstein
2016-12-24 14:11                 ` Brian Foster
2016-12-21 15:06         ` [RFC][PATCH 11/11] xfs: use common file type conversion Theodore Ts'o
2016-12-21 16:37           ` Amir Goldstein
2016-12-21 22:56             ` Theodore Ts'o
2016-12-22  5:54               ` Amir Goldstein
2016-12-22 20:30                 ` Amir Goldstein
2016-12-21 16:59           ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482178268-22883-11-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=boaz@plexistor.com \
    --cc=clm@fb.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=dushistov@mail.ru \
    --cc=jack@suse.com \
    --cc=jaegeuk@kernel.org \
    --cc=konishi.ryusuke@lab.ntt.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mfasheh@versity.com \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).