On 08/05/2021 15:28, Chao Yu wrote:>> >> +static int verify_sb_chksum(struct f2fs_super_block *sb)
+{ + if (get_sb(checksum_offset) != SB_CHKSUM_OFFSET) + return -1; + + if (f2fs_crc_valid(get_sb(crc), sb, get_sb(checksum_offset))) + return -1; + + return 0; +}How about reusing existed verify_sb_chksum() to avoid duplicated codes?+ +static void update_superblock(struct f2fs_super_block *sb, int sb_mask) +{ + int addr, ret; + u_int8_t *buf; + + buf = calloc(F2FS_BLKSIZE, 1); + ASSERT(buf); + + if (get_sb(feature) & F2FS_FEATURE_SB_CHKSUM) { + set_sb(crc, f2fs_cal_crc32(F2FS_SUPER_MAGIC, sb, + SB_CHKSUM_OFFSET)); + } + + memcpy(buf + F2FS_SUPER_OFFSET, sb, sizeof(*sb)); + for (addr = SB0_ADDR; addr < SB_MAX_ADDR; addr++) { + if (SB_MASK(addr) & sb_mask) { + ret = dev_write_block(buf, addr); + ASSERT(ret >= 0); + } + } + + free(buf); +}Ditto, >> ++int main(int argc, char **argv) +{ + if (argc < 2 || argc > 3) { + fprintf(stderr, "Usage: f2fslabel device [newlabel]\n"); + exit(1); + } + + f2fs_init_configuration(); + + c.devices[0].path = argv[1]; + + if (argc == 2) + print_label(); + else if (argc == 3) + change_label(argv[2]); + + return 0; +}IMO, this can be integrated into fsck/main.c?
Sure, it would rather be simpler than this and duplicated codes would be removed accordingly.
_______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
