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.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/fs/btrfs/mkfs.c b/fs/btrfs/mkfs.c
index 584aba44e801..fd4e5dea7e1b 100644
--- a/fs/btrfs/mkfs.c
+++ b/fs/btrfs/mkfs.c
@@ -23,17 +23,10 @@ int mkfs(int fd)
23 info[0].blocknr = 16; 23 info[0].blocknr = 16;
24 info[0].objectid = 1; 24 info[0].objectid = 1;
25 info[0].tree_root = 17; 25 info[0].tree_root = 17;
26 info[0].alloc_extent.blocknr = 0;
27 info[0].alloc_extent.num_blocks = 64;
28 /* 0-17 are used (inclusive) */
29 info[0].alloc_extent.num_used = 18;
30 26
31 info[1].blocknr = 16; 27 info[1].blocknr = 16;
32 info[1].objectid = 2; 28 info[1].objectid = 2;
33 info[1].tree_root = 64; 29 info[1].tree_root = 18;
34 info[1].alloc_extent.blocknr = 64;
35 info[1].alloc_extent.num_blocks = 64;
36 info[1].alloc_extent.num_used = 1;
37 ret = pwrite(fd, info, sizeof(info), 30 ret = pwrite(fd, info, sizeof(info),
38 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 31 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
39 if (ret != sizeof(info)) 32 if (ret != sizeof(info))
@@ -48,24 +41,36 @@ int mkfs(int fd)
48 return -1; 41 return -1;
49 42
50 empty_leaf.header.parentid = 2; 43 empty_leaf.header.parentid = 2;
51 empty_leaf.header.blocknr = 64; 44 empty_leaf.header.blocknr = 18;
52 empty_leaf.header.nritems = 2; 45 empty_leaf.header.nritems = 3;
46
47 /* item1, reserve blocks 0-16 */
53 item.key.objectid = 0; 48 item.key.objectid = 0;
54 item.key.offset = 64; 49 item.key.offset = 17;
55 item.key.flags = 0; 50 item.key.flags = 0;
56 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item); 51 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item);
57 item.size = sizeof(struct extent_item); 52 item.size = sizeof(struct extent_item);
58 extent_item.refs = 1; 53 extent_item.refs = 1;
59 extent_item.owner = 1; 54 extent_item.owner = 0;
60 memcpy(empty_leaf.items, &item, sizeof(item)); 55 memcpy(empty_leaf.items, &item, sizeof(item));
61 memcpy(empty_leaf.data + item.offset, &extent_item, item.size); 56 memcpy(empty_leaf.data + item.offset, &extent_item, item.size);
62 item.key.objectid = 64; 57
63 item.key.offset = 64; 58 /* item2, give block 17 to the root */
59 item.key.objectid = 17;
60 item.key.offset = 1;
64 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 2; 61 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 2;
65 extent_item.owner = 2; 62 extent_item.owner = 1;
66 memcpy(empty_leaf.items + 1, &item, sizeof(item)); 63 memcpy(empty_leaf.items + 1, &item, sizeof(item));
67 memcpy(empty_leaf.data + item.offset, &extent_item, item.size); 64 memcpy(empty_leaf.data + item.offset, &extent_item, item.size);
68 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 64 * CTREE_BLOCKSIZE); 65
66 /* item3, give block 18 for the extent root */
67 item.key.objectid = 18;
68 item.key.offset = 1;
69 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 3;
70 extent_item.owner = 2;
71 memcpy(empty_leaf.items + 2, &item, sizeof(item));
72 memcpy(empty_leaf.data + item.offset, &extent_item, item.size);
73 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * CTREE_BLOCKSIZE);
69 if (ret != sizeof(empty_leaf)) 74 if (ret != sizeof(empty_leaf))
70 return -1; 75 return -1;
71 return 0; 76 return 0;