diff options
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 2af5a41b9..e4f7e5455 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -220,8 +220,8 @@ static int get_boot(enum action what); | |||
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | static int32_t get_start_sect(const struct partition *p); | 223 | static unsigned get_start_sect(const struct partition *p); |
224 | static int32_t get_nr_sects(const struct partition *p); | 224 | static unsigned get_nr_sects(const struct partition *p); |
225 | 225 | ||
226 | /* | 226 | /* |
227 | * per partition table entry data | 227 | * per partition table entry data |
@@ -338,7 +338,9 @@ read_hex(const struct systypes *sys) | |||
338 | continue; | 338 | continue; |
339 | } | 339 | } |
340 | v = bb_strtoul(line_ptr, NULL, 16); | 340 | v = bb_strtoul(line_ptr, NULL, 16); |
341 | if (errno || v > 0xff) continue; | 341 | if (v > 0xff) |
342 | /* Bad input also triggers this */ | ||
343 | continue; | ||
342 | return v; | 344 | return v; |
343 | } | 345 | } |
344 | } | 346 | } |
@@ -393,15 +395,15 @@ STATIC_OSF void xbsd_print_disklabel(int); | |||
393 | #define SGI_XLV 0x0c | 395 | #define SGI_XLV 0x0c |
394 | #define SGI_XVM 0x0d | 396 | #define SGI_XVM 0x0d |
395 | #define SGI_ENTIRE_DISK SGI_VOLUME | 397 | #define SGI_ENTIRE_DISK SGI_VOLUME |
396 | #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) | 398 | #if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL |
397 | static uint16_t | 399 | static uint16_t |
398 | __swap16(uint16_t x) | 400 | fdisk_swap16(uint16_t x) |
399 | { | 401 | { |
400 | return (x << 8) | (x >> 8); | 402 | return (x << 8) | (x >> 8); |
401 | } | 403 | } |
402 | 404 | ||
403 | static uint32_t | 405 | static uint32_t |
404 | __swap32(uint32_t x) | 406 | fdisk_swap32(uint32_t x) |
405 | { | 407 | { |
406 | return (x << 24) | | 408 | return (x << 24) | |
407 | ((x & 0xFF00) << 8) | | 409 | ((x & 0xFF00) << 8) | |
@@ -578,7 +580,7 @@ set_start_sect(struct partition *p, unsigned start_sect) | |||
578 | } | 580 | } |
579 | #endif | 581 | #endif |
580 | 582 | ||
581 | static int32_t | 583 | static unsigned |
582 | get_start_sect(const struct partition *p) | 584 | get_start_sect(const struct partition *p) |
583 | { | 585 | { |
584 | return read4_little_endian(p->start4); | 586 | return read4_little_endian(p->start4); |
@@ -586,13 +588,13 @@ get_start_sect(const struct partition *p) | |||
586 | 588 | ||
587 | #if ENABLE_FEATURE_FDISK_WRITABLE | 589 | #if ENABLE_FEATURE_FDISK_WRITABLE |
588 | static void | 590 | static void |
589 | set_nr_sects(struct partition *p, int32_t nr_sects) | 591 | set_nr_sects(struct partition *p, unsigned nr_sects) |
590 | { | 592 | { |
591 | store4_little_endian(p->size4, nr_sects); | 593 | store4_little_endian(p->size4, nr_sects); |
592 | } | 594 | } |
593 | #endif | 595 | #endif |
594 | 596 | ||
595 | static int32_t | 597 | static unsigned |
596 | get_nr_sects(const struct partition *p) | 598 | get_nr_sects(const struct partition *p) |
597 | { | 599 | { |
598 | return read4_little_endian(p->size4); | 600 | return read4_little_endian(p->size4); |
@@ -1770,13 +1772,13 @@ change_sysid(void) | |||
1770 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | 1772 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ |
1771 | 1773 | ||
1772 | 1774 | ||
1773 | /* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993, | 1775 | /* check_consistency() and linear2chs() added Sat Mar 6 12:28:16 1993, |
1774 | * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross, | 1776 | * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross, |
1775 | * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S. | 1777 | * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S. |
1776 | * Lubkin Oct. 1991). */ | 1778 | * Lubkin Oct. 1991). */ |
1777 | 1779 | ||
1778 | static void | 1780 | static void |
1779 | long2chs(ulong ls, unsigned *c, unsigned *h, unsigned *s) | 1781 | linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s) |
1780 | { | 1782 | { |
1781 | int spc = heads * sectors; | 1783 | int spc = heads * sectors; |
1782 | 1784 | ||
@@ -1808,10 +1810,10 @@ check_consistency(const struct partition *p, int partition) | |||
1808 | pes = p->end_sector & 0x3f; | 1810 | pes = p->end_sector & 0x3f; |
1809 | 1811 | ||
1810 | /* compute logical beginning (c, h, s) */ | 1812 | /* compute logical beginning (c, h, s) */ |
1811 | long2chs(get_start_sect(p), &lbc, &lbh, &lbs); | 1813 | linear2chs(get_start_sect(p), &lbc, &lbh, &lbs); |
1812 | 1814 | ||
1813 | /* compute logical ending (c, h, s) */ | 1815 | /* compute logical ending (c, h, s) */ |
1814 | long2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); | 1816 | linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); |
1815 | 1817 | ||
1816 | /* Same physical / logical beginning? */ | 1818 | /* Same physical / logical beginning? */ |
1817 | if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { | 1819 | if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { |
@@ -2479,46 +2481,40 @@ write_table(void) | |||
2479 | static void | 2481 | static void |
2480 | reread_partition_table(int leave) | 2482 | reread_partition_table(int leave) |
2481 | { | 2483 | { |
2482 | int error = 0; | ||
2483 | int i; | 2484 | int i; |
2484 | 2485 | ||
2485 | printf(_("Calling ioctl() to re-read partition table.\n")); | 2486 | printf(_("Calling ioctl() to re-read partition table\n")); |
2486 | sync(); | 2487 | sync(); |
2487 | sleep(2); | 2488 | sleep(2); /* Huh? */ |
2488 | if ((i = ioctl(fd, BLKRRPART)) != 0) { | 2489 | i = ioctl(fd, BLKRRPART); |
2489 | error = errno; | 2490 | #if 0 |
2490 | } else { | 2491 | else { |
2491 | /* some kernel versions (1.2.x) seem to have trouble | 2492 | /* some kernel versions (1.2.x) seem to have trouble |
2492 | rereading the partition table, but if asked to do it | 2493 | rereading the partition table, but if asked to do it |
2493 | twice, the second time works. - biro@yggdrasil.com */ | 2494 | twice, the second time works. - biro@yggdrasil.com */ |
2494 | sync(); | 2495 | sync(); |
2495 | sleep(2); | 2496 | sleep(2); |
2496 | if ((i = ioctl(fd, BLKRRPART)) != 0) | 2497 | i = ioctl(fd, BLKRRPART); |
2497 | error = errno; | ||
2498 | } | 2498 | } |
2499 | #endif | ||
2499 | 2500 | ||
2500 | if (i) { | 2501 | if (i) { |
2501 | printf(_("\nWARNING: Re-reading the partition table " | 2502 | bb_perror_msg("WARNING: rereading partition table " |
2502 | "failed with error %d: %s.\n" | 2503 | "failed, kernel still uses old table"); |
2503 | "The kernel still uses the old table.\n" | ||
2504 | "The new table will be used " | ||
2505 | "at the next reboot.\n"), | ||
2506 | error, strerror(error)); | ||
2507 | } | 2504 | } |
2508 | 2505 | ||
2506 | #if 0 | ||
2509 | if (dos_changed) | 2507 | if (dos_changed) |
2510 | printf( | 2508 | printf( |
2511 | _("\nWARNING: If you have created or modified any DOS 6.x\n" | 2509 | _("\nWARNING: If you have created or modified any DOS 6.x\n" |
2512 | "partitions, please see the fdisk manual page for additional\n" | 2510 | "partitions, please see the fdisk manual page for additional\n" |
2513 | "information.\n")); | 2511 | "information.\n")); |
2512 | #endif | ||
2514 | 2513 | ||
2515 | if (leave) { | 2514 | if (leave) { |
2516 | close(fd); | 2515 | if (ENABLE_FEATURE_CLEAN_UP) |
2517 | 2516 | close(fd); | |
2518 | printf(_("Syncing disks.\n")); | 2517 | exit(i != 0); |
2519 | sync(); | ||
2520 | sleep(4); /* for sync() */ | ||
2521 | exit(!!i); | ||
2522 | } | 2518 | } |
2523 | } | 2519 | } |
2524 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | 2520 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ |
@@ -2544,7 +2540,6 @@ print_buffer(char *pbuffer) | |||
2544 | puts(""); | 2540 | puts(""); |
2545 | } | 2541 | } |
2546 | 2542 | ||
2547 | |||
2548 | static void | 2543 | static void |
2549 | print_raw(void) | 2544 | print_raw(void) |
2550 | { | 2545 | { |
@@ -2728,7 +2723,8 @@ try(const char *device, int user_specified) | |||
2728 | if (!user_specified) | 2723 | if (!user_specified) |
2729 | if (is_ide_cdrom_or_tape(device)) | 2724 | if (is_ide_cdrom_or_tape(device)) |
2730 | return; | 2725 | return; |
2731 | if ((fd = open(disk_device, type_open)) >= 0) { | 2726 | fd = open(disk_device, type_open); |
2727 | if (fd >= 0) { | ||
2732 | gb = get_boot(try_only); | 2728 | gb = get_boot(try_only); |
2733 | if (gb > 0) { /* I/O error */ | 2729 | if (gb > 0) { /* I/O error */ |
2734 | close(fd); | 2730 | close(fd); |
@@ -2861,7 +2857,7 @@ int fdisk_main(int argc, char **argv) | |||
2861 | type_open = O_RDONLY; | 2857 | type_open = O_RDONLY; |
2862 | if (argc > 0) { | 2858 | if (argc > 0) { |
2863 | int k; | 2859 | int k; |
2864 | #if __GNUC__ | 2860 | #if defined(__GNUC__) |
2865 | /* avoid gcc warning: | 2861 | /* avoid gcc warning: |
2866 | variable `k' might be clobbered by `longjmp' */ | 2862 | variable `k' might be clobbered by `longjmp' */ |
2867 | (void)&k; | 2863 | (void)&k; |