Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb60ceac authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse
Browse files

Btrfs: Add backing store, memory management

parent 4920c9ac
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line

ctree: ctree.o
	gcc -g -O2 -Wall -o ctree ctree.c
CFLAGS= -g -Wall

.c.o:
	$(CC) $(CFLAGS) -c $<

ctree: ctree.o disk-io.h ctree.h disk-io.o radix-tree.o radix-tree.h
	gcc $(CFLAGS) -o ctree ctree.o disk-io.o radix-tree.o

clean:
	rm ctree ctree.o
	rm ctree *.o
+272 −160

File changed.

Preview size limit exceeded, changes collapsed.

fs/btrfs/ctree.h

0 → 100644
+62 −0
Original line number Diff line number Diff line
#ifndef __CTREE__
#define __CTREE__

#define CTREE_BLOCKSIZE 4096

struct key {
	u64 objectid;
	u32 flags;
	u64 offset;
} __attribute__ ((__packed__));

struct header {
	u64 fsid[2]; /* FS specific uuid */
	u64 blocknr;
	u64 parentid;
	u32 csum;
	u32 ham;
	u16 nritems;
	u16 flags;
} __attribute__ ((__packed__));

#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \
			    (sizeof(struct key) + sizeof(u64)))

#define LEVEL_BITS 3
#define MAX_LEVEL (1 << LEVEL_BITS)
#define node_level(f) ((f) & (MAX_LEVEL-1))
#define is_leaf(f) (node_level(f) == 0)

struct tree_buffer;
struct ctree_root {
	struct tree_buffer *node;
	int fp;
	struct radix_tree_root cache_radix;
};

struct item {
	struct key key;
	u16 offset;
	u16 size;
} __attribute__ ((__packed__));

#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
struct leaf {
	struct header header;
	union {
		struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
		u8 data[CTREE_BLOCKSIZE-sizeof(struct header)];
	};
} __attribute__ ((__packed__));

struct node {
	struct header header;
	struct key keys[NODEPTRS_PER_BLOCK];
	u64 blockptrs[NODEPTRS_PER_BLOCK];
} __attribute__ ((__packed__));

struct ctree_path {
	struct tree_buffer *nodes[MAX_LEVEL];
	int slots[MAX_LEVEL];
};
#endif

fs/btrfs/disk-io.c

0 → 100644
+174 −0

File added.

Preview size limit exceeded, changes collapsed.

fs/btrfs/disk-io.h

0 → 100644
+21 −0
Original line number Diff line number Diff line
#ifndef __DISKIO__
#define __DISKIO__

struct tree_buffer {
	u64 blocknr;
	int count;
	union {
		struct node node;
		struct leaf leaf;
	};
};

struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr);
int write_tree_block(struct ctree_root *root, struct tree_buffer *buf);
struct ctree_root *open_ctree(char *filename);
int close_ctree(struct ctree_root *root);
void tree_block_release(struct ctree_root *root, struct tree_buffer *buf);
struct tree_buffer *alloc_free_block(struct ctree_root *root);
int update_root_block(struct ctree_root *root);

#endif
Loading