mirror of
https://github.com/kdave/btrfs-progs
synced 2025-03-25 04:16:32 +00:00
mkfs should initialize unused fields properly
we discovered speed setting is (probably unintentionally) initialized to 1 in make_btrfs(), while being initialized to 0 in btrfs_add_to_fsid(). initialization in make_btrfs() is due to reuse of buf after pwrite() without clearing it. consequently, code like btrfs_set_extent_generation(buf, extent_item, 1); writes to the same location in buf where speed will be placed, later. It may be a good idea to clear buf after each pwrite(), though leaving the struct btrfs_header intact. Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
This commit is contained in:
parent
c55248003c
commit
42f9568bfd
10
utils.c
10
utils.c
@ -212,6 +212,8 @@ int make_btrfs(int fd, const char *device, const char *label,
|
|||||||
BUG_ON(ret != leafsize);
|
BUG_ON(ret != leafsize);
|
||||||
|
|
||||||
/* create the items for the extent tree */
|
/* create the items for the extent tree */
|
||||||
|
memset(buf->data+sizeof(struct btrfs_header), 0,
|
||||||
|
leafsize-sizeof(struct btrfs_header));
|
||||||
nritems = 0;
|
nritems = 0;
|
||||||
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize);
|
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize);
|
||||||
for (i = 1; i < 7; i++) {
|
for (i = 1; i < 7; i++) {
|
||||||
@ -257,6 +259,8 @@ int make_btrfs(int fd, const char *device, const char *label,
|
|||||||
BUG_ON(ret != leafsize);
|
BUG_ON(ret != leafsize);
|
||||||
|
|
||||||
/* create the chunk tree */
|
/* create the chunk tree */
|
||||||
|
memset(buf->data+sizeof(struct btrfs_header), 0,
|
||||||
|
leafsize-sizeof(struct btrfs_header));
|
||||||
nritems = 0;
|
nritems = 0;
|
||||||
item_size = sizeof(*dev_item);
|
item_size = sizeof(*dev_item);
|
||||||
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) - item_size;
|
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) - item_size;
|
||||||
@ -338,6 +342,8 @@ int make_btrfs(int fd, const char *device, const char *label,
|
|||||||
ret = pwrite(fd, buf->data, leafsize, blocks[3]);
|
ret = pwrite(fd, buf->data, leafsize, blocks[3]);
|
||||||
|
|
||||||
/* create the device tree */
|
/* create the device tree */
|
||||||
|
memset(buf->data+sizeof(struct btrfs_header), 0,
|
||||||
|
leafsize-sizeof(struct btrfs_header));
|
||||||
nritems = 0;
|
nritems = 0;
|
||||||
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) -
|
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) -
|
||||||
sizeof(struct btrfs_dev_extent);
|
sizeof(struct btrfs_dev_extent);
|
||||||
@ -371,6 +377,8 @@ int make_btrfs(int fd, const char *device, const char *label,
|
|||||||
ret = pwrite(fd, buf->data, leafsize, blocks[4]);
|
ret = pwrite(fd, buf->data, leafsize, blocks[4]);
|
||||||
|
|
||||||
/* create the FS root */
|
/* create the FS root */
|
||||||
|
memset(buf->data+sizeof(struct btrfs_header), 0,
|
||||||
|
leafsize-sizeof(struct btrfs_header));
|
||||||
btrfs_set_header_bytenr(buf, blocks[5]);
|
btrfs_set_header_bytenr(buf, blocks[5]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, 0);
|
btrfs_set_header_nritems(buf, 0);
|
||||||
@ -379,6 +387,8 @@ int make_btrfs(int fd, const char *device, const char *label,
|
|||||||
BUG_ON(ret != leafsize);
|
BUG_ON(ret != leafsize);
|
||||||
|
|
||||||
/* finally create the csum root */
|
/* finally create the csum root */
|
||||||
|
memset(buf->data+sizeof(struct btrfs_header), 0,
|
||||||
|
leafsize-sizeof(struct btrfs_header));
|
||||||
btrfs_set_header_bytenr(buf, blocks[6]);
|
btrfs_set_header_bytenr(buf, blocks[6]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, 0);
|
btrfs_set_header_nritems(buf, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user