Skip to content

Commit 9abca1a

Browse files
hsiaoh2akpm00
authored andcommitted
nilfs2: use common implementation of file type
Patch series "nilfs2: assorted cleanups". This is a collection of cleanup patches, with only the last three focused on the log writer thread, the rest are miscellaneous. Patches 1/8, 4/8, and 7/8 adopt common implementations, 2/8 uses a generic macro, 5/8 removes dead code, 6/8 removes an unnecessary reference, and 3/8 and 8/8 each simplify a paticular messy implementation. This patch (of 8): Deduplicate the nilfs2 file type conversion implementation. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Huang Xiaojia <[email protected]> Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 093ebfb commit 9abca1a

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

fs/nilfs2/dir.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -231,37 +231,6 @@ static struct nilfs_dir_entry *nilfs_next_entry(struct nilfs_dir_entry *p)
231231
nilfs_rec_len_from_disk(p->rec_len));
232232
}
233233

234-
static unsigned char
235-
nilfs_filetype_table[NILFS_FT_MAX] = {
236-
[NILFS_FT_UNKNOWN] = DT_UNKNOWN,
237-
[NILFS_FT_REG_FILE] = DT_REG,
238-
[NILFS_FT_DIR] = DT_DIR,
239-
[NILFS_FT_CHRDEV] = DT_CHR,
240-
[NILFS_FT_BLKDEV] = DT_BLK,
241-
[NILFS_FT_FIFO] = DT_FIFO,
242-
[NILFS_FT_SOCK] = DT_SOCK,
243-
[NILFS_FT_SYMLINK] = DT_LNK,
244-
};
245-
246-
#define S_SHIFT 12
247-
static unsigned char
248-
nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = {
249-
[S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE,
250-
[S_IFDIR >> S_SHIFT] = NILFS_FT_DIR,
251-
[S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV,
252-
[S_IFBLK >> S_SHIFT] = NILFS_FT_BLKDEV,
253-
[S_IFIFO >> S_SHIFT] = NILFS_FT_FIFO,
254-
[S_IFSOCK >> S_SHIFT] = NILFS_FT_SOCK,
255-
[S_IFLNK >> S_SHIFT] = NILFS_FT_SYMLINK,
256-
};
257-
258-
static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode)
259-
{
260-
umode_t mode = inode->i_mode;
261-
262-
de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
263-
}
264-
265234
static int nilfs_readdir(struct file *file, struct dir_context *ctx)
266235
{
267236
loff_t pos = ctx->pos;
@@ -297,10 +266,7 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx)
297266
if (de->inode) {
298267
unsigned char t;
299268

300-
if (de->file_type < NILFS_FT_MAX)
301-
t = nilfs_filetype_table[de->file_type];
302-
else
303-
t = DT_UNKNOWN;
269+
t = fs_ftype_to_dtype(de->file_type);
304270

305271
if (!dir_emit(ctx, de->name, de->name_len,
306272
le64_to_cpu(de->inode), t)) {
@@ -444,7 +410,7 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
444410
err = nilfs_prepare_chunk(folio, from, to);
445411
BUG_ON(err);
446412
de->inode = cpu_to_le64(inode->i_ino);
447-
nilfs_set_de_type(de, inode);
413+
de->file_type = fs_umode_to_ftype(inode->i_mode);
448414
nilfs_commit_chunk(folio, mapping, from, to);
449415
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
450416
}
@@ -531,7 +497,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode)
531497
de->name_len = namelen;
532498
memcpy(de->name, name, namelen);
533499
de->inode = cpu_to_le64(inode->i_ino);
534-
nilfs_set_de_type(de, inode);
500+
de->file_type = fs_umode_to_ftype(inode->i_mode);
535501
nilfs_commit_chunk(folio, folio->mapping, from, to);
536502
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
537503
nilfs_mark_inode_dirty(dir);
@@ -612,14 +578,14 @@ int nilfs_make_empty(struct inode *inode, struct inode *parent)
612578
de->rec_len = nilfs_rec_len_to_disk(NILFS_DIR_REC_LEN(1));
613579
memcpy(de->name, ".\0\0", 4);
614580
de->inode = cpu_to_le64(inode->i_ino);
615-
nilfs_set_de_type(de, inode);
581+
de->file_type = fs_umode_to_ftype(inode->i_mode);
616582

617583
de = (struct nilfs_dir_entry *)(kaddr + NILFS_DIR_REC_LEN(1));
618584
de->name_len = 2;
619585
de->rec_len = nilfs_rec_len_to_disk(chunk_size - NILFS_DIR_REC_LEN(1));
620586
de->inode = cpu_to_le64(parent->i_ino);
621587
memcpy(de->name, "..\0", 4);
622-
nilfs_set_de_type(de, inode);
588+
de->file_type = fs_umode_to_ftype(inode->i_mode);
623589
kunmap_local(kaddr);
624590
nilfs_commit_chunk(folio, mapping, 0, chunk_size);
625591
fail:

0 commit comments

Comments
 (0)