]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libfdisk: support alignment to non power of 2
authorKarel Zak <kzak@redhat.com>
Mon, 8 Jun 2015 13:41:33 +0000 (15:41 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 8 Jun 2015 13:57:23 +0000 (15:57 +0200)
commit68a8648ce509f04113bca0e61d2f0f976a15c271
tree2c81cd8a245140acf72c2d71f1c83399b9469e21
parent1c8beb3dfbb155b2cea3764a15d40fdd9038cf9f
libfdisk: support alignment to non power of 2

Let's create a disk with 33553920 bytes optimal I/O size:

# modprobe scsi_debug dev_size_mb=1000 opt_blks=65535

and try to create partition:

 echo -e 'n\n\n\n\n+512M\np\nq\n'  | fdisk /dev/sdc

old version:

 Device     Boot Start     End Sectors  Size Id Type
 /dev/sdc1       65535 1114110 1048576  512M 83 Linux

The next partition will be expected on sector 1114110 + 1, but it's
not aligned to optimal I/O:

        ((1114110 + 1) * 512) % 33553920 = 8192

fixed version:

 Device     Boot Start     End Sectors  Size Id Type
 /dev/sdc1       65535 1114094 1048560  512M 83 Linux

        ((1114094 + 1) * 512) % 33553920 = 0

Note that the same problem with alignment calculation has been fixed
in Linux kernel by commit b8839b8c55f3fdd60dc36abcda7e0266aff7985c
(Oct 2014).

The patch also improves fdisk_align_lba_in_range() to not align sizes
smaller than grain (default 1MiB) to make it possible to create really
small partitions.

Reported-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/alignment.c