diff --git a/Makefile b/Makefile index 92caf10a..54b0f7d2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS = -O2 -g -Wall -fno-strict-aliasing -Werror +CFLAGS = -g -Wall -fno-strict-aliasing -Werror 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 \ @@ -7,6 +7,10 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef +INSTALL= install +prefix = /usr/local +bindir = $(prefix)/bin + progs = btrfsctl btrfsck mkfs.btrfs debug-tree # make C=1 to enable sparse @@ -49,6 +53,10 @@ quick-test: $(objects) quick-test.o clean : rm -f $(progs) cscope.out *.o .depend +install: $(progs) + $(INSTALL) -m755 -d $(DESTDIR)$(bindir) + $(INSTALL) $(progs) $(DESTDIR)$(bindir) + ifneq ($(wildcard .depend),) include .depend endif diff --git a/btrfsck.c b/btrfsck.c index 580fe440..e46e4acc 100644 --- a/btrfsck.c +++ b/btrfsck.c @@ -316,11 +316,13 @@ static int run_next_block(struct btrfs_root *root, struct btrfs_block_group_item *bi; bi = btrfs_item_ptr(leaf, i, struct btrfs_block_group_item); +#if 0 fprintf(stderr,"block group %Lu %Lu used %Lu ", btrfs_disk_key_objectid(disk_key), btrfs_disk_key_offset(disk_key), btrfs_block_group_used(bi)); fprintf(stderr, "flags %x\n", bi->flags); +#endif continue; } if (btrfs_disk_key_type(&leaf->items[i].key) != @@ -452,8 +454,6 @@ int main(int ac, char **av) { add_root_to_pending(root->fs_info->tree_root->node, bits, bits_nr, &extent_radix, &pending, &seen, &reada, &nodes); - add_root_to_pending(root->fs_info->dev_root->node, bits, bits_nr, - &extent_radix, &pending, &seen, &reada, &nodes); btrfs_init_path(&path); key.offset = 0; diff --git a/btrfsctl.c b/btrfsctl.c index 3710bc6a..74c39187 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -52,18 +52,6 @@ int main(int ac, char **av) } command = BTRFS_IOC_SNAP_CREATE; } - if (strcmp(av[i], "-a") == 0) { - if (i + 1 >= ac - 1) { - fprintf(stderr, "-a requires an arg"); - print_usage(); - } - name = av[i + 1]; - if (strlen(name) >= BTRFS_VOL_NAME_MAX) { - fprintf(stderr, "device name is too long\n"); - exit(1); - } - command = BTRFS_IOC_ADD_DISK; - } } if (command == 0) { fprintf(stderr, "no valid commands given\n"); diff --git a/ctree.h b/ctree.h index 9240fef5..b6944ec2 100644 --- a/ctree.h +++ b/ctree.h @@ -9,11 +9,10 @@ struct btrfs_trans_handle; #define BTRFS_MAGIC "_BtRfS_M" #define BTRFS_ROOT_TREE_OBJECTID 1ULL -#define BTRFS_DEV_TREE_OBJECTID 2ULL -#define BTRFS_EXTENT_TREE_OBJECTID 3ULL -#define BTRFS_FS_TREE_OBJECTID 4ULL -#define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL -#define BTRFS_FIRST_FREE_OBJECTID 6ULL +#define BTRFS_EXTENT_TREE_OBJECTID 2ULL +#define BTRFS_FS_TREE_OBJECTID 3ULL +#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL +#define BTRFS_FIRST_FREE_OBJECTID 5ULL /* * we can actually store much bigger names, but lets not confuse the rest @@ -98,12 +97,6 @@ struct btrfs_super_block { __le64 total_blocks; __le64 blocks_used; __le64 root_dir_objectid; - __le64 last_device_id; - /* fields below here vary with the underlying disk */ - __le64 device_block_start; - __le64 device_num_blocks; - __le64 device_root; - __le64 device_id; } __attribute__ ((__packed__)); /* @@ -243,11 +236,6 @@ struct btrfs_csum_item { u8 csum[BTRFS_CSUM_SIZE]; } __attribute__ ((__packed__)); -struct btrfs_device_item { - __le16 pathlen; - __le64 device_id; -} __attribute__ ((__packed__)); - /* tag for the radix tree of block groups in ram */ #define BTRFS_BLOCK_GROUP_DIRTY 0 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024) @@ -268,12 +256,10 @@ struct btrfs_fs_info { struct btrfs_root *fs_root; struct btrfs_root *extent_root; struct btrfs_root *tree_root; - struct btrfs_root *dev_root; struct btrfs_key current_insert; struct btrfs_key last_insert; struct radix_tree_root cache_radix; struct radix_tree_root pinned_radix; - struct radix_tree_root dev_radix; struct radix_tree_root block_group_radix; struct list_head trans; struct list_head cache; @@ -351,11 +337,6 @@ struct btrfs_root { */ #define BTRFS_BLOCK_GROUP_ITEM_KEY 34 -/* - * dev items list the devices that make up the FS - */ -#define BTRFS_DEV_ITEM_KEY 35 - /* * string items are for debugging. They just store a short string of * data in the FS @@ -846,61 +827,6 @@ static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 s->root_dir_objectid = cpu_to_le64(val); } -static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s) -{ - return le64_to_cpu(s->last_device_id); -} - -static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s, - u64 val) -{ - s->last_device_id = cpu_to_le64(val); -} - -static inline u64 btrfs_super_device_id(struct btrfs_super_block *s) -{ - return le64_to_cpu(s->device_id); -} - -static inline void btrfs_set_super_device_id(struct btrfs_super_block *s, - u64 val) -{ - s->device_id = cpu_to_le64(val); -} - -static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s) -{ - return le64_to_cpu(s->device_block_start); -} - -static inline void btrfs_set_super_device_block_start(struct btrfs_super_block - *s, u64 val) -{ - s->device_block_start = cpu_to_le64(val); -} - -static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s) -{ - return le64_to_cpu(s->device_num_blocks); -} - -static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block - *s, u64 val) -{ - s->device_num_blocks = cpu_to_le64(val); -} - -static inline u64 btrfs_super_device_root(struct btrfs_super_block *s) -{ - return le64_to_cpu(s->device_root); -} - -static inline void btrfs_set_super_device_root(struct btrfs_super_block - *s, u64 val) -{ - s->device_root = cpu_to_le64(val); -} - static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) { return (u8 *)l->items; @@ -996,28 +922,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct e->num_blocks = cpu_to_le64(val); } -static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d) -{ - return le16_to_cpu(d->pathlen); -} - -static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d, - u16 val) -{ - d->pathlen = cpu_to_le16(val); -} - -static inline u64 btrfs_device_id(struct btrfs_device_item *d) -{ - return le64_to_cpu(d->device_id); -} - -static inline void btrfs_set_device_id(struct btrfs_device_item *d, - u64 val) -{ - d->device_id = cpu_to_le64(val); -} - /* helper function to cast into the data area of the leaf. */ #define btrfs_item_ptr(leaf, slot, type) \ ((type *)(btrfs_leaf_data(leaf) + \ diff --git a/debug-tree.c b/debug-tree.c index 229546ae..9699e3c4 100644 --- a/debug-tree.c +++ b/debug-tree.c @@ -33,9 +33,6 @@ 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("dev tree\n"); - btrfs_print_tree(root->fs_info->dev_root, - root->fs_info->dev_root->node); btrfs_init_path(&path); key.offset = 0; key.objectid = 0; @@ -66,9 +63,6 @@ int main(int ac, char **av) { case BTRFS_ROOT_TREE_OBJECTID: printf("root "); break; - case BTRFS_DEV_TREE_OBJECTID: - printf("dev tree "); - break; case BTRFS_EXTENT_TREE_OBJECTID: printf("extent tree "); break; diff --git a/disk-io.c b/disk-io.c index d6a7a466..cb10c2d3 100644 --- a/disk-io.c +++ b/disk-io.c @@ -15,58 +15,12 @@ static int allocated_blocks = 0; int cache_max = 10000; -struct dev_lookup { - u64 block_start; - u64 num_blocks; - u64 device_id; - int fd; -}; - -int btrfs_insert_dev_radix(struct btrfs_root *root, - int fd, - u64 device_id, - u64 block_start, - u64 num_blocks) -{ - struct dev_lookup *lookup; - int ret; - - lookup = malloc(sizeof(*lookup)); - if (!lookup) - return -ENOMEM; - lookup->block_start = block_start; - lookup->num_blocks = num_blocks; - lookup->fd = fd; - lookup->device_id = device_id; -printf("inserting into dev radix %Lu %Lu\n", block_start, num_blocks); - - ret = radix_tree_insert(&root->fs_info->dev_radix, block_start + - num_blocks - 1, lookup); - return ret; -} - int btrfs_map_bh_to_logical(struct btrfs_root *root, struct btrfs_buffer *bh, u64 logical) { - struct dev_lookup *lookup[2]; - - int ret; - - root = root->fs_info->dev_root; - ret = radix_tree_gang_lookup(&root->fs_info->dev_radix, - (void **)lookup, - (unsigned long)logical, - ARRAY_SIZE(lookup)); - if (ret == 0 || lookup[0]->block_start > logical || - lookup[0]->block_start + lookup[0]->num_blocks <= logical) { - ret = -1; - goto out; - } - bh->fd = lookup[0]->fd; - bh->dev_blocknr = logical - lookup[0]->block_start; - ret = 0; -out: - return ret; + bh->fd = root->fs_info->fp; + bh->dev_blocknr = logical; + return 0; } static int check_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf) @@ -230,11 +184,6 @@ static int commit_tree_roots(struct btrfs_trans_handle *trans, struct btrfs_root *tree_root = fs_info->tree_root; struct btrfs_root *extent_root = fs_info->extent_root; - if (btrfs_super_device_root(fs_info->disk_super) != - fs_info->dev_root->node->blocknr) { - btrfs_set_super_device_root(fs_info->disk_super, - fs_info->dev_root->node->blocknr); - } btrfs_write_dirty_block_groups(trans, fs_info->extent_root); while(1) { old_extent_block = btrfs_root_blocknr(&extent_root->root_item); @@ -326,89 +275,6 @@ static int find_and_setup_root(struct btrfs_super_block *super, return 0; } -int btrfs_open_disk(struct btrfs_root *root, u64 device_id, - u64 block_start, u64 num_blocks, - char *filename, int name_len) -{ - char *null_filename; - int fd; - int ret; - - null_filename = malloc(name_len + 1); - if (!null_filename) - return -ENOMEM; - memcpy(null_filename, filename, name_len); - null_filename[name_len] = '\0'; - - fd = open(null_filename, O_RDWR); - if (fd < 0) { - ret = -1; - goto out; - } - - posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); - posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE); - ret = btrfs_insert_dev_radix(root, fd, device_id, - block_start, num_blocks); - BUG_ON(ret); - ret = 0; -out: - free(null_filename); - return ret; -} - -static int read_device_info(struct btrfs_root *root) -{ - struct btrfs_path path; - int ret; - struct btrfs_key key; - struct btrfs_leaf *leaf; - struct btrfs_device_item *dev_item; - int nritems; - int slot; - - root = root->fs_info->dev_root; - - btrfs_init_path(&path); - key.objectid = 0; - key.offset = 0; - key.flags = 0; - btrfs_set_key_type(&key, BTRFS_DEV_ITEM_KEY); - - ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); - leaf = &path.nodes[0]->leaf; - nritems = btrfs_header_nritems(&leaf->header); - while(1) { - slot = path.slots[0]; - if (slot >= nritems) { - ret = btrfs_next_leaf(root, &path); - if (ret) - break; - leaf = &path.nodes[0]->leaf; - nritems = btrfs_header_nritems(&leaf->header); - slot = path.slots[0]; - } - btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key); - if (btrfs_key_type(&key) != BTRFS_DEV_ITEM_KEY) { - path.slots[0]++; - continue; - } - dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_device_item); - if (btrfs_device_id(dev_item) != - btrfs_super_device_id(root->fs_info->disk_super)) { -printf("found key %Lu %Lu\n", key.objectid, key.offset); - ret = btrfs_open_disk(root, btrfs_device_id(dev_item), - key.objectid, key.offset, - (char *)(dev_item + 1), - btrfs_device_pathlen(dev_item)); - BUG_ON(ret); - } - path.slots[0]++; - } - btrfs_release_path(root, &path); - return 0; -} - struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super) { int fp; @@ -425,14 +291,11 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) struct btrfs_root *root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *tree_root = malloc(sizeof(struct btrfs_root)); - struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); - struct dev_lookup *dev_lookup; int ret; INIT_RADIX_TREE(&fs_info->cache_radix, GFP_KERNEL); INIT_RADIX_TREE(&fs_info->pinned_radix, GFP_KERNEL); - INIT_RADIX_TREE(&fs_info->dev_radix, GFP_KERNEL); INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL); INIT_LIST_HEAD(&fs_info->trans); INIT_LIST_HEAD(&fs_info->cache); @@ -442,7 +305,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) fs_info->fs_root = root; fs_info->tree_root = tree_root; fs_info->extent_root = extent_root; - fs_info->dev_root = dev_root; fs_info->last_inode_alloc = 0; fs_info->last_inode_alloc_dirid = 0; fs_info->disk_super = super; @@ -456,23 +318,6 @@ struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super) return NULL; } BUG_ON(ret < 0); - __setup_root(super, dev_root, fs_info, BTRFS_DEV_TREE_OBJECTID, fp); - - dev_lookup = malloc(sizeof(*dev_lookup)); - dev_lookup->fd = fp; - dev_lookup->device_id = btrfs_super_device_id(super); - dev_lookup->block_start = btrfs_super_device_block_start(super); - dev_lookup->num_blocks = btrfs_super_device_num_blocks(super); - ret = radix_tree_insert(&fs_info->dev_radix, - dev_lookup->block_start + - dev_lookup->num_blocks - 1, dev_lookup); - BUG_ON(ret); - - dev_root->node = read_tree_block(dev_root, - btrfs_super_device_root(super)); - - ret = read_device_info(dev_root); - BUG_ON(ret); __setup_root(super, tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID, fp); tree_root->node = read_tree_block(tree_root, btrfs_super_root(super)); @@ -520,30 +365,6 @@ static int drop_cache(struct btrfs_root *root) return 0; } -static int free_dev_radix(struct btrfs_fs_info *fs_info) -{ - struct dev_lookup *lookup[8]; - int ret; - int i; - while(1) { - ret = radix_tree_gang_lookup(&fs_info->dev_radix, - (void **)lookup, 0, - ARRAY_SIZE(lookup)); - if (!ret) - break; - for (i = 0; i < ret; i++) { - if (lookup[i]->device_id != - btrfs_super_device_id(fs_info->disk_super)) - close(lookup[i]->fd); - radix_tree_delete(&fs_info->dev_radix, - lookup[i]->block_start + - lookup[i]->num_blocks - 1); - free(lookup[i]); - } - } - return 0; -} - int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s) { int ret; @@ -559,7 +380,6 @@ int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s) drop_cache(root); BUG_ON(!list_empty(&root->fs_info->trans)); - free_dev_radix(root->fs_info); btrfs_free_block_groups(root->fs_info); close(root->fs_info->fp); if (root->node) @@ -570,9 +390,6 @@ int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s) if (root->fs_info->tree_root->node) btrfs_block_release(root->fs_info->tree_root, root->fs_info->tree_root->node); - if (root->fs_info->dev_root->node) - btrfs_block_release(root->fs_info->dev_root, - root->fs_info->dev_root->node); btrfs_block_release(root, root->commit_root); free(root); printf("on close %d blocks are allocated\n", allocated_blocks); diff --git a/mkfs.c b/mkfs.c index 14b1b898..4acadff9 100644 --- a/mkfs.c +++ b/mkfs.c @@ -166,12 +166,10 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) struct btrfs_item item; struct btrfs_extent_item extent_item; struct btrfs_inode_item *inode_item; - struct btrfs_device_item dev_item; char *block; int ret; u32 itemoff; u32 start_block = BTRFS_SUPER_INFO_OFFSET / blocksize; - u16 item_size; btrfs_set_super_generation(&super, 1); btrfs_set_super_blocknr(&super, start_block); @@ -179,12 +177,7 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) strcpy((char *)(&super.magic), BTRFS_MAGIC); btrfs_set_super_blocksize(&super, blocksize); btrfs_set_super_total_blocks(&super, num_blocks); - btrfs_set_super_blocks_used(&super, start_block + 5); - btrfs_set_super_device_block_start(&super, 0); - btrfs_set_super_device_num_blocks(&super, num_blocks); - btrfs_set_super_device_root(&super, start_block + 2); - btrfs_set_super_device_id(&super, 1); - btrfs_set_super_last_device_id(&super, 1); + btrfs_set_super_blocks_used(&super, start_block + 4); uuid_generate(super.fsid); block = malloc(blocksize); @@ -221,14 +214,14 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) btrfs_set_disk_key_type(&item.key, BTRFS_ROOT_ITEM_KEY); itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - sizeof(root_item); - btrfs_set_root_blocknr(&root_item, start_block + 3); + btrfs_set_root_blocknr(&root_item, start_block + 2); btrfs_set_item_offset(&item, itemoff); btrfs_set_disk_key_objectid(&item.key, BTRFS_EXTENT_TREE_OBJECTID); memcpy(empty_leaf->items, &item, sizeof(item)); memcpy(btrfs_leaf_data(empty_leaf) + itemoff, &root_item, sizeof(root_item)); - btrfs_set_root_blocknr(&root_item, start_block + 4); + btrfs_set_root_blocknr(&root_item, start_block + 3); itemoff = itemoff - sizeof(root_item); btrfs_set_item_offset(&item, itemoff); btrfs_set_disk_key_objectid(&item.key, BTRFS_FS_TREE_OBJECTID); @@ -237,32 +230,9 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) &root_item, sizeof(root_item)); ret = pwrite(fd, empty_leaf, blocksize, (start_block + 1) * blocksize); - /* create the item for the dev tree */ - btrfs_set_header_blocknr(&empty_leaf->header, start_block + 2); - btrfs_set_header_nritems(&empty_leaf->header, 1); - btrfs_set_disk_key_objectid(&item.key, 0); - btrfs_set_disk_key_offset(&item.key, num_blocks); - btrfs_set_disk_key_flags(&item.key, 0); - btrfs_set_disk_key_type(&item.key, BTRFS_DEV_ITEM_KEY); - - item_size = sizeof(struct btrfs_device_item) + strlen(pathname); - itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) - item_size; - btrfs_set_item_offset(&item, itemoff); - btrfs_set_item_size(&item, item_size); - btrfs_set_device_pathlen(&dev_item, strlen(pathname)); - btrfs_set_device_id(&dev_item, 1); - memcpy(empty_leaf->items, &item, sizeof(item)); - memcpy(btrfs_leaf_data(empty_leaf) + itemoff, &dev_item, - sizeof(dev_item)); - memcpy(btrfs_leaf_data(empty_leaf) + itemoff + sizeof(dev_item), - pathname, strlen(pathname)); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 2) * blocksize); - if (ret != blocksize) - return -1; - /* create the items for the extent tree */ - btrfs_set_header_blocknr(&empty_leaf->header, start_block + 3); - btrfs_set_header_nritems(&empty_leaf->header, 5); + btrfs_set_header_blocknr(&empty_leaf->header, start_block + 2); + btrfs_set_header_nritems(&empty_leaf->header, 4); /* item1, reserve blocks 0-16 */ btrfs_set_disk_key_objectid(&item.key, 0); @@ -288,7 +258,7 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), &extent_item, btrfs_item_size(&item)); - /* item3, give block 18 to the dev root */ + /* item3, give block 18 to the extent root */ btrfs_set_disk_key_objectid(&item.key, start_block + 2); btrfs_set_disk_key_offset(&item.key, 1); itemoff = itemoff - sizeof(struct btrfs_extent_item); @@ -297,7 +267,7 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), &extent_item, btrfs_item_size(&item)); - /* item4, give block 19 to the extent root */ + /* item4, give block 19 to the FS root */ btrfs_set_disk_key_objectid(&item.key, start_block + 3); btrfs_set_disk_key_offset(&item.key, 1); itemoff = itemoff - sizeof(struct btrfs_extent_item); @@ -305,23 +275,14 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize) memcpy(empty_leaf->items + 3, &item, sizeof(item)); memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), &extent_item, btrfs_item_size(&item)); - - /* item5, give block 20 to the FS root */ - btrfs_set_disk_key_objectid(&item.key, start_block + 4); - btrfs_set_disk_key_offset(&item.key, 1); - itemoff = itemoff - sizeof(struct btrfs_extent_item); - btrfs_set_item_offset(&item, itemoff); - memcpy(empty_leaf->items + 4, &item, sizeof(item)); - memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item), - &extent_item, btrfs_item_size(&item)); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 3) * blocksize); + ret = pwrite(fd, empty_leaf, blocksize, (start_block + 2) * blocksize); if (ret != blocksize) return -1; /* finally create the FS root */ - btrfs_set_header_blocknr(&empty_leaf->header, start_block + 4); + btrfs_set_header_blocknr(&empty_leaf->header, start_block + 3); btrfs_set_header_nritems(&empty_leaf->header, 0); - ret = pwrite(fd, empty_leaf, blocksize, (start_block + 4) * blocksize); + ret = pwrite(fd, empty_leaf, blocksize, (start_block + 3) * blocksize); if (ret != blocksize) return -1; return 0; diff --git a/print-tree.c b/print-tree.c index 35399cb3..5788c0ee 100644 --- a/print-tree.c +++ b/print-tree.c @@ -33,7 +33,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) struct btrfs_extent_item *ei; struct btrfs_root_item *ri; struct btrfs_dir_item *di; - struct btrfs_device_item *devi; struct btrfs_inode_item *ii; struct btrfs_file_extent_item *fi; struct btrfs_csum_item *ci; @@ -113,14 +112,6 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) printf("\t\tblock group used %Lu flags %x\n", btrfs_block_group_used(bi), bi->flags); break; - case BTRFS_DEV_ITEM_KEY: - devi = btrfs_item_ptr(l, i, struct btrfs_device_item); - printf("\t\tdev id %Lu namelen %u name %.*s\n", - btrfs_device_id(devi), - btrfs_device_pathlen(devi), - btrfs_device_pathlen(devi), - (char *)(devi + 1)); - break; case BTRFS_STRING_ITEM_KEY: printf("\t\titem data %.*s\n", btrfs_item_size(item), btrfs_leaf_data(l) + btrfs_item_offset(item));