btrfs: use common file type conversion
Deduplicate the btrfs file type conversion implementation - file systems
that use the same file types as defined by POSIX do not need to define
their own versions and can use the common helper functions decared in
fs_types.h and implemented in fs_types.c
Common implementation can be found via commit:
bbe7449e25
"fs: common implementation of file type"
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
7984ae52bb
commit
7d157c3d48
@ -203,8 +203,6 @@ struct btrfs_inode {
|
|||||||
struct inode vfs_inode;
|
struct inode vfs_inode;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern unsigned char btrfs_filetype_table[];
|
|
||||||
|
|
||||||
static inline struct btrfs_inode *BTRFS_I(const struct inode *inode)
|
static inline struct btrfs_inode *BTRFS_I(const struct inode *inode)
|
||||||
{
|
{
|
||||||
return container_of(inode, struct btrfs_inode, vfs_inode);
|
return container_of(inode, struct btrfs_inode, vfs_inode);
|
||||||
|
@ -1692,7 +1692,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
|
|||||||
name = (char *)(di + 1);
|
name = (char *)(di + 1);
|
||||||
name_len = btrfs_stack_dir_name_len(di);
|
name_len = btrfs_stack_dir_name_len(di);
|
||||||
|
|
||||||
d_type = btrfs_filetype_table[di->type];
|
d_type = fs_ftype_to_dtype(di->type);
|
||||||
btrfs_disk_key_to_cpu(&location, &di->location);
|
btrfs_disk_key_to_cpu(&location, &di->location);
|
||||||
|
|
||||||
over = !dir_emit(ctx, name, name_len,
|
over = !dir_emit(ctx, name, name_len,
|
||||||
|
@ -73,17 +73,6 @@ struct kmem_cache *btrfs_trans_handle_cachep;
|
|||||||
struct kmem_cache *btrfs_path_cachep;
|
struct kmem_cache *btrfs_path_cachep;
|
||||||
struct kmem_cache *btrfs_free_space_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_setsize(struct inode *inode, struct iattr *attr);
|
||||||
static int btrfs_truncate(struct inode *inode, bool skip_writeback);
|
static int btrfs_truncate(struct inode *inode, bool skip_writeback);
|
||||||
static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
|
static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
|
||||||
@ -5797,10 +5786,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
|
|||||||
return d_splice_alias(inode, 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
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All this infrastructure exists because dir_emit can fault, and we are holding
|
* All this infrastructure exists because dir_emit can fault, and we are holding
|
||||||
* the tree lock when doing readdir. For now just allocate a buffer and copy
|
* the tree lock when doing readdir. For now just allocate a buffer and copy
|
||||||
@ -5939,7 +5924,7 @@ again:
|
|||||||
name_ptr = (char *)(entry + 1);
|
name_ptr = (char *)(entry + 1);
|
||||||
read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
|
read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
|
||||||
name_len);
|
name_len);
|
||||||
put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)],
|
put_unaligned(fs_ftype_to_dtype(btrfs_dir_type(leaf, di)),
|
||||||
&entry->type);
|
&entry->type);
|
||||||
btrfs_dir_item_key_to_cpu(leaf, di, &location);
|
btrfs_dir_item_key_to_cpu(leaf, di, &location);
|
||||||
put_unaligned(location.objectid, &entry->ino);
|
put_unaligned(location.objectid, &entry->ino);
|
||||||
@ -6344,7 +6329,20 @@ fail:
|
|||||||
|
|
||||||
static inline u8 btrfs_inode_type(struct inode *inode)
|
static inline u8 btrfs_inode_type(struct inode *inode)
|
||||||
{
|
{
|
||||||
return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
|
/*
|
||||||
|
* Compile-time asserts that generic FT_* types still match
|
||||||
|
* BTRFS_FT_* types
|
||||||
|
*/
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_UNKNOWN != FT_UNKNOWN);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_REG_FILE != FT_REG_FILE);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_DIR != FT_DIR);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_CHRDEV != FT_CHRDEV);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_BLKDEV != FT_BLKDEV);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_FIFO != FT_FIFO);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_SOCK != FT_SOCK);
|
||||||
|
BUILD_BUG_ON(BTRFS_FT_SYMLINK != FT_SYMLINK);
|
||||||
|
|
||||||
|
return fs_umode_to_ftype(inode->i_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -307,6 +307,8 @@
|
|||||||
*
|
*
|
||||||
* Used by:
|
* Used by:
|
||||||
* struct btrfs_dir_item.type
|
* struct btrfs_dir_item.type
|
||||||
|
*
|
||||||
|
* Values 0..7 must match common file type values in fs_types.h.
|
||||||
*/
|
*/
|
||||||
#define BTRFS_FT_UNKNOWN 0
|
#define BTRFS_FT_UNKNOWN 0
|
||||||
#define BTRFS_FT_REG_FILE 1
|
#define BTRFS_FT_REG_FILE 1
|
||||||
|
Loading…
Reference in New Issue
Block a user