mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
format: add support for dev_fill() and extra dev_*() debugging.
Support an fs_io dev_fill(). This helps with devices that actually already return 0 on uninitialized data. It also helps with in memory devices using sparse libs: don't allocate a block of 0s. Signed-off-by: JP Abgrall <jpa@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
parent
15ea79b3ae
commit
a35529fce0
@ -665,6 +665,8 @@ extern int f2fs_get_device_info(struct f2fs_configuration *);
|
||||
|
||||
extern int dev_read(void *, __u64, size_t);
|
||||
extern int dev_write(void *, __u64, size_t);
|
||||
/* All bytes in the buffer must be 0 use dev_fill(). */
|
||||
extern int dev_fill(void *, __u64, size_t);
|
||||
|
||||
extern int dev_read_block(void *, __u64);
|
||||
extern int dev_read_blocks(void *, __u64, __u32 );
|
||||
|
@ -49,6 +49,18 @@ int dev_write(void *buf, __u64 offset, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_fill(void *buf, __u64 offset, size_t len)
|
||||
{
|
||||
/* Only allow fill to zero */
|
||||
if (*((__u8*)buf))
|
||||
return -1;
|
||||
if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0)
|
||||
return -1;
|
||||
if (write(config.fd, buf, len) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_read_block(void *buf, __u64 blk_addr)
|
||||
{
|
||||
return dev_read(buf, blk_addr * F2FS_BLKSIZE, F2FS_BLKSIZE);
|
||||
|
@ -376,10 +376,11 @@ static int f2fs_init_sit_area(void)
|
||||
sit_seg_addr = le32_to_cpu(super_block.sit_blkaddr);
|
||||
sit_seg_addr *= blk_size;
|
||||
|
||||
DBG(1, "\tFilling sit area at offset 0x%08"PRIx64"\n", sit_seg_addr);
|
||||
for (index = 0;
|
||||
index < (le32_to_cpu(super_block.segment_count_sit) / 2);
|
||||
index++) {
|
||||
if (dev_write(zero_buf, sit_seg_addr, seg_size)) {
|
||||
if (dev_fill(zero_buf, sit_seg_addr, seg_size)) {
|
||||
MSG(1, "\tError: While zeroing out the sit area \
|
||||
on disk!!!\n");
|
||||
return -1;
|
||||
@ -411,10 +412,11 @@ static int f2fs_init_nat_area(void)
|
||||
nat_seg_addr = le32_to_cpu(super_block.nat_blkaddr);
|
||||
nat_seg_addr *= blk_size;
|
||||
|
||||
DBG(1, "\tFilling nat area at offset 0x%08"PRIx64"\n", nat_seg_addr);
|
||||
for (index = 0;
|
||||
index < (le32_to_cpu(super_block.segment_count_nat) / 2);
|
||||
index++) {
|
||||
if (dev_write(nat_buf, nat_seg_addr, seg_size)) {
|
||||
if (dev_fill(nat_buf, nat_seg_addr, seg_size)) {
|
||||
MSG(1, "\tError: While zeroing out the nat area \
|
||||
on disk!!!\n");
|
||||
return -1;
|
||||
@ -510,6 +512,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
cp_seg_blk_offset = le32_to_cpu(super_block.segment0_blkaddr);
|
||||
cp_seg_blk_offset *= blk_size_bytes;
|
||||
|
||||
DBG(1, "\tWriting main segments, ckp at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(ckp, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the ckp to disk!!!\n");
|
||||
return -1;
|
||||
@ -523,6 +526,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
sum->entries[0].ofs_in_node = 0;
|
||||
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting segment summary for data, ckp at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -533,6 +537,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA);
|
||||
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting segment summary, ckp at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -562,6 +567,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
sum->sit_j.entries[5].se.vblocks = cpu_to_le16((CURSEG_COLD_DATA << 10));
|
||||
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting data sit for root, at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -575,6 +581,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
sum->entries[0].ofs_in_node = 0;
|
||||
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting Segment summary for node blocks, at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -585,6 +592,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE);
|
||||
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting Segment summary for data block (1/2), at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -594,6 +602,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
memset(sum, 0, sizeof(struct f2fs_summary_block));
|
||||
SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE);
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting Segment summary for data block (2/2), at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(sum, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the sum_blk to disk!!!\n");
|
||||
return -1;
|
||||
@ -601,6 +610,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
|
||||
/* 8. cp page2 */
|
||||
cp_seg_blk_offset += blk_size_bytes;
|
||||
DBG(1, "\tWriting cp page2, at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(ckp, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the ckp to disk!!!\n");
|
||||
return -1;
|
||||
@ -617,6 +627,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
cp_seg_blk_offset = (le32_to_cpu(super_block.segment0_blkaddr) +
|
||||
config.blks_per_seg) *
|
||||
blk_size_bytes;
|
||||
DBG(1, "\tWriting cp page 1 of checkpoint pack 2, at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(ckp, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the ckp to disk!!!\n");
|
||||
return -1;
|
||||
@ -624,6 +635,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
|
||||
/* 10. cp page 2 of check point pack 2 */
|
||||
cp_seg_blk_offset += blk_size_bytes * (le32_to_cpu(ckp->cp_pack_total_block_count) - 1);
|
||||
DBG(1, "\tWriting cp page 2 of checkpoint pack 2, at offset 0x%08"PRIx64"\n", cp_seg_blk_offset);
|
||||
if (dev_write(ckp, cp_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the ckp to disk!!!\n");
|
||||
return -1;
|
||||
@ -643,6 +655,7 @@ static int f2fs_write_super_block(void)
|
||||
|
||||
memcpy(zero_buff + F2FS_SUPER_OFFSET, &super_block,
|
||||
sizeof(super_block));
|
||||
DBG(1, "\tWriting super block, at offset 0x%08x\n", 0);
|
||||
for (index = 0; index < 2; index++) {
|
||||
if (dev_write(zero_buff, index * F2FS_BLKSIZE, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While while writing supe_blk \
|
||||
@ -709,6 +722,7 @@ static int f2fs_write_root_inode(void)
|
||||
config.blks_per_seg;
|
||||
main_area_node_seg_blk_offset *= blk_size_bytes;
|
||||
|
||||
DBG(1, "\tWriting root inode (hot node), at offset 0x%08"PRIx64"\n", main_area_node_seg_blk_offset);
|
||||
if (dev_write(raw_node, main_area_node_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the raw_node to disk!!!\n");
|
||||
return -1;
|
||||
@ -722,6 +736,7 @@ static int f2fs_write_root_inode(void)
|
||||
config.blks_per_seg;
|
||||
main_area_node_seg_blk_offset *= blk_size_bytes;
|
||||
|
||||
DBG(1, "\tWriting root inode (warm node), at offset 0x%08"PRIx64"\n", main_area_node_seg_blk_offset);
|
||||
if (dev_write(raw_node, main_area_node_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the raw_node to disk!!!\n");
|
||||
return -1;
|
||||
@ -759,6 +774,7 @@ static int f2fs_update_nat_root(void)
|
||||
nat_seg_blk_offset = le32_to_cpu(super_block.nat_blkaddr);
|
||||
nat_seg_blk_offset *= blk_size_bytes;
|
||||
|
||||
DBG(1, "\tWriting nat root, at offset 0x%08"PRIx64"\n", nat_seg_blk_offset);
|
||||
if (dev_write(nat_blk, nat_seg_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the nat_blk set0 to disk!\n");
|
||||
return -1;
|
||||
@ -799,6 +815,7 @@ static int f2fs_add_default_dentry_root(void)
|
||||
config.blks_per_seg;
|
||||
data_blk_offset *= blk_size_bytes;
|
||||
|
||||
DBG(1, "\tWriting default dentry root, at offset 0x%08"PRIx64"\n", data_blk_offset);
|
||||
if (dev_write(dent_blk, data_blk_offset, F2FS_BLKSIZE)) {
|
||||
MSG(1, "\tError: While writing the dentry_blk to disk!!!\n");
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user