[Bug 12471] New: fdisk for mediums with a block size != 512 bytes

bugzilla at busybox.net bugzilla at busybox.net
Tue Jan 14 19:20:04 UTC 2020


            Bug ID: 12471
           Summary: fdisk for mediums with a block size != 512 bytes
           Product: Busybox
           Version: 1.33.x
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P5
         Component: Other
          Assignee: unassigned at busybox.net
          Reporter: frank.mehnert at gmail.com
                CC: busybox-cvs at busybox.net
  Target Milestone: ---

util-linux/fdisk.c: Function bb_BLKGETSIZE_sectors() returns the number of
sectors and always assumes that a sector size is 512 bytes, at least if
ioctl(BLKGETSIZE64) works. This isn't necessarily true. Fdisk can also deal
with sector sizes of 1024, 2048 or 4096 bytes and the case for
ioctl(BLKGETSIZE) does it right: It divides the size by the sector_size as
opposed to ">> 9" in the first case.

Suggested fix:

diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index e58cb0fd1..c1350539b 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -501,7 +501,7 @@ static sector_t bb_BLKGETSIZE_sectors(int fd)

        if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {
                /* Got bytes, convert to 512 byte sectors */
-               v64 >>= 9;
+               v64 /= sector_size;
                if (v64 != (sector_t)v64) {
                        /* Not only DOS, but all other partition tables

There are other places in util-linux/fdisk.c which assume that sector_size is
512 bytes, for example list_disk_geometry() where total_number_of_sectors is

You are receiving this mail because:
You are on the CC list for the bug.

More information about the busybox-cvs mailing list