summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-06-09 09:22:37 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-06-09 09:22:37 -0400
commitb53a236c3eea3ce01a0054c249cb0b974b9568c6 (patch)
tree82277d8bd2b18794427464e1b7080e51af578387 /mkfs.c
parentf8d7bbd1fab8ed5c8f7c75d43c6dbe4bfb4f847a (diff)
remove device tree
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c59
1 files changed, 10 insertions, 49 deletions
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;