]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: move kernel geometry into blkdev
authorDavidlohr Bueso <dave@gnu.org>
Wed, 4 Apr 2012 17:01:24 +0000 (19:01 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Apr 2012 10:21:16 +0000 (12:21 +0200)
This is a more generic place for this ioctl.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
fdisk/fdisk.c
include/blkdev.h
lib/blkdev.c

index 8893a017493991ed1a74279aa73f4477815c12e8..126efb37821b8e167e90d5e0770fc7d3de53b512 100644 (file)
@@ -953,19 +953,6 @@ get_topology(int fd) {
                       sector_size, DEFAULT_SECTOR_SIZE);
 }
 
-static void
-get_kernel_geometry(int fd) {
-#ifdef HDIO_GETGEO
-       struct hd_geometry geometry;
-
-       if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-               kern_heads = geometry.heads;
-               kern_sectors = geometry.sectors;
-               /* never use geometry.cylinders - it is truncated */
-       }
-#endif
-}
-
 static void
 get_partition_table_geometry(void) {
        unsigned char *bufp = MBRbuffer;
@@ -1057,7 +1044,7 @@ get_geometry(int fd, struct geom *g) {
        kern_heads = kern_sectors = 0;
        pt_heads = pt_sectors = 0;
 
-       get_kernel_geometry(fd);
+       blkdev_get_geometry(fd, &kern_heads, &kern_sectors);
        get_partition_table_geometry();
 
        heads = user_heads ? user_heads :
index 6b18879761c3fef1ac924af12f93aa718ebb82f2..56dbce75c93fc3068b0e0c572a72ad3c36f4fa52 100644 (file)
@@ -110,4 +110,7 @@ int blkdev_get_physector_size(int fd, int *sector_size);
 /* is the device cdrom capable? */
 int blkdev_is_cdrom(int fd);
 
+/* get device's geometry - legacy */
+int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s);
+
 #endif /* BLKDEV_H */
index c59386d9c33db7e5bbfa3c4f524b9bb9f6fd3828..198669bdab490f2340b13db3d4225dd247559db3 100644 (file)
@@ -263,6 +263,29 @@ int blkdev_is_cdrom(int fd)
 #endif
 }
 
+/*
+ * Get kernel's interpretation of the device's geometry.
+ *
+ * Returns the heads and sectors - but not cylinders
+ * as it's truncated for disks with more than 65535 tracks.
+ *
+ * Note that this is deprecated in favor of LBA addressing.
+ */
+int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s)
+{
+#ifdef HDIO_GETGEO
+       struct hd_geometry geometry;
+
+       if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
+               *h = geometry.heads;
+               *s = geometry.sectors;
+       }
+#else
+       *h = 0;
+       *s = 0;
+#endif
+}
+
 #ifdef TEST_PROGRAM
 #include <stdio.h>
 #include <stdlib.h>