aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-15 19:03:33 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-15 19:03:33 -0400
commit1e1d27017c5986c1ea81181506042cf9cba3f6ea (patch)
treeaad9439d33f45543d7b041c3609ab180c2283526
parent1d4f6404de26df49eb8452f8fdf7672b59f407fc (diff)
Btrfs: add inode item
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/Makefile2
-rw-r--r--fs/btrfs/TODO1
-rw-r--r--fs/btrfs/ctree.h175
-rw-r--r--fs/btrfs/file-item.c7
-rw-r--r--fs/btrfs/inode-item.c37
5 files changed, 215 insertions, 7 deletions
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index ea3e1493baa9..36964f54bb47 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -2,7 +2,7 @@ CC=gcc
2CFLAGS = -g -Wall 2CFLAGS = -g -Wall
3headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h 3headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h
4objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \ 4objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \
5 root-tree.o dir-item.o hash.o 5 root-tree.o dir-item.o hash.o file-item.o inode-item.o
6 6
7# if you don't have sparse installed, use ls instead 7# if you don't have sparse installed, use ls instead
8CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ 8CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
diff --git a/fs/btrfs/TODO b/fs/btrfs/TODO
index 249e2e90bea8..2ae4b3aae1e5 100644
--- a/fs/btrfs/TODO
+++ b/fs/btrfs/TODO
@@ -9,6 +9,7 @@
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* Do actual block accounting
12* Check compat and incompat flags on the inode
12* Port into the kernel 13* Port into the kernel
13* Add virtual filesystems, mountable snapshots 14* Add virtual filesystems, mountable snapshots
14* Get rid of struct ctree_path, limiting tree levels held at one time 15* Get rid of struct ctree_path, limiting tree levels held at one time
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7a3492d5888e..dbf3917833fe 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -132,6 +132,37 @@ struct btrfs_extent_item {
132 __le64 owner; 132 __le64 owner;
133} __attribute__ ((__packed__)); 133} __attribute__ ((__packed__));
134 134
135struct btrfs_inode_timespec {
136 __le32 sec;
137 __le32 nsec;
138} __attribute__ ((__packed__));
139
140/*
141 * there is no padding here on purpose. If you want to extent the inode,
142 * make a new item type
143 */
144struct btrfs_inode_item {
145 __le64 generation;
146 __le64 size;
147 __le64 nblocks;
148 __le32 nlink;
149 __le32 uid;
150 __le32 gid;
151 __le32 mode;
152 __le32 rdev;
153 __le16 flags;
154 __le16 compat_flags;
155 struct btrfs_inode_timespec atime;
156 struct btrfs_inode_timespec ctime;
157 struct btrfs_inode_timespec mtime;
158 struct btrfs_inode_timespec otime;
159} __attribute__ ((__packed__));
160
161/* inline data is just a blob of bytes */
162struct btrfs_inline_data_item {
163 u8 data;
164} __attribute__ ((__packed__));
165
135struct btrfs_dir_item { 166struct btrfs_dir_item {
136 __le64 objectid; 167 __le64 objectid;
137 __le16 flags; 168 __le16 flags;
@@ -170,15 +201,149 @@ struct btrfs_root {
170 u32 blocksize; 201 u32 blocksize;
171}; 202};
172 203
173
174/* the lower bits in the key flags defines the item type */ 204/* the lower bits in the key flags defines the item type */
175#define BTRFS_KEY_TYPE_MAX 256 205#define BTRFS_KEY_TYPE_MAX 256
176#define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) 206#define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
207
208/*
209 * inode items have the data typically returned from stat and store other
210 * info about object characteristics. There is one for every file and dir in
211 * the FS
212 */
177#define BTRFS_INODE_ITEM_KEY 1 213#define BTRFS_INODE_ITEM_KEY 1
214
215/*
216 * dir items are the name -> inode pointers in a directory. There is one
217 * for every name in a directory.
218 */
178#define BTRFS_DIR_ITEM_KEY 2 219#define BTRFS_DIR_ITEM_KEY 2
179#define BTRFS_ROOT_ITEM_KEY 3 220/*
180#define BTRFS_EXTENT_ITEM_KEY 4 221 * inline data is file data that fits in the btree.
181#define BTRFS_STRING_ITEM_KEY 5 222 */
223#define BTRFS_INLINE_DATA_KEY 3
224/*
225 * extent data is for data that can't fit in the btree. It points to
226 * a (hopefully) huge chunk of disk
227 */
228#define BTRFS_EXTENT_DATA_KEY 4
229/*
230 * root items point to tree roots. There are typically in the root
231 * tree used by the super block to find all the other trees
232 */
233#define BTRFS_ROOT_ITEM_KEY 5
234/*
235 * extent items are in the extent map tree. These record which blocks
236 * are used, and how many references there are to each block
237 */
238#define BTRFS_EXTENT_ITEM_KEY 6
239/*
240 * string items are for debugging. They just store a short string of
241 * data in the FS
242 */
243#define BTRFS_STRING_ITEM_KEY 7
244
245static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
246{
247 return le64_to_cpu(i->generation);
248}
249
250static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
251 u64 val)
252{
253 i->generation = cpu_to_le64(val);
254}
255
256static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
257{
258 return le64_to_cpu(i->size);
259}
260
261static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
262{
263 i->size = cpu_to_le64(val);
264}
265
266static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
267{
268 return le64_to_cpu(i->nblocks);
269}
270
271static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
272{
273 i->nblocks = cpu_to_le64(val);
274}
275
276static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
277{
278 return le32_to_cpu(i->nlink);
279}
280
281static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
282{
283 i->nlink = cpu_to_le32(val);
284}
285
286static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
287{
288 return le32_to_cpu(i->uid);
289}
290
291static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
292{
293 i->uid = cpu_to_le32(val);
294}
295
296static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
297{
298 return le32_to_cpu(i->gid);
299}
300
301static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
302{
303 i->gid = cpu_to_le32(val);
304}
305
306static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
307{
308 return le32_to_cpu(i->mode);
309}
310
311static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
312{
313 i->mode = cpu_to_le32(val);
314}
315
316static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
317{
318 return le32_to_cpu(i->rdev);
319}
320
321static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
322{
323 i->rdev = cpu_to_le32(val);
324}
325
326static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
327{
328 return le16_to_cpu(i->flags);
329}
330
331static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
332{
333 i->flags = cpu_to_le16(val);
334}
335
336static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
337{
338 return le16_to_cpu(i->compat_flags);
339}
340
341static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
342 u16 val)
343{
344 i->compat_flags = cpu_to_le16(val);
345}
346
182 347
183static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) 348static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
184{ 349{
@@ -344,8 +509,6 @@ static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
344 btrfs_set_disk_key_flags(key, flags); 509 btrfs_set_disk_key_flags(key, flags);
345} 510}
346 511
347
348
349static inline u64 btrfs_header_blocknr(struct btrfs_header *h) 512static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
350{ 513{
351 return le64_to_cpu(h->blocknr); 514 return le64_to_cpu(h->blocknr);
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
new file mode 100644
index 000000000000..f5b36c732c5e
--- /dev/null
+++ b/fs/btrfs/file-item.c
@@ -0,0 +1,7 @@
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
diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c
new file mode 100644
index 000000000000..4908f9afdf86
--- /dev/null
+++ b/fs/btrfs/inode-item.c
@@ -0,0 +1,37 @@
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
8int btrfs_insert_inode(struct btrfs_root *root, u64 objectid,
9 struct btrfs_inode_item *inode_item)
10{
11 struct btrfs_path path;
12 struct btrfs_key key;
13 int ret;
14 key.objectid = objectid;
15 key.flags = 0;
16 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
17 key.offset = 0;
18
19 btrfs_init_path(&path);
20 ret = btrfs_insert_item(root, &key, inode_item, sizeof(*inode_item));
21 btrfs_release_path(root, &path);
22 return ret;
23}
24
25int btrfs_lookup_inode(struct btrfs_root *root, struct btrfs_path *path,
26 u64 objectid, int mod)
27{
28 struct btrfs_key key;
29 int ins_len = mod < 0 ? -1 : 0;
30 int cow = mod != 0;
31
32 key.objectid = objectid;
33 key.flags = 0;
34 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
35 key.offset = 0;
36 return btrfs_search_slot(root, &key, path, ins_len, cow);
37}