Commit 44b1d530 authored by Miklos Szeredi's avatar Miklos Szeredi

vfs: add d_is_dir()

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: default avatarMiklos Szeredi <mszeredi@suse.cz>
Reviewed-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 455c6fdb
...@@ -1796,7 +1796,7 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1796,7 +1796,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
if (err) if (err)
return err; return err;
} }
if (!d_is_directory(nd->path.dentry)) { if (!d_can_lookup(nd->path.dentry)) {
err = -ENOTDIR; err = -ENOTDIR;
break; break;
} }
...@@ -1817,7 +1817,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1817,7 +1817,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
struct dentry *root = nd->root.dentry; struct dentry *root = nd->root.dentry;
struct inode *inode = root->d_inode; struct inode *inode = root->d_inode;
if (*name) { if (*name) {
if (!d_is_directory(root)) if (!d_can_lookup(root))
return -ENOTDIR; return -ENOTDIR;
retval = inode_permission(inode, MAY_EXEC); retval = inode_permission(inode, MAY_EXEC);
if (retval) if (retval)
...@@ -1873,7 +1873,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1873,7 +1873,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
dentry = f.file->f_path.dentry; dentry = f.file->f_path.dentry;
if (*name) { if (*name) {
if (!d_is_directory(dentry)) { if (!d_can_lookup(dentry)) {
fdput(f); fdput(f);
return -ENOTDIR; return -ENOTDIR;
} }
...@@ -1955,7 +1955,7 @@ static int path_lookupat(int dfd, const char *name, ...@@ -1955,7 +1955,7 @@ static int path_lookupat(int dfd, const char *name,
err = complete_walk(nd); err = complete_walk(nd);
if (!err && nd->flags & LOOKUP_DIRECTORY) { if (!err && nd->flags & LOOKUP_DIRECTORY) {
if (!d_is_directory(nd->path.dentry)) { if (!d_can_lookup(nd->path.dentry)) {
path_put(&nd->path); path_put(&nd->path);
err = -ENOTDIR; err = -ENOTDIR;
} }
...@@ -2414,11 +2414,11 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir) ...@@ -2414,11 +2414,11 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
IS_IMMUTABLE(inode) || IS_SWAPFILE(inode)) IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
return -EPERM; return -EPERM;
if (isdir) { if (isdir) {
if (!d_is_directory(victim) && !d_is_autodir(victim)) if (!d_is_dir(victim))
return -ENOTDIR; return -ENOTDIR;
if (IS_ROOT(victim)) if (IS_ROOT(victim))
return -EBUSY; return -EBUSY;
} else if (d_is_directory(victim) || d_is_autodir(victim)) } else if (d_is_dir(victim))
return -EISDIR; return -EISDIR;
if (IS_DEADDIR(dir)) if (IS_DEADDIR(dir))
return -ENOENT; return -ENOENT;
...@@ -3016,11 +3016,10 @@ static int do_last(struct nameidata *nd, struct path *path, ...@@ -3016,11 +3016,10 @@ static int do_last(struct nameidata *nd, struct path *path,
} }
audit_inode(name, nd->path.dentry, 0); audit_inode(name, nd->path.dentry, 0);
error = -EISDIR; error = -EISDIR;
if ((open_flag & O_CREAT) && if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
(d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
goto out; goto out;
error = -ENOTDIR; error = -ENOTDIR;
if ((nd->flags & LOOKUP_DIRECTORY) && !d_is_directory(nd->path.dentry)) if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
goto out; goto out;
if (!S_ISREG(nd->inode->i_mode)) if (!S_ISREG(nd->inode->i_mode))
will_truncate = false; will_truncate = false;
...@@ -3744,7 +3743,7 @@ static long do_unlinkat(int dfd, const char __user *pathname) ...@@ -3744,7 +3743,7 @@ static long do_unlinkat(int dfd, const char __user *pathname)
slashes: slashes:
if (d_is_negative(dentry)) if (d_is_negative(dentry))
error = -ENOENT; error = -ENOENT;
else if (d_is_directory(dentry) || d_is_autodir(dentry)) else if (d_is_dir(dentry))
error = -EISDIR; error = -EISDIR;
else else
error = -ENOTDIR; error = -ENOTDIR;
...@@ -4123,7 +4122,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -4123,7 +4122,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode **delegated_inode) struct inode **delegated_inode)
{ {
int error; int error;
int is_dir = d_is_directory(old_dentry) || d_is_autodir(old_dentry); int is_dir = d_is_dir(old_dentry);
const unsigned char *old_name; const unsigned char *old_name;
if (old_dentry->d_inode == new_dentry->d_inode) if (old_dentry->d_inode == new_dentry->d_inode)
...@@ -4216,7 +4215,7 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname, ...@@ -4216,7 +4215,7 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
if (d_is_negative(old_dentry)) if (d_is_negative(old_dentry))
goto exit4; goto exit4;
/* unless the source is a directory trailing slashes give -ENOTDIR */ /* unless the source is a directory trailing slashes give -ENOTDIR */
if (!d_is_directory(old_dentry) && !d_is_autodir(old_dentry)) { if (!d_is_dir(old_dentry)) {
error = -ENOTDIR; error = -ENOTDIR;
if (oldnd.last.name[oldnd.last.len]) if (oldnd.last.name[oldnd.last.len])
goto exit4; goto exit4;
......
...@@ -429,7 +429,7 @@ static inline unsigned __d_entry_type(const struct dentry *dentry) ...@@ -429,7 +429,7 @@ static inline unsigned __d_entry_type(const struct dentry *dentry)
return dentry->d_flags & DCACHE_ENTRY_TYPE; return dentry->d_flags & DCACHE_ENTRY_TYPE;
} }
static inline bool d_is_directory(const struct dentry *dentry) static inline bool d_can_lookup(const struct dentry *dentry)
{ {
return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE; return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE;
} }
...@@ -439,6 +439,11 @@ static inline bool d_is_autodir(const struct dentry *dentry) ...@@ -439,6 +439,11 @@ static inline bool d_is_autodir(const struct dentry *dentry)
return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE; return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE;
} }
static inline bool d_is_dir(const struct dentry *dentry)
{
return d_can_lookup(dentry) || d_is_autodir(dentry);
}
static inline bool d_is_symlink(const struct dentry *dentry) static inline bool d_is_symlink(const struct dentry *dentry)
{ {
return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE; return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment