1 #define _XOPEN_SOURCE 500
8 #include "kerncompat.h"
9 #include "radix-tree.h"
15 struct ctree_root_info info[2];
16 struct leaf empty_leaf;
18 struct extent_item extent_item;
21 /* setup the super block area */
22 memset(info, 0, sizeof(info));
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;
33 info[1].tree_root = 64;
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),
38 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE));
39 if (ret != sizeof(info))
42 /* create leaves for the tree root and extent root */
43 memset(&empty_leaf, 0, sizeof(empty_leaf));
44 empty_leaf.header.parentid = 1;
45 empty_leaf.header.blocknr = 17;
46 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * CTREE_BLOCKSIZE);
47 if (ret != sizeof(empty_leaf))
50 empty_leaf.header.parentid = 2;
51 empty_leaf.header.blocknr = 64;
52 empty_leaf.header.nritems = 2;
53 item.key.objectid = 0;
56 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item);
57 item.size = sizeof(struct extent_item);
59 extent_item.owner = 1;
60 memcpy(empty_leaf.items, &item, sizeof(item));
61 memcpy(empty_leaf.data + item.offset, &extent_item, item.size);
62 item.key.objectid = 64;
64 item.offset = LEAF_DATA_SIZE - sizeof(struct extent_item) * 2;
65 extent_item.owner = 2;
66 memcpy(empty_leaf.items + 1, &item, sizeof(item));
67 memcpy(empty_leaf.data + item.offset, &extent_item, item.size);
68 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 64 * CTREE_BLOCKSIZE);
69 if (ret != sizeof(empty_leaf))