u_short, ulong exterminated
fdiskXXX: add a bit of sanity (not enough by far)
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 2af5a41..e4f7e54 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -220,8 +220,8 @@
}
-static int32_t get_start_sect(const struct partition *p);
-static int32_t get_nr_sects(const struct partition *p);
+static unsigned get_start_sect(const struct partition *p);
+static unsigned get_nr_sects(const struct partition *p);
/*
* per partition table entry data
@@ -338,7 +338,9 @@
continue;
}
v = bb_strtoul(line_ptr, NULL, 16);
- if (errno || v > 0xff) continue;
+ if (v > 0xff)
+ /* Bad input also triggers this */
+ continue;
return v;
}
}
@@ -393,15 +395,15 @@
#define SGI_XLV 0x0c
#define SGI_XVM 0x0d
#define SGI_ENTIRE_DISK SGI_VOLUME
-#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
+#if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL
static uint16_t
-__swap16(uint16_t x)
+fdisk_swap16(uint16_t x)
{
return (x << 8) | (x >> 8);
}
static uint32_t
-__swap32(uint32_t x)
+fdisk_swap32(uint32_t x)
{
return (x << 24) |
((x & 0xFF00) << 8) |
@@ -578,7 +580,7 @@
}
#endif
-static int32_t
+static unsigned
get_start_sect(const struct partition *p)
{
return read4_little_endian(p->start4);
@@ -586,13 +588,13 @@
#if ENABLE_FEATURE_FDISK_WRITABLE
static void
-set_nr_sects(struct partition *p, int32_t nr_sects)
+set_nr_sects(struct partition *p, unsigned nr_sects)
{
store4_little_endian(p->size4, nr_sects);
}
#endif
-static int32_t
+static unsigned
get_nr_sects(const struct partition *p)
{
return read4_little_endian(p->size4);
@@ -1770,13 +1772,13 @@
#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
-/* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993,
+/* check_consistency() and linear2chs() added Sat Mar 6 12:28:16 1993,
* faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross,
* Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S.
* Lubkin Oct. 1991). */
static void
-long2chs(ulong ls, unsigned *c, unsigned *h, unsigned *s)
+linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s)
{
int spc = heads * sectors;
@@ -1808,10 +1810,10 @@
pes = p->end_sector & 0x3f;
/* compute logical beginning (c, h, s) */
- long2chs(get_start_sect(p), &lbc, &lbh, &lbs);
+ linear2chs(get_start_sect(p), &lbc, &lbh, &lbs);
/* compute logical ending (c, h, s) */
- long2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les);
+ linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les);
/* Same physical / logical beginning? */
if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) {
@@ -2479,46 +2481,40 @@
static void
reread_partition_table(int leave)
{
- int error = 0;
int i;
- printf(_("Calling ioctl() to re-read partition table.\n"));
+ printf(_("Calling ioctl() to re-read partition table\n"));
sync();
- sleep(2);
- if ((i = ioctl(fd, BLKRRPART)) != 0) {
- error = errno;
- } else {
+ sleep(2); /* Huh? */
+ i = ioctl(fd, BLKRRPART);
+#if 0
+ 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 = ioctl(fd, BLKRRPART);
}
+#endif
if (i) {
- printf(_("\nWARNING: Re-reading the partition table "
- "failed with error %d: %s.\n"
- "The kernel still uses the old table.\n"
- "The new table will be used "
- "at the next reboot.\n"),
- error, strerror(error));
+ bb_perror_msg("WARNING: rereading partition table "
+ "failed, kernel still uses old table");
}
+#if 0
if (dos_changed)
printf(
_("\nWARNING: If you have created or modified any DOS 6.x\n"
"partitions, please see the fdisk manual page for additional\n"
"information.\n"));
+#endif
if (leave) {
- close(fd);
-
- printf(_("Syncing disks.\n"));
- sync();
- sleep(4); /* for sync() */
- exit(!!i);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(fd);
+ exit(i != 0);
}
}
#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
@@ -2544,7 +2540,6 @@
puts("");
}
-
static void
print_raw(void)
{
@@ -2728,7 +2723,8 @@
if (!user_specified)
if (is_ide_cdrom_or_tape(device))
return;
- if ((fd = open(disk_device, type_open)) >= 0) {
+ fd = open(disk_device, type_open);
+ if (fd >= 0) {
gb = get_boot(try_only);
if (gb > 0) { /* I/O error */
close(fd);
@@ -2861,7 +2857,7 @@
type_open = O_RDONLY;
if (argc > 0) {
int k;
-#if __GNUC__
+#if defined(__GNUC__)
/* avoid gcc warning:
variable `k' might be clobbered by `longjmp' */
(void)&k;