From: Luis Chamberlain <[email protected]>

f2fs currently only work with zoned storage devices with a zone
size which is a power of 2 (PO2). So check if a non-power of 2
zone is device is found, and if so disallow its use. This prevents
users from incorrectly using these devices.

This is a non-issue today give today's kernel does not allow NPO2
zon devices to exist. But these devices do exist, and so proactively
put a stop-gap measure in place to prevent the from being assumed
to be used.

Signed-off-by: Luis Chamberlain <[email protected]>
Signed-off-by: Pankaj Raghav <[email protected]>
---
 lib/libf2fs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 8fad1d7..a13ba32 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -882,6 +882,11 @@ static int open_check_fs(char *path, int flag)
        return open(path, O_RDONLY | flag);
 }
 
+static int is_power_of_2(unsigned long n)
+{
+       return (n != 0 && ((n & (n - 1)) == 0));
+}
+
 int get_device_info(int i)
 {
        int32_t fd = 0;
@@ -1043,6 +1048,13 @@ int get_device_info(int i)
                        return -1;
                }
 
+               if (!dev->zone_size || !is_power_of_2(dev->zone_size)) {
+                       MSG(0, "\tError: zoned: illegal zone size %lu (not a 
power of 2)\n",
+                                       dev->zone_size);
+                       free(stat_buf);
+                       return -1;
+               }
+
                /*
                 * Check zone configuration: for the first disk of a
                 * multi-device volume, conventional zones are needed.
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to