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;
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 :
/* 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 */
#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>