#define BTRFS_ROOT_TREE_OBJECTID 1ULL
#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
-#define BTRFS_INODE_MAP_OBJECTID 3ULL
-#define BTRFS_FS_TREE_OBJECTID 4ULL
-#define BTRFS_FIRST_FREE_OBJECTID 5ULL
+#define BTRFS_FS_TREE_OBJECTID 3ULL
+#define BTRFS_FIRST_FREE_OBJECTID 4ULL
/*
* we can actually store much bigger names, but lets not confuse the rest
__le64 blocknr; /* which block this node is supposed to live in */
__le64 generation;
__le64 parentid; /* objectid of the tree root */
- __le32 ham;
__le16 nritems;
__le16 flags;
u8 level;
u8 csum[BTRFS_CSUM_SIZE];
} __attribute__ ((__packed__));
-struct btrfs_inode_map_item {
- struct btrfs_disk_key key;
-} __attribute__ ((__packed__));
-
-
struct btrfs_fs_info {
struct btrfs_root *fs_root;
struct btrfs_root *extent_root;
struct btrfs_root *tree_root;
- struct btrfs_root *inode_root;
struct btrfs_key current_insert;
struct btrfs_key last_insert;
struct radix_tree_root cache_radix;
*/
#define BTRFS_EXTENT_ITEM_KEY 8
-/*
- * the inode map records which inode numbers are in use and where
- * they actually live on disk
- */
-#define BTRFS_INODE_MAP_ITEM_KEY 9
/*
* string items are for debugging. They just store a short string of
* data in the FS
*/
-#define BTRFS_STRING_ITEM_KEY 10
+#define BTRFS_STRING_ITEM_KEY 9
static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
{
int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
struct btrfs_root *fs_root,
u64 dirid, u64 *objectid);
-int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
- u64 objectid, struct btrfs_key *location);
-int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
- struct btrfs_root *root, struct btrfs_path *path,
- u64 objectid, int mod);
int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 objectid, struct btrfs_inode_item
*inode_item);
case BTRFS_EXTENT_TREE_OBJECTID:
printf("extent tree ");
break;
- case BTRFS_INODE_MAP_OBJECTID:
- printf("inode map");
- break;
}
printf("tree %Lu %Lu %u\n", found_key.objectid,
found_key.offset, found_key.flags);
btrfs_set_key_type(&inode_map, BTRFS_INODE_ITEM_KEY);
inode_map.offset = 0;
- ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map);
- if (ret)
- goto error;
-
initial_inode_init(root, &inode_item);
ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
if (ret)
goto out_release;
btrfs_release_path(root, path);
- /* delete the inode mapping */
- btrfs_init_path(path);
- ret = btrfs_lookup_inode_map(trans, root, path, file_objectid, -1);
- if (ret)
- goto out_release;
- ret = btrfs_del_item(trans, root->fs_info->inode_root, path);
- if (ret)
- goto out_release;
-
if (root->fs_info->last_inode_alloc > file_objectid)
root->fs_info->last_inode_alloc = file_objectid;
- btrfs_release_path(root, path);
ptr = radix_tree_delete(radix, radix_index);
if (!ptr) {
ret = -5555;
di = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
struct btrfs_dir_item);
objectid = btrfs_disk_key_objectid(&di->location);
- btrfs_release_path(root, &path);
- btrfs_init_path(&path);
- ret = btrfs_lookup_inode_map(trans, root, &path, objectid, 0);
}
btrfs_release_path(root, &path);
if (ret) {
loff_t offset = blocknr * root->blocksize;
struct btrfs_buffer *buf;
int ret;
-
buf = radix_tree_lookup(&root->fs_info->cache_radix, blocknr);
if (buf) {
buf->count++;
u64 old_extent_block;
struct btrfs_root *tree_root = fs_info->tree_root;
struct btrfs_root *extent_root = fs_info->extent_root;
- struct btrfs_root *inode_root = fs_info->inode_root;
- btrfs_set_root_blocknr(&inode_root->root_item,
- inode_root->node->blocknr);
- ret = btrfs_update_root(trans, tree_root,
- &inode_root->root_key,
- &inode_root->root_item);
- BUG_ON(ret);
while(1) {
old_extent_block = btrfs_root_blocknr(&extent_root->root_item);
if (old_extent_block == extent_root->node->blocknr)
struct btrfs_root *root = malloc(sizeof(struct btrfs_root));
struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
struct btrfs_root *tree_root = malloc(sizeof(struct btrfs_root));
- struct btrfs_root *inode_root = malloc(sizeof(struct btrfs_root));
struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
int ret;
fs_info->fs_root = root;
fs_info->tree_root = tree_root;
fs_info->extent_root = extent_root;
- fs_info->inode_root = inode_root;
fs_info->last_inode_alloc = 0;
fs_info->last_inode_alloc_dirid = 0;
fs_info->disk_super = super;
return NULL;
}
BUG_ON(ret < 0);
-
__setup_root(super, tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID, fp);
tree_root->node = read_tree_block(tree_root, btrfs_super_root(super));
BUG_ON(!tree_root->node);
BTRFS_EXTENT_TREE_OBJECTID, extent_root, fp);
BUG_ON(ret);
- ret = find_and_setup_root(super, tree_root, fs_info,
- BTRFS_INODE_MAP_OBJECTID, inode_root, fp);
- BUG_ON(ret);
-
ret = find_and_setup_root(super, tree_root, fs_info,
BTRFS_FS_TREE_OBJECTID, root, fp);
BUG_ON(ret);
if (root->fs_info->extent_root->node)
btrfs_block_release(root->fs_info->extent_root,
root->fs_info->extent_root->node);
- if (root->fs_info->inode_root->node)
- btrfs_block_release(root->fs_info->inode_root,
- root->fs_info->inode_root->node);
if (root->fs_info->tree_root->node)
btrfs_block_release(root->fs_info->tree_root,
root->fs_info->tree_root->node);
* walks the btree of allocated inodes and find a hole.
*/
int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
- struct btrfs_root *fs_root,
+ struct btrfs_root *root,
u64 dirid, u64 *objectid)
{
struct btrfs_path path;
u64 last_ino;
int start_found;
struct btrfs_leaf *l;
- struct btrfs_root *root = fs_root->fs_info->inode_root;
struct btrfs_key search_key;
u64 search_start = dirid;
- if (fs_root->fs_info->last_inode_alloc_dirid == dirid)
- search_start = fs_root->fs_info->last_inode_alloc;
+ if (root->fs_info->last_inode_alloc_dirid == dirid)
+ search_start = root->fs_info->last_inode_alloc;
if (search_start < BTRFS_FIRST_FREE_OBJECTID)
search_start = BTRFS_FIRST_FREE_OBJECTID;
search_key.objectid = search_start;
search_key.flags = 0;
- btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
search_key.offset = 0;
btrfs_init_path(&path);
btrfs_release_path(root, &path);
return ret;
}
-
-int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
- struct btrfs_root *fs_root,
- u64 objectid, struct btrfs_key *location)
-{
- int ret = 0;
- struct btrfs_path path;
- struct btrfs_inode_map_item *inode_item;
- struct btrfs_key key;
- struct btrfs_root *inode_root = fs_root->fs_info->inode_root;
-
- key.objectid = objectid;
- key.flags = 0;
- btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
- key.offset = 0;
- btrfs_init_path(&path);
- ret = btrfs_insert_empty_item(trans, inode_root, &path, &key,
- sizeof(struct btrfs_inode_map_item));
- if (ret)
- goto out;
-
- inode_item = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
- struct btrfs_inode_map_item);
- btrfs_cpu_key_to_disk(&inode_item->key, location);
-out:
- btrfs_release_path(inode_root, &path);
- return ret;
-}
-
-int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
- struct btrfs_root *fs_root, struct btrfs_path *path,
- u64 objectid, int mod)
-{
- int ret;
- struct btrfs_key key;
- int ins_len = mod < 0 ? -1 : 0;
- int cow = mod != 0;
- struct btrfs_root *inode_root = fs_root->fs_info->inode_root;
-
- key.objectid = objectid;
- key.flags = 0;
- key.offset = 0;
- btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
- ret = btrfs_search_slot(trans, inode_root, &key, path, ins_len, cow);
- return ret;
-}
-
btrfs_set_key_type(&inode_map, BTRFS_INODE_ITEM_KEY);
inode_map.offset = 0;
- ret = btrfs_insert_inode_map(trans, root, objectid, &inode_map);
- if (ret)
- goto error;
-
memset(&inode_item, 0, sizeof(inode_item));
btrfs_set_inode_generation(&inode_item, root->fs_info->generation);
btrfs_set_inode_size(&inode_item, 3);
int ret;
u32 itemoff;
u32 start_block = BTRFS_SUPER_INFO_OFFSET / blocksize;
-
btrfs_set_super_generation(&super, 1);
btrfs_set_super_blocknr(&super, start_block);
btrfs_set_super_root(&super, start_block + 1);
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_blocks_used(&super, start_block + 4);
uuid_generate(super.fsid);
block = malloc(blocksize);
btrfs_set_header_parentid(&empty_leaf->header,
BTRFS_ROOT_TREE_OBJECTID);
btrfs_set_header_blocknr(&empty_leaf->header, start_block + 1);
- btrfs_set_header_nritems(&empty_leaf->header, 3);
+ btrfs_set_header_nritems(&empty_leaf->header, 2);
btrfs_set_header_generation(&empty_leaf->header, 0);
memcpy(empty_leaf->header.fsid, super.fsid,
sizeof(empty_leaf->header.fsid));
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_INODE_MAP_OBJECTID);
- memcpy(empty_leaf->items + 1, &item, sizeof(item));
- memcpy(btrfs_leaf_data(empty_leaf) + itemoff,
- &root_item, sizeof(root_item));
-
- btrfs_set_root_blocknr(&root_item, start_block + 4);
- itemoff = itemoff - sizeof(root_item);
- btrfs_set_item_offset(&item, itemoff);
btrfs_set_disk_key_objectid(&item.key, BTRFS_FS_TREE_OBJECTID);
- memcpy(empty_leaf->items + 2, &item, sizeof(item));
+ memcpy(empty_leaf->items + 1, &item, sizeof(item));
memcpy(btrfs_leaf_data(empty_leaf) + itemoff,
&root_item, sizeof(root_item));
ret = pwrite(fd, empty_leaf, blocksize, (start_block + 1) * blocksize);
btrfs_set_header_parentid(&empty_leaf->header,
BTRFS_EXTENT_TREE_OBJECTID);
btrfs_set_header_blocknr(&empty_leaf->header, start_block + 2);
- btrfs_set_header_nritems(&empty_leaf->header, 5);
+ btrfs_set_header_nritems(&empty_leaf->header, 4);
/* item1, reserve blocks 0-16 */
btrfs_set_disk_key_objectid(&item.key, 0);
memcpy(btrfs_leaf_data(empty_leaf) + btrfs_item_offset(&item),
&extent_item, btrfs_item_size(&item));
- /* item4, give block 19 to the inode map */
+ /* item5, 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);
btrfs_set_item_offset(&item, itemoff);
- btrfs_set_extent_owner(&extent_item, BTRFS_INODE_MAP_OBJECTID);
- memcpy(empty_leaf->items + 3, &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 + 2) * blocksize);
- if (ret != blocksize)
- return -1;
-
- /* 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);
btrfs_set_extent_owner(&extent_item, BTRFS_FS_TREE_OBJECTID);
- memcpy(empty_leaf->items + 4, &item, sizeof(item));
+ memcpy(empty_leaf->items + 3, &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 + 2) * blocksize);
if (ret != blocksize)
return -1;
- /* create the inode map */
- btrfs_set_header_parentid(&empty_leaf->header,
- BTRFS_INODE_MAP_OBJECTID);
- 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 + 3) * blocksize);
- if (ret != blocksize)
- return -1;
-
/* finally create the FS root */
btrfs_set_header_parentid(&empty_leaf->header, BTRFS_FS_TREE_OBJECTID);
- 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;
if (ioctl(fd, BLKGETSIZE64, &size) >= 0) {
return size;
}
- return 0;
-}
+ return 0; }
int main(int ac, char **av)
{
struct btrfs_extent_item *ei;
struct btrfs_root_item *ri;
struct btrfs_dir_item *di;
- struct btrfs_inode_map_item *mi;
struct btrfs_inode_item *ii;
struct btrfs_file_extent_item *fi;
char *p;
printf("\t\textent data refs %u owner %Lu\n",
btrfs_extent_refs(ei), btrfs_extent_owner(ei));
break;
- case BTRFS_INODE_MAP_ITEM_KEY:
- mi = btrfs_item_ptr(l, i, struct btrfs_inode_map_item);
- printf("\t\tinode map key %Lu %Lu %u\n",
- btrfs_disk_key_objectid(&mi->key),
- btrfs_disk_key_offset(&mi->key),
- btrfs_disk_key_flags(&mi->key));
- break;
case BTRFS_EXTENT_DATA_KEY:
fi = btrfs_item_ptr(l, i,
struct btrfs_file_extent_item);