[PATCH] linux.c: use ioctl(BLKSSZGET) and ioctl(BLKBSZGET) appropriately

Matt Domsch Matt_Domsch at dell.com
Tue Jan 27 15:42:07 UTC 2009


BLKSSZGET is for physical sector size, BLKBSZGET is for logical sector
size.  Parted has until now been using a physical sector size of
PED_SECTOR_SIZE_DEFAULT, and using the kernel-reported physical sector
size as the logical sector size.

Signed-off-by: Matt Domsch <Matt_Domsch at dell.com>
---
 libparted/arch/linux.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index acd5997..0589ee0 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -194,7 +194,8 @@ struct hd_driveid {
 #define BLKRRPART  _IO(0x12,95) /* re-read partition table */
 #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 BLKSSZGET  _IO(0x12,104) /* get block device physical sector size */
+#define BLKBSZGET  _IOR(0x12,112,size_t) /* get block device logical sector size */
 #define BLKGETLASTSECT  _IO(0x12,108) /* get last sector of block device */
 #define BLKSETLASTSECT  _IO(0x12,109) /* set last sector of block device */
 
@@ -584,12 +585,13 @@ _have_devfs ()
         return have_devfs = S_ISCHR(sb.st_mode) ? 1 : 0;
 }
 
-static void 
+static void
 _device_set_sector_size (PedDevice* dev)
 {
         LinuxSpecific*  arch_specific = LINUX_SPECIFIC (dev);
-        int sector_size;
-        
+        int physical_sector_size=0;
+        size_t logical_sector_size=0ULL;
+
         dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
         dev->phys_sector_size = PED_SECTOR_SIZE_DEFAULT;
 
@@ -599,16 +601,27 @@ _device_set_sector_size (PedDevice* dev)
                 dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
                 return;
         }
-        
-        if (ioctl (arch_specific->fd, BLKSSZGET, &sector_size)) {
+
+        if (ioctl (arch_specific->fd, BLKBSZGET, &logical_sector_size)) {
+                ped_exception_throw (
+                        PED_EXCEPTION_WARNING,
+                        PED_EXCEPTION_OK,
+                        _("Could not determine logical sector size for %s: %s.\n"
+                          "Using the default logical sector size (%lld)."),
+                        dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
+        } else {
+                dev->sector_size = (long long)logical_sector_size;
+        }
+
+        if (ioctl (arch_specific->fd, BLKSSZGET, &physical_sector_size)) {
                 ped_exception_throw (
                         PED_EXCEPTION_WARNING,
                         PED_EXCEPTION_OK,
-                        _("Could not determine sector size for %s: %s.\n"
-                          "Using the default sector size (%lld)."),
+                        _("Could not determine physical sector size for %s: %s.\n"
+                          "Using the default physical sector size (%lld)."),
                         dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
         } else {
-                dev->sector_size = (long long)sector_size;
+                dev->phys_sector_size = (long long)physical_sector_size;
         }
 
         /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
-- 
1.6.0.5


-- 
Matt Domsch
Linux Technology Strategist, Dell Office of the CTO
linux.dell.com & www.dell.com/linux



More information about the parted-devel mailing list