diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-25 14:42:53 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-25 14:42:53 +0200 |
commit | 1ab3899d49bda113671bf787a43d90c683faf2a8 (patch) | |
tree | b0beb3f32fbed0fb8ac5426b646a8424bfacf9b9 | |
parent | c104549b483c83acdf3e12cfe3df2c6437fa6926 (diff) | |
download | busybox-w32-1ab3899d49bda113671bf787a43d90c683faf2a8.tar.gz busybox-w32-1ab3899d49bda113671bf787a43d90c683faf2a8.tar.bz2 busybox-w32-1ab3899d49bda113671bf787a43d90c683faf2a8.zip |
fdisk: code shrink
function old new delta
get_nonexisting_partition 119 104 -15
fdisk_main 2640 2622 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-33) Total: -33 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/fdisk.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 296716575..288b9235f 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -1631,6 +1631,26 @@ read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char * | |||
1631 | case 'k': | 1631 | case 'k': |
1632 | scale_shift = 10; /* 1024 */ | 1632 | scale_shift = 10; /* 1024 */ |
1633 | break; | 1633 | break; |
1634 | /* | ||
1635 | * fdisk from util-linux 2.31 seems to round '+NNNk' and '+NNNK' to megabytes, | ||
1636 | * (512-byte) sector count of the partition does not equal NNN*2: | ||
1637 | * | ||
1638 | * Last sector, +sectors or +size{K,M,G,T,P} (1953792-1000215215, default 1000215215): +9727k | ||
1639 | * Device Boot Start End Sectors Size Id Type | ||
1640 | * /dev/sdaN 1953792 1972223 18432 9M 83 Linux <-- size exactly 9*1024*1024 bytes | ||
1641 | * | ||
1642 | * Last sector, +sectors or +size{K,M,G,T,P} (1953792-1000215215, default 1000215215): +9728k | ||
1643 | * /dev/sdaN 1953792 1974271 20480 10M 83 Linux <-- size exactly 10*1024*1024 bytes | ||
1644 | * | ||
1645 | * If 'k' means 1000 bytes (not 1024), then 9728k = 9728*1000 = 9500*1024, | ||
1646 | * exactly halfway from 9000 to 10000, which explains why it jumps to next mbyte | ||
1647 | * at this value. | ||
1648 | * | ||
1649 | * 'm' does not seem to behave this way: it means 1024*1024 bytes. | ||
1650 | * | ||
1651 | * Not sure we want to copy this. If user says he wants 1234kbyte partition, | ||
1652 | * we do _exactly that_: 1234kbytes = 2468 sectors. | ||
1653 | */ | ||
1634 | case 'm': | 1654 | case 'm': |
1635 | scale_shift = 20; /* 1024*1024 */ | 1655 | scale_shift = 20; /* 1024*1024 */ |
1636 | break; | 1656 | break; |
@@ -1725,8 +1745,9 @@ get_existing_partition(int warn, unsigned max) | |||
1725 | } | 1745 | } |
1726 | 1746 | ||
1727 | static int | 1747 | static int |
1728 | get_nonexisting_partition(int warn, unsigned max) | 1748 | get_nonexisting_partition(void) |
1729 | { | 1749 | { |
1750 | const int max = 4; | ||
1730 | int pno = -1; | 1751 | int pno = -1; |
1731 | unsigned i; | 1752 | unsigned i; |
1732 | 1753 | ||
@@ -1748,7 +1769,7 @@ get_nonexisting_partition(int warn, unsigned max) | |||
1748 | return -1; | 1769 | return -1; |
1749 | 1770 | ||
1750 | not_unique: | 1771 | not_unique: |
1751 | return get_partition(warn, max); | 1772 | return get_partition(/*warn*/ 0, max); |
1752 | } | 1773 | } |
1753 | 1774 | ||
1754 | 1775 | ||
@@ -2619,8 +2640,9 @@ new_partition(void) | |||
2619 | "l logical (5 or over)" : "e extended")); | 2640 | "l logical (5 or over)" : "e extended")); |
2620 | while (1) { | 2641 | while (1) { |
2621 | c = read_nonempty(line); | 2642 | c = read_nonempty(line); |
2622 | if ((c | 0x20) == 'p') { | 2643 | c |= 0x20; /* lowercase */ |
2623 | i = get_nonexisting_partition(0, 4); | 2644 | if (c == 'p') { |
2645 | i = get_nonexisting_partition(); | ||
2624 | if (i >= 0) | 2646 | if (i >= 0) |
2625 | add_partition(i, LINUX_NATIVE); | 2647 | add_partition(i, LINUX_NATIVE); |
2626 | return; | 2648 | return; |
@@ -2630,7 +2652,7 @@ new_partition(void) | |||
2630 | return; | 2652 | return; |
2631 | } | 2653 | } |
2632 | if (c == 'e' && !extended_offset) { | 2654 | if (c == 'e' && !extended_offset) { |
2633 | i = get_nonexisting_partition(0, 4); | 2655 | i = get_nonexisting_partition(); |
2634 | if (i >= 0) | 2656 | if (i >= 0) |
2635 | add_partition(i, EXTENDED); | 2657 | add_partition(i, EXTENDED); |
2636 | return; | 2658 | return; |