Skip to content

Commit

Permalink
VFS: Split DCACHE_FILE_TYPE into regular and special types
Browse files Browse the repository at this point in the history
Split DCACHE_FILE_TYPE into DCACHE_REGULAR_TYPE (dentries representing regular
files) and DCACHE_SPECIAL_TYPE (representing blockdev, chardev, FIFO and
socket files).

d_is_reg() and d_is_special() are added to detect these subtypes and
d_is_file() is left as the union of the two.

This allows a number of places that use S_ISREG(dentry->d_inode->i_mode) to
use d_is_reg(dentry) instead.

Signed-off-by: David Howells <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
dhowells authored and ananjaser1211 committed Oct 15, 2023
1 parent cc4dee0 commit 403e0b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 13 additions & 5 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ EXPORT_SYMBOL(d_set_d_op);

static unsigned d_flags_for_inode(struct inode *inode)
{
unsigned add_flags = DCACHE_FILE_TYPE;
unsigned add_flags = DCACHE_REGULAR_TYPE;

if (!inode)
return DCACHE_MISS_TYPE;
Expand All @@ -1684,13 +1684,21 @@ static unsigned d_flags_for_inode(struct inode *inode)
else
inode->i_opflags |= IOP_LOOKUP;
}
} else if (unlikely(!(inode->i_opflags & IOP_NOFOLLOW))) {
if (unlikely(inode->i_op->follow_link))
goto type_determined;
}

if (unlikely(!(inode->i_opflags & IOP_NOFOLLOW))) {
if (unlikely(inode->i_op->follow_link)) {
add_flags = DCACHE_SYMLINK_TYPE;
else
inode->i_opflags |= IOP_NOFOLLOW;
goto type_determined;
}
inode->i_opflags |= IOP_NOFOLLOW;
}

if (unlikely(!S_ISREG(inode->i_mode)))
add_flags = DCACHE_SPECIAL_TYPE;

type_determined:
if (unlikely(IS_AUTOMOUNT(inode)))
add_flags |= DCACHE_NEED_AUTOMOUNT;
return add_flags;
Expand Down
17 changes: 14 additions & 3 deletions include/linux/dcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ struct dentry_operations {
#define DCACHE_MISS_TYPE 0x00000000 /* Negative dentry */
#define DCACHE_DIRECTORY_TYPE 0x00100000 /* Normal directory */
#define DCACHE_AUTODIR_TYPE 0x00200000 /* Lookupless directory (presumed automount) */
#define DCACHE_SYMLINK_TYPE 0x00300000 /* Symlink */
#define DCACHE_FILE_TYPE 0x00400000 /* Other file type */
#define DCACHE_REGULAR_TYPE 0x00400000 /* Regular file type (or fallthru to such) */
#define DCACHE_SPECIAL_TYPE 0x00500000 /* Other file type (or fallthru to such) */
#define DCACHE_SYMLINK_TYPE 0x00600000 /* Symlink (or fallthru to such) */

#define DCACHE_MAY_FREE 0x00800000
#define DCACHE_OP_SELECT_INODE 0x02000000 /* Unioned entry: dcache op selects inode */
Expand Down Expand Up @@ -454,9 +455,19 @@ static inline bool d_is_symlink(const struct dentry *dentry)
return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;
}

static inline bool d_is_reg(const struct dentry *dentry)
{
return __d_entry_type(dentry) == DCACHE_REGULAR_TYPE;
}

static inline bool d_is_special(const struct dentry *dentry)
{
return __d_entry_type(dentry) == DCACHE_SPECIAL_TYPE;
}

static inline bool d_is_file(const struct dentry *dentry)
{
return __d_entry_type(dentry) == DCACHE_FILE_TYPE;
return d_is_reg(dentry) || d_is_special(dentry);
}

static inline bool d_is_negative(const struct dentry *dentry)
Expand Down

0 comments on commit 403e0b4

Please sign in to comment.