From 6b0054a2c6dddb43155220cac13848df98d74423 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 24 Jul 2008 00:46:05 +0200 Subject: [PATCH] fdisk: non-linux support (BLK* and HDIO_*) BLK* and HDIO_* are not available on all platform. Work around this in a few places. [kzak@redhat.com: split the original patch to small patches] Signed-off-by: Samuel Thibault Signed-off-by: Karel Zak --- fdisk/cfdisk.c | 4 ++++ fdisk/fdisk.c | 7 ++++++- fdisk/fdisksgilabel.c | 2 ++ fdisk/fdisksunlabel.c | 5 ++++- fdisk/gpt.c | 4 ++++ fdisk/sfdisk.c | 12 ++++++++++-- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 9d32a190..300518d6 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -1685,6 +1685,7 @@ fill_p_info(void) { clear_warning(); } +#ifdef BLKFLSBUF /* Blocks are visible in more than one way: e.g. as block on /dev/hda and as block on /dev/hda3 By a bug in the Linux buffer cache, we will see the old @@ -1694,6 +1695,7 @@ fill_p_info(void) { so this only plays a role if we want to show volume labels. */ ioctl(fd, BLKFLSBUF); /* ignore errors */ /* e.g. Permission Denied */ +#endif if (blkdev_get_sectors(fd, &llsectors) == -1) fatal(_("Cannot get disk size"), 3); @@ -1903,10 +1905,12 @@ write_part_table(void) { } if (is_bdev) { +#ifdef BLKRRPART sync(); sleep(2); if (!ioctl(fd,BLKRRPART)) changed = TRUE; +#endif sync(); sleep(4); diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 58b8bbde..d3fb1ea9 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -2261,10 +2261,15 @@ reread_partition_table(int leave) { i = fstat(fd, &statbuf); if (i == 0 && S_ISBLK(statbuf.st_mode)) { - printf(_("Calling ioctl() to re-read partition table.\n")); sync(); sleep(2); +#ifdef BLKRRPART + printf(_("Calling ioctl() to re-read partition table.\n")); i = ioctl(fd, BLKRRPART); +#else + errno = ENOSYS; + i = 1; +#endif } if (i) { diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index 14b2d610..9f87751d 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -713,6 +713,7 @@ create_sgilabel(void) res = blkdev_get_sectors(fd, &llsectors); +#ifdef HDIO_GETGEO if (!ioctl(fd, HDIO_GETGEO, &geometry)) { heads = geometry.heads; sectors = geometry.sectors; @@ -733,6 +734,7 @@ create_sgilabel(void) " > 33.8 GB.\n"), disk_device, cylinders); } } +#endif for (i = 0; i < 4; i++) { old[i].sysid = 0; if (valid_part_table_flag(MBRbuffer)) { diff --git a/fdisk/fdisksunlabel.c b/fdisk/fdisksunlabel.c index f4e8671e..e6f17256 100644 --- a/fdisk/fdisksunlabel.c +++ b/fdisk/fdisksunlabel.c @@ -212,6 +212,7 @@ void create_sunlabel(void) res = blkdev_get_sectors(fd, &llsectors); sec_fac = sector_size / 512; +#ifdef HDIO_GETGEO if (!ioctl(fd, HDIO_GETGEO, &geometry)) { heads = geometry.heads; sectors = geometry.sectors; @@ -228,7 +229,9 @@ void create_sunlabel(void) "This value may be truncated for devices" " > 33.8 GB.\n"), disk_device, cylinders); } - } else { + } else +#endif + { heads = read_int(1,1,1024,0,_("Heads")); sectors = read_int(1,1,1024,0,_("Sectors/track")); cylinders = read_int(1,1,65535,0,_("Cylinders")); diff --git a/fdisk/gpt.c b/fdisk/gpt.c index 2c96b026..8cdf57f5 100644 --- a/fdisk/gpt.c +++ b/fdisk/gpt.c @@ -131,6 +131,7 @@ last_lba(int fd) return sectors - 1; } +#ifdef __linux__ static ssize_t read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count) { @@ -148,6 +149,7 @@ read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count) return !rc; } +#endif static ssize_t read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) @@ -159,6 +161,7 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) lseek(fd, offset, SEEK_SET); bytesread = read(fd, buffer, bytes); +#ifdef __linux__ /* Kludge. This is necessary to read/write the last block of an odd-sized disk, until Linux 2.5.x kernel fixes. This is only used by gpt.c, and only to read @@ -166,6 +169,7 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) */ if (!bytesread && !(last_lba(fd) & 1) && lba == last_lba(fd)) bytesread = read_lastoddsector(fd, lba, buffer, bytes); +#endif return bytesread; } diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index d737d69d..f70b1629 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -446,7 +446,10 @@ get_geometry(char *dev, int fd, int silent) { unsigned long long sectors; struct geometry R; - if (ioctl(fd, HDIO_GETGEO, &g)) { +#ifdef HDIO_GETGEO + if (ioctl(fd, HDIO_GETGEO, &g)) +#endif + { g.heads = g.sectors = g.cylinders = g.start = 0; if (!silent) do_warn(_("Disk %s: cannot get geometry\n"), dev); @@ -790,7 +793,12 @@ add_sector_and_offset(struct disk_desc *z) { /* tell the kernel to reread the partition tables */ static int reread_ioctl(int fd) { - if (ioctl(fd, BLKRRPART)) { +#ifdef BLKRRPART + if (ioctl(fd, BLKRRPART)) +#else + errno = ENOSYS; +#endif + { perror("BLKRRPART"); /* 2.6.8 returns EIO for a zero table */ -- 2.39.5