diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-25 13:45:36 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-25 13:52:30 +0200 |
| commit | c104549b483c83acdf3e12cfe3df2c6437fa6926 (patch) | |
| tree | e5ab8683d8cb94e3dbf1c3531c9f6de070ea358c /util-linux | |
| parent | 163e637ffb47425d9f5027755b7cb4877d77b0cb (diff) | |
| download | busybox-w32-c104549b483c83acdf3e12cfe3df2c6437fa6926.tar.gz busybox-w32-c104549b483c83acdf3e12cfe3df2c6437fa6926.tar.bz2 busybox-w32-c104549b483c83acdf3e12cfe3df2c6437fa6926.zip | |
fdisk: sync up with some util-linux 2.31 behavior
= display default is no longer in cylinders
= +sizeC is no longer supported
= add +sizeT suffix - terabytes are here
= K,M,G,T and k,m,g,t suffixes all are binary, not decimal
= +sizeM results in last sector +(size * 1Mbyte - 1), not +(size * 1Mbyte)
= fix comparison to "YES" answer for sgi/sun
function old new delta
read_int 492 519 +27
fdisk_main 2644 2640 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 27/-4) Total: 23 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/fdisk.c | 90 | ||||
| -rw-r--r-- | util-linux/fdisk_sgi.c | 2 | ||||
| -rw-r--r-- | util-linux/fdisk_sun.c | 2 |
3 files changed, 46 insertions, 48 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index e47bc7324..296716575 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
| @@ -426,7 +426,7 @@ struct globals { | |||
| 426 | unsigned sector_offset; // = 1; | 426 | unsigned sector_offset; // = 1; |
| 427 | unsigned g_heads, g_sectors, g_cylinders; | 427 | unsigned g_heads, g_sectors, g_cylinders; |
| 428 | smallint /* enum label_type */ current_label_type; | 428 | smallint /* enum label_type */ current_label_type; |
| 429 | smallint display_in_cyl_units; // = 1; | 429 | smallint display_in_cyl_units; |
| 430 | #if ENABLE_FEATURE_OSF_LABEL | 430 | #if ENABLE_FEATURE_OSF_LABEL |
| 431 | smallint possibly_osf_label; | 431 | smallint possibly_osf_label; |
| 432 | #endif | 432 | #endif |
| @@ -488,7 +488,6 @@ struct globals { | |||
| 488 | sector_size = DEFAULT_SECTOR_SIZE; \ | 488 | sector_size = DEFAULT_SECTOR_SIZE; \ |
| 489 | sector_offset = 1; \ | 489 | sector_offset = 1; \ |
| 490 | g_partitions = 4; \ | 490 | g_partitions = 4; \ |
| 491 | display_in_cyl_units = 1; \ | ||
| 492 | units_per_sector = 1; \ | 491 | units_per_sector = 1; \ |
| 493 | dos_compatible_flag = 1; \ | 492 | dos_compatible_flag = 1; \ |
| 494 | } while (0) | 493 | } while (0) |
| @@ -639,25 +638,6 @@ seek_sector(sector_t secno) | |||
| 639 | } | 638 | } |
| 640 | 639 | ||
| 641 | #if ENABLE_FEATURE_FDISK_WRITABLE | 640 | #if ENABLE_FEATURE_FDISK_WRITABLE |
| 642 | /* Read line; return 0 or first printable char */ | ||
| 643 | static int | ||
| 644 | read_line(const char *prompt) | ||
| 645 | { | ||
| 646 | int sz; | ||
| 647 | |||
| 648 | sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer)); | ||
| 649 | if (sz <= 0) | ||
| 650 | exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */ | ||
| 651 | |||
| 652 | if (line_buffer[sz-1] == '\n') | ||
| 653 | line_buffer[--sz] = '\0'; | ||
| 654 | |||
| 655 | line_ptr = line_buffer; | ||
| 656 | while (*line_ptr != '\0' && (unsigned char)*line_ptr <= ' ') | ||
| 657 | line_ptr++; | ||
| 658 | return *line_ptr; | ||
| 659 | } | ||
| 660 | |||
| 661 | static void | 641 | static void |
| 662 | set_all_unchanged(void) | 642 | set_all_unchanged(void) |
| 663 | { | 643 | { |
| @@ -680,6 +660,25 @@ write_part_table_flag(char *b) | |||
| 680 | b[511] = 0xaa; | 660 | b[511] = 0xaa; |
| 681 | } | 661 | } |
| 682 | 662 | ||
| 663 | /* Read line; return 0 or first printable non-space char */ | ||
| 664 | static int | ||
| 665 | read_line(const char *prompt) | ||
| 666 | { | ||
| 667 | int sz; | ||
| 668 | |||
| 669 | sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer)); | ||
| 670 | if (sz <= 0) | ||
| 671 | exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */ | ||
| 672 | |||
| 673 | if (line_buffer[sz-1] == '\n') | ||
| 674 | line_buffer[--sz] = '\0'; | ||
| 675 | |||
| 676 | line_ptr = line_buffer; | ||
| 677 | while (*line_ptr != '\0' && (unsigned char)*line_ptr <= ' ') | ||
| 678 | line_ptr++; | ||
| 679 | return *line_ptr; | ||
| 680 | } | ||
| 681 | |||
| 683 | static char | 682 | static char |
| 684 | read_nonempty(const char *mesg) | 683 | read_nonempty(const char *mesg) |
| 685 | { | 684 | { |
| @@ -1614,7 +1613,7 @@ read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char * | |||
| 1614 | 1613 | ||
| 1615 | if (*line_ptr == '+' || *line_ptr == '-') { | 1614 | if (*line_ptr == '+' || *line_ptr == '-') { |
| 1616 | int minus = (*line_ptr == '-'); | 1615 | int minus = (*line_ptr == '-'); |
| 1617 | int absolute = 0; | 1616 | unsigned scale_shift; |
| 1618 | 1617 | ||
| 1619 | if (sizeof(value) <= sizeof(long)) | 1618 | if (sizeof(value) <= sizeof(long)) |
| 1620 | value = strtoul(line_ptr + 1, NULL, 10); | 1619 | value = strtoul(line_ptr + 1, NULL, 10); |
| @@ -1622,48 +1621,46 @@ read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char * | |||
| 1622 | value = strtoull(line_ptr + 1, NULL, 10); | 1621 | value = strtoull(line_ptr + 1, NULL, 10); |
| 1623 | 1622 | ||
| 1624 | /* (1) if 2nd char is digit, use_default = 0. | 1623 | /* (1) if 2nd char is digit, use_default = 0. |
| 1625 | * (2) move line_ptr to first non-digit. */ | 1624 | * (2) move line_ptr to first non-digit. |
| 1625 | */ | ||
| 1626 | while (isdigit(*++line_ptr)) | 1626 | while (isdigit(*++line_ptr)) |
| 1627 | use_default = 0; | 1627 | use_default = 0; |
| 1628 | 1628 | ||
| 1629 | switch (*line_ptr) { | 1629 | scale_shift = 0; |
| 1630 | case 'c': | 1630 | switch (*line_ptr | 0x20) { |
| 1631 | case 'C': | ||
| 1632 | if (!display_in_cyl_units) | ||
| 1633 | value *= g_heads * g_sectors; | ||
| 1634 | break; | ||
| 1635 | case 'K': | ||
| 1636 | absolute = 1024; | ||
| 1637 | break; | ||
| 1638 | case 'k': | 1631 | case 'k': |
| 1639 | absolute = 1000; | 1632 | scale_shift = 10; /* 1024 */ |
| 1640 | break; | 1633 | break; |
| 1641 | case 'm': | 1634 | case 'm': |
| 1642 | case 'M': | 1635 | scale_shift = 20; /* 1024*1024 */ |
| 1643 | absolute = 1000000; | ||
| 1644 | break; | 1636 | break; |
| 1645 | case 'g': | 1637 | case 'g': |
| 1646 | case 'G': | 1638 | scale_shift = 30; /* 1024*1024*1024 */ |
| 1647 | absolute = 1000000000; | 1639 | break; |
| 1640 | case 't': | ||
| 1641 | scale_shift = 40; /* 1024*1024*1024*1024 */ | ||
| 1648 | break; | 1642 | break; |
| 1649 | default: | 1643 | default: |
| 1650 | break; | 1644 | break; |
| 1651 | } | 1645 | } |
| 1652 | if (absolute) { | 1646 | if (scale_shift) { |
| 1653 | ullong bytes; | 1647 | ullong bytes; |
| 1654 | unsigned long unit; | 1648 | unsigned long unit; |
| 1655 | 1649 | ||
| 1656 | bytes = (ullong) value * absolute; | 1650 | bytes = (ullong) value << scale_shift; |
| 1657 | unit = sector_size * units_per_sector; | 1651 | unit = sector_size * units_per_sector; |
| 1658 | bytes += unit/2; /* round */ | 1652 | bytes += unit/2; /* round */ |
| 1659 | bytes /= unit; | 1653 | bytes /= unit; |
| 1660 | value = bytes; | 1654 | value = (bytes != 0 ? bytes - 1 : 0); |
| 1661 | } | 1655 | } |
| 1662 | if (minus) | 1656 | if (minus) |
| 1663 | value = -value; | 1657 | value = -value; |
| 1664 | value += base; | 1658 | value += base; |
| 1665 | } else { | 1659 | } else { |
| 1666 | value = atoi(line_ptr); | 1660 | if (sizeof(value) <= sizeof(long)) |
| 1661 | value = strtoul(line_ptr, NULL, 10); | ||
| 1662 | else | ||
| 1663 | value = strtoull(line_ptr, NULL, 10); | ||
| 1667 | while (isdigit(*line_ptr)) { | 1664 | while (isdigit(*line_ptr)) { |
| 1668 | line_ptr++; | 1665 | line_ptr++; |
| 1669 | use_default = 0; | 1666 | use_default = 0; |
| @@ -2529,8 +2526,9 @@ add_partition(int n, int sys) | |||
| 2529 | stop = limit; | 2526 | stop = limit; |
| 2530 | } else { | 2527 | } else { |
| 2531 | snprintf(mesg, sizeof(mesg), | 2528 | snprintf(mesg, sizeof(mesg), |
| 2532 | "Last %s or +size or +sizeM or +sizeK", | 2529 | "Last %s or +size{,K,M,G,T}", |
| 2533 | str_units(SINGULAR)); | 2530 | str_units(SINGULAR) |
| 2531 | ); | ||
| 2534 | stop = read_int(cround(start), cround(limit), cround(limit), cround(start), mesg); | 2532 | stop = read_int(cround(start), cround(limit), cround(limit), cround(start), mesg); |
| 2535 | if (display_in_cyl_units) { | 2533 | if (display_in_cyl_units) { |
| 2536 | stop = stop * units_per_sector - 1; | 2534 | stop = stop * units_per_sector - 1; |
| @@ -2614,9 +2612,9 @@ new_partition(void) | |||
| 2614 | } else { | 2612 | } else { |
| 2615 | char c, line[80]; | 2613 | char c, line[80]; |
| 2616 | snprintf(line, sizeof(line), | 2614 | snprintf(line, sizeof(line), |
| 2617 | "Command action\n" | 2615 | "Partition type\n" |
| 2618 | " %s\n" | 2616 | " p primary partition (1-4)\n" |
| 2619 | " p primary partition (1-4)\n", | 2617 | " %s\n", |
| 2620 | (extended_offset ? | 2618 | (extended_offset ? |
| 2621 | "l logical (5 or over)" : "e extended")); | 2619 | "l logical (5 or over)" : "e extended")); |
| 2622 | while (1) { | 2620 | while (1) { |
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c index 1cf0af5cc..0e5491a19 100644 --- a/util-linux/fdisk_sgi.c +++ b/util-linux/fdisk_sgi.c | |||
| @@ -623,7 +623,7 @@ sgi_change_sysid(int i, int sys) | |||
| 623 | "retrieve from its directory standalone tools like sash and fx.\n" | 623 | "retrieve from its directory standalone tools like sash and fx.\n" |
| 624 | "Only the \"SGI volume\" entire disk section may violate this.\n" | 624 | "Only the \"SGI volume\" entire disk section may violate this.\n" |
| 625 | "Type YES if you are sure about tagging this partition differently.\n"); | 625 | "Type YES if you are sure about tagging this partition differently.\n"); |
| 626 | if (strcmp(line_ptr, "YES\n") != 0) | 626 | if (strcmp(line_ptr, "YES") != 0) |
| 627 | return; | 627 | return; |
| 628 | } | 628 | } |
| 629 | sgilabel->partitions[i].id = SGI_SSWAP32(sys); | 629 | sgilabel->partitions[i].id = SGI_SSWAP32(sys); |
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c index f62a53ac6..3697a69b9 100644 --- a/util-linux/fdisk_sun.c +++ b/util-linux/fdisk_sun.c | |||
| @@ -606,7 +606,7 @@ sun_change_sysid(int i, int sys) | |||
| 606 | "there may destroy your partition table and bootblock.\n" | 606 | "there may destroy your partition table and bootblock.\n" |
| 607 | "Type YES if you're very sure you would like that partition\n" | 607 | "Type YES if you're very sure you would like that partition\n" |
| 608 | "tagged with 82 (Linux swap): "); | 608 | "tagged with 82 (Linux swap): "); |
| 609 | if (strcmp(line_ptr, "YES\n")) | 609 | if (strcmp(line_ptr, "YES") != 0) |
| 610 | return; | 610 | return; |
| 611 | } | 611 | } |
| 612 | switch (sys) { | 612 | switch (sys) { |
