diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-04 12:03:33 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-04 12:03:33 +0100 |
| commit | 72fbc81224351fd883c84967f5685ee016d791db (patch) | |
| tree | 70747f66196d47794069fd3fb9a738558677034f | |
| parent | 8aba5f6347518b09cb82a3330c574268919ed9bc (diff) | |
| download | busybox-w32-72fbc81224351fd883c84967f5685ee016d791db.tar.gz busybox-w32-72fbc81224351fd883c84967f5685ee016d791db.tar.bz2 busybox-w32-72fbc81224351fd883c84967f5685ee016d791db.zip | |
fdisk: code shrink
function old new delta
new_partition 1054 1066 +12
list_table 1366 1370 +4
update_units 32 35 +3
list_disk_geometry 68 71 +3
get_geometry 535 538 +3
fdisk_fatal 38 41 +3
warn_cylinders 42 44 +2
xbsd_print_disklabel 836 834 -2
create_doslabel 110 108 -2
change_units 49 45 -4
xbsd_new_part 477 456 -21
add_partition 1278 1246 -32
.rodata 107059 107008 -51
fdisk_main 4775 4618 -157
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/7 up/down: 30/-269) Total: -239 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | util-linux/fdisk.c | 178 | ||||
| -rw-r--r-- | util-linux/fdisk_gpt.c | 8 | ||||
| -rw-r--r-- | util-linux/fdisk_osf.c | 8 | ||||
| -rw-r--r-- | util-linux/fdisk_sgi.c | 4 | ||||
| -rw-r--r-- | util-linux/fdisk_sun.c | 4 |
5 files changed, 75 insertions, 127 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 470194af9..6611d3954 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
| @@ -114,15 +114,25 @@ | |||
| 114 | #endif | 114 | #endif |
| 115 | #include <assert.h> /* assert */ | 115 | #include <assert.h> /* assert */ |
| 116 | #include <sys/mount.h> | 116 | #include <sys/mount.h> |
| 117 | #include "libbb.h" | ||
| 118 | #include "unicode.h" | ||
| 117 | #if !defined(BLKSSZGET) | 119 | #if !defined(BLKSSZGET) |
| 118 | # define BLKSSZGET _IO(0x12, 104) | 120 | # define BLKSSZGET _IO(0x12, 104) |
| 119 | #endif | 121 | #endif |
| 120 | #if !defined(BLKGETSIZE64) | 122 | #if !defined(BLKGETSIZE64) |
| 121 | # define BLKGETSIZE64 _IOR(0x12,114,size_t) | 123 | # define BLKGETSIZE64 _IOR(0x12,114,size_t) |
| 122 | #endif | 124 | #endif |
| 123 | #include "libbb.h" | 125 | |
| 124 | #include "unicode.h" | 126 | /* Get device geometry in this struct: */ |
| 125 | #define HDIO_GETGEO 0x0301 /* get device geometry */ | 127 | #define HDIO_GETGEO 0x0301 |
| 128 | struct hd_geometry { | ||
| 129 | unsigned char heads; | ||
| 130 | unsigned char sectors; | ||
| 131 | unsigned short cylinders; | ||
| 132 | unsigned long start; | ||
| 133 | }; | ||
| 134 | |||
| 135 | typedef unsigned long long ullong; | ||
| 126 | 136 | ||
| 127 | #if BB_LITTLE_ENDIAN | 137 | #if BB_LITTLE_ENDIAN |
| 128 | # define inline_if_little_endian ALWAYS_INLINE | 138 | # define inline_if_little_endian ALWAYS_INLINE |
| @@ -155,19 +165,8 @@ | |||
| 155 | #define LINUX_LVM 0x8e | 165 | #define LINUX_LVM 0x8e |
| 156 | #define LINUX_RAID 0xfd | 166 | #define LINUX_RAID 0xfd |
| 157 | 167 | ||
| 158 | enum { | ||
| 159 | OPT_b = 1 << 0, | ||
| 160 | OPT_C = 1 << 1, | ||
| 161 | OPT_H = 1 << 2, | ||
| 162 | OPT_l = 1 << 3, | ||
| 163 | OPT_S = 1 << 4, | ||
| 164 | OPT_u = 1 << 5, | ||
| 165 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, | ||
| 166 | }; | ||
| 167 | |||
| 168 | typedef unsigned long long ullong; | ||
| 169 | /* Used for sector numbers. Partition formats we know | 168 | /* Used for sector numbers. Partition formats we know |
| 170 | * do not support more than 2^32 sectors | 169 | * (except GPT!) do not support more than 2^32 sectors. |
| 171 | */ | 170 | */ |
| 172 | typedef uint32_t sector_t; | 171 | typedef uint32_t sector_t; |
| 173 | #if UINT_MAX == 0xffffffff | 172 | #if UINT_MAX == 0xffffffff |
| @@ -180,12 +179,19 @@ typedef uint32_t sector_t; | |||
| 180 | # error Cant detect sizeof(uint32_t) | 179 | # error Cant detect sizeof(uint32_t) |
| 181 | #endif | 180 | #endif |
| 182 | 181 | ||
| 183 | struct hd_geometry { | 182 | enum { |
| 184 | unsigned char heads; | 183 | OPT_b = 1 << 0, |
| 185 | unsigned char sectors; | 184 | OPT_C = 1 << 1, |
| 186 | unsigned short cylinders; | 185 | OPT_H = 1 << 2, |
| 187 | unsigned long start; | 186 | OPT_l = 1 << 3, |
| 187 | OPT_S = 1 << 4, | ||
| 188 | OPT_u = 1 << 5, | ||
| 189 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, | ||
| 188 | }; | 190 | }; |
| 191 | #define USER_SET_SECTOR_SIZE (option_mask32 & OPT_b) | ||
| 192 | #define NOWARN_OPT_ls (!ENABLE_FEATURE_FDISK_WRITABLE || (option_mask32 & (OPT_l|OPT_s))) | ||
| 193 | #define DISPLAY_IN_CYL_UNITS (!(option_mask32 & OPT_u)) | ||
| 194 | #define TOGGLE_DISPLAY_IN_CYL_UNITS (option_mask32 ^= OPT_u) | ||
| 189 | 195 | ||
| 190 | /* TODO: just #if ENABLE_FEATURE_FDISK_WRITABLE */ | 196 | /* TODO: just #if ENABLE_FEATURE_FDISK_WRITABLE */ |
| 191 | /* (currently fdisk_sun/sgi.c do not have proper WRITABLE #ifs) */ | 197 | /* (currently fdisk_sun/sgi.c do not have proper WRITABLE #ifs) */ |
| @@ -421,7 +427,7 @@ enum { | |||
| 421 | }; | 427 | }; |
| 422 | 428 | ||
| 423 | #if ENABLE_FEATURE_GPT_LABEL | 429 | #if ENABLE_FEATURE_GPT_LABEL |
| 424 | struct gpt_header; | 430 | struct gpt_header; |
| 425 | #endif | 431 | #endif |
| 426 | 432 | ||
| 427 | /* Globals */ | 433 | /* Globals */ |
| @@ -434,19 +440,12 @@ struct globals { | |||
| 434 | unsigned sector_size; // = DEFAULT_SECTOR_SIZE; | 440 | unsigned sector_size; // = DEFAULT_SECTOR_SIZE; |
| 435 | unsigned sector_offset; // = 1; | 441 | unsigned sector_offset; // = 1; |
| 436 | unsigned g_heads, g_sectors, g_cylinders; | 442 | unsigned g_heads, g_sectors, g_cylinders; |
| 437 | smallint user_set_sector_size; | ||
| 438 | smallint /* enum label_type */ current_label_type; | 443 | smallint /* enum label_type */ current_label_type; |
| 439 | smallint display_in_cyl_units; | ||
| 440 | #if ENABLE_FEATURE_OSF_LABEL | 444 | #if ENABLE_FEATURE_OSF_LABEL |
| 441 | smallint possibly_osf_label; | 445 | smallint possibly_osf_label; |
| 442 | #endif | 446 | #endif |
| 443 | 447 | ||
| 444 | smallint listing; /* no aborts for fdisk -l */ | ||
| 445 | smallint dos_compatible_flag; // = 1; | 448 | smallint dos_compatible_flag; // = 1; |
| 446 | #if ENABLE_FEATURE_FDISK_WRITABLE | ||
| 447 | //int dos_changed; | ||
| 448 | smallint nowarn; /* no warnings for fdisk -l/-s */ | ||
| 449 | #endif | ||
| 450 | #if ENABLE_FEATURE_SUN_LABEL | 449 | #if ENABLE_FEATURE_SUN_LABEL |
| 451 | smallint sun_other_endian; | 450 | smallint sun_other_endian; |
| 452 | smallint sun_scsi_disk; | 451 | smallint sun_scsi_disk; |
| @@ -486,17 +485,13 @@ struct globals { | |||
| 486 | #define g_partitions (G.g_partitions ) | 485 | #define g_partitions (G.g_partitions ) |
| 487 | #define units_per_sector (G.units_per_sector ) | 486 | #define units_per_sector (G.units_per_sector ) |
| 488 | #define sector_size (G.sector_size ) | 487 | #define sector_size (G.sector_size ) |
| 489 | #define user_set_sector_size (G.user_set_sector_size) | ||
| 490 | #define sector_offset (G.sector_offset ) | 488 | #define sector_offset (G.sector_offset ) |
| 491 | #define g_heads (G.g_heads ) | 489 | #define g_heads (G.g_heads ) |
| 492 | #define g_sectors (G.g_sectors ) | 490 | #define g_sectors (G.g_sectors ) |
| 493 | #define g_cylinders (G.g_cylinders ) | 491 | #define g_cylinders (G.g_cylinders ) |
| 494 | #define current_label_type (G.current_label_type ) | 492 | #define current_label_type (G.current_label_type ) |
| 495 | #define display_in_cyl_units (G.display_in_cyl_units) | ||
| 496 | #define possibly_osf_label (G.possibly_osf_label ) | 493 | #define possibly_osf_label (G.possibly_osf_label ) |
| 497 | #define listing (G.listing ) | ||
| 498 | #define dos_compatible_flag (G.dos_compatible_flag ) | 494 | #define dos_compatible_flag (G.dos_compatible_flag ) |
| 499 | #define nowarn (G.nowarn ) | ||
| 500 | #define ext_index (G.ext_index ) | 495 | #define ext_index (G.ext_index ) |
| 501 | #define user_cylinders (G.user_cylinders ) | 496 | #define user_cylinders (G.user_cylinders ) |
| 502 | #define user_heads (G.user_heads ) | 497 | #define user_heads (G.user_heads ) |
| @@ -592,7 +587,7 @@ static sector_t bb_getsize_in_sectors(int fd) | |||
| 592 | #define IS_EXTENDED(i) \ | 587 | #define IS_EXTENDED(i) \ |
| 593 | ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) | 588 | ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) |
| 594 | 589 | ||
| 595 | #define cround(n) (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n)) | 590 | #define cround(n) (DISPLAY_IN_CYL_UNITS ? ((n)/units_per_sector)+1 : (n)) |
| 596 | 591 | ||
| 597 | #define scround(x) (((x)+units_per_sector-1)/units_per_sector) | 592 | #define scround(x) (((x)+units_per_sector-1)/units_per_sector) |
| 598 | 593 | ||
| @@ -657,7 +652,7 @@ get_part_table(int i) | |||
| 657 | static ALWAYS_INLINE const char * | 652 | static ALWAYS_INLINE const char * |
| 658 | str_units(void) | 653 | str_units(void) |
| 659 | { | 654 | { |
| 660 | return display_in_cyl_units ? "cylinder" : "sector"; | 655 | return DISPLAY_IN_CYL_UNITS ? "cylinder" : "sector"; |
| 661 | } | 656 | } |
| 662 | 657 | ||
| 663 | static int | 658 | static int |
| @@ -668,7 +663,9 @@ valid_part_table_flag(const char *mbuffer) | |||
| 668 | 663 | ||
| 669 | static void fdisk_fatal(const char *why) | 664 | static void fdisk_fatal(const char *why) |
| 670 | { | 665 | { |
| 671 | if (listing) { | 666 | if (!ENABLE_FEATURE_FDISK_WRITABLE /* this assumes -l */ |
| 667 | || (option_mask32 & OPT_l) | ||
| 668 | ) { | ||
| 672 | close_dev_fd(); | 669 | close_dev_fd(); |
| 673 | longjmp(listingbuf, 1); | 670 | longjmp(listingbuf, 1); |
| 674 | } | 671 | } |
| @@ -937,24 +934,6 @@ get_partition_start_from_dev_start(const struct pte *pe) | |||
| 937 | } | 934 | } |
| 938 | 935 | ||
| 939 | #if ENABLE_FEATURE_FDISK_WRITABLE | 936 | #if ENABLE_FEATURE_FDISK_WRITABLE |
| 940 | /* | ||
| 941 | * Avoid warning about DOS partitions when no DOS partition was changed. | ||
| 942 | * Here a heuristic "is probably dos partition". | ||
| 943 | * We might also do the opposite and warn in all cases except | ||
| 944 | * for "is probably nondos partition". | ||
| 945 | */ | ||
| 946 | #ifdef UNUSED | ||
| 947 | static int | ||
| 948 | is_dos_partition(int t) | ||
| 949 | { | ||
| 950 | return (t == 1 || t == 4 || t == 6 || | ||
| 951 | t == 0x0b || t == 0x0c || t == 0x0e || | ||
| 952 | t == 0x11 || t == 0x12 || t == 0x14 || t == 0x16 || | ||
| 953 | t == 0x1b || t == 0x1c || t == 0x1e || t == 0x24 || | ||
| 954 | t == 0xc1 || t == 0xc4 || t == 0xc6); | ||
| 955 | } | ||
| 956 | #endif | ||
| 957 | |||
| 958 | static void | 937 | static void |
| 959 | menu(void) | 938 | menu(void) |
| 960 | { | 939 | { |
| @@ -1023,70 +1002,44 @@ menu(void) | |||
| 1023 | } | 1002 | } |
| 1024 | #endif /* FEATURE_FDISK_WRITABLE */ | 1003 | #endif /* FEATURE_FDISK_WRITABLE */ |
| 1025 | 1004 | ||
| 1026 | |||
| 1027 | #if ENABLE_FEATURE_FDISK_ADVANCED | 1005 | #if ENABLE_FEATURE_FDISK_ADVANCED |
| 1028 | static void | 1006 | static void |
| 1029 | xmenu(void) | 1007 | xmenu(void) |
| 1030 | { | 1008 | { |
| 1031 | puts("Command Action"); | 1009 | puts("Command Action"); |
| 1010 | puts("c\tchange number of cylinders"); | ||
| 1011 | puts("h\tchange number of heads"); | ||
| 1012 | puts("s\tchange number of sectors/track"); | ||
| 1032 | if (LABEL_IS_SUN) { | 1013 | if (LABEL_IS_SUN) { |
| 1033 | puts("a\tchange number of alternate cylinders"); /*sun*/ | 1014 | puts("a\tchange number of alternate cylinders"); /*sun*/ |
| 1034 | puts("c\tchange number of cylinders"); | 1015 | puts("y\tchange number of physical cylinders"); /*sun*/ |
| 1035 | puts("d\tprint the raw data in the partition table"); | ||
| 1036 | puts("e\tchange number of extra sectors per cylinder");/*sun*/ | 1016 | puts("e\tchange number of extra sectors per cylinder");/*sun*/ |
| 1037 | puts("h\tchange number of heads"); | ||
| 1038 | puts("i\tchange interleave factor"); /*sun*/ | 1017 | puts("i\tchange interleave factor"); /*sun*/ |
| 1039 | puts("o\tchange rotation speed (rpm)"); /*sun*/ | 1018 | puts("o\tchange rotation speed (rpm)"); /*sun*/ |
| 1040 | puts("p\tprint the partition table"); | ||
| 1041 | puts("q\tquit without saving changes"); | ||
| 1042 | puts("r\treturn to main menu"); | ||
| 1043 | puts("s\tchange number of sectors/track"); | ||
| 1044 | puts("v\tverify the partition table"); | ||
| 1045 | puts("w\twrite table to disk and exit"); | ||
| 1046 | puts("y\tchange number of physical cylinders"); /*sun*/ | ||
| 1047 | } else if (LABEL_IS_SGI) { | 1019 | } else if (LABEL_IS_SGI) { |
| 1048 | puts("b\tmove beginning of data in a partition"); /* !sun */ | 1020 | puts("b\tmove beginning of data in a partition"); /* !sun */ |
| 1049 | puts("c\tchange number of cylinders"); | ||
| 1050 | puts("d\tprint the raw data in the partition table"); | ||
| 1051 | puts("e\tlist extended partitions"); /* !sun */ | ||
| 1052 | puts("g\tcreate an IRIX (SGI) partition table");/* sgi */ | 1021 | puts("g\tcreate an IRIX (SGI) partition table");/* sgi */ |
| 1053 | puts("h\tchange number of heads"); | 1022 | puts("e\tlist extended partitions"); /* !sun */ |
| 1054 | puts("p\tprint the partition table"); | ||
| 1055 | puts("q\tquit without saving changes"); | ||
| 1056 | puts("r\treturn to main menu"); | ||
| 1057 | puts("s\tchange number of sectors/track"); | ||
| 1058 | puts("v\tverify the partition table"); | ||
| 1059 | puts("w\twrite table to disk and exit"); | ||
| 1060 | } else if (LABEL_IS_AIX) { | 1023 | } else if (LABEL_IS_AIX) { |
| 1061 | puts("b\tmove beginning of data in a partition"); /* !sun */ | 1024 | puts("b\tmove beginning of data in a partition"); /* !sun */ |
| 1062 | puts("c\tchange number of cylinders"); | 1025 | # if ENABLE_FEATURE_SGI_LABEL |
| 1063 | puts("d\tprint the raw data in the partition table"); | 1026 | puts("g\tcreate an IRIX (SGI) partition table"); |
| 1027 | # endif | ||
| 1064 | puts("e\tlist extended partitions"); /* !sun */ | 1028 | puts("e\tlist extended partitions"); /* !sun */ |
| 1065 | puts("g\tcreate an IRIX (SGI) partition table");/* sgi */ | ||
| 1066 | puts("h\tchange number of heads"); | ||
| 1067 | puts("p\tprint the partition table"); | ||
| 1068 | puts("q\tquit without saving changes"); | ||
| 1069 | puts("r\treturn to main menu"); | ||
| 1070 | puts("s\tchange number of sectors/track"); | ||
| 1071 | puts("v\tverify the partition table"); | ||
| 1072 | puts("w\twrite table to disk and exit"); | ||
| 1073 | } else { | 1029 | } else { |
| 1030 | puts("f\tfix partition order"); /* !sun, !aix, !sgi */ | ||
| 1074 | puts("b\tmove beginning of data in a partition"); /* !sun */ | 1031 | puts("b\tmove beginning of data in a partition"); /* !sun */ |
| 1075 | puts("c\tchange number of cylinders"); | 1032 | # if ENABLE_FEATURE_SGI_LABEL |
| 1076 | puts("d\tprint the raw data in the partition table"); | 1033 | puts("g\tcreate an IRIX (SGI) partition table"); |
| 1034 | # endif | ||
| 1077 | puts("e\tlist extended partitions"); /* !sun */ | 1035 | puts("e\tlist extended partitions"); /* !sun */ |
| 1078 | puts("f\tfix partition order"); /* !sun, !aix, !sgi */ | ||
| 1079 | #if ENABLE_FEATURE_SGI_LABEL | ||
| 1080 | puts("g\tcreate an IRIX (SGI) partition table");/* sgi */ | ||
| 1081 | #endif | ||
| 1082 | puts("h\tchange number of heads"); | ||
| 1083 | puts("p\tprint the partition table"); | ||
| 1084 | puts("q\tquit without saving changes"); | ||
| 1085 | puts("r\treturn to main menu"); | ||
| 1086 | puts("s\tchange number of sectors/track"); | ||
| 1087 | puts("v\tverify the partition table"); | ||
| 1088 | puts("w\twrite table to disk and exit"); | ||
| 1089 | } | 1036 | } |
| 1037 | puts("d\tprint the raw data in the partition table"); | ||
| 1038 | puts("p\tprint the partition table"); | ||
| 1039 | puts("v\tverify the partition table"); | ||
| 1040 | puts("w\twrite table to disk and exit"); | ||
| 1041 | puts("q\tquit without saving changes"); | ||
| 1042 | puts("r\treturn to main menu"); | ||
| 1090 | } | 1043 | } |
| 1091 | #endif /* ADVANCED mode */ | 1044 | #endif /* ADVANCED mode */ |
| 1092 | 1045 | ||
| @@ -1245,7 +1198,7 @@ update_units(void) | |||
| 1245 | { | 1198 | { |
| 1246 | int cyl_units = g_heads * g_sectors; | 1199 | int cyl_units = g_heads * g_sectors; |
| 1247 | 1200 | ||
| 1248 | if (display_in_cyl_units && cyl_units) | 1201 | if (DISPLAY_IN_CYL_UNITS && cyl_units) |
| 1249 | units_per_sector = cyl_units; | 1202 | units_per_sector = cyl_units; |
| 1250 | else | 1203 | else |
| 1251 | units_per_sector = 1; /* in sectors */ | 1204 | units_per_sector = 1; /* in sectors */ |
| @@ -1255,7 +1208,7 @@ update_units(void) | |||
| 1255 | static void | 1208 | static void |
| 1256 | warn_cylinders(void) | 1209 | warn_cylinders(void) |
| 1257 | { | 1210 | { |
| 1258 | if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn) | 1211 | if (LABEL_IS_DOS && g_cylinders > 1024 && !NOWARN_OPT_ls) |
| 1259 | printf("\n" | 1212 | printf("\n" |
| 1260 | "The number of cylinders for this disk is set to %u.\n" | 1213 | "The number of cylinders for this disk is set to %u.\n" |
| 1261 | "There is nothing wrong with that, but this is larger than 1024,\n" | 1214 | "There is nothing wrong with that, but this is larger than 1024,\n" |
| @@ -1384,7 +1337,7 @@ create_doslabel(void) | |||
| 1384 | static void | 1337 | static void |
| 1385 | get_sectorsize(void) | 1338 | get_sectorsize(void) |
| 1386 | { | 1339 | { |
| 1387 | if (!user_set_sector_size) { | 1340 | if (!USER_SET_SECTOR_SIZE) { |
| 1388 | int arg; | 1341 | int arg; |
| 1389 | if (ioctl(dev_fd, BLKSSZGET, &arg) == 0 && arg >= 512) | 1342 | if (ioctl(dev_fd, BLKSSZGET, &arg) == 0 && arg >= 512) |
| 1390 | sector_size = arg; | 1343 | sector_size = arg; |
| @@ -1839,7 +1792,7 @@ get_nonexisting_partition(void) | |||
| 1839 | static void | 1792 | static void |
| 1840 | change_units(void) | 1793 | change_units(void) |
| 1841 | { | 1794 | { |
| 1842 | display_in_cyl_units = !display_in_cyl_units; | 1795 | TOGGLE_DISPLAY_IN_CYL_UNITS; |
| 1843 | update_units(); | 1796 | update_units(); |
| 1844 | printf("Changing display/entry units to %ss\n", | 1797 | printf("Changing display/entry units to %ss\n", |
| 1845 | str_units()); | 1798 | str_units()); |
| @@ -2540,7 +2493,7 @@ add_partition(int n, int sys) | |||
| 2540 | fill_bounds(first, last); | 2493 | fill_bounds(first, last); |
| 2541 | if (n < 4) { | 2494 | if (n < 4) { |
| 2542 | start = sector_offset; | 2495 | start = sector_offset; |
| 2543 | if (display_in_cyl_units || !total_number_of_sectors) | 2496 | if (DISPLAY_IN_CYL_UNITS || !total_number_of_sectors) |
| 2544 | limit = (sector_t) g_heads * g_sectors * g_cylinders - 1; | 2497 | limit = (sector_t) g_heads * g_sectors * g_cylinders - 1; |
| 2545 | else | 2498 | else |
| 2546 | limit = total_number_of_sectors - 1; | 2499 | limit = total_number_of_sectors - 1; |
| @@ -2553,7 +2506,7 @@ add_partition(int n, int sys) | |||
| 2553 | start = extended_offset + sector_offset; | 2506 | start = extended_offset + sector_offset; |
| 2554 | limit = get_start_sect(q) + get_nr_sects(q) - 1; | 2507 | limit = get_start_sect(q) + get_nr_sects(q) - 1; |
| 2555 | } | 2508 | } |
| 2556 | if (display_in_cyl_units) | 2509 | if (DISPLAY_IN_CYL_UNITS) |
| 2557 | for (i = 0; i < g_partitions; i++) | 2510 | for (i = 0; i < g_partitions; i++) |
| 2558 | first[i] = (cround(first[i]) - 1) * units_per_sector; | 2511 | first[i] = (cround(first[i]) - 1) * units_per_sector; |
| 2559 | 2512 | ||
| @@ -2581,7 +2534,7 @@ add_partition(int n, int sys) | |||
| 2581 | 2534 | ||
| 2582 | saved_start = start; | 2535 | saved_start = start; |
| 2583 | start = read_int(cround(saved_start), cround(saved_start), cround(limit), 0, mesg); | 2536 | start = read_int(cround(saved_start), cround(saved_start), cround(limit), 0, mesg); |
| 2584 | if (display_in_cyl_units) { | 2537 | if (DISPLAY_IN_CYL_UNITS) { |
| 2585 | start = (start - 1) * units_per_sector; | 2538 | start = (start - 1) * units_per_sector; |
| 2586 | if (start < saved_start) | 2539 | if (start < saved_start) |
| 2587 | start = saved_start; | 2540 | start = saved_start; |
| @@ -2622,7 +2575,7 @@ add_partition(int n, int sys) | |||
| 2622 | str_units() | 2575 | str_units() |
| 2623 | ); | 2576 | ); |
| 2624 | stop = read_int(cround(start), cround(limit), cround(limit), cround(start), mesg); | 2577 | stop = read_int(cround(start), cround(limit), cround(limit), cround(start), mesg); |
| 2625 | if (display_in_cyl_units) { | 2578 | if (DISPLAY_IN_CYL_UNITS) { |
| 2626 | stop = stop * units_per_sector - 1; | 2579 | stop = stop * units_per_sector - 1; |
| 2627 | if (stop >limit) | 2580 | if (stop >limit) |
| 2628 | stop = limit; | 2581 | stop = limit; |
| @@ -3112,7 +3065,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3112 | close_dev_fd(); /* needed: fd 3 must not stay closed */ | 3065 | close_dev_fd(); /* needed: fd 3 must not stay closed */ |
| 3113 | 3066 | ||
| 3114 | opt = getopt32(argv, "^" "b:+C:+H:+lS:+u"IF_FEATURE_FDISK_BLKSIZE("s")"\0" | 3067 | opt = getopt32(argv, "^" "b:+C:+H:+lS:+u"IF_FEATURE_FDISK_BLKSIZE("s")"\0" |
| 3115 | /* among -s and -l, the last one takes preference */ | 3068 | /* among -s and -l, the last one takes precedence */ |
| 3116 | IF_FEATURE_FDISK_BLKSIZE("s-l:l-s"), | 3069 | IF_FEATURE_FDISK_BLKSIZE("s-l:l-s"), |
| 3117 | §or_size, &user_cylinders, &user_heads, &user_sectors); | 3070 | §or_size, &user_cylinders, &user_heads, &user_sectors); |
| 3118 | argv += optind; | 3071 | argv += optind; |
| @@ -3122,7 +3075,6 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3122 | if (opt & OPT_s) { | 3075 | if (opt & OPT_s) { |
| 3123 | int j; | 3076 | int j; |
| 3124 | 3077 | ||
| 3125 | nowarn = 1; | ||
| 3126 | if (!argv[0]) | 3078 | if (!argv[0]) |
| 3127 | bb_show_usage(); | 3079 | bb_show_usage(); |
| 3128 | for (j = 0; argv[j]; j++) { | 3080 | for (j = 0; argv[j]; j++) { |
| @@ -3141,7 +3093,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3141 | } | 3093 | } |
| 3142 | #endif | 3094 | #endif |
| 3143 | 3095 | ||
| 3144 | if (opt & OPT_b) { | 3096 | //if (opt & OPT_b) { |
| 3145 | /* Ugly: this sector size is really per device, | 3097 | /* Ugly: this sector size is really per device, |
| 3146 | * so cannot be combined with multiple disks, | 3098 | * so cannot be combined with multiple disks, |
| 3147 | * and the same goes for the C/H/S options. | 3099 | * and the same goes for the C/H/S options. |
| @@ -3152,22 +3104,18 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3152 | ) { | 3104 | ) { |
| 3153 | bb_show_usage(); | 3105 | bb_show_usage(); |
| 3154 | } | 3106 | } |
| 3155 | sector_offset = 2; | 3107 | //} |
| 3156 | user_set_sector_size = 1; | ||
| 3157 | } | ||
| 3158 | if (user_heads <= 0 || user_heads >= 256) | 3108 | if (user_heads <= 0 || user_heads >= 256) |
| 3159 | user_heads = 0; | 3109 | user_heads = 0; |
| 3160 | if (user_sectors <= 0 || user_sectors >= 64) | 3110 | if (user_sectors <= 0 || user_sectors >= 64) |
| 3161 | user_sectors = 0; | 3111 | user_sectors = 0; |
| 3162 | if (opt & OPT_u) | 3112 | //if (opt & OPT_u) |
| 3163 | display_in_cyl_units = 0; | 3113 | // DISPLAY_IN_CYL_UNITS = 0; |
| 3164 | 3114 | ||
| 3165 | #if ENABLE_FEATURE_FDISK_WRITABLE | 3115 | #if ENABLE_FEATURE_FDISK_WRITABLE |
| 3166 | if (opt & OPT_l) { | 3116 | if (opt & OPT_l) { |
| 3167 | nowarn = 1; | ||
| 3168 | #endif | 3117 | #endif |
| 3169 | if (*argv) { | 3118 | if (*argv) { |
| 3170 | listing = 1; | ||
| 3171 | do { | 3119 | do { |
| 3172 | open_list_and_close(*argv, 1); | 3120 | open_list_and_close(*argv, 1); |
| 3173 | } while (*++argv); | 3121 | } while (*++argv); |
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index 251c9e202..c085af79c 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c | |||
| @@ -178,7 +178,7 @@ check_gpt_label(void) | |||
| 178 | G.gpt_hdr->hdr_crc32 = 0; | 178 | G.gpt_hdr->hdr_crc32 = 0; |
| 179 | if (gpt_crc32(G.gpt_hdr, SWAP_LE32(G.gpt_hdr->hdr_size)) != crc) { | 179 | if (gpt_crc32(G.gpt_hdr, SWAP_LE32(G.gpt_hdr->hdr_size)) != crc) { |
| 180 | /* FIXME: read the backup table */ | 180 | /* FIXME: read the backup table */ |
| 181 | puts("\nwarning: GPT header CRC is invalid\n"); | 181 | puts("\nwarning: GPT header CRC is invalid"); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | G.gpt_n_parts = SWAP_LE32(G.gpt_hdr->n_parts); | 184 | G.gpt_n_parts = SWAP_LE32(G.gpt_hdr->n_parts); |
| @@ -187,7 +187,7 @@ check_gpt_label(void) | |||
| 187 | || G.gpt_part_entry_len > GPT_MAX_PART_ENTRY_LEN | 187 | || G.gpt_part_entry_len > GPT_MAX_PART_ENTRY_LEN |
| 188 | || SWAP_LE32(G.gpt_hdr->hdr_size) > sector_size | 188 | || SWAP_LE32(G.gpt_hdr->hdr_size) > sector_size |
| 189 | ) { | 189 | ) { |
| 190 | puts("\nwarning: can't parse GPT disklabel\n"); | 190 | puts("\nwarning: can't parse GPT disklabel"); |
| 191 | current_label_type = LABEL_DOS; | 191 | current_label_type = LABEL_DOS; |
| 192 | return 0; | 192 | return 0; |
| 193 | } | 193 | } |
| @@ -201,10 +201,10 @@ check_gpt_label(void) | |||
| 201 | 201 | ||
| 202 | if (gpt_crc32(G.gpt_part_array, part_array_len) != G.gpt_hdr->part_array_crc32) { | 202 | if (gpt_crc32(G.gpt_part_array, part_array_len) != G.gpt_hdr->part_array_crc32) { |
| 203 | /* FIXME: read the backup table */ | 203 | /* FIXME: read the backup table */ |
| 204 | puts("\nwarning: GPT array CRC is invalid\n"); | 204 | puts("\nwarning: GPT array CRC is invalid"); |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | puts("Found valid GPT with protective MBR; using GPT\n"); | 207 | puts("Found valid GPT with protective MBR; using GPT"); |
| 208 | 208 | ||
| 209 | current_label_type = LABEL_GPT; | 209 | current_label_type = LABEL_GPT; |
| 210 | return 1; | 210 | return 1; |
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 5d6b4cbcf..f34390e01 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c | |||
| @@ -280,7 +280,7 @@ static struct bsd_globals *bsd_globals_ptr; | |||
| 280 | /* Code */ | 280 | /* Code */ |
| 281 | 281 | ||
| 282 | #define bsd_cround(n) \ | 282 | #define bsd_cround(n) \ |
| 283 | (display_in_cyl_units ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n)) | 283 | (DISPLAY_IN_CYL_UNITS ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n)) |
| 284 | 284 | ||
| 285 | /* | 285 | /* |
| 286 | * Test whether the whole disk has BSD disk label magic. | 286 | * Test whether the whole disk has BSD disk label magic. |
| @@ -472,7 +472,7 @@ xbsd_new_part(void) | |||
| 472 | begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end), | 472 | begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end), |
| 473 | 0, mesg); | 473 | 0, mesg); |
| 474 | 474 | ||
| 475 | if (display_in_cyl_units) | 475 | if (DISPLAY_IN_CYL_UNITS) |
| 476 | begin = (begin - 1) * xbsd_dlabel.d_secpercyl; | 476 | begin = (begin - 1) * xbsd_dlabel.d_secpercyl; |
| 477 | 477 | ||
| 478 | snprintf(mesg, sizeof(mesg), "Last %s or +size or +sizeM or +sizeK", | 478 | snprintf(mesg, sizeof(mesg), "Last %s or +size or +sizeM or +sizeK", |
| @@ -480,7 +480,7 @@ xbsd_new_part(void) | |||
| 480 | end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end), | 480 | end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end), |
| 481 | bsd_cround(begin), mesg); | 481 | bsd_cround(begin), mesg); |
| 482 | 482 | ||
| 483 | if (display_in_cyl_units) | 483 | if (DISPLAY_IN_CYL_UNITS) |
| 484 | end = end * xbsd_dlabel.d_secpercyl - 1; | 484 | end = end * xbsd_dlabel.d_secpercyl - 1; |
| 485 | 485 | ||
| 486 | xbsd_dlabel.d_partitions[i].p_size = end - begin + 1; | 486 | xbsd_dlabel.d_partitions[i].p_size = end - begin + 1; |
| @@ -541,7 +541,7 @@ xbsd_print_disklabel(int show_all) | |||
| 541 | pp = lp->d_partitions; | 541 | pp = lp->d_partitions; |
| 542 | for (i = 0; i < lp->d_npartitions; i++, pp++) { | 542 | for (i = 0; i < lp->d_npartitions; i++, pp++) { |
| 543 | if (pp->p_size) { | 543 | if (pp->p_size) { |
| 544 | if (display_in_cyl_units && lp->d_secpercyl) { | 544 | if (DISPLAY_IN_CYL_UNITS && lp->d_secpercyl) { |
| 545 | printf(" %c: %8lu%c %8lu%c %8lu%c ", | 545 | printf(" %c: %8lu%c %8lu%c %8lu%c ", |
| 546 | 'a' + i, | 546 | 'a' + i, |
| 547 | (unsigned long) pp->p_offset / lp->d_secpercyl + 1, | 547 | (unsigned long) pp->p_offset / lp->d_secpercyl + 1, |
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c index 656cb02fc..000178049 100644 --- a/util-linux/fdisk_sgi.c +++ b/util-linux/fdisk_sgi.c | |||
| @@ -735,7 +735,7 @@ sgi_add_partition(int n, int sys) | |||
| 735 | first = read_int(scround(first), scround(first), scround(last)-1, | 735 | first = read_int(scround(first), scround(first), scround(last)-1, |
| 736 | 0, mesg); | 736 | 0, mesg); |
| 737 | } | 737 | } |
| 738 | if (display_in_cyl_units) | 738 | if (DISPLAY_IN_CYL_UNITS) |
| 739 | first *= units_per_sector; | 739 | first *= units_per_sector; |
| 740 | else | 740 | else |
| 741 | first = first; /* align to cylinder if you know how ... */ | 741 | first = first; /* align to cylinder if you know how ... */ |
| @@ -749,7 +749,7 @@ sgi_add_partition(int n, int sys) | |||
| 749 | snprintf(mesg, sizeof(mesg), " Last %s", str_units()); | 749 | snprintf(mesg, sizeof(mesg), " Last %s", str_units()); |
| 750 | last = read_int(scround(first), scround(last)-1, scround(last)-1, | 750 | last = read_int(scround(first), scround(last)-1, scround(last)-1, |
| 751 | scround(first), mesg)+1; | 751 | scround(first), mesg)+1; |
| 752 | if (display_in_cyl_units) | 752 | if (DISPLAY_IN_CYL_UNITS) |
| 753 | last *= units_per_sector; | 753 | last *= units_per_sector; |
| 754 | else | 754 | else |
| 755 | last = last; /* align to cylinder if You know how ... */ | 755 | last = last; /* align to cylinder if You know how ... */ |
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c index e9b9ffd11..aab0a9825 100644 --- a/util-linux/fdisk_sun.c +++ b/util-linux/fdisk_sun.c | |||
| @@ -504,7 +504,7 @@ add_sun_partition(int n, int sys) | |||
| 504 | else | 504 | else |
| 505 | first = read_int(scround(start), scround(stop)+1, | 505 | first = read_int(scround(start), scround(stop)+1, |
| 506 | scround(stop), 0, mesg); | 506 | scround(stop), 0, mesg); |
| 507 | if (display_in_cyl_units) { | 507 | if (DISPLAY_IN_CYL_UNITS) { |
| 508 | first *= units_per_sector; | 508 | first *= units_per_sector; |
| 509 | } else { | 509 | } else { |
| 510 | /* Starting sector has to be properly aligned */ | 510 | /* Starting sector has to be properly aligned */ |
| @@ -562,7 +562,7 @@ and is of type 'Whole disk'\n"); | |||
| 562 | else | 562 | else |
| 563 | last = read_int(scround(first), scround(stop), scround(stop), | 563 | last = read_int(scround(first), scround(stop), scround(stop), |
| 564 | scround(first), mesg); | 564 | scround(first), mesg); |
| 565 | if (display_in_cyl_units) | 565 | if (DISPLAY_IN_CYL_UNITS) |
| 566 | last *= units_per_sector; | 566 | last *= units_per_sector; |
| 567 | if (n == 2 && !first) { | 567 | if (n == 2 && !first) { |
| 568 | if (last >= stop2) { | 568 | if (last >= stop2) { |
