diff --git a/[refs] b/[refs] index 09988f37ffbf..514210f50c5b 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 70f09f1fdf38cd7fca39913978d18cf998ab2c80 +refs/heads/master: c663e5d80ebec426916ad2aa5400c7ec99aa572e diff --git a/trunk/fs/namei.c b/trunk/fs/namei.c index a7f7f44119b3..fa8df81ce8ca 100644 --- a/trunk/fs/namei.c +++ b/trunk/fs/namei.c @@ -1577,19 +1577,35 @@ int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd) * * Simple function to lookup and return a dentry and create it * if it doesn't exist. Is SMP-safe. + * + * Returns with nd->dentry->d_inode->i_sem locked. */ struct dentry *lookup_create(struct nameidata *nd, int is_dir) { - struct dentry *dentry; + struct dentry *dentry = ERR_PTR(-EEXIST); down(&nd->dentry->d_inode->i_sem); - dentry = ERR_PTR(-EEXIST); + /* + * Yucky last component or no last component at all? + * (foo/., foo/.., /////) + */ if (nd->last_type != LAST_NORM) goto fail; nd->flags &= ~LOOKUP_PARENT; + + /* + * Do the final lookup. + */ dentry = lookup_hash(&nd->last, nd->dentry); if (IS_ERR(dentry)) goto fail; + + /* + * Special case - lookup gave negative, but... we had foo/bar/ + * From the vfs_mknod() POV we just have a negative dentry - + * all is fine. Let's be bastards - you had / on the end, you've + * been asking for (non-existent) directory. -ENOENT for you. + */ if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode) goto enoent; return dentry;