]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: setup: fix disk size for 4Kn block devices
authorChristoph Heiss <c.heiss@proxmox.com>
Wed, 9 Aug 2023 13:44:23 +0000 (15:44 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 23 Aug 2023 08:19:53 +0000 (10:19 +0200)
This can be tested by creating a block device with 4K sectorsize using
the following QEMU args:
  -device virtio-blk,drive=testdrive4k,logical_block_size=4096,physical_block_size=4096
  -drive file=/path/to/4k-testdisk.img,if=none,id=testdrive4k

The 4k-testdisk.img was created with:
  qemu-img create -f qcow2 /path/to/4k-testdisk.img 16G

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
proxmox-tui-installer/src/setup.rs

index e51bb4da79d517e97f7a849bb0daf6c36fccf107..c071b800049154f1c5380192282e3ac01877a559 100644 (file)
@@ -283,7 +283,10 @@ where
         .map(
             |(index, device, size_mb, model, logical_bsize, _syspath)| Disk {
                 index: index.to_string(),
-                size: (size_mb * logical_bsize as f64) / 1024. / 1024. / 1024.,
+                // Linux always reports the size of block devices in sectors, where one sector is
+                // defined as being 2^9 = 512 bytes in size.
+                // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/blk_types.h?h=v6.4#n30
+                size: (size_mb * 512.) / 1024. / 1024. / 1024.,
                 block_size: logical_bsize,
                 path: device,
                 model: (!model.is_empty()).then_some(model),