diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-02 15:18:25 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-02 15:26:03 +0100 |
| commit | 4855fbe6a84ae151be66d82f4b0dcb4601ac457e (patch) | |
| tree | 27c3100dbb3b0d51709da678767c954f61a79abd /util-linux/fdisk.c | |
| parent | 705c9b3487928df07d218f8327d1f4951b17a6bd (diff) | |
| download | busybox-w32-4855fbe6a84ae151be66d82f4b0dcb4601ac457e.tar.gz busybox-w32-4855fbe6a84ae151be66d82f4b0dcb4601ac457e.tar.bz2 busybox-w32-4855fbe6a84ae151be66d82f4b0dcb4601ac457e.zip | |
fdisk: uncomment -s support
function old new delta
bb_BLKGETSIZE_sectors - 191 +191
fdisk_main 4674 4774 +100
packed_usage 35941 35997 +56
.rodata 107069 107089 +20
get_geometry 665 511 -154
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 367/-154) Total: 213 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/fdisk.c')
| -rw-r--r-- | util-linux/fdisk.c | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index f49a6219a..820992801 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
| @@ -22,6 +22,11 @@ | |||
| 22 | //config: depends on FDISK | 22 | //config: depends on FDISK |
| 23 | //config: depends on !LFS # with LFS no special code is needed | 23 | //config: depends on !LFS # with LFS no special code is needed |
| 24 | //config: | 24 | //config: |
| 25 | //config:config FEATURE_FDISK_BLKSIZE | ||
| 26 | //config: bool "Support -s option to list sizes" | ||
| 27 | //config: default y | ||
| 28 | //config: depends on FDISK | ||
| 29 | //config: | ||
| 25 | //config:config FEATURE_FDISK_WRITABLE | 30 | //config:config FEATURE_FDISK_WRITABLE |
| 26 | //config: bool "Write support" | 31 | //config: bool "Write support" |
| 27 | //config: default y | 32 | //config: default y |
| @@ -85,12 +90,6 @@ | |||
| 85 | 90 | ||
| 86 | //kbuild:lib-$(CONFIG_FDISK) += fdisk.o | 91 | //kbuild:lib-$(CONFIG_FDISK) += fdisk.o |
| 87 | 92 | ||
| 88 | /* Looks like someone forgot to add this to config system */ | ||
| 89 | //usage:#ifndef ENABLE_FEATURE_FDISK_BLKSIZE | ||
| 90 | //usage:# define ENABLE_FEATURE_FDISK_BLKSIZE 0 | ||
| 91 | //usage:# define IF_FEATURE_FDISK_BLKSIZE(a) | ||
| 92 | //usage:#endif | ||
| 93 | //usage: | ||
| 94 | //usage:#define fdisk_trivial_usage | 93 | //usage:#define fdisk_trivial_usage |
| 95 | //usage: "[-ul" IF_FEATURE_FDISK_BLKSIZE("s") "] " | 94 | //usage: "[-ul" IF_FEATURE_FDISK_BLKSIZE("s") "] " |
| 96 | //usage: "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" | 95 | //usage: "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" |
| @@ -99,7 +98,9 @@ | |||
| 99 | //usage: "\n -u Start and End are in sectors (instead of cylinders)" | 98 | //usage: "\n -u Start and End are in sectors (instead of cylinders)" |
| 100 | //usage: "\n -l Show partition table for each DISK, then exit" | 99 | //usage: "\n -l Show partition table for each DISK, then exit" |
| 101 | //usage: IF_FEATURE_FDISK_BLKSIZE( | 100 | //usage: IF_FEATURE_FDISK_BLKSIZE( |
| 102 | //usage: "\n -s Show partition sizes in kb for each DISK, then exit" | 101 | //usage: "\n -s Show sizes in kb for each DISK, then exit" |
| 102 | //NB: util-linux 2.41.1 says: "-s,--getsz: display device size in 512-byte sectors" | ||
| 103 | //but in fact, util-linux 2.41.1 shows the size in KILOBYTES! | ||
| 103 | //usage: ) | 104 | //usage: ) |
| 104 | //usage: "\n -b 2048 (for certain MO disks) use 2048-byte sectors" | 105 | //usage: "\n -b 2048 (for certain MO disks) use 2048-byte sectors" |
| 105 | //usage: "\n -C CYLINDERS Set number of cylinders/heads/sectors" | 106 | //usage: "\n -C CYLINDERS Set number of cylinders/heads/sectors" |
| @@ -127,13 +128,6 @@ | |||
| 127 | # define inline_if_little_endian /* nothing */ | 128 | # define inline_if_little_endian /* nothing */ |
| 128 | #endif | 129 | #endif |
| 129 | 130 | ||
| 130 | |||
| 131 | /* Looks like someone forgot to add this to config system */ | ||
| 132 | #ifndef ENABLE_FEATURE_FDISK_BLKSIZE | ||
| 133 | # define ENABLE_FEATURE_FDISK_BLKSIZE 0 | ||
| 134 | # define IF_FEATURE_FDISK_BLKSIZE(a) | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #define DEFAULT_SECTOR_SIZE 512 | 131 | #define DEFAULT_SECTOR_SIZE 512 |
| 138 | #define DEFAULT_SECTOR_SIZE_STR "512" | 132 | #define DEFAULT_SECTOR_SIZE_STR "512" |
| 139 | #define MAX_SECTOR_SIZE 2048 | 133 | #define MAX_SECTOR_SIZE 2048 |
| @@ -527,6 +521,7 @@ static sector_t bb_BLKGETSIZE_sectors(int fd) | |||
| 527 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { | 521 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { |
| 528 | /* Got bytes, convert to 512 byte sectors */ | 522 | /* Got bytes, convert to 512 byte sectors */ |
| 529 | v64 >>= 9; | 523 | v64 >>= 9; |
| 524 | //FIXME: should be "v64 /= sector_size" instead? | ||
| 530 | if (v64 != (sector_t)v64) { | 525 | if (v64 != (sector_t)v64) { |
| 531 | ret_trunc: | 526 | ret_trunc: |
| 532 | /* Not only DOS, but all other partition tables | 527 | /* Not only DOS, but all other partition tables |
| @@ -534,12 +529,12 @@ static sector_t bb_BLKGETSIZE_sectors(int fd) | |||
| 534 | * sector counts or offsets | 529 | * sector counts or offsets |
| 535 | */ | 530 | */ |
| 536 | bb_simple_error_msg("device has more than 2^32 sectors, can't use all of them"); | 531 | bb_simple_error_msg("device has more than 2^32 sectors, can't use all of them"); |
| 537 | v64 = (uint32_t)-1L; | 532 | v64 = (sector_t)-1L; |
| 538 | } | 533 | } |
| 539 | return v64; | 534 | return v64; |
| 540 | } | 535 | } |
| 541 | /* Needs temp of type long */ | 536 | /* Needs temp of type long */ |
| 542 | if (ioctl(fd, BLKGETSIZE, &longsectors)) { | 537 | if (ioctl(fd, BLKGETSIZE, &longsectors) != 0) { |
| 543 | /* Perhaps this is a disk image */ | 538 | /* Perhaps this is a disk image */ |
| 544 | off_t sz = lseek(fd, 0, SEEK_END); | 539 | off_t sz = lseek(fd, 0, SEEK_END); |
| 545 | longsectors = 0; | 540 | longsectors = 0; |
| @@ -3062,9 +3057,37 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3062 | 3057 | ||
| 3063 | close_dev_fd(); /* needed: fd 3 must not stay closed */ | 3058 | close_dev_fd(); /* needed: fd 3 must not stay closed */ |
| 3064 | 3059 | ||
| 3065 | opt = getopt32(argv, "b:+C:+H:+lS:+u" IF_FEATURE_FDISK_BLKSIZE("s"), | 3060 | opt = getopt32(argv, "^" "b:+C:+H:+lS:+u"IF_FEATURE_FDISK_BLKSIZE("s")"\0" |
| 3066 | §or_size, &user_cylinders, &user_heads, &user_sectors); | 3061 | /* among -s and -l, the last one takes preference */ |
| 3062 | IF_FEATURE_FDISK_BLKSIZE("s-l:l-s"), | ||
| 3063 | §or_size, &user_cylinders, &user_heads, &user_sectors); | ||
| 3067 | argv += optind; | 3064 | argv += optind; |
| 3065 | |||
| 3066 | #if ENABLE_FEATURE_FDISK_BLKSIZE | ||
| 3067 | /* -s ignores -b SECTSIZE, has to be before OPT_b check */ | ||
| 3068 | if (opt & OPT_s) { | ||
| 3069 | int j; | ||
| 3070 | |||
| 3071 | sector_size = 512; | ||
| 3072 | nowarn = 1; | ||
| 3073 | if (!argv[0]) | ||
| 3074 | bb_show_usage(); | ||
| 3075 | for (j = 0; argv[j]; j++) { | ||
| 3076 | unsigned long long size; | ||
| 3077 | int fd = xopen(argv[j], O_RDONLY); | ||
| 3078 | size = bb_BLKGETSIZE_sectors(fd) / 2; | ||
| 3079 | //NB: util-linux 2.41.1 says: "-s,--getsz: display device size in 512-byte sectors" | ||
| 3080 | //but in fact, util-linux 2.41.1 shows the size in KILOBYTES! | ||
| 3081 | close(fd); | ||
| 3082 | if (!argv[1]) | ||
| 3083 | printf("%llu\n", size); | ||
| 3084 | else | ||
| 3085 | printf("%s: %llu\n", argv[j], size); | ||
| 3086 | } | ||
| 3087 | return 0; | ||
| 3088 | } | ||
| 3089 | #endif | ||
| 3090 | |||
| 3068 | if (opt & OPT_b) { | 3091 | if (opt & OPT_b) { |
| 3069 | /* Ugly: this sector size is really per device, | 3092 | /* Ugly: this sector size is really per device, |
| 3070 | * so cannot be combined with multiple disks, | 3093 | * so cannot be combined with multiple disks, |
| @@ -3084,7 +3107,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3084 | if (user_sectors <= 0 || user_sectors >= 64) | 3107 | if (user_sectors <= 0 || user_sectors >= 64) |
| 3085 | user_sectors = 0; | 3108 | user_sectors = 0; |
| 3086 | if (opt & OPT_u) | 3109 | if (opt & OPT_u) |
| 3087 | display_in_cyl_units = 0; // -u | 3110 | display_in_cyl_units = 0; |
| 3088 | 3111 | ||
| 3089 | #if ENABLE_FEATURE_FDISK_WRITABLE | 3112 | #if ENABLE_FEATURE_FDISK_WRITABLE |
| 3090 | if (opt & OPT_l) { | 3113 | if (opt & OPT_l) { |
| @@ -3103,30 +3126,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3103 | return 0; | 3126 | return 0; |
| 3104 | #if ENABLE_FEATURE_FDISK_WRITABLE | 3127 | #if ENABLE_FEATURE_FDISK_WRITABLE |
| 3105 | } | 3128 | } |
| 3106 | #endif | ||
| 3107 | |||
| 3108 | #if ENABLE_FEATURE_FDISK_BLKSIZE | ||
| 3109 | if (opt & OPT_s) { | ||
| 3110 | int j; | ||
| 3111 | |||
| 3112 | nowarn = 1; | ||
| 3113 | if (!argv[0]) | ||
| 3114 | bb_show_usage(); | ||
| 3115 | for (j = 0; argv[j]; j++) { | ||
| 3116 | unsigned long long size; | ||
| 3117 | fd = xopen(argv[j], O_RDONLY); | ||
| 3118 | size = bb_BLKGETSIZE_sectors(fd) / 2; | ||
| 3119 | close(fd); | ||
| 3120 | if (argv[1]) | ||
| 3121 | printf("%llu\n", size); | ||
| 3122 | else | ||
| 3123 | printf("%s: %llu\n", argv[j], size); | ||
| 3124 | } | ||
| 3125 | return 0; | ||
| 3126 | } | ||
| 3127 | #endif | ||
| 3128 | 3129 | ||
| 3129 | #if ENABLE_FEATURE_FDISK_WRITABLE | ||
| 3130 | if (!argv[0] || argv[1]) | 3130 | if (!argv[0] || argv[1]) |
| 3131 | bb_show_usage(); | 3131 | bb_show_usage(); |
| 3132 | 3132 | ||
| @@ -3170,10 +3170,10 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3170 | else | 3170 | else |
| 3171 | sgi_set_bootfile(line_ptr); | 3171 | sgi_set_bootfile(line_ptr); |
| 3172 | } | 3172 | } |
| 3173 | #if ENABLE_FEATURE_OSF_LABEL | 3173 | # if ENABLE_FEATURE_OSF_LABEL |
| 3174 | else | 3174 | else |
| 3175 | bsd_select(); | 3175 | bsd_select(); |
| 3176 | #endif | 3176 | # endif |
| 3177 | break; | 3177 | break; |
| 3178 | case 'c': | 3178 | case 'c': |
| 3179 | if (LABEL_IS_DOS) | 3179 | if (LABEL_IS_DOS) |
| @@ -3229,9 +3229,9 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3229 | bb_putchar('\n'); | 3229 | bb_putchar('\n'); |
| 3230 | return 0; | 3230 | return 0; |
| 3231 | case 's': | 3231 | case 's': |
| 3232 | #if ENABLE_FEATURE_SUN_LABEL | 3232 | # if ENABLE_FEATURE_SUN_LABEL |
| 3233 | create_sunlabel(); | 3233 | create_sunlabel(); |
| 3234 | #endif | 3234 | # endif |
| 3235 | break; | 3235 | break; |
| 3236 | case 't': | 3236 | case 't': |
| 3237 | change_sysid(); | 3237 | change_sysid(); |
| @@ -3245,7 +3245,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3245 | case 'w': | 3245 | case 'w': |
| 3246 | write_table(); /* does not return */ | 3246 | write_table(); /* does not return */ |
| 3247 | break; | 3247 | break; |
| 3248 | #if ENABLE_FEATURE_FDISK_ADVANCED | 3248 | # if ENABLE_FEATURE_FDISK_ADVANCED |
| 3249 | case 'x': | 3249 | case 'x': |
| 3250 | if (LABEL_IS_SGI) { | 3250 | if (LABEL_IS_SGI) { |
| 3251 | puts("\n\tSorry, no experts menu for SGI " | 3251 | puts("\n\tSorry, no experts menu for SGI " |
| @@ -3253,7 +3253,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
| 3253 | } else | 3253 | } else |
| 3254 | xselect(); | 3254 | xselect(); |
| 3255 | break; | 3255 | break; |
| 3256 | #endif | 3256 | # endif |
| 3257 | default: | 3257 | default: |
| 3258 | unknown_command(c); | 3258 | unknown_command(c); |
| 3259 | menu(); | 3259 | menu(); |
