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

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

Btrfs: Better block record keeping, real mkfs

parent 293ffd5f
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ CC=gcc
CFLAGS = -g -Wall -Werror
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h \
	  transaction.h
objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \
objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
	  root-tree.o dir-item.o hash.o file-item.o inode-item.o \
	  inode-map.o \

@@ -16,7 +16,10 @@ check=sparse $(CHECKFLAGS)
	$(check) $<
	$(CC) $(CFLAGS) -c $<

all: tester debug-tree quick-test dir-test tags
all: tester debug-tree quick-test dir-test tags mkfs.btrfs

mkfs.btrfs: $(objects) mkfs.o
	gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o

debug-tree: $(objects) debug-tree.o
	gcc $(CFLAGS) -o debug-tree $(objects) debug-tree.o
+1 −0
Original line number Diff line number Diff line
@@ -223,6 +223,7 @@ struct btrfs_fs_info {
	int cache_size;
	int fp;
	struct btrfs_trans_handle *running_transaction;
	struct btrfs_super_block *disk_super;
};

/*
+12 −1
Original line number Diff line number Diff line
@@ -10,8 +10,17 @@
int main(int ac, char **av) {
	struct btrfs_super_block super;
	struct btrfs_root *root;

	if (ac != 2) {
		fprintf(stderr, "usage: %s device\n", av[0]);
		exit(1);
	}
	radix_tree_init();
	root = open_ctree("dbfile", &super);
	root = open_ctree(av[1], &super);
	if (!root) {
		fprintf(stderr, "unable to open %s\n", av[1]);
		exit(1);
	}
	printf("fs tree\n");
	btrfs_print_tree(root, root->node);
	printf("map tree\n");
@@ -23,5 +32,7 @@ int main(int ac, char **av) {
	printf("root tree\n");
	btrfs_print_tree(root->fs_info->tree_root,
			 root->fs_info->tree_root->node);
	printf("total blocks %Lu\n", btrfs_super_total_blocks(&super));
	printf("blocks used %Lu\n", btrfs_super_blocks_used(&super));
	return 0;
}
+0 −2
Original line number Diff line number Diff line
@@ -425,8 +425,6 @@ int main(int ac, char **av)
	struct btrfs_trans_handle *trans;
	radix_tree_init();

	printf("removing old tree\n");
	unlink("dbfile");
	root = open_ctree("dbfile", &super);
	trans = btrfs_start_transaction(root, 1);

+3 −8
Original line number Diff line number Diff line
@@ -293,19 +293,14 @@ struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super)
	fs_info->inode_root = inode_root;
	fs_info->last_inode_alloc = 0;
	fs_info->last_inode_alloc_dirid = 0;
	fs_info->disk_super = super;
	memset(&fs_info->current_insert, 0, sizeof(fs_info->current_insert));
	memset(&fs_info->last_insert, 0, sizeof(fs_info->last_insert));

	ret = pread(fp, super, sizeof(struct btrfs_super_block),
		     BTRFS_SUPER_INFO_OFFSET);
	if (ret == 0 || btrfs_super_root(super) == 0) {
		printf("making new FS!\n");
		ret = mkfs(fp, 0, 1024);
		if (ret)
			return NULL;
		ret = pread(fp, super, sizeof(struct btrfs_super_block),
			     BTRFS_SUPER_INFO_OFFSET);
		if (ret != sizeof(struct btrfs_super_block))
		BUG();
		return NULL;
	}
	BUG_ON(ret < 0);
Loading