[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] libparted: use ioctl(BLKPBSZGET) to get phys sector size
From: |
Yang Bai |
Subject: |
[PATCH] libparted: use ioctl(BLKPBSZGET) to get phys sector size |
Date: |
Wed, 17 Oct 2012 22:27:33 +0800 |
Before, we use ioctl(BLKSSZGET) to get a disk's sector size and use this
value as both logical and physical sector size, but this value is just
the logical sector size. For physical sector size, we should use
ioctl(BLKPBSZGET). Since the popular of 4K AF hard disks, the logical
sector size if different from the physical one. Without blkid, we cant
get the right info about the disk so we could not align right the
partitions on this disk.
This patch has been tested on 2.6.32 kernel and we can get the right
sector sizes without blkid.
Signed-off-by: Yang Bai <address@hidden>
---
libparted/arch/linux.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index e2c4139..9452977 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -203,6 +203,7 @@ struct hd_driveid {
#define BLKGETSIZE _IO(0x12,96) /* return device size */
#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
#define BLKSSZGET _IO(0x12,104) /* get block device sector size */
+#define BLKPBSZGET _IO(0x12,123) /* get device physical sector size */
#define BLKGETLASTSECT _IO(0x12,108) /* get last sector of block device */
#define BLKSETLASTSECT _IO(0x12,109) /* set last sector of block device */
@@ -659,6 +660,7 @@ _device_set_sector_size (PedDevice* dev)
{
LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
int sector_size;
+ int phys_sector_size;
dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
dev->phys_sector_size = PED_SECTOR_SIZE_DEFAULT;
@@ -670,7 +672,8 @@ _device_set_sector_size (PedDevice* dev)
return;
}
- if (ioctl (arch_specific->fd, BLKSSZGET, §or_size)) {
+ if (ioctl(arch_specific->fd, BLKSSZGET, §or_size) ||
+ ioctl(arch_specific->fd, BLKPBSZGET, &phys_sector_size)) {
ped_exception_throw (
PED_EXCEPTION_WARNING,
PED_EXCEPTION_OK,
@@ -679,7 +682,7 @@ _device_set_sector_size (PedDevice* dev)
dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
} else {
dev->sector_size = (long long)sector_size;
- dev->phys_sector_size = dev->sector_size;
+ dev->phys_sector_size = (long long)phys_sector_size;
}
#if USE_BLKID
--
1.7.10.4
- [PATCH] libparted: use ioctl(BLKPBSZGET) to get phys sector size,
Yang Bai <=