forked from luck/tmp_suning_uos_patched
Btrfs: Remove special cases for "." and ".."
Date: Sun, 17 Aug 2008 15:14:48 +0100 We never get asked by the VFS to lookup either of them, and we can handle the readdir() case a lot more simply, too. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
21af804c07
commit
5ecc7e5d1d
@ -1702,42 +1702,9 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
|
|||||||
struct btrfs_root *root = BTRFS_I(dir)->root;
|
struct btrfs_root *root = BTRFS_I(dir)->root;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (namelen == 1 && strcmp(name, ".") == 0) {
|
|
||||||
location->objectid = dir->i_ino;
|
|
||||||
location->type = BTRFS_INODE_ITEM_KEY;
|
|
||||||
location->offset = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
BUG_ON(!path);
|
BUG_ON(!path);
|
||||||
|
|
||||||
if (namelen == 2 && strcmp(name, "..") == 0) {
|
|
||||||
struct btrfs_key key;
|
|
||||||
struct extent_buffer *leaf;
|
|
||||||
int slot;
|
|
||||||
|
|
||||||
key.objectid = dir->i_ino;
|
|
||||||
key.offset = (u64)-1;
|
|
||||||
btrfs_set_key_type(&key, BTRFS_INODE_REF_KEY);
|
|
||||||
if (ret < 0 || path->slots[0] == 0)
|
|
||||||
goto out_err;
|
|
||||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
|
||||||
BUG_ON(ret == 0);
|
|
||||||
ret = 0;
|
|
||||||
leaf = path->nodes[0];
|
|
||||||
slot = path->slots[0] - 1;
|
|
||||||
|
|
||||||
btrfs_item_key_to_cpu(leaf, &key, slot);
|
|
||||||
if (key.objectid != dir->i_ino ||
|
|
||||||
key.type != BTRFS_INODE_REF_KEY) {
|
|
||||||
goto out_err;
|
|
||||||
}
|
|
||||||
location->objectid = key.offset;
|
|
||||||
location->type = BTRFS_INODE_ITEM_KEY;
|
|
||||||
location->offset = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
|
di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
|
||||||
namelen, 0);
|
namelen, 0);
|
||||||
if (IS_ERR(di))
|
if (IS_ERR(di))
|
||||||
@ -1960,29 +1927,14 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
|
|||||||
|
|
||||||
/* special case for .., just use the back ref */
|
/* special case for .., just use the back ref */
|
||||||
if (filp->f_pos == 1) {
|
if (filp->f_pos == 1) {
|
||||||
btrfs_set_key_type(&key, BTRFS_INODE_REF_KEY);
|
u64 pino = parent_ino(filp->f_path.dentry);
|
||||||
key.offset = (u64)-1;
|
|
||||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
|
||||||
if (ret < 0 || path->slots[0] == 0) {
|
|
||||||
btrfs_release_path(root, path);
|
|
||||||
goto read_dir_items;
|
|
||||||
}
|
|
||||||
BUG_ON(ret == 0);
|
|
||||||
leaf = path->nodes[0];
|
|
||||||
slot = path->slots[0] - 1;
|
|
||||||
btrfs_item_key_to_cpu(leaf, &found_key, slot);
|
|
||||||
btrfs_release_path(root, path);
|
|
||||||
if (found_key.objectid != key.objectid ||
|
|
||||||
found_key.type != BTRFS_INODE_REF_KEY)
|
|
||||||
goto read_dir_items;
|
|
||||||
over = filldir(dirent, "..", 2,
|
over = filldir(dirent, "..", 2,
|
||||||
2, found_key.offset, DT_DIR);
|
2, pino, DT_DIR);
|
||||||
if (over)
|
if (over)
|
||||||
goto nopos;
|
goto nopos;
|
||||||
filp->f_pos = 2;
|
filp->f_pos = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_dir_items:
|
|
||||||
btrfs_set_key_type(&key, key_type);
|
btrfs_set_key_type(&key, key_type);
|
||||||
key.offset = filp->f_pos;
|
key.offset = filp->f_pos;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user