]> err.no Git - util-linux/commitdiff
fdisk: eliminate redundant call to open()
authorMarkus Rinne <markus.ka.rinne@gmail.com>
Wed, 22 Sep 2010 19:11:54 +0000 (22:11 +0300)
committerKarel Zak <kzak@redhat.com>
Thu, 30 Sep 2010 20:52:42 +0000 (22:52 +0200)
Don't use open() in get_boot() if it's called with an argument try_only,
because the file has already been opened by the caller.

Signed-off-by: Markus Rinne <markus.ka.rinne@gmail.com>
fdisk/fdisk.c

index 68293213c0771e154787183c05046a371f2e905e..1f841d17d13a2edf50a01b9ac7d89d5b44a27662 100644 (file)
@@ -1213,14 +1213,14 @@ get_boot(enum action what) {
        if (what == create_empty_dos)
                goto got_dos_table;             /* skip reading disk */
 
-       if ((fd = open(disk_device, type_open)) < 0) {
-           if ((fd = open(disk_device, O_RDONLY)) < 0) {
-               if (what == try_only)
-                   return 1;
-               fatal(unable_to_open);
-           } else
-               printf(_("You will not be able to write "
-                        "the partition table.\n"));
+       if (what != try_only) {
+               if ((fd = open(disk_device, type_open)) < 0) {
+                       if ((fd = open(disk_device, O_RDONLY)) < 0)
+                               fatal(unable_to_open);
+                       else
+                               printf(_("You will not be able to write "
+                                           "the partition table.\n"));
+               }
        }
 
        if (512 != read(fd, MBRbuffer, 512)) {