summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan2007-09-04 00:10:16 +0200
committerKarel Zak2007-09-05 11:52:28 +0200
commitedd867fac28720d4d9a7c05cc110dcf63a57b255 (patch)
tree469b737026f9b6eb48eec4181c6bfc721927d7e0
parentrename: add description about option -V to manpage (diff)
downloadkernel-qcow2-util-linux-edd867fac28720d4d9a7c05cc110dcf63a57b255.tar.gz
kernel-qcow2-util-linux-edd867fac28720d4d9a7c05cc110dcf63a57b255.tar.xz
kernel-qcow2-util-linux-edd867fac28720d4d9a7c05cc110dcf63a57b255.zip
fdisk: doing useless ioctl when editing an image
When editing a disk image, fdisk wants to ask the kernel to reread the partition table which is useless and provokes an error, a wrong exit code and some waiting. This annoys me as I can't check the return code in my script and because I have to wait a few seconds each time. This trivial patch makes it only do the ioctl on block devices. It also simplifies code by dropping some workaround for kernel 1.2.x Signed-off-by: Pascal Terjan <pterjan@linuxfr.org>
-rw-r--r--fdisk/fdisk.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index dac14c2f5..89a49253b 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2248,22 +2248,15 @@ write_table(void) {
void
reread_partition_table(int leave) {
- int error = 0;
int i;
+ struct stat statbuf;
- printf(_("Calling ioctl() to re-read partition table.\n"));
- sync();
- sleep(2);
- if ((i = ioctl(fd, BLKRRPART)) != 0) {
- error = errno;
- } else {
- /* some kernel versions (1.2.x) seem to have trouble
- rereading the partition table, but if asked to do it
- twice, the second time works. - biro@yggdrasil.com */
- sync();
- sleep(2);
- if ((i = ioctl(fd, BLKRRPART)) != 0)
- error = errno;
+ i = fstat(fd, &statbuf);
+ if (i == 0 && S_ISBLK(statbuf.st_mode)) {
+ printf(_("Calling ioctl() to re-read partition table.\n"));
+ sync();
+ sleep(2);
+ i = ioctl(fd, BLKRRPART);
}
if (i) {
@@ -2272,7 +2265,7 @@ reread_partition_table(int leave) {
"The kernel still uses the old table.\n"
"The new table will be used "
"at the next reboot.\n"),
- error, strerror(error));
+ errno, strerror(errno));
}
if (dos_changed)