diff options
author | Jaegeuk Kim <jaegeuk@google.com> | 2023-11-10 04:08:15 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-11-10 04:08:15 +0000 |
commit | 8851cfaacf2cfd47c68e14dcd889416f730e350b (patch) | |
tree | 0aa9eb91c525006ddbb5ca4a0652ef8b4ab554aa | |
parent | c911db8f360a60e587c1c03887ee2bce2edbe480 (diff) | |
parent | a08d617951348f26544e0d2827e24643b883b9d1 (diff) | |
download | f2fs-tools-8851cfaacf2cfd47c68e14dcd889416f730e350b.tar.gz |
Upgrade f2fs-tools to f71fbf8f3dee4eefdddac1abaaf4ae76bb9a48b3 am: f5d5adbf61 am: fbada0bc73 am: a08d617951
Original change: https://android-review.googlesource.com/c/platform/external/f2fs-tools/+/2825403
Change-Id: Ibd293c378792c5cb869f95f07ac663591edb44ed
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | fsck/defrag.c | 2 | ||||
-rw-r--r-- | fsck/dir.c | 18 | ||||
-rw-r--r-- | fsck/dump.c | 20 | ||||
-rw-r--r-- | fsck/fsck.c | 135 | ||||
-rw-r--r-- | fsck/fsck.h | 4 | ||||
-rw-r--r-- | fsck/mkquota.c | 2 | ||||
-rw-r--r-- | fsck/mount.c | 83 | ||||
-rw-r--r-- | fsck/node.c | 4 | ||||
-rw-r--r-- | fsck/node.h | 2 | ||||
-rw-r--r-- | fsck/resize.c | 26 | ||||
-rw-r--r-- | fsck/segment.c | 52 | ||||
-rw-r--r-- | fsck/xattr.c | 9 | ||||
-rw-r--r-- | include/f2fs_fs.h | 2 | ||||
-rw-r--r-- | lib/libf2fs_zoned.c | 28 |
15 files changed, 207 insertions, 186 deletions
@@ -13,11 +13,11 @@ third_party { type: GIT value: "https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git" } - version: "d860afaebd1e04839047d247fa5d1cfcdeaeefb6" + version: "f71fbf8f3dee4eefdddac1abaaf4ae76bb9a48b3" license_type: RESTRICTED last_upgrade_date { year: 2023 - month: 10 - day: 26 + month: 11 + day: 9 } } diff --git a/fsck/defrag.c b/fsck/defrag.c index a630a78..90c2962 100644 --- a/fsck/defrag.c +++ b/fsck/defrag.c @@ -11,7 +11,7 @@ static int migrate_block(struct f2fs_sb_info *sbi, u64 from, u64 to) { - void *raw = calloc(BLOCK_SZ, 1); + void *raw = calloc(F2FS_BLKSIZE, 1); struct seg_entry *se; struct f2fs_summary sum; u64 offset; @@ -130,7 +130,7 @@ static int find_in_level(struct f2fs_sb_info *sbi, struct f2fs_node *dir, bidx = dir_block_index(level, dir_level, le32_to_cpu(namehash) % nbucket); end_block = bidx + nblock; - dentry_blk = calloc(BLOCK_SZ, 1); + dentry_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(dentry_blk); memset(&dn, 0, sizeof(dn)); @@ -247,7 +247,7 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, return -EINVAL; } - dentry_blk = calloc(BLOCK_SZ, 1); + dentry_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(dentry_blk); current_depth = le32_to_cpu(parent->i.i_current_depth); @@ -349,7 +349,7 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) get_node_info(sbi, ino, &ni); - dent_blk = calloc(BLOCK_SZ, 1); + dent_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(dent_blk); F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).hash_code = 0; @@ -398,7 +398,7 @@ static void page_symlink(struct f2fs_sb_info *sbi, struct f2fs_node *inode, return; } - data_blk = calloc(BLOCK_SZ, 1); + data_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(data_blk); memcpy(data_blk, symname, symlen); @@ -578,7 +578,7 @@ int convert_inline_dentry(struct f2fs_sb_info *sbi, struct f2fs_node *node, struct f2fs_dentry_block *dentry_blk; struct f2fs_dentry_ptr src, dst; - dentry_blk = calloc(BLOCK_SZ, 1); + dentry_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(dentry_blk); set_new_dnode(&dn, node, NULL, ino); @@ -698,7 +698,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) if (de->from_devino) found_hardlink = f2fs_search_hardlink(sbi, de); - parent = calloc(BLOCK_SZ, 1); + parent = calloc(F2FS_BLKSIZE, 1); ASSERT(parent); ret = dev_read_block(parent, ni.blk_addr); @@ -722,7 +722,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) goto free_parent_dir; } - child = calloc(BLOCK_SZ, 1); + child = calloc(F2FS_BLKSIZE, 1); ASSERT(child); if (found_hardlink && found_hardlink->to_ino) { @@ -770,7 +770,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) /* Replace child with original block */ free(child); - child = calloc(BLOCK_SZ, 1); + child = calloc(F2FS_BLKSIZE, 1); ASSERT(child); ret = dev_read_block(child, blkaddr); @@ -838,7 +838,7 @@ int f2fs_find_path(struct f2fs_sb_info *sbi, char *path, nid_t *ino) return -ENOENT; *ino = F2FS_ROOT_INO(sbi); - parent = calloc(BLOCK_SZ, 1); + parent = calloc(F2FS_BLKSIZE, 1); ASSERT(parent); p = strtok(path, "/"); diff --git a/fsck/dump.c b/fsck/dump.c index 864a3c3..b2e990b 100644 --- a/fsck/dump.c +++ b/fsck/dump.c @@ -43,9 +43,9 @@ void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat) char buf[BUF_SZ]; int fd, ret, pack; - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); - node_block = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_block = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_block); fd = open("dump_nat", O_CREAT|O_WRONLY|O_TRUNC, 0666); @@ -321,7 +321,7 @@ static void dump_node_blk(struct f2fs_sb_info *sbi, int ntype, get_node_info(sbi, nid, &ni); - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); dev_read_block(node_blk, ni.blk_addr); @@ -558,7 +558,7 @@ void dump_node_scan_disk(struct f2fs_sb_info *sbi, nid_t nid) pgoff_t end_blkaddr = start_blkaddr + (SM_I(sbi)->main_segments << sbi->log_blocks_per_seg); - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); MSG(0, "Info: scan all nid: %u from block_addr [%lu: %lu]\n", nid, start_blkaddr, end_blkaddr); @@ -590,7 +590,7 @@ int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force) get_node_info(sbi, nid, &ni); - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); DBG(1, "Node ID [0x%x]\n", nid); @@ -632,7 +632,7 @@ static void dump_node_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr) struct f2fs_node *node_blk; int ret; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); ret = dev_read_block(node_blk, blk_addr); @@ -675,7 +675,7 @@ static void dump_data_offset(u32 blk_addr, int ofs_in_node) unsigned int node_ofs; int ret; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); ret = dev_read_block(node_blk, blk_addr); @@ -697,7 +697,7 @@ static void dump_node_offset(u32 blk_addr) struct f2fs_node *node_blk; int ret; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); ret = dev_read_block(node_blk, blk_addr); @@ -712,7 +712,7 @@ static int has_dirent(u32 blk_addr, int is_inline, int *enc_name) struct f2fs_node *node_blk; int ret, is_dentry = 0; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); ret = dev_read_block(node_blk, blk_addr); @@ -737,7 +737,7 @@ static void dump_dirent(u32 blk_addr, int is_inline, int enc_name) void *inline_dentry, *blk; int ret, i = 0; - blk = calloc(BLOCK_SZ, 1); + blk = calloc(F2FS_BLKSIZE, 1); ASSERT(blk); ret = dev_read_block(blk, blk_addr); diff --git a/fsck/fsck.c b/fsck/fsck.c index f1a55db..55eddca 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -236,7 +236,7 @@ static int is_valid_summary(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, struct node_info ni; int ret = 0; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk != NULL); if (!IS_VALID_NID(sbi, nid)) @@ -545,7 +545,7 @@ int fsck_sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid, struct node_info ni; int ret; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk != NULL); ret = sanity_check_nid(sbi, nid, node_blk, ftype, ntype, &ni); @@ -564,7 +564,7 @@ static int fsck_chk_xattr_blk(struct f2fs_sb_info *sbi, u32 ino, if (x_nid == 0x0) return 0; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk != NULL); /* Sanity check */ @@ -590,7 +590,7 @@ int fsck_chk_node_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode, struct node_info ni; struct f2fs_node *node_blk = NULL; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk != NULL); if (sanity_check_nid(sbi, nid, node_blk, ftype, ntype, &ni)) @@ -657,7 +657,7 @@ int fsck_chk_root_inode(struct f2fs_sb_info *sbi) u32 last_ctime_nsec = 0; int ret = -EINVAL; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); MSG(0, "Info: root inode is corrupted, search and relink it\n"); @@ -735,7 +735,6 @@ fix: struct f2fs_fsck *fsck = F2FS_FSCK(sbi); FIX_MSG("Relink root inode, blkaddr: 0x%x", last_blkaddr); - update_nat_journal_blkaddr(sbi, root_ino, last_blkaddr); update_nat_blkaddr(sbi, root_ino, root_ino, last_blkaddr); if (f2fs_test_bit(root_ino, fsck->nat_area_bitmap)) @@ -2013,7 +2012,7 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, int casefolded, u32 blk_addr, struct f2fs_dentry *new_dentry; int dentries, ret; - de_blk = (struct f2fs_dentry_block *)calloc(BLOCK_SZ, 1); + de_blk = (struct f2fs_dentry_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(de_blk != NULL); ret = dev_read_block(de_blk, blk_addr); @@ -2113,10 +2112,10 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) f2fs_ra_meta_pages(sbi, start_blk, orphan_blkaddr, META_CP); - orphan_blk = calloc(BLOCK_SZ, 1); + orphan_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(orphan_blk); - new_blk = calloc(BLOCK_SZ, 1); + new_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(new_blk); for (i = 0; i < orphan_blkaddr; i++) { @@ -2164,8 +2163,8 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) ret = dev_write_block(new_blk, start_blk + i); ASSERT(ret >= 0); } - memset(orphan_blk, 0, BLOCK_SZ); - memset(new_blk, 0, BLOCK_SZ); + memset(orphan_blk, 0, F2FS_BLKSIZE); + memset(new_blk, 0, F2FS_BLKSIZE); } free(orphan_blk); free(new_blk); @@ -2442,7 +2441,7 @@ static void fix_hard_links(struct f2fs_sb_info *sbi) if (fsck->hard_link_list_head == NULL) return; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk != NULL); node = fsck->hard_link_list_head; @@ -2482,7 +2481,7 @@ static void flush_curseg_sit_entries(struct f2fs_sb_info *sbi) struct f2fs_sit_block *sit_blk; int i; - sit_blk = calloc(BLOCK_SZ, 1); + sit_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(sit_blk); /* update curseg sit entries, since we may change * a segment type in move_curseg_info @@ -2526,7 +2525,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi) struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); unsigned long long cp_blk_no; - u32 flags = c.alloc_failed ? CP_FSCK_FLAG: CP_UMOUNT_FLAG; + u32 flags = c.alloc_failed ? CP_FSCK_FLAG : + (c.roll_forward ? 0 : CP_UMOUNT_FLAG); block_t orphan_blks = 0; block_t cp_blocks; u32 i; @@ -2658,10 +2658,9 @@ static int check_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) struct curseg_info *curseg = CURSEG_I(sbi, type); struct f2fs_fsck *fsck = F2FS_FSCK(sbi); struct blk_zone blkz; - block_t cs_block, wp_block, zone_last_vblock; + block_t cs_block, wp_block; uint64_t cs_sector, wp_sector; int i, ret; - unsigned int zone_segno; int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT; /* get the device the curseg points to */ @@ -2695,49 +2694,28 @@ static int check_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) (blk_zone_wp_sector(&blkz) >> log_sectors_per_block); wp_sector = blk_zone_wp_sector(&blkz); - if (cs_sector == wp_sector) - return 0; - - if (cs_sector > wp_sector) { + if (cs_sector == wp_sector) { + if (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) + return 0; + MSG(0, "Correct write pointer. But, we can't trust it, " + "since the previous mount wasn't safely unmounted: " + "curseg %d[0x%x,0x%x]\n", + type, curseg->segno, curseg->next_blkoff); + } else if (cs_sector > wp_sector) { MSG(0, "Inconsistent write pointer with curseg %d: " "curseg %d[0x%x,0x%x] > wp[0x%x,0x%x]\n", type, type, curseg->segno, curseg->next_blkoff, + GET_SEGNO(sbi, wp_block), + OFFSET_IN_SEG(sbi, wp_block)); + if (!c.fix_on) + fsck->chk.wp_inconsistent_zones++; + } else { + MSG(0, "Write pointer goes advance from curseg %d: " + "curseg %d[0x%x,0x%x] wp[0x%x,0x%x]\n", + type, type, curseg->segno, curseg->next_blkoff, GET_SEGNO(sbi, wp_block), OFFSET_IN_SEG(sbi, wp_block)); - fsck->chk.wp_inconsistent_zones++; - return -EINVAL; - } - - MSG(0, "Write pointer goes advance from curseg %d: " - "curseg %d[0x%x,0x%x] wp[0x%x,0x%x]\n", - type, type, curseg->segno, curseg->next_blkoff, - GET_SEGNO(sbi, wp_block), OFFSET_IN_SEG(sbi, wp_block)); - - zone_segno = GET_SEG_FROM_SEC(sbi, - GET_SEC_FROM_SEG(sbi, curseg->segno)); - zone_last_vblock = START_BLOCK(sbi, zone_segno) + - last_vblk_off_in_zone(sbi, zone_segno); - - /* - * If valid blocks exist between the curseg position and the write - * pointer, they are fsync data. This is not an error to fix. Leave it - * for kernel to recover later. - * If valid blocks exist between the curseg's zone start and the curseg - * position, or if there is no valid block in the curseg's zone, fix - * the inconsistency between the curseg and the writ pointer. - * Of Note is that if there is no valid block in the curseg's zone, - * last_vblk_off_in_zone() returns -1 and zone_last_vblock is always - * smaller than cs_block. - */ - if (cs_block <= zone_last_vblock && zone_last_vblock < wp_block) { - MSG(0, "Curseg has fsync data: curseg %d[0x%x,0x%x] " - "last valid block in zone[0x%x,0x%x]\n", - type, curseg->segno, curseg->next_blkoff, - GET_SEGNO(sbi, zone_last_vblock), - OFFSET_IN_SEG(sbi, zone_last_vblock)); - return 0; } - fsck->chk.wp_inconsistent_zones++; return -EINVAL; } @@ -2751,7 +2729,7 @@ static int check_curseg_write_pointer(struct f2fs_sb_info *UNUSED(sbi), #endif -int check_curseg_offset(struct f2fs_sb_info *sbi, int type) +int check_curseg_offset(struct f2fs_sb_info *sbi, int type, bool check_wp) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct curseg_info *curseg = CURSEG_I(sbi, type); @@ -2785,30 +2763,30 @@ int check_curseg_offset(struct f2fs_sb_info *sbi, int type) } } - if (c.zoned_model == F2FS_ZONED_HM) + if (check_wp && c.zoned_model == F2FS_ZONED_HM) return check_curseg_write_pointer(sbi, type); return 0; } -int check_curseg_offsets(struct f2fs_sb_info *sbi) +int check_curseg_offsets(struct f2fs_sb_info *sbi, bool check_wp) { int i, ret; for (i = 0; i < NO_CHECK_TYPE; i++) { - ret = check_curseg_offset(sbi, i); + ret = check_curseg_offset(sbi, i, check_wp); if (ret) return ret; } return 0; } -static void fix_curseg_info(struct f2fs_sb_info *sbi) +static void fix_curseg_info(struct f2fs_sb_info *sbi, bool check_wp) { int i, need_update = 0; for (i = 0; i < NO_CHECK_TYPE; i++) { - if (check_curseg_offset(sbi, i)) { + if (check_curseg_offset(sbi, i, check_wp)) { update_curseg_info(sbi, i); need_update = 1; } @@ -3277,10 +3255,8 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque) struct f2fs_fsck *fsck = F2FS_FSCK(sbi); block_t zone_block, wp_block, wp_blkoff; unsigned int zone_segno, wp_segno; - struct curseg_info *cs; - int cs_index, ret, last_valid_blkoff; + int ret, last_valid_blkoff; int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT; - unsigned int segs_per_zone = sbi->segs_per_sec * sbi->secs_per_zone; if (blk_zone_conv(blkz)) return 0; @@ -3296,14 +3272,6 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque) wp_segno = GET_SEGNO(sbi, wp_block); wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); - /* if a curseg points to the zone, skip the check */ - for (cs_index = 0; cs_index < NO_CHECK_TYPE; cs_index++) { - cs = &SM_I(sbi)->curseg_array[cs_index]; - if (zone_segno <= cs->segno && - cs->segno < zone_segno + segs_per_zone) - return 0; - } - last_valid_blkoff = last_vblk_off_in_zone(sbi, zone_segno); /* @@ -3339,10 +3307,27 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque) if (last_valid_blkoff + zone_block > wp_block) { MSG(0, "Unexpected invalid write pointer: wp[0x%x,0x%x]\n", wp_segno, wp_blkoff); + if (!c.fix_on) + fsck->chk.wp_inconsistent_zones++; + } + + if (!c.fix_on) return 0; + + ret = f2fs_finish_zone(wpd->dev_index, blkz); + if (ret) { + u64 fill_sects = blk_zone_length(blkz) - + (blk_zone_wp_sector(blkz) - blk_zone_sector(blkz)); + printf("[FSCK] Finishing zone failed: %s\n", dev->path); + ret = dev_fill(NULL, wp_block * F2FS_BLKSIZE, + (fill_sects >> log_sectors_per_block) * F2FS_BLKSIZE); + if (ret) + printf("[FSCK] Fill up zone failed: %s\n", dev->path); } - return 0; + if (!ret) + fsck->chk.wp_fixed = 1; + return ret; } static void fix_wp_sit_alignment(struct f2fs_sb_info *sbi) @@ -3388,8 +3373,8 @@ void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *sbi) if (c.zoned_model != F2FS_ZONED_HM) return; - if (check_curseg_offsets(sbi) && c.fix_on) { - fix_curseg_info(sbi); + if (check_curseg_offsets(sbi, true) && c.fix_on) { + fix_curseg_info(sbi, true); fsck->chk.wp_fixed = 1; } @@ -3583,7 +3568,7 @@ int fsck_verify(struct f2fs_sb_info *sbi) } printf("[FSCK] next block offset is free "); - if (check_curseg_offsets(sbi) == 0) { + if (check_curseg_offsets(sbi, false) == 0) { printf(" [Ok..]\n"); } else { printf(" [Fail]\n"); @@ -3636,7 +3621,7 @@ int fsck_verify(struct f2fs_sb_info *sbi) fix_nat_entries(sbi); rewrite_sit_area_bitmap(sbi); fix_wp_sit_alignment(sbi); - fix_curseg_info(sbi); + fix_curseg_info(sbi, false); fix_checksum(sbi); fix_checkpoints(sbi); } else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG) || diff --git a/fsck/fsck.h b/fsck/fsck.h index c25f381..f6f15e7 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -126,8 +126,6 @@ struct f2fs_fsck { struct quota_ctx *qctx; }; -#define BLOCK_SZ F2FS_BLKSIZE - enum NODE_TYPE { TYPE_INODE = 37, TYPE_DIRECT_NODE = 43, @@ -207,8 +205,6 @@ extern void update_sum_entry(struct f2fs_sb_info *, block_t, struct f2fs_summary *); extern void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); extern void nullify_nat_entry(struct f2fs_sb_info *, u32); -extern void update_nat_journal_blkaddr(struct f2fs_sb_info *sbi, u32 nid, - block_t blkaddr); extern void rewrite_sit_area_bitmap(struct f2fs_sb_info *); extern void build_nat_area_bitmap(struct f2fs_sb_info *); extern void build_sit_area_bitmap(struct f2fs_sb_info *); diff --git a/fsck/mkquota.c b/fsck/mkquota.c index d18141e..2451b58 100644 --- a/fsck/mkquota.c +++ b/fsck/mkquota.c @@ -302,7 +302,7 @@ void quota_add_inode_usage(quota_ctx_t qctx, f2fs_ino_t ino, UINT_TO_VOIDPTR(ino), NULL); } - qsize_t space = (inode->i_blocks - 1) * BLOCK_SZ; + qsize_t space = (inode->i_blocks - 1) * F2FS_BLKSIZE; quota_data_add(qctx, inode, space); quota_data_inodes(qctx, inode, +1); } diff --git a/fsck/mount.c b/fsck/mount.c index 3b02d73..72516f4 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -859,7 +859,7 @@ void update_superblock(struct f2fs_super_block *sb, int sb_mask) uint8_t *buf; u32 old_crc, new_crc; - buf = calloc(BLOCK_SZ, 1); + buf = calloc(F2FS_BLKSIZE, 1); ASSERT(buf); if (get_sb(feature) & F2FS_FEATURE_SB_CHKSUM) { @@ -2366,7 +2366,7 @@ struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *sbi, } } - sum_blk = calloc(BLOCK_SZ, 1); + sum_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(sum_blk); ret = dev_read_block(sum_blk, ssa_blk); @@ -2410,7 +2410,7 @@ static void get_nat_entry(struct f2fs_sb_info *sbi, nid_t nid, if (lookup_nat_in_journal(sbi, nid, raw_nat) >= 0) return; - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); entry_off = nid % NAT_ENTRY_PER_BLOCK; @@ -2432,7 +2432,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid, block_t oldaddr, startaddr, endaddr; int ret; - node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1); + node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); get_node_info(sbi, nid, &ni); @@ -2479,12 +2479,27 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid, void update_nat_blkaddr(struct f2fs_sb_info *sbi, nid_t ino, nid_t nid, block_t newaddr) { - struct f2fs_nat_block *nat_block; + struct f2fs_nat_block *nat_block = NULL; + struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); + struct f2fs_nat_entry *entry; pgoff_t block_addr; int entry_off; - int ret; + int ret, i; + + for (i = 0; i < nats_in_cursum(journal); i++) { + if (le32_to_cpu(nid_in_journal(journal, i)) == nid) { + entry = &nat_in_journal(journal, i); + entry->block_addr = cpu_to_le32(newaddr); + if (ino) + entry->ino = cpu_to_le32(ino); + MSG(0, "update nat(nid:%d) blkaddr [0x%x] in journal\n", + nid, newaddr); + goto update_cache; + } + } - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); entry_off = nid % NAT_ENTRY_PER_BLOCK; @@ -2493,15 +2508,19 @@ void update_nat_blkaddr(struct f2fs_sb_info *sbi, nid_t ino, ret = dev_read_block(nat_block, block_addr); ASSERT(ret >= 0); + entry = &nat_block->entries[entry_off]; if (ino) - nat_block->entries[entry_off].ino = cpu_to_le32(ino); - nat_block->entries[entry_off].block_addr = cpu_to_le32(newaddr); - if (c.func == FSCK) - F2FS_FSCK(sbi)->entries[nid] = nat_block->entries[entry_off]; + entry->ino = cpu_to_le32(ino); + entry->block_addr = cpu_to_le32(newaddr); ret = dev_write_block(nat_block, block_addr); ASSERT(ret >= 0); - free(nat_block); +update_cache: + if (c.func == FSCK) + F2FS_FSCK(sbi)->entries[nid] = *entry; + + if (nat_block) + free(nat_block); } void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) @@ -2532,7 +2551,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) unsigned int i, segno, end; unsigned int readed, start_blk = 0; - sit_blk = calloc(BLOCK_SZ, 1); + sit_blk = calloc(F2FS_BLKSIZE, 1); if (!sit_blk) { MSG(1, "\tError: Calloc failed for build_sit_entries!\n"); return -ENOMEM; @@ -2684,7 +2703,7 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) struct f2fs_summary_block *sum = curseg->sum_blk; char *ptr = NULL; - sit_blk = calloc(BLOCK_SZ, 1); + sit_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(sit_blk); /* remove sit journal */ F2FS_SUMMARY_BLOCK_JOURNAL(sum)->n_sits = 0; @@ -2734,7 +2753,7 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) unsigned int segno; int i; - sit_blk = calloc(BLOCK_SZ, 1); + sit_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(sit_blk); for (i = 0; i < sits_in_cursum(journal); i++) { struct f2fs_sit_entry *sit; @@ -2770,7 +2789,7 @@ static int flush_nat_journal_entries(struct f2fs_sb_info *sbi) int ret; int i = 0; - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); next: if (i >= nats_in_cursum(journal)) { @@ -2814,7 +2833,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi) struct f2fs_sit_block *sit_blk; unsigned int segno = 0; - sit_blk = calloc(BLOCK_SZ, 1); + sit_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(sit_blk); /* update free segments */ for (segno = 0; segno < MAIN_SEGS(sbi); segno++) { @@ -3120,6 +3139,9 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) int ret; int i = 0; + if (c.func == FSCK) + F2FS_FSCK(sbi)->entries[nid].block_addr = 0; + /* check in journal */ for (i = 0; i < nats_in_cursum(journal); i++) { if (le32_to_cpu(nid_in_journal(journal, i)) == nid) { @@ -3129,7 +3151,7 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) return; } } - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); entry_off = nid % NAT_ENTRY_PER_BLOCK; @@ -3153,24 +3175,6 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) free(nat_block); } -void update_nat_journal_blkaddr(struct f2fs_sb_info *sbi, u32 nid, - block_t blkaddr) -{ - struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); - int i; - - for (i = 0; i < nats_in_cursum(journal); i++) { - if (le32_to_cpu(nid_in_journal(journal, i)) == nid) { - nat_in_journal(journal, i).block_addr = - cpu_to_le32(blkaddr); - MSG(0, "update nat(nid:%d) blkaddr [0x%x] in journal\n", - nid, blkaddr); - return; - } - } -} - void duplicate_checkpoint(struct f2fs_sb_info *sbi) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); @@ -3218,7 +3222,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi) struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); block_t orphan_blks = 0; unsigned long long cp_blk_no; - u32 flags = CP_UMOUNT_FLAG; + u32 flags = c.roll_forward ? 0 : CP_UMOUNT_FLAG; int i, ret; uint32_t crc = 0; @@ -3331,7 +3335,7 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi) int ret; unsigned int i; - nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1); + nat_block = (struct f2fs_nat_block *)calloc(F2FS_BLKSIZE, 1); ASSERT(nat_block); /* Alloc & build nat entry bitmap */ @@ -3837,6 +3841,9 @@ static int record_fsync_data(struct f2fs_sb_info *sbi) if (ret) goto out; + if (c.func == FSCK && inode_list.next != &inode_list) + c.roll_forward = 1; + ret = late_build_segment_manager(sbi); if (ret < 0) { ERR_MSG("late_build_segment_manager failed\n"); diff --git a/fsck/node.c b/fsck/node.c index 3761470..d53756d 100644 --- a/fsck/node.c +++ b/fsck/node.c @@ -125,7 +125,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi, f2fs_inode = dn->inode_blk; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(dn->nid); @@ -290,7 +290,7 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, struct node_info ni; get_node_info(sbi, nids[i], &ni); - dn->node_blk = calloc(BLOCK_SZ, 1); + dn->node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(dn->node_blk); ret = dev_read_block(dn->node_blk, ni.blk_addr); diff --git a/fsck/node.h b/fsck/node.h index a6108ac..ac0e7b3 100644 --- a/fsck/node.h +++ b/fsck/node.h @@ -35,7 +35,7 @@ static inline unsigned int ADDRS_PER_PAGE(struct f2fs_sb_info *sbi, if (!inode_blk) { struct node_info ni; - inode_blk = calloc(BLOCK_SZ, 2); + inode_blk = calloc(F2FS_BLKSIZE, 2); ASSERT(inode_blk); get_node_info(sbi, ino, &ni); diff --git a/fsck/resize.c b/fsck/resize.c index 6c3f4bd..a3424b4 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -167,7 +167,7 @@ safe_resize: static void migrate_main(struct f2fs_sb_info *sbi, unsigned int offset) { - void *raw = calloc(BLOCK_SZ, 1); + void *raw = calloc(F2FS_BLKSIZE, 1); struct seg_entry *se; block_t from, to; int i, j, ret; @@ -243,7 +243,7 @@ static void migrate_ssa(struct f2fs_sb_info *sbi, MAIN_SEGS(sbi) - offset; block_t blkaddr; int ret; - void *zero_block = calloc(BLOCK_SZ, 1); + void *zero_block = calloc(F2FS_BLKSIZE, 1); ASSERT(zero_block); if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) { @@ -287,9 +287,9 @@ static int shrink_nats(struct f2fs_sb_info *sbi, pgoff_t block_addr; int seg_off; - nat_block = malloc(BLOCK_SZ); + nat_block = malloc(F2FS_BLKSIZE); ASSERT(nat_block); - zero_block = calloc(BLOCK_SZ, 1); + zero_block = calloc(F2FS_BLKSIZE, 1); ASSERT(zero_block); nat_blocks = get_newsb(segment_count_nat) >> 1; @@ -309,7 +309,7 @@ static int shrink_nats(struct f2fs_sb_info *sbi, ret = dev_read_block(nat_block, block_addr); ASSERT(ret >= 0); - if (memcmp(zero_block, nat_block, BLOCK_SZ)) { + if (memcmp(zero_block, nat_block, F2FS_BLKSIZE)) { ret = -1; goto not_avail; } @@ -336,7 +336,7 @@ static void migrate_nat(struct f2fs_sb_info *sbi, pgoff_t block_addr; int seg_off; - nat_block = malloc(BLOCK_SZ); + nat_block = malloc(F2FS_BLKSIZE); ASSERT(nat_block); for (nid = nm_i->max_nid - 1; nid >= 0; nid -= NAT_ENTRY_PER_BLOCK) { @@ -364,7 +364,7 @@ static void migrate_nat(struct f2fs_sb_info *sbi, ASSERT(ret >= 0); } /* zero out newly assigned nids */ - memset(nat_block, 0, BLOCK_SZ); + memset(nat_block, 0, F2FS_BLKSIZE); nat_blocks = get_newsb(segment_count_nat) >> 1; nat_blocks = nat_blocks << get_sb(log_blocks_per_seg); new_max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks; @@ -396,7 +396,7 @@ static void migrate_sit(struct f2fs_sb_info *sbi, struct sit_info *sit_i = SIT_I(sbi); unsigned int ofs = 0, pre_ofs = 0; unsigned int segno, index; - struct f2fs_sit_block *sit_blk = calloc(BLOCK_SZ, 1); + struct f2fs_sit_block *sit_blk = calloc(F2FS_BLKSIZE, 1); block_t sit_blks = get_newsb(segment_count_sit) << (sbi->log_blocks_per_seg - 1); struct seg_entry *se; @@ -430,7 +430,7 @@ static void migrate_sit(struct f2fs_sb_info *sbi, DBG(1, "Write valid sit: %x\n", blk_addr); pre_ofs = ofs; - memset(sit_blk, 0, BLOCK_SZ); + memset(sit_blk, 0, F2FS_BLKSIZE); } sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno - offset)]; @@ -464,10 +464,10 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, void *buf; int i, ret; - new_cp = calloc(new_cp_blks * BLOCK_SZ, 1); + new_cp = calloc(new_cp_blks * F2FS_BLKSIZE, 1); ASSERT(new_cp); - buf = malloc(BLOCK_SZ); + buf = malloc(F2FS_BLKSIZE); ASSERT(buf); /* ovp / free segments */ @@ -561,7 +561,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, ret = dev_write_block(new_cp, new_cp_blk_no++); ASSERT(ret >= 0); - memset(buf, 0, BLOCK_SZ); + memset(buf, 0, F2FS_BLKSIZE); for (i = 0; i < get_newsb(cp_payload); i++) { ret = dev_write_block(buf, new_cp_blk_no++); ASSERT(ret >= 0); @@ -594,7 +594,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, write_nat_bits(sbi, new_sb, new_cp, sbi->cur_cp == 1 ? 2 : 1); /* disable old checkpoint */ - memset(buf, 0, BLOCK_SZ); + memset(buf, 0, F2FS_BLKSIZE); ret = dev_write_block(buf, old_cp_blk_no); ASSERT(ret >= 0); diff --git a/fsck/segment.c b/fsck/segment.c index 4b05fd4..934004e 100644 --- a/fsck/segment.c +++ b/fsck/segment.c @@ -36,8 +36,8 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, ERR_MSG("Not enough space\n"); return -ENOSPC; } - if (is_node && fsck->chk.valid_node_cnt > - sbi->total_valid_node_count) { + if (is_node && fsck->chk.valid_node_cnt >= + sbi->total_node_count) { ERR_MSG("Not enough space for node block\n"); return -ENOSPC; } @@ -131,7 +131,7 @@ int new_data_block(struct f2fs_sb_info *sbi, void *block, type = CURSEG_HOT_DATA; ASSERT(dn->node_blk); - memset(block, 0, BLOCK_SZ); + memset(block, 0, F2FS_BLKSIZE); get_node_info(sbi, dn->nid, &ni); set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); @@ -157,7 +157,7 @@ u64 f2fs_quota_size(struct quota_file *qf) struct f2fs_node *inode; u64 filesize; - inode = (struct f2fs_node *) calloc(BLOCK_SZ, 1); + inode = (struct f2fs_node *) calloc(F2FS_BLKSIZE, 1); ASSERT(inode); /* Read inode */ @@ -188,9 +188,9 @@ u64 f2fs_read(struct f2fs_sb_info *sbi, nid_t ino, u8 *buffer, memset(&dn, 0, sizeof(dn)); /* Memory allocation for block buffer and inode. */ - blk_buffer = calloc(BLOCK_SZ, 2); + blk_buffer = calloc(F2FS_BLKSIZE, 2); ASSERT(blk_buffer); - inode = (struct f2fs_node*)(blk_buffer + BLOCK_SZ); + inode = (struct f2fs_node*)(blk_buffer + F2FS_BLKSIZE); /* Read inode */ get_node_info(sbi, ino, &ni); @@ -225,13 +225,13 @@ u64 f2fs_read(struct f2fs_sb_info *sbi, nid_t ino, u8 *buffer, if (blkaddr == NULL_ADDR || blkaddr == NEW_ADDR) break; - off_in_blk = offset % BLOCK_SZ; - len_in_blk = BLOCK_SZ - off_in_blk; + off_in_blk = offset % F2FS_BLKSIZE; + len_in_blk = F2FS_BLKSIZE - off_in_blk; if (len_in_blk > count) len_in_blk = count; /* Read data from single block. */ - if (len_in_blk < BLOCK_SZ) { + if (len_in_blk < F2FS_BLKSIZE) { ASSERT(dev_read_block(blk_buffer, blkaddr) >= 0); memcpy(buffer, blk_buffer + off_in_blk, len_in_blk); } else { @@ -290,9 +290,9 @@ static u64 f2fs_write_ex(struct f2fs_sb_info *sbi, nid_t ino, u8 *buffer, ASSERT(offset % F2FS_BLKSIZE == 0); /* block boundary only */ /* Memory allocation for block buffer and inode. */ - blk_buffer = calloc(BLOCK_SZ, 2); + blk_buffer = calloc(F2FS_BLKSIZE, 2); ASSERT(blk_buffer); - inode = (struct f2fs_node*)(blk_buffer + BLOCK_SZ); + inode = (struct f2fs_node*)(blk_buffer + F2FS_BLKSIZE); /* Read inode */ get_node_info(sbi, ino, &ni); @@ -340,13 +340,13 @@ static u64 f2fs_write_ex(struct f2fs_sb_info *sbi, nid_t ino, u8 *buffer, idirty |= dn.idirty; } - off_in_blk = offset % BLOCK_SZ; - len_in_blk = BLOCK_SZ - off_in_blk; + off_in_blk = offset % F2FS_BLKSIZE; + len_in_blk = F2FS_BLKSIZE - off_in_blk; if (len_in_blk > count) len_in_blk = count; /* Write data to single block. */ - if (len_in_blk < BLOCK_SZ) { + if (len_in_blk < F2FS_BLKSIZE) { ASSERT(dev_read_block(blk_buffer, blkaddr) >= 0); memcpy(blk_buffer + off_in_blk, buffer, len_in_blk); ASSERT(dev_write_block(blk_buffer, blkaddr) >= 0); @@ -406,7 +406,7 @@ void f2fs_filesize_update(struct f2fs_sb_info *sbi, nid_t ino, u64 filesize) struct node_info ni; struct f2fs_node *inode; - inode = calloc(BLOCK_SZ, 1); + inode = calloc(F2FS_BLKSIZE, 1); ASSERT(inode); get_node_info(sbi, ino, &ni); @@ -504,7 +504,7 @@ static void update_largest_extent(struct f2fs_sb_info *sbi, nid_t ino) memset(&dn, 0, sizeof(dn)); largest_ext.len = cur_ext.len = 0; - inode = (struct f2fs_node *) calloc(BLOCK_SZ, 1); + inode = (struct f2fs_node *) calloc(F2FS_BLKSIZE, 1); ASSERT(inode); /* Read inode info */ @@ -572,7 +572,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) { int fd, n = -1; pgoff_t off = 0; - u8 buffer[BLOCK_SZ]; + u8 buffer[F2FS_BLKSIZE]; struct node_info ni; struct f2fs_node *node_blk; @@ -602,7 +602,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) get_node_info(sbi, de->ino, &ni); - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); ret = dev_read_block(node_blk, ni.blk_addr); @@ -616,7 +616,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) node_blk->i.i_extra_isize = cpu_to_le16(calc_extra_isize()); } - n = read(fd, buffer, BLOCK_SZ); + n = read(fd, buffer, F2FS_BLKSIZE); ASSERT((unsigned long)n == de->size); memcpy(inline_data_addr(node_blk), buffer, de->size); node_blk->i.i_size = cpu_to_le64(de->size); @@ -629,7 +629,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) u8 *rbuf = c.compress.cc.rbuf; unsigned int cblocks = 0; - node_blk = calloc(BLOCK_SZ, 1); + node_blk = calloc(F2FS_BLKSIZE, 1); ASSERT(node_blk); /* read inode */ @@ -649,11 +649,11 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) int ret = c.compress.ops->compress(&c.compress.cc); u64 wlen; u32 csize = ALIGN_UP(c.compress.cc.clen + - COMPRESS_HEADER_SIZE, BLOCK_SZ); + COMPRESS_HEADER_SIZE, F2FS_BLKSIZE); unsigned int cur_cblk; if (ret || n < c.compress.cc.rlen || - n < (int)(csize + BLOCK_SZ * + n < (int)(csize + F2FS_BLKSIZE * c.compress.min_blocks)) { wlen = f2fs_write(sbi, de->ino, rbuf, n, off); ASSERT((int)wlen == n); @@ -663,14 +663,14 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) ASSERT(!wlen); wlen = f2fs_write_compress_data(sbi, de->ino, (u8 *)c.compress.cc.cbuf, - csize, off + BLOCK_SZ); + csize, off + F2FS_BLKSIZE); ASSERT(wlen == csize); c.compress.ops->reset(&c.compress.cc); cur_cblk = (c.compress.cc.rlen - csize) / - BLOCK_SZ; + F2FS_BLKSIZE; cblocks += cur_cblk; wlen = f2fs_fix_mutable(sbi, de->ino, - off + BLOCK_SZ + csize, + off + F2FS_BLKSIZE + csize, cur_cblk); ASSERT(!wlen); } @@ -703,7 +703,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de) } #endif } else { - while ((n = read(fd, buffer, BLOCK_SZ)) > 0) { + while ((n = read(fd, buffer, F2FS_BLKSIZE)) > 0) { f2fs_write(sbi, de->ino, buffer, n, off); off += n; } diff --git a/fsck/xattr.c b/fsck/xattr.c index 9ccf361..3163639 100644 --- a/fsck/xattr.c +++ b/fsck/xattr.c @@ -30,7 +30,7 @@ void *read_all_xattrs(struct f2fs_sb_info *sbi, struct f2fs_node *inode, return NULL; } - txattr_addr = calloc(inline_size + BLOCK_SZ, 1); + txattr_addr = calloc(inline_size + F2FS_BLKSIZE, 1); ASSERT(txattr_addr); if (inline_size) @@ -44,6 +44,9 @@ void *read_all_xattrs(struct f2fs_sb_info *sbi, struct f2fs_node *inode, get_node_info(sbi, xnid, &ni); ret = dev_read_block(txattr_addr + inline_size, ni.blk_addr); ASSERT(ret >= 0); + memset(txattr_addr + inline_size + F2FS_BLKSIZE - + sizeof(struct node_footer), 0, + sizeof(struct node_footer)); } header = XATTR_HDR(txattr_addr); @@ -110,7 +113,7 @@ void write_all_xattrs(struct f2fs_sb_info *sbi, set_new_dnode(&dn, inode, NULL, xnid); get_node_info(sbi, xnid, &ni); blkaddr = ni.blk_addr; - xattr_node = calloc(BLOCK_SZ, 1); + xattr_node = calloc(F2FS_BLKSIZE, 1); ASSERT(xattr_node); ret = dev_read_block(xattr_node, ni.blk_addr); if (ret < 0) @@ -161,7 +164,7 @@ int f2fs_setxattr(struct f2fs_sb_info *sbi, nid_t ino, int index, const char *na ASSERT(index == F2FS_XATTR_INDEX_SECURITY); get_node_info(sbi, ino, &ni); - inode = calloc(BLOCK_SZ, 1); + inode = calloc(F2FS_BLKSIZE, 1); ASSERT(inode); ret = dev_read_block(inode, ni.blk_addr); ASSERT(ret >= 0); diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index abd5abf..6df2e73 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1513,6 +1513,7 @@ struct f2fs_configuration { unsigned int feature; /* defined features */ unsigned int quota_bits; /* quota bits */ time_t fixed_time; + int roll_forward; /* mkfs parameters */ int fake_seed; @@ -1750,6 +1751,7 @@ extern int f2fs_report_zones(int, report_zones_cb_t *, void *); extern int f2fs_check_zones(int); int f2fs_reset_zone(int, void *); extern int f2fs_reset_zones(int); +int f2fs_finish_zone(int i, void *blkzone); extern uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb); #define SIZE_ALIGN(val, size) (((val) + (size) - 1) / (size)) diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c index 2ab2497..ba9286f 100644 --- a/lib/libf2fs_zoned.c +++ b/lib/libf2fs_zoned.c @@ -502,6 +502,28 @@ out: return ret; } +int f2fs_finish_zone(int i, void *blkzone) +{ + struct blk_zone *blkz = (struct blk_zone *)blkzone; + struct device_info *dev = c.devices + i; + struct blk_zone_range range; + int ret; + + if (!blk_zone_seq(blkz) || blk_zone_empty(blkz)) + return 0; + + /* Non empty sequential zone: finish */ + range.sector = blk_zone_sector(blkz); + range.nr_sectors = blk_zone_length(blkz); + ret = ioctl(dev->fd, BLKFINISHZONE, &range); + if (ret != 0) { + ret = -errno; + ERR_MSG("ioctl BLKFINISHZONE failed: errno=%d\n", errno); + } + + return ret; +} + uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb) { #ifdef HAVE_BLK_ZONE_REP_V2 @@ -588,6 +610,12 @@ int f2fs_reset_zones(int i) return -1; } +int f2fs_finish_zone(int i, void *UNUSED(blkzone)) +{ + ERR_MSG("%d: Unsupported zoned block device\n", i); + return -1; +} + uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb) { return get_sb(segment_count_main); |