diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index fdbf7c7..8125e9f 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1560,9 +1560,11 @@ blk_zone_cond_str(struct blk_zone *blkz) #endif +struct blk_zone; + extern int f2fs_get_zoned_model(int); extern int f2fs_get_zone_blocks(int); -extern int f2fs_report_zone(int, uint64_t, void *); +extern int f2fs_report_zone(int, uint64_t, struct blk_zone *); typedef int (report_zones_cb_t)(int i, void *, void *); extern int f2fs_report_zones(int, report_zones_cb_t *, void *); extern int f2fs_check_zones(int); diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c index 3ece298..c98eff6 100644 --- a/lib/libf2fs_zoned.c +++ b/lib/libf2fs_zoned.c @@ -202,21 +202,26 @@ int f2fs_get_zone_blocks(int i) return 0; } -int f2fs_report_zone(int i, uint64_t sector, void *blkzone) +int f2fs_report_zone(int i, uint64_t sector, struct blk_zone *blkzone) { - struct blk_zone *blkz = (struct blk_zone *)blkzone; - struct blk_zone_report *rep; + struct one_zone_report { + struct blk_zone_report rep; + struct blk_zone zone; + } *rep; int ret = -1; - rep = calloc(1, sizeof(struct blk_zone_report) + - sizeof(struct blk_zone)); + static_assert(sizeof(*rep) == sizeof(rep->rep) + sizeof(rep->zone), ""); + + rep = calloc(1, sizeof(*rep)); if (!rep) { ERR_MSG("No memory for report zones\n"); return -ENOMEM; } - rep->sector = sector; - rep->nr_zones = 1; + rep->rep = (struct blk_zone_report){ + .sector = sector, + .nr_zones = 1, + }; ret = ioctl(c.devices[i].fd, BLKREPORTZONE, rep); if (ret != 0) { ret = -errno; @@ -224,7 +229,7 @@ int f2fs_report_zone(int i, uint64_t sector, void *blkzone) goto out; } - *blkz = *(struct blk_zone *)(rep + 1); + *blkzone = rep->zone; out: free(rep); return ret; @@ -533,7 +538,8 @@ uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb) #else -int f2fs_report_zone(int i, uint64_t UNUSED(sector), void *UNUSED(blkzone)) +int f2fs_report_zone(int i, uint64_t UNUSED(sector), + struct blk_zone *UNUSED(blkzone)) { ERR_MSG("%d: Unsupported zoned block device\n", i); return -1;