diff options
author | Denis Vlasenko | 2006-12-19 20:32:02 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-12-19 20:32:02 +0000 |
commit | 28703015ab71784f40bc97f720ed900e26bd03ca (patch) | |
tree | ff0f9a21d1822c9a2f35819db4156d9555f56116 /util-linux/fdisk.c | |
parent | f58906b6463436f6a19f72d43c3ab4ba69d79104 (diff) | |
download | busybox-28703015ab71784f40bc97f720ed900e26bd03ca.zip busybox-28703015ab71784f40bc97f720ed900e26bd03ca.tar.gz |
u_short, ulong exterminated
fdiskXXX: add a bit of sanity (not enough by far)
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r-- | util-linux/fdisk.c | 68 |
1 files changed, 32 insertions, 36 deletions
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 int get_boot(enum action what); } -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 @@ read_hex(const struct systypes *sys) 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 @@ STATIC_OSF void xbsd_print_disklabel(int); #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 @@ set_start_sect(struct partition *p, unsigned start_sect) } #endif -static int32_t +static unsigned get_start_sect(const struct partition *p) { return read4_little_endian(p->start4); @@ -586,13 +588,13 @@ get_start_sect(const struct partition *p) #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 @@ change_sysid(void) #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 @@ check_consistency(const struct partition *p, int partition) 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 @@ write_table(void) 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 @@ print_buffer(char *pbuffer) puts(""); } - static void print_raw(void) { @@ -2728,7 +2723,8 @@ try(const char *device, int user_specified) 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 @@ int fdisk_main(int argc, char **argv) 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; |