forked from Mirrors/btrfs-progs
Allow large blocks
parent
f6f9229537
commit
f12d799856
11
btrfsck.c
11
btrfsck.c
|
@ -55,7 +55,7 @@ static int check_node(struct btrfs_root *root,
|
|||
|
||||
if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(root))
|
||||
return 1;
|
||||
if (parent_key->flags) {
|
||||
if (parent_key->type) {
|
||||
if (memcmp(parent_key, &node->ptrs[0].key,
|
||||
sizeof(struct btrfs_disk_key)))
|
||||
return 1;
|
||||
|
@ -91,7 +91,7 @@ static int check_leaf(struct btrfs_root *root,
|
|||
if (nritems == 0)
|
||||
return 0;
|
||||
|
||||
if (parent_key->flags && memcmp(parent_key, &leaf->items[0].key,
|
||||
if (parent_key->type && memcmp(parent_key, &leaf->items[0].key,
|
||||
sizeof(struct btrfs_disk_key))) {
|
||||
fprintf(stderr, "leaf parent key incorrect %llu\n",
|
||||
(unsigned long long)btrfs_header_blocknr(&leaf->header));
|
||||
|
@ -287,9 +287,9 @@ static int run_next_block(struct btrfs_root *root,
|
|||
u64 offset;
|
||||
set_radix_bit(reada, bits[i]);
|
||||
btrfs_map_bh_to_logical(root, &reada_buf, bits[i]);
|
||||
offset = reada_buf.dev_blocknr * root->blocksize;
|
||||
offset = reada_buf.dev_blocknr * root->sectorsize;
|
||||
last_block = bits[i];
|
||||
readahead(reada_buf.fd, offset, root->blocksize);
|
||||
readahead(reada_buf.fd, offset, root->sectorsize);
|
||||
}
|
||||
}
|
||||
*last = bits[0];
|
||||
|
@ -471,7 +471,7 @@ int main(int ac, char **av) {
|
|||
|
||||
root = open_ctree(av[1], &super);
|
||||
|
||||
bits_nr = 1024 * 1024 / root->blocksize;
|
||||
bits_nr = 1024 * 1024 / root->sectorsize;
|
||||
bits = malloc(bits_nr * sizeof(unsigned long));
|
||||
if (!bits) {
|
||||
perror("malloc");
|
||||
|
@ -484,7 +484,6 @@ int main(int ac, char **av) {
|
|||
btrfs_init_path(&path);
|
||||
key.offset = 0;
|
||||
key.objectid = 0;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
|
||||
ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
|
||||
&key, &path, 0, 0);
|
||||
|
|
8
ctree.c
8
ctree.c
|
@ -65,7 +65,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
return 0;
|
||||
}
|
||||
cow = btrfs_alloc_free_block(trans, root);
|
||||
memcpy(&cow->node, &buf->node, root->blocksize);
|
||||
memcpy(&cow->node, &buf->node, root->sectorsize);
|
||||
btrfs_set_header_blocknr(&cow->node.header, cow->blocknr);
|
||||
btrfs_set_header_owner(&cow->node.header, root->root_key.objectid);
|
||||
*cow_ret = cow;
|
||||
|
@ -148,9 +148,9 @@ int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
|
|||
return 1;
|
||||
if (k1.objectid < k2->objectid)
|
||||
return -1;
|
||||
if (k1.flags > k2->flags)
|
||||
if (k1.type > k2->type)
|
||||
return 1;
|
||||
if (k1.flags < k2->flags)
|
||||
if (k1.type < k2->type)
|
||||
return -1;
|
||||
if (k1.offset > k2->offset)
|
||||
return 1;
|
||||
|
@ -698,7 +698,7 @@ static int insert_new_root(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
|
||||
t = btrfs_alloc_free_block(trans, root);
|
||||
c = &t->node;
|
||||
memset(c, 0, root->blocksize);
|
||||
memset(c, 0, root->sectorsize);
|
||||
btrfs_set_header_nritems(&c->header, 1);
|
||||
btrfs_set_header_level(&c->header, level);
|
||||
btrfs_set_header_blocknr(&c->header, t->blocknr);
|
||||
|
|
111
ctree.h
111
ctree.h
|
@ -24,7 +24,7 @@
|
|||
|
||||
struct btrfs_trans_handle;
|
||||
|
||||
#define BTRFS_MAGIC "_BtRfS_M"
|
||||
#define BTRFS_MAGIC "_B2RfS_M"
|
||||
|
||||
#define BTRFS_ROOT_TREE_OBJECTID 1ULL
|
||||
#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
|
||||
|
@ -69,13 +69,13 @@ struct btrfs_trans_handle;
|
|||
*/
|
||||
struct btrfs_disk_key {
|
||||
__le64 objectid;
|
||||
__le32 flags;
|
||||
u8 type;
|
||||
__le64 offset;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_key {
|
||||
u64 objectid;
|
||||
u32 flags;
|
||||
u8 type;
|
||||
u64 offset;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
|
@ -88,17 +88,17 @@ struct btrfs_header {
|
|||
__le64 blocknr; /* which block this node is supposed to live in */
|
||||
__le64 generation;
|
||||
__le64 owner;
|
||||
__le16 nritems;
|
||||
__le32 nritems;
|
||||
__le16 flags;
|
||||
u8 level;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
#define BTRFS_MAX_LEVEL 8
|
||||
#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
|
||||
#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
|
||||
sizeof(struct btrfs_header)) / \
|
||||
(sizeof(struct btrfs_disk_key) + sizeof(u64)))
|
||||
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
|
||||
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
|
||||
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
|
||||
|
||||
struct btrfs_buffer;
|
||||
/*
|
||||
|
@ -116,7 +116,9 @@ struct btrfs_super_block {
|
|||
__le64 total_blocks;
|
||||
__le64 blocks_used;
|
||||
__le64 root_dir_objectid;
|
||||
__le32 blocksize;
|
||||
__le32 sectorsize;
|
||||
__le32 nodesize;
|
||||
__le32 leafsize;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/*
|
||||
|
@ -126,7 +128,7 @@ struct btrfs_super_block {
|
|||
struct btrfs_item {
|
||||
struct btrfs_disk_key key;
|
||||
__le32 offset;
|
||||
__le16 size;
|
||||
__le32 size;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/*
|
||||
|
@ -305,7 +307,16 @@ struct btrfs_root {
|
|||
struct btrfs_root_item root_item;
|
||||
struct btrfs_key root_key;
|
||||
struct btrfs_fs_info *fs_info;
|
||||
u32 blocksize;
|
||||
|
||||
/* data allocations are done in sectorsize units */
|
||||
u32 sectorsize;
|
||||
|
||||
/* node allocations are done in nodesize units */
|
||||
u32 nodesize;
|
||||
|
||||
/* leaf allocations are done in leafsize units */
|
||||
u32 leafsize;
|
||||
|
||||
int ref_cows;
|
||||
u32 type;
|
||||
};
|
||||
|
@ -557,17 +568,17 @@ static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
|
|||
|
||||
static inline u32 btrfs_item_end(struct btrfs_item *item)
|
||||
{
|
||||
return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
|
||||
return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_item_size(struct btrfs_item *item)
|
||||
static inline u32 btrfs_item_size(struct btrfs_item *item)
|
||||
{
|
||||
return le16_to_cpu(item->size);
|
||||
return le32_to_cpu(item->size);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
|
||||
static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
|
||||
{
|
||||
item->size = cpu_to_le16(val);
|
||||
item->size = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
|
||||
|
@ -604,7 +615,7 @@ static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
|
|||
struct btrfs_disk_key *disk)
|
||||
{
|
||||
cpu->offset = le64_to_cpu(disk->offset);
|
||||
cpu->flags = le32_to_cpu(disk->flags);
|
||||
cpu->type = le32_to_cpu(disk->type);
|
||||
cpu->objectid = le64_to_cpu(disk->objectid);
|
||||
}
|
||||
|
||||
|
@ -612,7 +623,7 @@ static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
|
|||
struct btrfs_key *cpu)
|
||||
{
|
||||
disk->offset = cpu_to_le64(cpu->offset);
|
||||
disk->flags = cpu_to_le32(cpu->flags);
|
||||
disk->type = cpu_to_le32(cpu->type);
|
||||
disk->objectid = cpu_to_le64(cpu->objectid);
|
||||
}
|
||||
|
||||
|
@ -638,42 +649,24 @@ static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
|
|||
disk->offset = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
|
||||
static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
|
||||
{
|
||||
return le32_to_cpu(disk->flags);
|
||||
return key->type;
|
||||
}
|
||||
|
||||
static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
|
||||
u32 val)
|
||||
static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
|
||||
{
|
||||
disk->flags = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
|
||||
{
|
||||
return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
|
||||
}
|
||||
|
||||
static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
|
||||
u32 val)
|
||||
{
|
||||
u32 flags = btrfs_disk_key_flags(key);
|
||||
BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
|
||||
val = val << BTRFS_KEY_TYPE_SHIFT;
|
||||
flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
|
||||
btrfs_set_disk_key_flags(key, flags);
|
||||
key->type = val;
|
||||
}
|
||||
|
||||
static inline u32 btrfs_key_type(struct btrfs_key *key)
|
||||
{
|
||||
return key->flags >> BTRFS_KEY_TYPE_SHIFT;
|
||||
return key->type;
|
||||
}
|
||||
|
||||
static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
|
||||
{
|
||||
BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
|
||||
val = val << BTRFS_KEY_TYPE_SHIFT;
|
||||
key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
|
||||
key->type = val;
|
||||
}
|
||||
|
||||
static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
|
||||
|
@ -708,14 +701,14 @@ static inline void btrfs_set_header_owner(struct btrfs_header *h,
|
|||
h->owner = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_header_nritems(struct btrfs_header *h)
|
||||
static inline u32 btrfs_header_nritems(struct btrfs_header *h)
|
||||
{
|
||||
return le16_to_cpu(h->nritems);
|
||||
return le32_to_cpu(h->nritems);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
|
||||
static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
|
||||
{
|
||||
h->nritems = cpu_to_le16(val);
|
||||
h->nritems = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_header_flags(struct btrfs_header *h)
|
||||
|
@ -848,15 +841,37 @@ static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
|
|||
s->blocks_used = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
|
||||
static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
|
||||
{
|
||||
return le32_to_cpu(s->blocksize);
|
||||
return le32_to_cpu(s->sectorsize);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
|
||||
static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
|
||||
u32 val)
|
||||
{
|
||||
s->blocksize = cpu_to_le32(val);
|
||||
s->sectorsize = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
|
||||
{
|
||||
return le32_to_cpu(s->nodesize);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
|
||||
u32 val)
|
||||
{
|
||||
s->nodesize = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
|
||||
{
|
||||
return le32_to_cpu(s->leafsize);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
|
||||
u32 val)
|
||||
{
|
||||
s->leafsize = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
|
||||
|
|
|
@ -54,7 +54,6 @@ int main(int ac, char **av) {
|
|||
btrfs_init_path(&path);
|
||||
key.offset = 0;
|
||||
key.objectid = 0;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
|
||||
ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
|
||||
&key, &path, 0, 0);
|
||||
|
@ -87,7 +86,7 @@ int main(int ac, char **av) {
|
|||
}
|
||||
printf("tree %llu %u %llu\n",
|
||||
(unsigned long long)found_key.objectid,
|
||||
found_key.flags,
|
||||
found_key.type,
|
||||
(unsigned long long)found_key.offset);
|
||||
btrfs_print_tree(root, buf);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
u32 data_size;
|
||||
|
||||
key.objectid = dir;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
|
||||
if (name_len == 1 && *name == '.')
|
||||
key.offset = 1;
|
||||
|
@ -121,7 +120,6 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
int cow = mod != 0;
|
||||
|
||||
key.objectid = dir;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
|
||||
ret = btrfs_name_hash(name, name_len, &key.offset);
|
||||
BUG_ON(ret);
|
||||
|
|
26
disk-io.c
26
disk-io.c
|
@ -76,7 +76,7 @@ struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr)
|
|||
struct btrfs_buffer *buf;
|
||||
int ret;
|
||||
|
||||
buf = malloc(sizeof(struct btrfs_buffer) + root->blocksize);
|
||||
buf = malloc(sizeof(struct btrfs_buffer) + root->sectorsize);
|
||||
if (!buf)
|
||||
return buf;
|
||||
allocated_blocks++;
|
||||
|
@ -126,9 +126,9 @@ struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr)
|
|||
if (!buf)
|
||||
return NULL;
|
||||
btrfs_map_bh_to_logical(root, buf, blocknr);
|
||||
ret = pread(buf->fd, &buf->node, root->blocksize,
|
||||
buf->dev_blocknr * root->blocksize);
|
||||
if (ret != root->blocksize) {
|
||||
ret = pread(buf->fd, &buf->node, root->sectorsize,
|
||||
buf->dev_blocknr * root->sectorsize);
|
||||
if (ret != root->sectorsize) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
|||
int btrfs_csum_node(struct btrfs_root *root, struct btrfs_node *node)
|
||||
{
|
||||
u32 crc;
|
||||
size_t len = root->blocksize - BTRFS_CSUM_SIZE;
|
||||
size_t len = root->sectorsize - BTRFS_CSUM_SIZE;
|
||||
|
||||
crc = crc32c(0, (char *)(node) + BTRFS_CSUM_SIZE, len);
|
||||
memcpy(node->header.csum, &crc, BTRFS_CRC32_SIZE);
|
||||
|
@ -173,10 +173,10 @@ int btrfs_csum_node(struct btrfs_root *root, struct btrfs_node *node)
|
|||
int btrfs_csum_super(struct btrfs_root *root, struct btrfs_super_block *super)
|
||||
{
|
||||
u32 crc;
|
||||
char block[root->blocksize];
|
||||
size_t len = root->blocksize - BTRFS_CSUM_SIZE;
|
||||
char block[root->sectorsize];
|
||||
size_t len = root->sectorsize - BTRFS_CSUM_SIZE;
|
||||
|
||||
memset(block, 0, root->blocksize);
|
||||
memset(block, 0, root->sectorsize);
|
||||
memcpy(block, super, sizeof(*super));
|
||||
|
||||
crc = crc32c(0, block + BTRFS_CSUM_SIZE, len);
|
||||
|
@ -197,9 +197,9 @@ int write_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
|||
|
||||
btrfs_csum_node(root, &buf->node);
|
||||
|
||||
ret = pwrite(buf->fd, &buf->node, root->blocksize,
|
||||
buf->dev_blocknr * root->blocksize);
|
||||
if (ret != root->blocksize)
|
||||
ret = pwrite(buf->fd, &buf->node, root->sectorsize,
|
||||
buf->dev_blocknr * root->sectorsize);
|
||||
if (ret != root->sectorsize)
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
@ -293,7 +293,9 @@ static int __setup_root(struct btrfs_super_block *super,
|
|||
{
|
||||
root->node = NULL;
|
||||
root->commit_root = NULL;
|
||||
root->blocksize = btrfs_super_blocksize(super);
|
||||
root->sectorsize = btrfs_super_sectorsize(super);
|
||||
root->nodesize = btrfs_super_nodesize(super);
|
||||
root->leafsize = btrfs_super_leafsize(super);
|
||||
root->ref_cows = 0;
|
||||
root->fs_info = fs_info;
|
||||
memset(&root->root_key, 0, sizeof(root->root_key));
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
struct btrfs_buffer {
|
||||
u64 blocknr;
|
||||
u64 dev_blocknr;
|
||||
u32 size;
|
||||
int count;
|
||||
int fd;
|
||||
struct list_head dirty;
|
||||
|
|
|
@ -57,7 +57,6 @@ static int inc_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
&ins);
|
||||
btrfs_init_path(&path);
|
||||
key.objectid = blocknr;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
|
||||
key.offset = 1;
|
||||
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, &path,
|
||||
|
@ -88,7 +87,6 @@ static int lookup_block_ref(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
btrfs_init_path(&path);
|
||||
key.objectid = blocknr;
|
||||
key.offset = 1;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
|
||||
ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, &path,
|
||||
0, 0);
|
||||
|
@ -258,10 +256,9 @@ static int finish_current_insert(struct btrfs_trans_handle *trans, struct
|
|||
btrfs_set_extent_refs(&extent_item, 1);
|
||||
btrfs_set_extent_owner(&extent_item, extent_root->root_key.objectid);
|
||||
ins.offset = 1;
|
||||
ins.flags = 0;
|
||||
btrfs_set_key_type(&ins, BTRFS_EXTENT_ITEM_KEY);
|
||||
|
||||
for (i = 0; i < extent_root->fs_info->current_insert.flags; i++) {
|
||||
for (i = 0; i < extent_root->fs_info->current_insert.type; i++) {
|
||||
ins.objectid = extent_root->fs_info->current_insert.objectid +
|
||||
i;
|
||||
super_blocks_used = btrfs_super_blocks_used(info->disk_super);
|
||||
|
@ -298,7 +295,6 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
|
||||
BUG_ON(pin && num_blocks != 1);
|
||||
key.objectid = blocknr;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
|
||||
key.offset = num_blocks;
|
||||
|
||||
|
@ -439,7 +435,6 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
if (root->fs_info->last_insert.objectid > search_start)
|
||||
search_start = root->fs_info->last_insert.objectid;
|
||||
|
||||
ins->flags = 0;
|
||||
btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
|
||||
|
||||
check_failed:
|
||||
|
@ -512,7 +507,7 @@ check_pending:
|
|||
BUG_ON(root->fs_info->current_insert.offset);
|
||||
root->fs_info->current_insert.offset = total_needed - num_blocks;
|
||||
root->fs_info->current_insert.objectid = ins->objectid + num_blocks;
|
||||
root->fs_info->current_insert.flags = 0;
|
||||
root->fs_info->current_insert.type = 0;
|
||||
root->fs_info->last_insert.objectid = ins->objectid;
|
||||
ins->offset = num_blocks;
|
||||
return 0;
|
||||
|
@ -545,11 +540,11 @@ static int alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
if (root == extent_root) {
|
||||
BUG_ON(extent_root->fs_info->current_insert.offset == 0);
|
||||
BUG_ON(num_blocks != 1);
|
||||
BUG_ON(extent_root->fs_info->current_insert.flags ==
|
||||
BUG_ON(extent_root->fs_info->current_insert.type ==
|
||||
extent_root->fs_info->current_insert.offset);
|
||||
ins->offset = 1;
|
||||
ins->objectid = extent_root->fs_info->current_insert.objectid +
|
||||
extent_root->fs_info->current_insert.flags++;
|
||||
extent_root->fs_info->current_insert.type++;
|
||||
return 0;
|
||||
}
|
||||
ret = find_free_extent(trans, root, num_blocks, search_start,
|
||||
|
@ -762,12 +757,11 @@ int btrfs_read_block_groups(struct btrfs_root *root)
|
|||
struct btrfs_key key;
|
||||
struct btrfs_key found_key;
|
||||
struct btrfs_leaf *leaf;
|
||||
u64 group_size_blocks = BTRFS_BLOCK_GROUP_SIZE / root->blocksize;
|
||||
u64 group_size_blocks = BTRFS_BLOCK_GROUP_SIZE / root->sectorsize;
|
||||
|
||||
root = root->fs_info->extent_root;
|
||||
key.objectid = 0;
|
||||
key.offset = group_size_blocks;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
btrfs_init_path(&path);
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
struct btrfs_key key;
|
||||
int ret;
|
||||
key.objectid = objectid;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
|
||||
key.offset = 0;
|
||||
|
||||
|
@ -51,7 +50,6 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
int cow = mod != 0;
|
||||
|
||||
key.objectid = objectid;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
|
||||
key.offset = 0;
|
||||
return btrfs_search_slot(trans, root, &key, path, ins_len, cow);
|
||||
|
|
|
@ -48,7 +48,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
|
|||
if (search_start < BTRFS_FIRST_FREE_OBJECTID)
|
||||
search_start = BTRFS_FIRST_FREE_OBJECTID;
|
||||
search_key.objectid = search_start;
|
||||
search_key.flags = 0;
|
||||
search_key.type = 0;
|
||||
search_key.offset = 0;
|
||||
|
||||
btrfs_init_path(&path);
|
||||
|
|
29
mkfs.c
29
mkfs.c
|
@ -52,7 +52,6 @@ static int __make_root_dir(struct btrfs_trans_handle *trans,
|
|||
buf[1] = '.';
|
||||
|
||||
inode_map.objectid = objectid;
|
||||
inode_map.flags = 0;
|
||||
btrfs_set_key_type(&inode_map, BTRFS_INODE_ITEM_KEY);
|
||||
inode_map.offset = 0;
|
||||
|
||||
|
@ -95,11 +94,10 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
|||
|
||||
root = root->fs_info->extent_root;
|
||||
/* first we bootstrap the things into cache */
|
||||
group_size_blocks = BTRFS_BLOCK_GROUP_SIZE / root->blocksize;
|
||||
group_size_blocks = BTRFS_BLOCK_GROUP_SIZE / root->sectorsize;
|
||||
cache = malloc(sizeof(*cache));
|
||||
cache->key.objectid = 0;
|
||||
cache->key.offset = group_size_blocks;
|
||||
cache->key.flags = 0;
|
||||
btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
memset(&cache->item, 0, sizeof(cache->item));
|
||||
btrfs_set_block_group_used(&cache->item,
|
||||
|
@ -114,7 +112,6 @@ static int make_block_groups(struct btrfs_trans_handle *trans,
|
|||
cache = malloc(sizeof(*cache));
|
||||
cache->key.objectid = cur_start;
|
||||
cache->key.offset = group_size_blocks;
|
||||
cache->key.flags = 0;
|
||||
btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY);
|
||||
memset(&cache->item, 0, sizeof(cache->item));
|
||||
if (nr % 3)
|
||||
|
@ -194,7 +191,12 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize)
|
|||
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);
|
||||
|
||||
printf("blocksize is %d\n", blocksize);
|
||||
btrfs_set_super_sectorsize(&super, blocksize);
|
||||
btrfs_set_super_leafsize(&super, blocksize);
|
||||
btrfs_set_super_nodesize(&super, blocksize);
|
||||
|
||||
btrfs_set_super_total_blocks(&super, num_blocks);
|
||||
btrfs_set_super_blocks_used(&super, start_block + 4);
|
||||
uuid_generate(super.fsid);
|
||||
|
@ -229,7 +231,6 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize)
|
|||
btrfs_set_root_dirid(&root_item, 0);
|
||||
btrfs_set_root_refs(&root_item, 1);
|
||||
btrfs_set_disk_key_offset(&item.key, 0);
|
||||
btrfs_set_disk_key_flags(&item.key, 0);
|
||||
btrfs_set_item_size(&item, sizeof(root_item));
|
||||
btrfs_set_disk_key_type(&item.key, BTRFS_ROOT_ITEM_KEY);
|
||||
|
||||
|
@ -258,7 +259,7 @@ int mkfs(int fd, char *pathname, u64 num_blocks, u32 blocksize)
|
|||
/* item1, reserve blocks 0-16 */
|
||||
btrfs_set_disk_key_objectid(&item.key, 0);
|
||||
btrfs_set_disk_key_offset(&item.key, start_block + 1);
|
||||
btrfs_set_disk_key_flags(&item.key, 0);
|
||||
btrfs_set_disk_key_type(&item.key, 0);
|
||||
btrfs_set_disk_key_type(&item.key, BTRFS_EXTENT_ITEM_KEY);
|
||||
itemoff = __BTRFS_LEAF_DATA_SIZE(blocksize) -
|
||||
sizeof(struct btrfs_extent_item);
|
||||
|
@ -331,7 +332,7 @@ int main(int ac, char **av)
|
|||
struct stat st;
|
||||
int ret;
|
||||
int i;
|
||||
char *buf = malloc(4096);
|
||||
char *buf = malloc(8192);
|
||||
char *realpath_name;
|
||||
|
||||
radix_tree_init();
|
||||
|
@ -365,22 +366,22 @@ int main(int ac, char **av)
|
|||
fprintf(stderr, "unable to find %s size\n", file);
|
||||
exit(1);
|
||||
}
|
||||
block_count /= 4096;
|
||||
block_count /= 8192;
|
||||
}
|
||||
if (block_count < 256) {
|
||||
fprintf(stderr, "device %s is too small\n", file);
|
||||
exit(1);
|
||||
}
|
||||
memset(buf, 0, 4096);
|
||||
memset(buf, 0, 8192);
|
||||
for(i = 0; i < 64; i++) {
|
||||
ret = write(fd, buf, 4096);
|
||||
if (ret != 4096) {
|
||||
ret = write(fd, buf, 8192);
|
||||
if (ret != 8192) {
|
||||
fprintf(stderr, "unable to zero fill device\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
realpath_name = realpath(file, NULL);
|
||||
ret = mkfs(fd, realpath_name, block_count, 4096);
|
||||
ret = mkfs(fd, realpath_name, block_count, 8192);
|
||||
if (ret) {
|
||||
fprintf(stderr, "error during mkfs %d\n", ret);
|
||||
exit(1);
|
||||
|
@ -391,7 +392,7 @@ int main(int ac, char **av)
|
|||
exit(1);
|
||||
}
|
||||
printf("fs created on %s blocksize %d blocks %llu\n",
|
||||
file, 4096, (unsigned long long)block_count);
|
||||
file, 8192, (unsigned long long)block_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
|
|||
printf("\titem %d key (%llu %x %llu) itemoff %d itemsize %d\n",
|
||||
i,
|
||||
(unsigned long long)btrfs_disk_key_objectid(&item->key),
|
||||
btrfs_disk_key_flags(&item->key),
|
||||
btrfs_disk_key_type(&item->key),
|
||||
(unsigned long long)btrfs_disk_key_offset(&item->key),
|
||||
btrfs_item_offset(item),
|
||||
btrfs_item_size(item));
|
||||
|
@ -103,7 +103,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
|
|||
&ri->drop_progress);
|
||||
printf("\t\tdrop key %Lu %x %Lu level %d\n",
|
||||
(unsigned long long)drop_key.objectid,
|
||||
drop_key.flags,
|
||||
drop_key.type,
|
||||
(unsigned long long)drop_key.offset,
|
||||
ri->drop_level);
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
|
|||
printf("\tkey %d (%llu %x %llu) block %llu\n",
|
||||
i,
|
||||
(unsigned long long)c->ptrs[i].key.objectid,
|
||||
c->ptrs[i].key.flags,
|
||||
c->ptrs[i].key.type,
|
||||
(unsigned long long)c->ptrs[i].key.offset,
|
||||
(unsigned long long)btrfs_node_blockptr(c, i));
|
||||
fflush(stdout);
|
||||
|
|
|
@ -34,7 +34,7 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
|
|||
int slot;
|
||||
|
||||
search_key.objectid = objectid;
|
||||
search_key.flags = (u32)-1;
|
||||
search_key.type = (u8)-1;
|
||||
search_key.offset = (u64)-1;
|
||||
|
||||
btrfs_init_path(&path);
|
||||
|
|
Loading…
Reference in New Issue