diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-15 15:18:43 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-15 15:18:43 -0400 |
commit | 1d4f6404de26df49eb8452f8fdf7672b59f407fc (patch) | |
tree | 9bbc9fdd45f8e9fc5444e8c84f4777a607c13e2b /fs/btrfs/dir-item.c | |
parent | 24af03ea5e765d57860c975efcdcd41ec7f63fd9 (diff) |
Btrfs: directory testing code and dir item fixes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/dir-item.c')
-rw-r--r-- | fs/btrfs/dir-item.c | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index 2a888e97e1a2..8043b2ef10d1 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c | |||
@@ -18,6 +18,7 @@ int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len, | |||
18 | 18 | ||
19 | key.objectid = dir; | 19 | key.objectid = dir; |
20 | key.flags = 0; | 20 | key.flags = 0; |
21 | btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY); | ||
21 | ret = btrfs_name_hash(name, name_len, &key.offset); | 22 | ret = btrfs_name_hash(name, name_len, &key.offset); |
22 | BUG_ON(ret); | 23 | BUG_ON(ret); |
23 | btrfs_init_path(&path); | 24 | btrfs_init_path(&path); |
@@ -38,65 +39,40 @@ out: | |||
38 | return ret; | 39 | return ret; |
39 | } | 40 | } |
40 | 41 | ||
41 | int btrfs_del_dir_item(struct btrfs_root *root, u64 dir, char *name, | 42 | int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path, |
42 | int name_len) | 43 | u64 dir, char *name, int name_len, int mod) |
43 | { | 44 | { |
44 | int ret = 0; | 45 | int ret; |
45 | struct btrfs_path path; | ||
46 | struct btrfs_key key; | 46 | struct btrfs_key key; |
47 | int ins_len = mod < 0 ? -1 : 0; | ||
48 | int cow = mod != 0; | ||
47 | 49 | ||
48 | key.objectid = dir; | 50 | key.objectid = dir; |
49 | key.flags = 0; | 51 | key.flags = 0; |
52 | btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY); | ||
50 | ret = btrfs_name_hash(name, name_len, &key.offset); | 53 | ret = btrfs_name_hash(name, name_len, &key.offset); |
51 | BUG_ON(ret); | 54 | BUG_ON(ret); |
52 | btrfs_init_path(&path); | 55 | ret = btrfs_search_slot(root, &key, path, ins_len, cow); |
53 | ret = btrfs_search_slot(root, &key, &path, 0, 1); | ||
54 | if (ret) | ||
55 | goto out; | ||
56 | ret = btrfs_del_item(root, &path); | ||
57 | out: | ||
58 | btrfs_release_path(root, &path); | ||
59 | return ret; | 56 | return ret; |
60 | } | 57 | } |
61 | 58 | ||
62 | int btrfs_lookup_dir_item(struct btrfs_root *root, u64 dir, char *name, | 59 | int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, |
63 | int name_len, u64 *objectid) | 60 | char *name, int name_len) |
64 | { | 61 | { |
65 | int ret = 0; | 62 | struct btrfs_item *item; |
66 | struct btrfs_path path; | ||
67 | struct btrfs_dir_item *dir_item; | 63 | struct btrfs_dir_item *dir_item; |
68 | char *name_ptr; | 64 | char *name_ptr; |
69 | struct btrfs_key key; | ||
70 | u32 item_len; | 65 | u32 item_len; |
71 | struct btrfs_item *item; | 66 | item = path->nodes[0]->leaf.items + path->slots[0]; |
72 | |||
73 | key.objectid = dir; | ||
74 | key.flags = 0; | ||
75 | ret = btrfs_name_hash(name, name_len, &key.offset); | ||
76 | BUG_ON(ret); | ||
77 | btrfs_init_path(&path); | ||
78 | ret = btrfs_search_slot(root, &key, &path, 0, 0); | ||
79 | if (ret) | ||
80 | goto out; | ||
81 | |||
82 | dir_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], | ||
83 | struct btrfs_dir_item); | ||
84 | |||
85 | item = path.nodes[0]->leaf.items + path.slots[0]; | ||
86 | item_len = btrfs_item_size(item); | 67 | item_len = btrfs_item_size(item); |
87 | if (item_len != name_len + sizeof(struct btrfs_dir_item)) { | 68 | if (item_len != name_len + sizeof(struct btrfs_dir_item)) { |
88 | BUG(); | 69 | return 0; |
89 | ret = 1; | ||
90 | goto out; | ||
91 | } | 70 | } |
71 | dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0], | ||
72 | struct btrfs_dir_item); | ||
92 | name_ptr = (char *)(dir_item + 1); | 73 | name_ptr = (char *)(dir_item + 1); |
93 | if (memcmp(name_ptr, name, name_len)) { | 74 | if (memcmp(name_ptr, name, name_len)) { |
94 | BUG(); | 75 | return 0; |
95 | ret = 1; | ||
96 | goto out; | ||
97 | } | 76 | } |
98 | *objectid = btrfs_dir_objectid(dir_item); | 77 | return 1; |
99 | out: | ||
100 | btrfs_release_path(root, &path); | ||
101 | return ret; | ||
102 | } | 78 | } |