Commit c663e5d80ebec426916ad2aa5400c7ec99aa572e
Committed by
Linus Torvalds
1 parent
70f09f1fdf
Exists in
master
and in
20 other branches
[PATCH] add some comments to lookup_create()
In a duplicate of lookup_create in the af_unix code Al commented what's going on nicely, so let's bring that over to lookup_create before the copy is going away (I'll send a patch soon) Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 1 changed file with 18 additions and 2 deletions Side-by-side Diff
fs/namei.c
... | ... | @@ -1577,19 +1577,35 @@ |
1577 | 1577 | * |
1578 | 1578 | * Simple function to lookup and return a dentry and create it |
1579 | 1579 | * if it doesn't exist. Is SMP-safe. |
1580 | + * | |
1581 | + * Returns with nd->dentry->d_inode->i_sem locked. | |
1580 | 1582 | */ |
1581 | 1583 | struct dentry *lookup_create(struct nameidata *nd, int is_dir) |
1582 | 1584 | { |
1583 | - struct dentry *dentry; | |
1585 | + struct dentry *dentry = ERR_PTR(-EEXIST); | |
1584 | 1586 | |
1585 | 1587 | down(&nd->dentry->d_inode->i_sem); |
1586 | - dentry = ERR_PTR(-EEXIST); | |
1588 | + /* | |
1589 | + * Yucky last component or no last component at all? | |
1590 | + * (foo/., foo/.., /////) | |
1591 | + */ | |
1587 | 1592 | if (nd->last_type != LAST_NORM) |
1588 | 1593 | goto fail; |
1589 | 1594 | nd->flags &= ~LOOKUP_PARENT; |
1595 | + | |
1596 | + /* | |
1597 | + * Do the final lookup. | |
1598 | + */ | |
1590 | 1599 | dentry = lookup_hash(&nd->last, nd->dentry); |
1591 | 1600 | if (IS_ERR(dentry)) |
1592 | 1601 | goto fail; |
1602 | + | |
1603 | + /* | |
1604 | + * Special case - lookup gave negative, but... we had foo/bar/ | |
1605 | + * From the vfs_mknod() POV we just have a negative dentry - | |
1606 | + * all is fine. Let's be bastards - you had / on the end, you've | |
1607 | + * been asking for (non-existent) directory. -ENOENT for you. | |
1608 | + */ | |
1593 | 1609 | if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode) |
1594 | 1610 | goto enoent; |
1595 | 1611 | return dentry; |