Skip to content

Commit

Permalink
fs: consolidate duplicate dt_type helpers
Browse files Browse the repository at this point in the history
There are three copies of the same dt_type helper sprinkled around the
tree. Convert them to use the common fs_umode_to_dtype function instead,
which has the added advantage of properly returning DT_UNKNOWN when
given a mode that contains an unrecognized type.

Cc: Chuck Lever <[email protected]>
Cc: Phillip Potter <[email protected]>
Suggested-by: Christian Brauner <[email protected]>
Signed-off-by: Jeff Layton <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Christian Brauner <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
jtlayton authored and brauner committed Apr 3, 2023
1 parent 4f704d9 commit 364595a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
9 changes: 2 additions & 7 deletions fs/configfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1599,12 +1599,6 @@ static int configfs_dir_close(struct inode *inode, struct file *file)
return 0;
}

/* Relationship between s_mode and the DT_xxx types */
static inline unsigned char dt_type(struct configfs_dirent *sd)
{
return (sd->s_mode >> 12) & 15;
}

static int configfs_readdir(struct file *file, struct dir_context *ctx)
{
struct dentry *dentry = file->f_path.dentry;
Expand Down Expand Up @@ -1654,7 +1648,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
name = configfs_get_name(next);
len = strlen(name);

if (!dir_emit(ctx, name, len, ino, dt_type(next)))
if (!dir_emit(ctx, name, len, ino,
fs_umode_to_dtype(next->s_mode)))
return 0;

spin_lock(&configfs_dirent_lock);
Expand Down
8 changes: 1 addition & 7 deletions fs/kernfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,12 +1748,6 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
return error;
}

/* Relationship between mode and the DT_xxx types */
static inline unsigned char dt_type(struct kernfs_node *kn)
{
return (kn->mode >> 12) & 15;
}

static int kernfs_dir_fop_release(struct inode *inode, struct file *filp)
{
kernfs_put(filp->private_data);
Expand Down Expand Up @@ -1831,7 +1825,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)
pos;
pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
const char *name = pos->name;
unsigned int type = dt_type(pos);
unsigned int type = fs_umode_to_dtype(pos->mode);
int len = strlen(name);
ino_t ino = kernfs_ino(pos);

Expand Down
9 changes: 2 additions & 7 deletions fs/libfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
}
EXPORT_SYMBOL(dcache_dir_lseek);

/* Relationship between i_mode and the DT_xxx types */
static inline unsigned char dt_type(struct inode *inode)
{
return (inode->i_mode >> 12) & 15;
}

/*
* Directory is locked and all positive dentries in it are safe, since
* for ramfs-type trees they can't go away without unlink() or rmdir(),
Expand All @@ -206,7 +200,8 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)

while ((next = scan_positives(cursor, p, 1, next)) != NULL) {
if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
d_inode(next)->i_ino, dt_type(d_inode(next))))
d_inode(next)->i_ino,
fs_umode_to_dtype(d_inode(next)->i_mode)))
break;
ctx->pos++;
p = &next->d_child;
Expand Down

0 comments on commit 364595a

Please sign in to comment.