]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkzone: make alignment check for zone size generic
authorPankaj Raghav <p.raghav@samsung.com>
Fri, 22 Apr 2022 15:02:03 +0000 (17:02 +0200)
committerPankaj Raghav <p.raghav@samsung.com>
Thu, 4 Aug 2022 16:22:49 +0000 (18:22 +0200)
The zone offset and length alignment checks are based on a power-of-2(po2)
zone size assumption.

Make that calculation generic as there are ongoing efforts[1] to support
zoned devices with non-po2 zone sizes.

[1]
https://lore.kernel.org/all/20220803094801.177490-1-p.raghav@samsung.com/
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
sys-utils/blkzone.c

index 04e2660044fce6f39511a111b381a372b9f57f0c..ff6eff10d75a4a1d5a29b011833bfca2a3d0bb1d 100644 (file)
@@ -347,7 +347,7 @@ static int blkzone_action(struct blkzone_control *ctl)
 
        fd = init_device(ctl, O_WRONLY | (ctl->force ? 0 : O_EXCL));
 
-       if (ctl->offset & (zonesize - 1))
+       if (ctl->offset % zonesize )
                errx(EXIT_FAILURE, _("%s: offset %" PRIu64 " is not aligned "
                        "to zone size %lu"),
                        ctl->devname, ctl->offset, zonesize);
@@ -365,7 +365,7 @@ static int blkzone_action(struct blkzone_control *ctl)
                zlen = ctl->total_sectors - ctl->offset;
 
        if (ctl->length &&
-           (zlen & (zonesize - 1)) &&
+          (zlen % zonesize) &&
            ctl->offset + zlen != ctl->total_sectors)
                errx(EXIT_FAILURE, _("%s: number of sectors %" PRIu64 " is not aligned "
                        "to zone size %lu"),