aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2022-06-23 11:12:06 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2022-07-21 19:27:23 -0700
commit5317d184f49960f57398afb39264416805311a3f (patch)
tree8caca4f2f93674b770e48330dd8161cdc7659db9
parent92e2e526090ffbb3f579f5e6ff4cd362454b4122 (diff)
downloadf2fs-tools-5317d184f49960f57398afb39264416805311a3f.tar.gz
Improve compile-time type checking for f2fs_report_zone()
Change the type of the third argument of f2fs_report_zone() from void * into struct blk_zone * to enable type checking. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--include/f2fs_fs.h4
-rw-r--r--lib/libf2fs_zoned.c24
2 files changed, 18 insertions, 10 deletions
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 d8de66b..a0dd8bd 100644
--- a/lib/libf2fs_zoned.c
+++ b/lib/libf2fs_zoned.c
@@ -200,21 +200,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;
@@ -222,7 +227,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;
@@ -531,7 +536,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;