aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-16 08:46:49 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-16 08:46:49 -0400
commita8a2ee0c600a213d13170c2f4d7bd0b304bbec19 (patch)
tree91c98147b03657985b386a1bad74a9d0095d2606 /fs/btrfs
parent1e1d27017c5986c1ea81181506042cf9cba3f6ea (diff)
Btrfs: add a name_len to dir items, reorder key
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/ctree.c8
-rw-r--r--fs/btrfs/ctree.h14
-rw-r--r--fs/btrfs/dir-item.c14
-rw-r--r--fs/btrfs/dir-test.c6
-rw-r--r--fs/btrfs/print-tree.c8
5 files changed, 25 insertions, 25 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 7edfbd468042..68f66b320a88 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -107,14 +107,14 @@ static int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
107 return 1; 107 return 1;
108 if (k1.objectid < k2->objectid) 108 if (k1.objectid < k2->objectid)
109 return -1; 109 return -1;
110 if (k1.offset > k2->offset)
111 return 1;
112 if (k1.offset < k2->offset)
113 return -1;
114 if (k1.flags > k2->flags) 110 if (k1.flags > k2->flags)
115 return 1; 111 return 1;
116 if (k1.flags < k2->flags) 112 if (k1.flags < k2->flags)
117 return -1; 113 return -1;
114 if (k1.offset > k2->offset)
115 return 1;
116 if (k1.offset < k2->offset)
117 return -1;
118 return 0; 118 return 0;
119} 119}
120 120
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index dbf3917833fe..7c66b647ea24 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -26,14 +26,14 @@
26 */ 26 */
27struct btrfs_disk_key { 27struct btrfs_disk_key {
28 __le64 objectid; 28 __le64 objectid;
29 __le64 offset;
30 __le32 flags; 29 __le32 flags;
30 __le64 offset;
31} __attribute__ ((__packed__)); 31} __attribute__ ((__packed__));
32 32
33struct btrfs_key { 33struct btrfs_key {
34 u64 objectid; 34 u64 objectid;
35 u64 offset;
36 u32 flags; 35 u32 flags;
36 u64 offset;
37} __attribute__ ((__packed__)); 37} __attribute__ ((__packed__));
38 38
39/* 39/*
@@ -166,6 +166,7 @@ struct btrfs_inline_data_item {
166struct btrfs_dir_item { 166struct btrfs_dir_item {
167 __le64 objectid; 167 __le64 objectid;
168 __le16 flags; 168 __le16 flags;
169 __le16 name_len;
169 u8 type; 170 u8 type;
170} __attribute__ ((__packed__)); 171} __attribute__ ((__packed__));
171 172
@@ -431,9 +432,14 @@ static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
431 d->type = val; 432 d->type = val;
432} 433}
433 434
434static inline u32 btrfs_dir_name_len(struct btrfs_item *i) 435static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
436{
437 return le16_to_cpu(d->name_len);
438}
439
440static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
435{ 441{
436 return btrfs_item_size(i) - sizeof(struct btrfs_dir_item); 442 d->name_len = cpu_to_le16(val);
437} 443}
438 444
439static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 445static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
index 8043b2ef10d1..a42a67b99753 100644
--- a/fs/btrfs/dir-item.c
+++ b/fs/btrfs/dir-item.c
@@ -32,6 +32,7 @@ int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len,
32 btrfs_set_dir_objectid(dir_item, objectid); 32 btrfs_set_dir_objectid(dir_item, objectid);
33 btrfs_set_dir_type(dir_item, type); 33 btrfs_set_dir_type(dir_item, type);
34 btrfs_set_dir_flags(dir_item, 0); 34 btrfs_set_dir_flags(dir_item, 0);
35 btrfs_set_dir_name_len(dir_item, name_len);
35 name_ptr = (char *)(dir_item + 1); 36 name_ptr = (char *)(dir_item + 1);
36 memcpy(name_ptr, name, name_len); 37 memcpy(name_ptr, name, name_len);
37out: 38out:
@@ -59,20 +60,15 @@ int btrfs_lookup_dir_item(struct btrfs_root *root, struct btrfs_path *path,
59int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, 60int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
60 char *name, int name_len) 61 char *name, int name_len)
61{ 62{
62 struct btrfs_item *item;
63 struct btrfs_dir_item *dir_item; 63 struct btrfs_dir_item *dir_item;
64 char *name_ptr; 64 char *name_ptr;
65 u32 item_len; 65
66 item = path->nodes[0]->leaf.items + path->slots[0];
67 item_len = btrfs_item_size(item);
68 if (item_len != name_len + sizeof(struct btrfs_dir_item)) {
69 return 0;
70 }
71 dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0], 66 dir_item = btrfs_item_ptr(&path->nodes[0]->leaf, path->slots[0],
72 struct btrfs_dir_item); 67 struct btrfs_dir_item);
68 if (btrfs_dir_name_len(dir_item) != name_len)
69 return 0;
73 name_ptr = (char *)(dir_item + 1); 70 name_ptr = (char *)(dir_item + 1);
74 if (memcmp(name_ptr, name, name_len)) { 71 if (memcmp(name_ptr, name, name_len))
75 return 0; 72 return 0;
76 }
77 return 1; 73 return 1;
78} 74}
diff --git a/fs/btrfs/dir-test.c b/fs/btrfs/dir-test.c
index b482b8f49f8a..f73aa7623398 100644
--- a/fs/btrfs/dir-test.c
+++ b/fs/btrfs/dir-test.c
@@ -81,8 +81,7 @@ error:
81 di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], 81 di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
82 struct btrfs_dir_item); 82 struct btrfs_dir_item);
83 found = (char *)(di + 1); 83 found = (char *)(di + 1);
84 found_len = btrfs_dir_name_len(path.nodes[0]->leaf.items + 84 found_len = btrfs_dir_name_len(di);
85 path.slots[0]);
86 btrfs_name_hash(buf, strlen(buf), &myhash); 85 btrfs_name_hash(buf, strlen(buf), &myhash);
87 btrfs_name_hash(found, found_len, &foundhash); 86 btrfs_name_hash(found, found_len, &foundhash);
88 if (myhash != foundhash) 87 if (myhash != foundhash)
@@ -227,8 +226,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
227 slot = path.slots[0]; 226 slot = path.slots[0];
228 di = btrfs_item_ptr(&path.nodes[0]->leaf, slot, 227 di = btrfs_item_ptr(&path.nodes[0]->leaf, slot,
229 struct btrfs_dir_item); 228 struct btrfs_dir_item);
230 found_len = btrfs_dir_name_len(path.nodes[0]->leaf.items + 229 found_len = btrfs_dir_name_len(di);
231 slot);
232 memcpy(buf, (char *)(di + 1), found_len); 230 memcpy(buf, (char *)(di + 1), found_len);
233 BUG_ON(found_len > 128); 231 BUG_ON(found_len > 128);
234 buf[found_len] = '\0'; 232 buf[found_len] = '\0';
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index ad244d658117..0bb5c38427c9 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -23,11 +23,11 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
23 for (i = 0 ; i < nr ; i++) { 23 for (i = 0 ; i < nr ; i++) {
24 item = l->items + i; 24 item = l->items + i;
25 type = btrfs_disk_key_type(&item->key); 25 type = btrfs_disk_key_type(&item->key);
26 printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n", 26 printf("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n",
27 i, 27 i,
28 btrfs_disk_key_objectid(&item->key), 28 btrfs_disk_key_objectid(&item->key),
29 btrfs_disk_key_offset(&item->key),
30 btrfs_disk_key_flags(&item->key), 29 btrfs_disk_key_flags(&item->key),
30 btrfs_disk_key_offset(&item->key),
31 btrfs_item_offset(item), 31 btrfs_item_offset(item),
32 btrfs_item_size(item)); 32 btrfs_item_size(item));
33 switch (type) { 33 switch (type) {
@@ -81,11 +81,11 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
81 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr); 81 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
82 fflush(stdout); 82 fflush(stdout);
83 for (i = 0; i < nr; i++) { 83 for (i = 0; i < nr; i++) {
84 printf("\tkey %d (%Lu %Lu %u) block %Lu\n", 84 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
85 i, 85 i,
86 c->ptrs[i].key.objectid, 86 c->ptrs[i].key.objectid,
87 c->ptrs[i].key.offset,
88 c->ptrs[i].key.flags, 87 c->ptrs[i].key.flags,
88 c->ptrs[i].key.offset,
89 btrfs_node_blockptr(c, i)); 89 btrfs_node_blockptr(c, i));
90 fflush(stdout); 90 fflush(stdout);
91 } 91 }