#define LINUX_LVM 0x8e
#define LINUX_RAID 0xfd
+
+enum {
+ OPT_b = 1 << 0,
+ OPT_C = 1 << 1,
+ OPT_H = 1 << 2,
+ OPT_l = 1 << 3,
+ OPT_S = 1 << 4,
+ OPT_u = 1 << 5,
+ OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE,
+};
+
+
/* Used for sector numbers. Today's disk sizes make it necessary */
typedef unsigned long long ullong;
s |= (sector >> 2) & 0xc0; \
} while (0)
+static void
+close_dev_fd(void)
+{
+ /* Not really closing, but making sure it is open, and to harmless place */
+ xmove_fd(xopen(bb_dev_null, O_RDONLY), dev_fd);
+}
+
#if ENABLE_FEATURE_FDISK_WRITABLE
/* read line; return 0 or first printable char */
static int
static void fdisk_fatal(const char *why)
{
if (listing) {
- close(dev_fd);
+ close_dev_fd();
longjmp(listingbuf, 1);
}
bb_error_msg_and_die(why, disk_device);
return 1;
fdisk_fatal(unable_to_open);
}
- xmove_fd(fd, dev_fd);
printf("'%s' is opened for read only\n", disk_device);
}
+ xmove_fd(fd, dev_fd);
if (512 != read(dev_fd, MBRbuffer, 512)) {
if (what == TRY_ONLY) {
- close(dev_fd);
+ close_dev_fd();
return 1;
}
fdisk_fatal(unable_to_read);
if (leave) {
if (ENABLE_FEATURE_CLEAN_UP)
- close(dev_fd);
+ close_dev_fd();
exit(i != 0);
}
}
break;
case 'q':
if (ENABLE_FEATURE_CLEAN_UP)
- close(dev_fd);
+ close_dev_fd();
bb_putchar('\n');
exit(0);
case 'r':
#endif
}
ret:
- close(dev_fd);
+ close_dev_fd();
}
/* for fdisk -l: try all things in /proc/partitions
*
* Options -C, -H, -S set the geometry.
*/
- enum {
- OPT_b = 1 << 0,
- OPT_C = 1 << 1,
- OPT_H = 1 << 2,
- OPT_l = 1 << 3,
- OPT_S = 1 << 4,
- OPT_u = 1 << 5,
- OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE,
- };
-
INIT_G();
- close(dev_fd); /* just in case */
+ close_dev_fd(); /* needed: fd 3 must not stay closed */
opt_complementary = "b+:C+:H+:S+"; /* numeric params */
opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"),
list_table(0);
break;
case 'q':
- close(dev_fd);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close_dev_fd();
bb_putchar('\n');
return 0;
case 's':