]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: fix error message for too small devices
authorKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2012 09:40:46 +0000 (11:40 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2012 09:40:46 +0000 (11:40 +0200)
 # touch ~/a
 # fdisk -l ~/a
 # fdisk: cannot open /root/a: Success

should be (at least):
 fdisk: cannot open /root/a: Invalid argument

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/utils.c

index 07348d3803099baff596c6a2760a39ea3b02e55c..d8a4bd1848deab92930f461d2c11be3dd4b0b61a 100644 (file)
@@ -76,8 +76,11 @@ static int __init_mbr_buffer(struct fdisk_context *cxt)
                goto fail;
 
        /* read MBR */
-       if (512 != read(cxt->dev_fd, cxt->mbr, 512))
+       if (512 != read(cxt->dev_fd, cxt->mbr, 512)) {
+               if (errno == 0)
+                       errno = EINVAL; /* probably too small file/device */
                goto fail;
+       }
 
        return 0;
 fail: