aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/mkfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/mkfs.c')
-rw-r--r--fs/btrfs/mkfs.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/fs/btrfs/mkfs.c b/fs/btrfs/mkfs.c
index 5290423343f8..0f77babcd306 100644
--- a/fs/btrfs/mkfs.c
+++ b/fs/btrfs/mkfs.c
@@ -14,7 +14,7 @@ int mkfs(int fd)
14{ 14{
15 struct ctree_root_info info[2]; 15 struct ctree_root_info info[2];
16 struct leaf empty_leaf; 16 struct leaf empty_leaf;
17 struct item item; 17 struct btrfs_item item;
18 struct extent_item extent_item; 18 struct extent_item extent_item;
19 int ret; 19 int ret;
20 20
@@ -45,31 +45,37 @@ int mkfs(int fd)
45 btrfs_set_header_nritems(&empty_leaf.header, 3); 45 btrfs_set_header_nritems(&empty_leaf.header, 3);
46 46
47 /* item1, reserve blocks 0-16 */ 47 /* item1, reserve blocks 0-16 */
48 item.key.objectid = cpu_to_le64(0); 48 btrfs_set_key_objectid(&item.key, 0);
49 item.key.offset = cpu_to_le64(17); 49 btrfs_set_key_offset(&item.key, 17);
50 item.key.flags = cpu_to_le32(0); 50 btrfs_set_key_flags(&item.key, 0);
51 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item); 51 btrfs_set_item_offset(&item,
52 item.size = sizeof(struct extent_item); 52 LEAF_DATA_SIZE - sizeof(struct extent_item));
53 btrfs_set_item_size(&item, sizeof(struct extent_item));
53 extent_item.refs = 1; 54 extent_item.refs = 1;
54 extent_item.owner = 0; 55 extent_item.owner = 0;
55 memcpy(empty_leaf.items, &item, sizeof(item)); 56 memcpy(empty_leaf.items, &item, sizeof(item));
56 memcpy(empty_leaf.data + item.offset, &extent_item, item.size); 57 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
58 btrfs_item_size(&item));
57 59
58 /* item2, give block 17 to the root */ 60 /* item2, give block 17 to the root */
59 item.key.objectid = cpu_to_le64(17); 61 btrfs_set_key_objectid(&item.key, 17);
60 item.key.offset = cpu_to_le64(1); 62 btrfs_set_key_offset(&item.key, 1);
61 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 2; 63 btrfs_set_item_offset(&item,
64 LEAF_DATA_SIZE - sizeof(struct extent_item) * 2);
62 extent_item.owner = 1; 65 extent_item.owner = 1;
63 memcpy(empty_leaf.items + 1, &item, sizeof(item)); 66 memcpy(empty_leaf.items + 1, &item, sizeof(item));
64 memcpy(empty_leaf.data + item.offset, &extent_item, item.size); 67 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
68 btrfs_item_size(&item));
65 69
66 /* item3, give block 18 for the extent root */ 70 /* item3, give block 18 for the extent root */
67 item.key.objectid = cpu_to_le64(18); 71 btrfs_set_key_objectid(&item.key, 18);
68 item.key.offset = cpu_to_le64(1); 72 btrfs_set_key_offset(&item.key, 1);
69 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 3; 73 btrfs_set_item_offset(&item,
74 LEAF_DATA_SIZE - sizeof(struct extent_item) * 3);
70 extent_item.owner = 2; 75 extent_item.owner = 2;
71 memcpy(empty_leaf.items + 2, &item, sizeof(item)); 76 memcpy(empty_leaf.items + 2, &item, sizeof(item));
72 memcpy(empty_leaf.data + item.offset, &extent_item, item.size); 77 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
78 btrfs_item_size(&item));
73 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * CTREE_BLOCKSIZE); 79 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * CTREE_BLOCKSIZE);
74 if (ret != sizeof(empty_leaf)) 80 if (ret != sizeof(empty_leaf))
75 return -1; 81 return -1;