diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-15 12:56:47 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-15 12:56:47 -0400 |
commit | 62e2749e03a855d98855f9ce032dbe72d5fad148 (patch) | |
tree | ed12521d1bde4ac7eda7f917b57b3cab1e76539d /fs | |
parent | a1516c8921ce2c148b69493e858d95bc79c92f01 (diff) |
Btrfs: Use a chunk of the key flags to record the item type.
Add (untested and simple) directory item code
Fix comp_keys to use the new key ordering
Add btrfs_insert_empty_item
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/Makefile | 2 | ||||
-rw-r--r-- | fs/btrfs/TODO | 1 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 51 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 182 | ||||
-rw-r--r-- | fs/btrfs/dir-item.c | 102 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 17 | ||||
-rw-r--r-- | fs/btrfs/hash.c | 86 | ||||
-rw-r--r-- | fs/btrfs/hasher.c | 23 | ||||
-rw-r--r-- | fs/btrfs/kerncompat.h | 1 | ||||
-rw-r--r-- | fs/btrfs/mkfs.c | 28 | ||||
-rw-r--r-- | fs/btrfs/print-tree.c | 36 | ||||
-rw-r--r-- | fs/btrfs/quick-test.c | 3 | ||||
-rw-r--r-- | fs/btrfs/random-test.c | 10 | ||||
-rw-r--r-- | fs/btrfs/root-tree.c | 2 |
14 files changed, 435 insertions, 109 deletions
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 13ed6313ac85..ee78cdd08c04 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile | |||
@@ -3,7 +3,7 @@ CC=gcc | |||
3 | CFLAGS = -g -Wall | 3 | CFLAGS = -g -Wall |
4 | headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h | 4 | headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h |
5 | objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \ | 5 | objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \ |
6 | root-tree.o | 6 | root-tree.o dir-item.o hash.o |
7 | 7 | ||
8 | # if you don't have sparse installed, use ls instead | 8 | # if you don't have sparse installed, use ls instead |
9 | CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ | 9 | CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ |
diff --git a/fs/btrfs/TODO b/fs/btrfs/TODO index 8142be88d71c..249e2e90bea8 100644 --- a/fs/btrfs/TODO +++ b/fs/btrfs/TODO | |||
@@ -8,6 +8,7 @@ | |||
8 | * Add block mapping tree (simple dm layer) | 8 | * Add block mapping tree (simple dm layer) |
9 | * Add simple tree locking (semaphore per tree) | 9 | * Add simple tree locking (semaphore per tree) |
10 | * Make allocator smarter | 10 | * Make allocator smarter |
11 | * Do actual block accounting | ||
11 | * Port into the kernel | 12 | * Port into the kernel |
12 | * Add virtual filesystems, mountable snapshots | 13 | * Add virtual filesystems, mountable snapshots |
13 | * Get rid of struct ctree_path, limiting tree levels held at one time | 14 | * Get rid of struct ctree_path, limiting tree levels held at one time |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index ece8de7f38ef..7edfbd468042 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.flags > k2->flags) | ||
111 | return 1; | ||
112 | if (k1.flags < k2->flags) | ||
113 | return -1; | ||
114 | if (k1.offset > k2->offset) | 110 | if (k1.offset > k2->offset) |
115 | return 1; | 111 | return 1; |
116 | if (k1.offset < k2->offset) | 112 | if (k1.offset < k2->offset) |
117 | return -1; | 113 | return -1; |
114 | if (k1.flags > k2->flags) | ||
115 | return 1; | ||
116 | if (k1.flags < k2->flags) | ||
117 | return -1; | ||
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
120 | 120 | ||
@@ -1122,8 +1122,8 @@ static int split_leaf(struct btrfs_root *root, struct btrfs_path *path, | |||
1122 | * Given a key and some data, insert an item into the tree. | 1122 | * Given a key and some data, insert an item into the tree. |
1123 | * This does all the path init required, making room in the tree if needed. | 1123 | * This does all the path init required, making room in the tree if needed. |
1124 | */ | 1124 | */ |
1125 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | 1125 | int btrfs_insert_empty_item(struct btrfs_root *root, struct btrfs_path *path, |
1126 | void *data, int data_size) | 1126 | struct btrfs_key *cpu_key, u32 data_size) |
1127 | { | 1127 | { |
1128 | int ret = 0; | 1128 | int ret = 0; |
1129 | int slot; | 1129 | int slot; |
@@ -1132,7 +1132,6 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1132 | struct btrfs_buffer *leaf_buf; | 1132 | struct btrfs_buffer *leaf_buf; |
1133 | u32 nritems; | 1133 | u32 nritems; |
1134 | unsigned int data_end; | 1134 | unsigned int data_end; |
1135 | struct btrfs_path path; | ||
1136 | struct btrfs_disk_key disk_key; | 1135 | struct btrfs_disk_key disk_key; |
1137 | 1136 | ||
1138 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); | 1137 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); |
@@ -1140,17 +1139,16 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1140 | /* create a root if there isn't one */ | 1139 | /* create a root if there isn't one */ |
1141 | if (!root->node) | 1140 | if (!root->node) |
1142 | BUG(); | 1141 | BUG(); |
1143 | btrfs_init_path(&path); | 1142 | ret = btrfs_search_slot(root, cpu_key, path, data_size, 1); |
1144 | ret = btrfs_search_slot(root, cpu_key, &path, data_size, 1); | ||
1145 | if (ret == 0) { | 1143 | if (ret == 0) { |
1146 | btrfs_release_path(root, &path); | 1144 | btrfs_release_path(root, path); |
1147 | return -EEXIST; | 1145 | return -EEXIST; |
1148 | } | 1146 | } |
1149 | if (ret < 0) | 1147 | if (ret < 0) |
1150 | goto out; | 1148 | goto out; |
1151 | 1149 | ||
1152 | slot_orig = path.slots[0]; | 1150 | slot_orig = path->slots[0]; |
1153 | leaf_buf = path.nodes[0]; | 1151 | leaf_buf = path->nodes[0]; |
1154 | leaf = &leaf_buf->leaf; | 1152 | leaf = &leaf_buf->leaf; |
1155 | 1153 | ||
1156 | nritems = btrfs_header_nritems(&leaf->header); | 1154 | nritems = btrfs_header_nritems(&leaf->header); |
@@ -1160,7 +1158,7 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1160 | sizeof(struct btrfs_item) + data_size) | 1158 | sizeof(struct btrfs_item) + data_size) |
1161 | BUG(); | 1159 | BUG(); |
1162 | 1160 | ||
1163 | slot = path.slots[0]; | 1161 | slot = path->slots[0]; |
1164 | BUG_ON(slot < 0); | 1162 | BUG_ON(slot < 0); |
1165 | if (slot != nritems) { | 1163 | if (slot != nritems) { |
1166 | int i; | 1164 | int i; |
@@ -1186,23 +1184,42 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1186 | data_end, old_data - data_end); | 1184 | data_end, old_data - data_end); |
1187 | data_end = old_data; | 1185 | data_end = old_data; |
1188 | } | 1186 | } |
1189 | /* copy the new data in */ | 1187 | /* setup the item for the new data */ |
1190 | memcpy(&leaf->items[slot].key, &disk_key, | 1188 | memcpy(&leaf->items[slot].key, &disk_key, |
1191 | sizeof(struct btrfs_disk_key)); | 1189 | sizeof(struct btrfs_disk_key)); |
1192 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); | 1190 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); |
1193 | btrfs_set_item_size(leaf->items + slot, data_size); | 1191 | btrfs_set_item_size(leaf->items + slot, data_size); |
1194 | memcpy(btrfs_leaf_data(leaf) + data_end - data_size, data, data_size); | ||
1195 | btrfs_set_header_nritems(&leaf->header, nritems + 1); | 1192 | btrfs_set_header_nritems(&leaf->header, nritems + 1); |
1196 | 1193 | ||
1197 | ret = 0; | 1194 | ret = 0; |
1198 | if (slot == 0) | 1195 | if (slot == 0) |
1199 | ret = fixup_low_keys(root, &path, &disk_key, 1); | 1196 | ret = fixup_low_keys(root, path, &disk_key, 1); |
1200 | 1197 | ||
1201 | BUG_ON(list_empty(&leaf_buf->dirty)); | 1198 | BUG_ON(list_empty(&leaf_buf->dirty)); |
1202 | if (btrfs_leaf_free_space(root, leaf) < 0) | 1199 | if (btrfs_leaf_free_space(root, leaf) < 0) |
1203 | BUG(); | 1200 | BUG(); |
1204 | check_leaf(root, &path, 0); | 1201 | check_leaf(root, path, 0); |
1205 | out: | 1202 | out: |
1203 | return ret; | ||
1204 | } | ||
1205 | |||
1206 | /* | ||
1207 | * Given a key and some data, insert an item into the tree. | ||
1208 | * This does all the path init required, making room in the tree if needed. | ||
1209 | */ | ||
1210 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | ||
1211 | void *data, u32 data_size) | ||
1212 | { | ||
1213 | int ret = 0; | ||
1214 | struct btrfs_path path; | ||
1215 | u8 *ptr; | ||
1216 | |||
1217 | btrfs_init_path(&path); | ||
1218 | ret = btrfs_insert_empty_item(root, &path, cpu_key, data_size); | ||
1219 | if (!ret) { | ||
1220 | ptr = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], u8); | ||
1221 | memcpy(ptr, data, data_size); | ||
1222 | } | ||
1206 | btrfs_release_path(root, &path); | 1223 | btrfs_release_path(root, &path); |
1207 | return ret; | 1224 | return ret; |
1208 | } | 1225 | } |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 73ebc824924a..e8a26fd8ea9f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -58,39 +58,6 @@ struct btrfs_header { | |||
58 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | 58 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) |
59 | 59 | ||
60 | struct btrfs_buffer; | 60 | struct btrfs_buffer; |
61 | |||
62 | struct btrfs_root_item { | ||
63 | __le64 blocknr; | ||
64 | __le32 flags; | ||
65 | __le64 block_limit; | ||
66 | __le64 blocks_used; | ||
67 | __le32 refs; | ||
68 | }; | ||
69 | |||
70 | /* | ||
71 | * in ram representation of the tree. extent_root is used for all allocations | ||
72 | * and for the extent tree extent_root root. current_insert is used | ||
73 | * only for the extent tree. | ||
74 | */ | ||
75 | struct btrfs_root { | ||
76 | struct btrfs_buffer *node; | ||
77 | struct btrfs_buffer *commit_root; | ||
78 | struct btrfs_root *extent_root; | ||
79 | struct btrfs_root *tree_root; | ||
80 | struct btrfs_key current_insert; | ||
81 | struct btrfs_key last_insert; | ||
82 | int fp; | ||
83 | struct radix_tree_root cache_radix; | ||
84 | struct radix_tree_root pinned_radix; | ||
85 | struct list_head trans; | ||
86 | struct list_head cache; | ||
87 | int cache_size; | ||
88 | int ref_cows; | ||
89 | struct btrfs_root_item root_item; | ||
90 | struct btrfs_key root_key; | ||
91 | u32 blocksize; | ||
92 | }; | ||
93 | |||
94 | /* | 61 | /* |
95 | * the super block basically lists the main trees of the FS | 62 | * the super block basically lists the main trees of the FS |
96 | * it currently lacks any block count etc etc | 63 | * it currently lacks any block count etc etc |
@@ -108,8 +75,7 @@ struct btrfs_super_block { | |||
108 | } __attribute__ ((__packed__)); | 75 | } __attribute__ ((__packed__)); |
109 | 76 | ||
110 | /* | 77 | /* |
111 | * A leaf is full of items. The exact type of item is defined by | 78 | * A leaf is full of items. offset and size tell us where to find |
112 | * the key flags parameter. offset and size tell us where to find | ||
113 | * the item in the leaf (relative to the start of the data area) | 79 | * the item in the leaf (relative to the start of the data area) |
114 | */ | 80 | */ |
115 | struct btrfs_item { | 81 | struct btrfs_item { |
@@ -145,15 +111,6 @@ struct btrfs_node { | |||
145 | } __attribute__ ((__packed__)); | 111 | } __attribute__ ((__packed__)); |
146 | 112 | ||
147 | /* | 113 | /* |
148 | * items in the extent btree are used to record the objectid of the | ||
149 | * owner of the block and the number of references | ||
150 | */ | ||
151 | struct btrfs_extent_item { | ||
152 | __le32 refs; | ||
153 | __le64 owner; | ||
154 | } __attribute__ ((__packed__)); | ||
155 | |||
156 | /* | ||
157 | * btrfs_paths remember the path taken from the root down to the leaf. | 114 | * btrfs_paths remember the path taken from the root down to the leaf. |
158 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | 115 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point |
159 | * to any other levels that are present. | 116 | * to any other levels that are present. |
@@ -166,6 +123,94 @@ struct btrfs_path { | |||
166 | int slots[BTRFS_MAX_LEVEL]; | 123 | int slots[BTRFS_MAX_LEVEL]; |
167 | }; | 124 | }; |
168 | 125 | ||
126 | /* | ||
127 | * items in the extent btree are used to record the objectid of the | ||
128 | * owner of the block and the number of references | ||
129 | */ | ||
130 | struct btrfs_extent_item { | ||
131 | __le32 refs; | ||
132 | __le64 owner; | ||
133 | } __attribute__ ((__packed__)); | ||
134 | |||
135 | struct btrfs_dir_item { | ||
136 | __le64 objectid; | ||
137 | __le16 flags; | ||
138 | u8 type; | ||
139 | } __attribute__ ((__packed__)); | ||
140 | |||
141 | struct btrfs_root_item { | ||
142 | __le64 blocknr; | ||
143 | __le32 flags; | ||
144 | __le64 block_limit; | ||
145 | __le64 blocks_used; | ||
146 | __le32 refs; | ||
147 | }; | ||
148 | |||
149 | /* | ||
150 | * in ram representation of the tree. extent_root is used for all allocations | ||
151 | * and for the extent tree extent_root root. current_insert is used | ||
152 | * only for the extent tree. | ||
153 | */ | ||
154 | struct btrfs_root { | ||
155 | struct btrfs_buffer *node; | ||
156 | struct btrfs_buffer *commit_root; | ||
157 | struct btrfs_root *extent_root; | ||
158 | struct btrfs_root *tree_root; | ||
159 | struct btrfs_key current_insert; | ||
160 | struct btrfs_key last_insert; | ||
161 | int fp; | ||
162 | struct radix_tree_root cache_radix; | ||
163 | struct radix_tree_root pinned_radix; | ||
164 | struct list_head trans; | ||
165 | struct list_head cache; | ||
166 | int cache_size; | ||
167 | int ref_cows; | ||
168 | struct btrfs_root_item root_item; | ||
169 | struct btrfs_key root_key; | ||
170 | u32 blocksize; | ||
171 | }; | ||
172 | |||
173 | |||
174 | /* the lower bits in the key flags defines the item type */ | ||
175 | #define BTRFS_KEY_TYPE_MAX 256 | ||
176 | #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) | ||
177 | #define BTRFS_INODE_ITEM_KEY 1 | ||
178 | #define BTRFS_DIR_ITEM_KEY 2 | ||
179 | #define BTRFS_ROOT_ITEM_KEY 3 | ||
180 | #define BTRFS_EXTENT_ITEM_KEY 4 | ||
181 | #define BTRFS_STRING_ITEM_KEY 5 | ||
182 | |||
183 | static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d) | ||
184 | { | ||
185 | return le64_to_cpu(d->objectid); | ||
186 | } | ||
187 | |||
188 | static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val) | ||
189 | { | ||
190 | d->objectid = cpu_to_le64(val); | ||
191 | } | ||
192 | |||
193 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) | ||
194 | { | ||
195 | return le16_to_cpu(d->flags); | ||
196 | } | ||
197 | |||
198 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) | ||
199 | { | ||
200 | d->flags = cpu_to_le16(val); | ||
201 | } | ||
202 | |||
203 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) | ||
204 | { | ||
205 | return d->type; | ||
206 | } | ||
207 | |||
208 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) | ||
209 | { | ||
210 | d->type = val; | ||
211 | } | ||
212 | |||
213 | |||
169 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) | 214 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
170 | { | 215 | { |
171 | return le64_to_cpu(ei->owner); | 216 | return le64_to_cpu(ei->owner); |
@@ -238,39 +283,65 @@ static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |||
238 | disk->objectid = cpu_to_le64(cpu->objectid); | 283 | disk->objectid = cpu_to_le64(cpu->objectid); |
239 | } | 284 | } |
240 | 285 | ||
241 | static inline u64 btrfs_key_objectid(struct btrfs_disk_key *disk) | 286 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
242 | { | 287 | { |
243 | return le64_to_cpu(disk->objectid); | 288 | return le64_to_cpu(disk->objectid); |
244 | } | 289 | } |
245 | 290 | ||
246 | static inline void btrfs_set_key_objectid(struct btrfs_disk_key *disk, | 291 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
247 | u64 val) | 292 | u64 val) |
248 | { | 293 | { |
249 | disk->objectid = cpu_to_le64(val); | 294 | disk->objectid = cpu_to_le64(val); |
250 | } | 295 | } |
251 | 296 | ||
252 | static inline u64 btrfs_key_offset(struct btrfs_disk_key *disk) | 297 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
253 | { | 298 | { |
254 | return le64_to_cpu(disk->offset); | 299 | return le64_to_cpu(disk->offset); |
255 | } | 300 | } |
256 | 301 | ||
257 | static inline void btrfs_set_key_offset(struct btrfs_disk_key *disk, | 302 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
258 | u64 val) | 303 | u64 val) |
259 | { | 304 | { |
260 | disk->offset = cpu_to_le64(val); | 305 | disk->offset = cpu_to_le64(val); |
261 | } | 306 | } |
262 | 307 | ||
263 | static inline u32 btrfs_key_flags(struct btrfs_disk_key *disk) | 308 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
264 | { | 309 | { |
265 | return le32_to_cpu(disk->flags); | 310 | return le32_to_cpu(disk->flags); |
266 | } | 311 | } |
267 | 312 | ||
268 | static inline void btrfs_set_key_flags(struct btrfs_disk_key *disk, | 313 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
269 | u32 val) | 314 | u32 val) |
270 | { | 315 | { |
271 | disk->flags = cpu_to_le32(val); | 316 | disk->flags = cpu_to_le32(val); |
272 | } | 317 | } |
273 | 318 | ||
319 | static inline u32 btrfs_key_type(struct btrfs_key *key) | ||
320 | { | ||
321 | return key->flags & BTRFS_KEY_TYPE_MASK; | ||
322 | } | ||
323 | |||
324 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) | ||
325 | { | ||
326 | return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK; | ||
327 | } | ||
328 | |||
329 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type) | ||
330 | { | ||
331 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | ||
332 | key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | ||
333 | } | ||
334 | |||
335 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type) | ||
336 | { | ||
337 | u32 flags = btrfs_disk_key_flags(key); | ||
338 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | ||
339 | flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | ||
340 | btrfs_set_disk_key_flags(key, flags); | ||
341 | } | ||
342 | |||
343 | |||
344 | |||
274 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) | 345 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
275 | { | 346 | { |
276 | return le64_to_cpu(h->blocknr); | 347 | return le64_to_cpu(h->blocknr); |
@@ -407,7 +478,6 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) | |||
407 | { | 478 | { |
408 | return (u8 *)l->items; | 479 | return (u8 *)l->items; |
409 | } | 480 | } |
410 | |||
411 | /* helper function to cast into the data area of the leaf. */ | 481 | /* helper function to cast into the data area of the leaf. */ |
412 | #define btrfs_item_ptr(leaf, slot, type) \ | 482 | #define btrfs_item_ptr(leaf, slot, type) \ |
413 | ((type *)(btrfs_leaf_data(leaf) + \ | 483 | ((type *)(btrfs_leaf_data(leaf) + \ |
@@ -422,7 +492,9 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); | |||
422 | void btrfs_init_path(struct btrfs_path *p); | 492 | void btrfs_init_path(struct btrfs_path *p); |
423 | int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path); | 493 | int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path); |
424 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, | 494 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, |
425 | void *data, int data_size); | 495 | void *data, u32 data_size); |
496 | int btrfs_insert_empty_item(struct btrfs_root *root, struct btrfs_path *path, | ||
497 | struct btrfs_key *cpu_key, u32 data_size); | ||
426 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); | 498 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
427 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); | 499 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
428 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); | 500 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); |
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c new file mode 100644 index 000000000000..2a888e97e1a2 --- /dev/null +++ b/fs/btrfs/dir-item.c | |||
@@ -0,0 +1,102 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "kerncompat.h" | ||
4 | #include "radix-tree.h" | ||
5 | #include "ctree.h" | ||
6 | #include "disk-io.h" | ||
7 | #include "hash.h" | ||
8 | |||
9 | int btrfs_insert_dir_item(struct btrfs_root *root, char *name, int name_len, | ||
10 | u64 dir, u64 objectid, u8 type) | ||
11 | { | ||
12 | int ret = 0; | ||
13 | struct btrfs_path path; | ||
14 | struct btrfs_dir_item *dir_item; | ||
15 | char *name_ptr; | ||
16 | struct btrfs_key key; | ||
17 | u32 data_size; | ||
18 | |||
19 | key.objectid = dir; | ||
20 | key.flags = 0; | ||
21 | ret = btrfs_name_hash(name, name_len, &key.offset); | ||
22 | BUG_ON(ret); | ||
23 | btrfs_init_path(&path); | ||
24 | data_size = sizeof(*dir_item) + name_len; | ||
25 | ret = btrfs_insert_empty_item(root, &path, &key, data_size); | ||
26 | if (ret) | ||
27 | goto out; | ||
28 | |||
29 | dir_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], | ||
30 | struct btrfs_dir_item); | ||
31 | btrfs_set_dir_objectid(dir_item, objectid); | ||
32 | btrfs_set_dir_type(dir_item, type); | ||
33 | btrfs_set_dir_flags(dir_item, 0); | ||
34 | name_ptr = (char *)(dir_item + 1); | ||
35 | memcpy(name_ptr, name, name_len); | ||
36 | out: | ||
37 | btrfs_release_path(root, &path); | ||
38 | return ret; | ||
39 | } | ||
40 | |||
41 | int btrfs_del_dir_item(struct btrfs_root *root, u64 dir, char *name, | ||
42 | int name_len) | ||
43 | { | ||
44 | int ret = 0; | ||
45 | struct btrfs_path path; | ||
46 | struct btrfs_key key; | ||
47 | |||
48 | key.objectid = dir; | ||
49 | key.flags = 0; | ||
50 | ret = btrfs_name_hash(name, name_len, &key.offset); | ||
51 | BUG_ON(ret); | ||
52 | btrfs_init_path(&path); | ||
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; | ||
60 | } | ||
61 | |||
62 | int btrfs_lookup_dir_item(struct btrfs_root *root, u64 dir, char *name, | ||
63 | int name_len, u64 *objectid) | ||
64 | { | ||
65 | int ret = 0; | ||
66 | struct btrfs_path path; | ||
67 | struct btrfs_dir_item *dir_item; | ||
68 | char *name_ptr; | ||
69 | struct btrfs_key key; | ||
70 | u32 item_len; | ||
71 | struct btrfs_item *item; | ||
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); | ||
87 | if (item_len != name_len + sizeof(struct btrfs_dir_item)) { | ||
88 | BUG(); | ||
89 | ret = 1; | ||
90 | goto out; | ||
91 | } | ||
92 | name_ptr = (char *)(dir_item + 1); | ||
93 | if (memcmp(name_ptr, name, name_len)) { | ||
94 | BUG(); | ||
95 | ret = 1; | ||
96 | goto out; | ||
97 | } | ||
98 | *objectid = btrfs_dir_objectid(dir_item); | ||
99 | out: | ||
100 | btrfs_release_path(root, &path); | ||
101 | return ret; | ||
102 | } | ||
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d4f1ec328399..c81e14162ef1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -35,6 +35,7 @@ static int inc_block_ref(struct btrfs_root *root, u64 blocknr) | |||
35 | btrfs_init_path(&path); | 35 | btrfs_init_path(&path); |
36 | key.objectid = blocknr; | 36 | key.objectid = blocknr; |
37 | key.flags = 0; | 37 | key.flags = 0; |
38 | btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); | ||
38 | key.offset = 1; | 39 | key.offset = 1; |
39 | ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 1); | 40 | ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 1); |
40 | if (ret != 0) | 41 | if (ret != 0) |
@@ -61,8 +62,9 @@ static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs) | |||
61 | struct btrfs_extent_item *item; | 62 | struct btrfs_extent_item *item; |
62 | btrfs_init_path(&path); | 63 | btrfs_init_path(&path); |
63 | key.objectid = blocknr; | 64 | key.objectid = blocknr; |
64 | key.flags = 0; | ||
65 | key.offset = 1; | 65 | key.offset = 1; |
66 | key.flags = 0; | ||
67 | btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); | ||
66 | ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 0); | 68 | ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 0); |
67 | if (ret != 0) | 69 | if (ret != 0) |
68 | BUG(); | 70 | BUG(); |
@@ -123,6 +125,7 @@ static int finish_current_insert(struct btrfs_root *extent_root) | |||
123 | btrfs_header_parentid(&extent_root->node->node.header)); | 125 | btrfs_header_parentid(&extent_root->node->node.header)); |
124 | ins.offset = 1; | 126 | ins.offset = 1; |
125 | ins.flags = 0; | 127 | ins.flags = 0; |
128 | btrfs_set_key_type(&ins, BTRFS_EXTENT_ITEM_KEY); | ||
126 | 129 | ||
127 | for (i = 0; i < extent_root->current_insert.flags; i++) { | 130 | for (i = 0; i < extent_root->current_insert.flags; i++) { |
128 | ins.objectid = extent_root->current_insert.objectid + i; | 131 | ins.objectid = extent_root->current_insert.objectid + i; |
@@ -149,6 +152,7 @@ static int __free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks) | |||
149 | 152 | ||
150 | key.objectid = blocknr; | 153 | key.objectid = blocknr; |
151 | key.flags = 0; | 154 | key.flags = 0; |
155 | btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); | ||
152 | key.offset = num_blocks; | 156 | key.offset = num_blocks; |
153 | 157 | ||
154 | find_free_extent(root, 0, 0, (u64)-1, &ins); | 158 | find_free_extent(root, 0, 0, (u64)-1, &ins); |
@@ -228,7 +232,6 @@ static int run_pending(struct btrfs_root *extent_root) | |||
228 | */ | 232 | */ |
229 | int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks) | 233 | int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks) |
230 | { | 234 | { |
231 | struct btrfs_key key; | ||
232 | struct btrfs_root *extent_root = root->extent_root; | 235 | struct btrfs_root *extent_root = root->extent_root; |
233 | struct btrfs_buffer *t; | 236 | struct btrfs_buffer *t; |
234 | int pending_ret; | 237 | int pending_ret; |
@@ -240,9 +243,6 @@ int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks) | |||
240 | CTREE_EXTENT_PENDING_DEL); | 243 | CTREE_EXTENT_PENDING_DEL); |
241 | return 0; | 244 | return 0; |
242 | } | 245 | } |
243 | key.objectid = blocknr; | ||
244 | key.flags = 0; | ||
245 | key.offset = num_blocks; | ||
246 | ret = __free_extent(root, blocknr, num_blocks); | 246 | ret = __free_extent(root, blocknr, num_blocks); |
247 | pending_ret = run_pending(root->extent_root); | 247 | pending_ret = run_pending(root->extent_root); |
248 | return ret ? ret : pending_ret; | 248 | return ret ? ret : pending_ret; |
@@ -252,7 +252,7 @@ int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks) | |||
252 | * walks the btree of allocated extents and find a hole of a given size. | 252 | * walks the btree of allocated extents and find a hole of a given size. |
253 | * The key ins is changed to record the hole: | 253 | * The key ins is changed to record the hole: |
254 | * ins->objectid == block start | 254 | * ins->objectid == block start |
255 | * ins->flags = 0 | 255 | * ins->flags = BTRFS_EXTENT_ITEM_KEY |
256 | * ins->offset == number of blocks | 256 | * ins->offset == number of blocks |
257 | * Any available blocks before search_start are skipped. | 257 | * Any available blocks before search_start are skipped. |
258 | */ | 258 | */ |
@@ -275,11 +275,14 @@ static int find_free_extent(struct btrfs_root *orig_root, u64 num_blocks, | |||
275 | total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3; | 275 | total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3; |
276 | if (root->last_insert.objectid > search_start) | 276 | if (root->last_insert.objectid > search_start) |
277 | search_start = root->last_insert.objectid; | 277 | search_start = root->last_insert.objectid; |
278 | |||
279 | ins->flags = 0; | ||
280 | btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); | ||
281 | |||
278 | check_failed: | 282 | check_failed: |
279 | btrfs_init_path(&path); | 283 | btrfs_init_path(&path); |
280 | ins->objectid = search_start; | 284 | ins->objectid = search_start; |
281 | ins->offset = 0; | 285 | ins->offset = 0; |
282 | ins->flags = 0; | ||
283 | start_found = 0; | 286 | start_found = 0; |
284 | ret = btrfs_search_slot(root, ins, &path, 0, 0); | 287 | ret = btrfs_search_slot(root, ins, &path, 0, 0); |
285 | if (ret < 0) | 288 | if (ret < 0) |
diff --git a/fs/btrfs/hash.c b/fs/btrfs/hash.c new file mode 100644 index 000000000000..92c37eece1f2 --- /dev/null +++ b/fs/btrfs/hash.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Original copy from: | ||
3 | * linux/fs/ext3/hash.c | ||
4 | * | ||
5 | * Copyright (C) 2002 by Theodore Ts'o | ||
6 | * | ||
7 | * This file is released under the GPL v2. | ||
8 | * | ||
9 | * This file may be redistributed under the terms of the GNU Public | ||
10 | * License. | ||
11 | */ | ||
12 | |||
13 | #include "kerncompat.h" | ||
14 | #define DELTA 0x9E3779B9 | ||
15 | |||
16 | static void TEA_transform(__u32 buf[2], __u32 const in[]) | ||
17 | { | ||
18 | __u32 sum = 0; | ||
19 | __u32 b0 = buf[0], b1 = buf[1]; | ||
20 | __u32 a = in[0], b = in[1], c = in[2], d = in[3]; | ||
21 | int n = 16; | ||
22 | |||
23 | do { | ||
24 | sum += DELTA; | ||
25 | b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); | ||
26 | b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); | ||
27 | } while(--n); | ||
28 | |||
29 | buf[0] += b0; | ||
30 | buf[1] += b1; | ||
31 | } | ||
32 | |||
33 | static void str2hashbuf(const char *msg, int len, __u32 *buf, int num) | ||
34 | { | ||
35 | __u32 pad, val; | ||
36 | int i; | ||
37 | |||
38 | pad = (__u32)len | ((__u32)len << 8); | ||
39 | pad |= pad << 16; | ||
40 | |||
41 | val = pad; | ||
42 | if (len > num*4) | ||
43 | len = num * 4; | ||
44 | for (i=0; i < len; i++) { | ||
45 | if ((i % 4) == 0) | ||
46 | val = pad; | ||
47 | val = msg[i] + (val << 8); | ||
48 | if ((i % 4) == 3) { | ||
49 | *buf++ = val; | ||
50 | val = pad; | ||
51 | num--; | ||
52 | } | ||
53 | } | ||
54 | if (--num >= 0) | ||
55 | *buf++ = val; | ||
56 | while (--num >= 0) | ||
57 | *buf++ = pad; | ||
58 | } | ||
59 | |||
60 | int btrfs_name_hash(const char *name, int len, u64 *hash_result) | ||
61 | { | ||
62 | __u32 hash; | ||
63 | __u32 minor_hash = 0; | ||
64 | const char *p; | ||
65 | __u32 in[8], buf[2]; | ||
66 | |||
67 | /* Initialize the default seed for the hash checksum functions */ | ||
68 | buf[0] = 0x67452301; | ||
69 | buf[1] = 0xefcdab89; | ||
70 | buf[2] = 0x98badcfe; | ||
71 | buf[3] = 0x10325476; | ||
72 | |||
73 | p = name; | ||
74 | while (len > 0) { | ||
75 | str2hashbuf(p, len, in, 4); | ||
76 | TEA_transform(buf, in); | ||
77 | len -= 16; | ||
78 | p += 16; | ||
79 | } | ||
80 | hash = buf[0]; | ||
81 | minor_hash = buf[1]; | ||
82 | *hash_result = buf[0]; | ||
83 | *hash_result <<= 32; | ||
84 | *hash_result |= buf[1]; | ||
85 | return 0; | ||
86 | } | ||
diff --git a/fs/btrfs/hasher.c b/fs/btrfs/hasher.c new file mode 100644 index 000000000000..96702da4329c --- /dev/null +++ b/fs/btrfs/hasher.c | |||
@@ -0,0 +1,23 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "kerncompat.h" | ||
5 | #include "hash.h" | ||
6 | |||
7 | int main() { | ||
8 | u64 result; | ||
9 | int ret; | ||
10 | char line[255]; | ||
11 | char *p; | ||
12 | while(1) { | ||
13 | p = fgets(line, 255, stdin); | ||
14 | if (!p) | ||
15 | break; | ||
16 | if (strlen(line) == 0) | ||
17 | continue; | ||
18 | ret = btrfs_name_hash(line, strlen(line), &result); | ||
19 | BUG_ON(ret); | ||
20 | printf("hash returns %Lu\n", result); | ||
21 | } | ||
22 | return 0; | ||
23 | } | ||
diff --git a/fs/btrfs/kerncompat.h b/fs/btrfs/kerncompat.h index 56239b922ba6..105d3f584089 100644 --- a/fs/btrfs/kerncompat.h +++ b/fs/btrfs/kerncompat.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | typedef unsigned int u32; | 23 | typedef unsigned int u32; |
24 | typedef u32 __u32; | ||
24 | typedef unsigned long long u64; | 25 | typedef unsigned long long u64; |
25 | typedef unsigned char u8; | 26 | typedef unsigned char u8; |
26 | typedef unsigned short u16; | 27 | typedef unsigned short u16; |
diff --git a/fs/btrfs/mkfs.c b/fs/btrfs/mkfs.c index 317d20ce759d..9aa900811c33 100644 --- a/fs/btrfs/mkfs.c +++ b/fs/btrfs/mkfs.c | |||
@@ -50,9 +50,10 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
50 | itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - sizeof(root_item); | 50 | itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - sizeof(root_item); |
51 | btrfs_set_item_offset(&item, itemoff); | 51 | btrfs_set_item_offset(&item, itemoff); |
52 | btrfs_set_item_size(&item, sizeof(root_item)); | 52 | btrfs_set_item_size(&item, sizeof(root_item)); |
53 | btrfs_set_key_objectid(&item.key, BTRFS_EXTENT_TREE_OBJECTID); | 53 | btrfs_set_disk_key_objectid(&item.key, BTRFS_EXTENT_TREE_OBJECTID); |
54 | btrfs_set_key_offset(&item.key, 0); | 54 | btrfs_set_disk_key_offset(&item.key, 0); |
55 | btrfs_set_key_flags(&item.key, 0); | 55 | btrfs_set_disk_key_flags(&item.key, 0); |
56 | btrfs_set_disk_key_type(&item.key, BTRFS_ROOT_ITEM_KEY); | ||
56 | memcpy(empty_leaf->items, &item, sizeof(item)); | 57 | memcpy(empty_leaf->items, &item, sizeof(item)); |
57 | memcpy(btrfs_leaf_data(empty_leaf) + itemoff, | 58 | memcpy(btrfs_leaf_data(empty_leaf) + itemoff, |
58 | &root_item, sizeof(root_item)); | 59 | &root_item, sizeof(root_item)); |
@@ -60,7 +61,7 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
60 | btrfs_set_root_blocknr(&root_item, start_block + 3); | 61 | btrfs_set_root_blocknr(&root_item, start_block + 3); |
61 | itemoff = itemoff - sizeof(root_item); | 62 | itemoff = itemoff - sizeof(root_item); |
62 | btrfs_set_item_offset(&item, itemoff); | 63 | btrfs_set_item_offset(&item, itemoff); |
63 | btrfs_set_key_objectid(&item.key, BTRFS_FS_TREE_OBJECTID); | 64 | btrfs_set_disk_key_objectid(&item.key, BTRFS_FS_TREE_OBJECTID); |
64 | memcpy(empty_leaf->items + 1, &item, sizeof(item)); | 65 | memcpy(empty_leaf->items + 1, &item, sizeof(item)); |
65 | memcpy(btrfs_leaf_data(empty_leaf) + itemoff, | 66 | memcpy(btrfs_leaf_data(empty_leaf) + itemoff, |
66 | &root_item, sizeof(root_item)); | 67 | &root_item, sizeof(root_item)); |
@@ -73,9 +74,10 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
73 | btrfs_set_header_nritems(&empty_leaf->header, 4); | 74 | btrfs_set_header_nritems(&empty_leaf->header, 4); |
74 | 75 | ||
75 | /* item1, reserve blocks 0-16 */ | 76 | /* item1, reserve blocks 0-16 */ |
76 | btrfs_set_key_objectid(&item.key, 0); | 77 | btrfs_set_disk_key_objectid(&item.key, 0); |
77 | btrfs_set_key_offset(&item.key, start_block + 1); | 78 | btrfs_set_disk_key_offset(&item.key, start_block + 1); |
78 | btrfs_set_key_flags(&item.key, 0); | 79 | btrfs_set_disk_key_flags(&item.key, 0); |
80 | btrfs_set_disk_key_type(&item.key, BTRFS_EXTENT_ITEM_KEY); | ||
79 | itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - | 81 | itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - |
80 | sizeof(struct btrfs_extent_item); | 82 | sizeof(struct btrfs_extent_item); |
81 | btrfs_set_item_offset(&item, itemoff); | 83 | btrfs_set_item_offset(&item, itemoff); |
@@ -87,8 +89,8 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
87 | &extent_item, btrfs_item_size(&item)); | 89 | &extent_item, btrfs_item_size(&item)); |
88 | 90 | ||
89 | /* item2, give block 17 to the root */ | 91 | /* item2, give block 17 to the root */ |
90 | btrfs_set_key_objectid(&item.key, start_block + 1); | 92 | btrfs_set_disk_key_objectid(&item.key, start_block + 1); |
91 | btrfs_set_key_offset(&item.key, 1); | 93 | btrfs_set_disk_key_offset(&item.key, 1); |
92 | itemoff = itemoff - sizeof(struct btrfs_extent_item); | 94 | itemoff = itemoff - sizeof(struct btrfs_extent_item); |
93 | btrfs_set_item_offset(&item, itemoff); | 95 | btrfs_set_item_offset(&item, itemoff); |
94 | btrfs_set_extent_owner(&extent_item, BTRFS_ROOT_TREE_OBJECTID); | 96 | btrfs_set_extent_owner(&extent_item, BTRFS_ROOT_TREE_OBJECTID); |
@@ -97,8 +99,8 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
97 | &extent_item, btrfs_item_size(&item)); | 99 | &extent_item, btrfs_item_size(&item)); |
98 | 100 | ||
99 | /* item3, give block 18 to the extent root */ | 101 | /* item3, give block 18 to the extent root */ |
100 | btrfs_set_key_objectid(&item.key, start_block + 2); | 102 | btrfs_set_disk_key_objectid(&item.key, start_block + 2); |
101 | btrfs_set_key_offset(&item.key, 1); | 103 | btrfs_set_disk_key_offset(&item.key, 1); |
102 | itemoff = itemoff - sizeof(struct btrfs_extent_item); | 104 | itemoff = itemoff - sizeof(struct btrfs_extent_item); |
103 | btrfs_set_item_offset(&item, itemoff); | 105 | btrfs_set_item_offset(&item, itemoff); |
104 | btrfs_set_extent_owner(&extent_item, BTRFS_EXTENT_TREE_OBJECTID); | 106 | btrfs_set_extent_owner(&extent_item, BTRFS_EXTENT_TREE_OBJECTID); |
@@ -107,8 +109,8 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize) | |||
107 | &extent_item, btrfs_item_size(&item)); | 109 | &extent_item, btrfs_item_size(&item)); |
108 | 110 | ||
109 | /* item4, give block 19 to the FS root */ | 111 | /* item4, give block 19 to the FS root */ |
110 | btrfs_set_key_objectid(&item.key, start_block + 3); | 112 | btrfs_set_disk_key_objectid(&item.key, start_block + 3); |
111 | btrfs_set_key_offset(&item.key, 1); | 113 | btrfs_set_disk_key_offset(&item.key, 1); |
112 | itemoff = itemoff - sizeof(struct btrfs_extent_item); | 114 | itemoff = itemoff - sizeof(struct btrfs_extent_item); |
113 | btrfs_set_item_offset(&item, itemoff); | 115 | btrfs_set_item_offset(&item, itemoff); |
114 | btrfs_set_extent_owner(&extent_item, BTRFS_FS_TREE_OBJECTID); | 116 | btrfs_set_extent_owner(&extent_item, BTRFS_FS_TREE_OBJECTID); |
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index 4c710190343d..f2745b247473 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c | |||
@@ -12,27 +12,41 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) | |||
12 | struct btrfs_item *item; | 12 | struct btrfs_item *item; |
13 | struct btrfs_extent_item *ei; | 13 | struct btrfs_extent_item *ei; |
14 | struct btrfs_root_item *ri; | 14 | struct btrfs_root_item *ri; |
15 | u32 type; | ||
15 | printf("leaf %Lu total ptrs %d free space %d\n", | 16 | printf("leaf %Lu total ptrs %d free space %d\n", |
16 | btrfs_header_blocknr(&l->header), nr, | 17 | btrfs_header_blocknr(&l->header), nr, |
17 | btrfs_leaf_free_space(root, l)); | 18 | btrfs_leaf_free_space(root, l)); |
18 | fflush(stdout); | 19 | fflush(stdout); |
19 | for (i = 0 ; i < nr ; i++) { | 20 | for (i = 0 ; i < nr ; i++) { |
20 | item = l->items + i; | 21 | item = l->items + i; |
22 | type = btrfs_disk_key_type(&item->key); | ||
21 | printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n", | 23 | printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n", |
22 | i, | 24 | i, |
23 | btrfs_key_objectid(&item->key), | 25 | btrfs_disk_key_objectid(&item->key), |
24 | btrfs_key_offset(&item->key), | 26 | btrfs_disk_key_offset(&item->key), |
25 | btrfs_key_flags(&item->key), | 27 | btrfs_disk_key_flags(&item->key), |
26 | btrfs_item_offset(item), | 28 | btrfs_item_offset(item), |
27 | btrfs_item_size(item)); | 29 | btrfs_item_size(item)); |
28 | printf("\t\titem data %.*s\n", btrfs_item_size(item), | 30 | switch (type) { |
29 | btrfs_leaf_data(l) + btrfs_item_offset(item)); | 31 | case BTRFS_INODE_ITEM_KEY: |
30 | ei = btrfs_item_ptr(l, i, struct btrfs_extent_item); | 32 | break; |
31 | printf("\t\textent data refs %u owner %Lu\n", | 33 | case BTRFS_DIR_ITEM_KEY: |
32 | btrfs_extent_refs(ei), btrfs_extent_owner(ei)); | 34 | break; |
33 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); | 35 | case BTRFS_ROOT_ITEM_KEY: |
34 | printf("\t\troot data blocknr %Lu refs %u\n", | 36 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); |
35 | btrfs_root_blocknr(ri), btrfs_root_refs(ri)); | 37 | printf("\t\troot data blocknr %Lu refs %u\n", |
38 | btrfs_root_blocknr(ri), btrfs_root_refs(ri)); | ||
39 | break; | ||
40 | case BTRFS_EXTENT_ITEM_KEY: | ||
41 | ei = btrfs_item_ptr(l, i, struct btrfs_extent_item); | ||
42 | printf("\t\textent data refs %u owner %Lu\n", | ||
43 | btrfs_extent_refs(ei), btrfs_extent_owner(ei)); | ||
44 | break; | ||
45 | case BTRFS_STRING_ITEM_KEY: | ||
46 | printf("\t\titem data %.*s\n", btrfs_item_size(item), | ||
47 | btrfs_leaf_data(l) + btrfs_item_offset(item)); | ||
48 | break; | ||
49 | }; | ||
36 | fflush(stdout); | 50 | fflush(stdout); |
37 | } | 51 | } |
38 | } | 52 | } |
diff --git a/fs/btrfs/quick-test.c b/fs/btrfs/quick-test.c index d9287cad35c9..3a2571617121 100644 --- a/fs/btrfs/quick-test.c +++ b/fs/btrfs/quick-test.c | |||
@@ -30,6 +30,8 @@ int main(int ac, char **av) { | |||
30 | 30 | ||
31 | root = open_ctree("dbfile", &super); | 31 | root = open_ctree("dbfile", &super); |
32 | srand(55); | 32 | srand(55); |
33 | ins.flags = 0; | ||
34 | btrfs_set_key_type(&ins, BTRFS_STRING_ITEM_KEY); | ||
33 | for (i = 0; i < run_size; i++) { | 35 | for (i = 0; i < run_size; i++) { |
34 | buf = malloc(64); | 36 | buf = malloc(64); |
35 | num = next_key(i, max_key); | 37 | num = next_key(i, max_key); |
@@ -39,7 +41,6 @@ int main(int ac, char **av) { | |||
39 | fprintf(stderr, "insert %d:%d\n", num, i); | 41 | fprintf(stderr, "insert %d:%d\n", num, i); |
40 | ins.objectid = num; | 42 | ins.objectid = num; |
41 | ins.offset = 0; | 43 | ins.offset = 0; |
42 | ins.flags = 0; | ||
43 | ret = btrfs_insert_item(root, &ins, buf, strlen(buf)); | 44 | ret = btrfs_insert_item(root, &ins, buf, strlen(buf)); |
44 | if (!ret) | 45 | if (!ret) |
45 | tree_size++; | 46 | tree_size++; |
diff --git a/fs/btrfs/random-test.c b/fs/btrfs/random-test.c index a8ef0478991b..f05135f13f9a 100644 --- a/fs/btrfs/random-test.c +++ b/fs/btrfs/random-test.c | |||
@@ -18,6 +18,7 @@ static int setup_key(struct radix_tree_root *root, struct btrfs_key *key, | |||
18 | int ret; | 18 | int ret; |
19 | 19 | ||
20 | key->flags = 0; | 20 | key->flags = 0; |
21 | btrfs_set_key_type(key, BTRFS_STRING_ITEM_KEY); | ||
21 | key->offset = 0; | 22 | key->offset = 0; |
22 | again: | 23 | again: |
23 | ret = radix_tree_gang_lookup(root, (void **)res, num, 2); | 24 | ret = radix_tree_gang_lookup(root, (void **)res, num, 2); |
@@ -157,6 +158,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix, | |||
157 | 158 | ||
158 | key.offset = 0; | 159 | key.offset = 0; |
159 | key.flags = 0; | 160 | key.flags = 0; |
161 | btrfs_set_key_type(&key, BTRFS_STRING_ITEM_KEY); | ||
160 | key.objectid = (unsigned long)-1; | 162 | key.objectid = (unsigned long)-1; |
161 | while(nr-- >= 0) { | 163 | while(nr-- >= 0) { |
162 | btrfs_init_path(&path); | 164 | btrfs_init_path(&path); |
@@ -173,7 +175,8 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix, | |||
173 | path.slots[0] -= 1; | 175 | path.slots[0] -= 1; |
174 | } | 176 | } |
175 | slot = path.slots[0]; | 177 | slot = path.slots[0]; |
176 | found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key); | 178 | found = btrfs_disk_key_objectid( |
179 | &path.nodes[0]->leaf.items[slot].key); | ||
177 | ret = btrfs_del_item(root, &path); | 180 | ret = btrfs_del_item(root, &path); |
178 | count++; | 181 | count++; |
179 | if (ret) { | 182 | if (ret) { |
@@ -257,6 +260,7 @@ static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix) | |||
257 | 260 | ||
258 | key.offset = 0; | 261 | key.offset = 0; |
259 | key.flags = 0; | 262 | key.flags = 0; |
263 | btrfs_set_key_type(&key, BTRFS_STRING_ITEM_KEY); | ||
260 | key.objectid = (unsigned long)-1; | 264 | key.objectid = (unsigned long)-1; |
261 | while(1) { | 265 | while(1) { |
262 | btrfs_init_path(&path); | 266 | btrfs_init_path(&path); |
@@ -274,8 +278,8 @@ static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix) | |||
274 | slot -= 1; | 278 | slot -= 1; |
275 | } | 279 | } |
276 | for (i = slot; i >= 0; i--) { | 280 | for (i = slot; i >= 0; i--) { |
277 | found = btrfs_key_objectid(&path.nodes[0]-> | 281 | found = btrfs_disk_key_objectid(&path.nodes[0]-> |
278 | leaf.items[i].key); | 282 | leaf.items[i].key); |
279 | radix_tree_preload(GFP_KERNEL); | 283 | radix_tree_preload(GFP_KERNEL); |
280 | ret = radix_tree_insert(radix, found, (void *)found); | 284 | ret = radix_tree_insert(radix, found, (void *)found); |
281 | if (ret) { | 285 | if (ret) { |
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 03aa7c2c6336..a24b47274037 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c | |||
@@ -27,7 +27,7 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, | |||
27 | l = &path.nodes[0]->leaf; | 27 | l = &path.nodes[0]->leaf; |
28 | BUG_ON(path.slots[0] == 0); | 28 | BUG_ON(path.slots[0] == 0); |
29 | slot = path.slots[0] - 1; | 29 | slot = path.slots[0] - 1; |
30 | if (btrfs_key_objectid(&l->items[slot].key) != objectid) { | 30 | if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) { |
31 | ret = 1; | 31 | ret = 1; |
32 | goto out; | 32 | goto out; |
33 | } | 33 | } |