Commit db8bf54b17afbc609432464c543597c7e1101358

Authored by Miklos Szeredi
Committed by Greg Kroah-Hartman
1 parent 9a7e59763e

vfs: add d_is_dir()

commit 44b1d53043c482225196e8a9cd9f35163a1b3336 upstream.

Add d_is_dir(dentry) helper which is analogous to S_ISDIR().

To avoid confusion, rename d_is_directory() to d_can_lookup().

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Reviewed-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 2 changed files with 17 additions and 13 deletions Side-by-side Diff

... ... @@ -1797,7 +1797,7 @@
1797 1797 if (err)
1798 1798 return err;
1799 1799 }
1800   - if (!d_is_directory(nd->path.dentry)) {
  1800 + if (!d_can_lookup(nd->path.dentry)) {
1801 1801 err = -ENOTDIR;
1802 1802 break;
1803 1803 }
... ... @@ -1818,7 +1818,7 @@
1818 1818 struct dentry *root = nd->root.dentry;
1819 1819 struct inode *inode = root->d_inode;
1820 1820 if (*name) {
1821   - if (!d_is_directory(root))
  1821 + if (!d_can_lookup(root))
1822 1822 return -ENOTDIR;
1823 1823 retval = inode_permission(inode, MAY_EXEC);
1824 1824 if (retval)
... ... @@ -1874,7 +1874,7 @@
1874 1874 dentry = f.file->f_path.dentry;
1875 1875  
1876 1876 if (*name) {
1877   - if (!d_is_directory(dentry)) {
  1877 + if (!d_can_lookup(dentry)) {
1878 1878 fdput(f);
1879 1879 return -ENOTDIR;
1880 1880 }
... ... @@ -1956,7 +1956,7 @@
1956 1956 err = complete_walk(nd);
1957 1957  
1958 1958 if (!err && nd->flags & LOOKUP_DIRECTORY) {
1959   - if (!d_is_directory(nd->path.dentry)) {
  1959 + if (!d_can_lookup(nd->path.dentry)) {
1960 1960 path_put(&nd->path);
1961 1961 err = -ENOTDIR;
1962 1962 }
1963 1963  
... ... @@ -2416,11 +2416,11 @@
2416 2416 IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
2417 2417 return -EPERM;
2418 2418 if (isdir) {
2419   - if (!d_is_directory(victim) && !d_is_autodir(victim))
  2419 + if (!d_is_dir(victim))
2420 2420 return -ENOTDIR;
2421 2421 if (IS_ROOT(victim))
2422 2422 return -EBUSY;
2423   - } else if (d_is_directory(victim) || d_is_autodir(victim))
  2423 + } else if (d_is_dir(victim))
2424 2424 return -EISDIR;
2425 2425 if (IS_DEADDIR(dir))
2426 2426 return -ENOENT;
2427 2427  
... ... @@ -3018,11 +3018,10 @@
3018 3018 }
3019 3019 audit_inode(name, nd->path.dentry, 0);
3020 3020 error = -EISDIR;
3021   - if ((open_flag & O_CREAT) &&
3022   - (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
  3021 + if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
3023 3022 goto out;
3024 3023 error = -ENOTDIR;
3025   - if ((nd->flags & LOOKUP_DIRECTORY) && !d_is_directory(nd->path.dentry))
  3024 + if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
3026 3025 goto out;
3027 3026 if (!S_ISREG(nd->inode->i_mode))
3028 3027 will_truncate = false;
... ... @@ -3746,7 +3745,7 @@
3746 3745 slashes:
3747 3746 if (d_is_negative(dentry))
3748 3747 error = -ENOENT;
3749   - else if (d_is_directory(dentry) || d_is_autodir(dentry))
  3748 + else if (d_is_dir(dentry))
3750 3749 error = -EISDIR;
3751 3750 else
3752 3751 error = -ENOTDIR;
... ... @@ -4125,7 +4124,7 @@
4125 4124 struct inode **delegated_inode)
4126 4125 {
4127 4126 int error;
4128   - int is_dir = d_is_directory(old_dentry) || d_is_autodir(old_dentry);
  4127 + int is_dir = d_is_dir(old_dentry);
4129 4128 const unsigned char *old_name;
4130 4129  
4131 4130 if (old_dentry->d_inode == new_dentry->d_inode)
... ... @@ -4218,7 +4217,7 @@
4218 4217 if (d_is_negative(old_dentry))
4219 4218 goto exit4;
4220 4219 /* unless the source is a directory trailing slashes give -ENOTDIR */
4221   - if (!d_is_directory(old_dentry) && !d_is_autodir(old_dentry)) {
  4220 + if (!d_is_dir(old_dentry)) {
4222 4221 error = -ENOTDIR;
4223 4222 if (oldnd.last.name[oldnd.last.len])
4224 4223 goto exit4;
include/linux/dcache.h
... ... @@ -429,7 +429,7 @@
429 429 return dentry->d_flags & DCACHE_ENTRY_TYPE;
430 430 }
431 431  
432   -static inline bool d_is_directory(const struct dentry *dentry)
  432 +static inline bool d_can_lookup(const struct dentry *dentry)
433 433 {
434 434 return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE;
435 435 }
... ... @@ -437,6 +437,11 @@
437 437 static inline bool d_is_autodir(const struct dentry *dentry)
438 438 {
439 439 return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE;
  440 +}
  441 +
  442 +static inline bool d_is_dir(const struct dentry *dentry)
  443 +{
  444 + return d_can_lookup(dentry) || d_is_autodir(dentry);
440 445 }
441 446  
442 447 static inline bool d_is_symlink(const struct dentry *dentry)