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;
29 info
[1].tree_root
= 18;
30 ret
= pwrite(fd
, info
, sizeof(info
),
31 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE
));
32 if (ret
!= sizeof(info
))
35 /* create leaves for the tree root and extent root */
36 memset(&empty_leaf
, 0, sizeof(empty_leaf
));
37 empty_leaf
.header
.parentid
= 1;
38 empty_leaf
.header
.blocknr
= 17;
39 ret
= pwrite(fd
, &empty_leaf
, sizeof(empty_leaf
), 17 * CTREE_BLOCKSIZE
);
40 if (ret
!= sizeof(empty_leaf
))
43 empty_leaf
.header
.parentid
= 2;
44 empty_leaf
.header
.blocknr
= 18;
45 empty_leaf
.header
.nritems
= 3;
47 /* item1, reserve blocks 0-16 */
48 item
.key
.objectid
= 0;
51 item
.offset
= LEAF_DATA_SIZE
- sizeof(struct extent_item
);
52 item
.size
= sizeof(struct extent_item
);
54 extent_item
.owner
= 0;
55 memcpy(empty_leaf
.items
, &item
, sizeof(item
));
56 memcpy(empty_leaf
.data
+ item
.offset
, &extent_item
, item
.size
);
58 /* item2, give block 17 to the root */
59 item
.key
.objectid
= 17;
61 item
.offset
= LEAF_DATA_SIZE
- sizeof(struct extent_item
) * 2;
62 extent_item
.owner
= 1;
63 memcpy(empty_leaf
.items
+ 1, &item
, sizeof(item
));
64 memcpy(empty_leaf
.data
+ item
.offset
, &extent_item
, item
.size
);
66 /* item3, give block 18 for the extent root */
67 item
.key
.objectid
= 18;
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
);
74 if (ret
!= sizeof(empty_leaf
))