[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] BLKGETSIZE64 support for parted 1.4.24
From: |
Matt Domsch |
Subject: |
[PATCH] BLKGETSIZE64 support for parted 1.4.24 |
Date: |
Mon, 22 Jul 2002 10:41:08 -0500 (CDT) |
This adds BLKGETSIZE64 support for parted 1.4.24. This code was added to
the kernel ~2.4.15, but was broken until 2.4.18. Likewise, in the 2.5.x
tree, it was broken until 2.5.4. This adds a test for a valid kernel, and
uses it if possible. This will be important when 64-bit block number
devices become reality (soon in 2.5.x, likely backported to 2.4.x in
the next 9-12 months).
A similar patch will be send against parted 1.6.2.
Thanks,
Matt
--
Matt Domsch
Sr. Software Engineer, Lead Engineer, Architect
Dell Linux Solutions www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com
#1 US Linux Server provider for 2001 and Q1/2002! (IDC May 2002)
diff -urNp --exclude-from=/home/mdomsch/excludes --minimal
parted-1.4.24/libparted/device.c parted-1.4.24.blkgetsize64/libparted/device.c
--- parted-1.4.24/libparted/device.c Sat Jan 26 12:03:25 2002
+++ parted-1.4.24.blkgetsize64/libparted/device.c Sun Jul 21 21:33:54 2002
@@ -40,6 +40,7 @@
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
#include <sys/stat.h>
+#include <sys/utsname.h>
#include <scsi/scsi.h>
#include <parted/parted.h>
@@ -58,6 +59,7 @@
#define BLKSSZGET _IO(0x12,104) /* get block device sector size */
#define BLKGETLASTSECT _IO(0x12,108) /* get last sector of block device */
#define BLKSETLASTSECT _IO(0x12,109) /* set last sector of block device */
+#define BLKGETSIZE64 _IOR(0x12,114,sizeof(uint64_t)) /* return device size
in bytes (u64 *arg) */
struct blkdev_ioctl_param {
unsigned int block;
@@ -381,13 +383,54 @@ device_get_sector_size (PedDevice* dev)
#endif /* !linux */
}
+/**
+ * kernel_has_blkgetsize64()
+ *
+ * Returns: 0 on false, 1 on true
+ * True means linux kernel is 2.4.x, x>=18, or
+ * is 2.5.x, x>4, or
+ * is > 2.5
+ */
+#ifdef linux
+static int
+kernel_has_blkgetsize64(void)
+{
+ int major=0, minor=0, patch=0, parsed;
+ int rc;
+ struct utsname u;
+
+ memset(&u, 0, sizeof(u));
+ rc = uname(&u);
+ if (rc) return 0;
+
+ parsed = sscanf(u.release, "%d.%d.%d", &major, &minor, &patch);
+ if (parsed < 3) return 0;
+ if (major > 2) return 1;
+ if (major == 2 && minor > 5) return 1;
+ if (major == 2 && minor == 5 && patch >= 4) return 1;
+ if (major == 2 && minor == 4 && patch >= 18) return 1;
+ return 0;
+}
+#else
+static int
+kernel_has_blkgetsize64(void)
+{
+}
+#endif
+
/* TODO: do a binary search if BLKGETSIZE doesn't work?! */
static PedSector
device_get_length (PedDevice* dev)
{
unsigned long size;
+ uint64_t bytes=0;
PED_ASSERT (dev->open_count, return 0);
+ if (kernel_has_blkgetsize64()) {
+ if (ioctl(dev->fd, BLKGETSIZE64, &bytes) == 0) {
+ return bytes / device_get_sector_size(dev);
+ }
+ }
if (ioctl (dev->fd, BLKGETSIZE, &size)) {
ped_exception_throw (
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] BLKGETSIZE64 support for parted 1.4.24,
Matt Domsch <=