diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-16 03:03:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-16 03:03:13 +0200 |
commit | ddf7850f2b775c2148f76cd7e839b8a6e667de8e (patch) | |
tree | 7f70a23e698c6a1ddb04416259c65450fbc0d522 /util-linux/fdisk_sun.c | |
parent | 8dc0e1929e3af3b1673e5a8e486808386400c020 (diff) | |
download | busybox-w32-ddf7850f2b775c2148f76cd7e839b8a6e667de8e.tar.gz busybox-w32-ddf7850f2b775c2148f76cd7e839b8a6e667de8e.tar.bz2 busybox-w32-ddf7850f2b775c2148f76cd7e839b8a6e667de8e.zip |
fdisk: add a warning and truncate disks with >= 2^32 sectors
As a result, for sectors we can use uint32_t instead of long long,
and on 32 bits it has drastic effects:
function old new delta
get_geometry 619 646 +27
set_sun_partition 148 150 +2
get_partition 134 135 +1
xbsd_write_bootstrap 382 381 -1
xbsd_readlabel 247 246 -1
bsd_select 1674 1672 -2
sun_other_endian 4 1 -3
scsi_disk 4 1 -3
floppy 4 1 -3
fdisk_main 3735 3732 -3
read_maybe_empty 43 37 -6
create_doslabel 111 104 -7
read_line 97 88 -9
add_logical 117 107 -10
write_table 599 588 -11
new_partition 1684 1670 -14
list_disk_geometry 229 215 -14
wrong_p_order 130 110 -20
xselect 3142 3114 -28
seek_sector 71 40 -31
get_boot 1576 1533 -43
fill_bounds 174 128 -46
delete_partition 603 551 -52
list_table 1401 1232 -169
set_partition 459 286 -173
verify 1840 1495 -345
add_partition 2486 1270 -1216
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/24 up/down: 30/-2210) Total: -2180 bytes
text data bss dec hex filename
848812 460 7116 856388 d1144 busybox_old
846620 460 7108 854188 d08ac busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | util-linux/fdisk_sun.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c index 9cdf869e9..fa6f7e48b 100644 --- a/util-linux/fdisk_sun.c +++ b/util-linux/fdisk_sun.c | |||
@@ -27,9 +27,9 @@ | |||
27 | 27 | ||
28 | #define SCSI_IOCTL_GET_IDLUN 0x5382 | 28 | #define SCSI_IOCTL_GET_IDLUN 0x5382 |
29 | 29 | ||
30 | static int sun_other_endian; | 30 | static smallint sun_other_endian; |
31 | static int scsi_disk; | 31 | static smallint scsi_disk; |
32 | static int floppy; | 32 | static smallint floppy; |
33 | 33 | ||
34 | #ifndef IDE0_MAJOR | 34 | #ifndef IDE0_MAJOR |
35 | #define IDE0_MAJOR 3 | 35 | #define IDE0_MAJOR 3 |
@@ -81,7 +81,7 @@ static const char *const sun_sys_types[] = { | |||
81 | 81 | ||
82 | 82 | ||
83 | static void | 83 | static void |
84 | set_sun_partition(int i, uint start, uint stop, int sysid) | 84 | set_sun_partition(int i, unsigned start, unsigned stop, int sysid) |
85 | { | 85 | { |
86 | sunlabel->infos[i].id = sysid; | 86 | sunlabel->infos[i].id = sysid; |
87 | sunlabel->partitions[i].start_cylinder = | 87 | sunlabel->partitions[i].start_cylinder = |
@@ -98,7 +98,8 @@ check_sun_label(void) | |||
98 | int csum; | 98 | int csum; |
99 | 99 | ||
100 | if (sunlabel->magic != SUN_LABEL_MAGIC | 100 | if (sunlabel->magic != SUN_LABEL_MAGIC |
101 | && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) { | 101 | && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED |
102 | ) { | ||
102 | current_label_type = LABEL_DOS; | 103 | current_label_type = LABEL_DOS; |
103 | sun_other_endian = 0; | 104 | sun_other_endian = 0; |
104 | return 0; | 105 | return 0; |
@@ -173,7 +174,7 @@ sun_autoconfigure_scsi(void) | |||
173 | return NULL; | 174 | return NULL; |
174 | 175 | ||
175 | sprintf(buffer, | 176 | sprintf(buffer, |
176 | "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n", | 177 | "Host: scsi%u Channel: %02u Id: %02u Lun: %02u\n", |
177 | /* This is very wrong (works only if you have one HBA), | 178 | /* This is very wrong (works only if you have one HBA), |
178 | but I haven't found a way how to get hostno | 179 | but I haven't found a way how to get hostno |
179 | from the current kernel */ | 180 | from the current kernel */ |
@@ -317,7 +318,7 @@ create_sunlabel(void) | |||
317 | } | 318 | } |
318 | 319 | ||
319 | snprintf((char *)(sunlabel->info), sizeof(sunlabel->info), | 320 | snprintf((char *)(sunlabel->info), sizeof(sunlabel->info), |
320 | "%s%s%s cyl %d alt %d hd %d sec %d", | 321 | "%s%s%s cyl %u alt %u hd %u sec %u", |
321 | p ? p->vendor : "", (p && *p->vendor) ? " " : "", | 322 | p ? p->vendor : "", (p && *p->vendor) ? " " : "", |
322 | p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"), | 323 | p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"), |
323 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), g_heads, g_sectors); | 324 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), g_heads, g_sectors); |
@@ -361,7 +362,7 @@ toggle_sunflags(int i, unsigned char mask) | |||
361 | } | 362 | } |
362 | 363 | ||
363 | static void | 364 | static void |
364 | fetch_sun(uint *starts, uint *lens, uint *start, uint *stop) | 365 | fetch_sun(unsigned *starts, unsigned *lens, unsigned *start, unsigned *stop) |
365 | { | 366 | { |
366 | int i, continuous = 1; | 367 | int i, continuous = 1; |
367 | 368 | ||
@@ -390,7 +391,7 @@ fetch_sun(uint *starts, uint *lens, uint *start, uint *stop) | |||
390 | } | 391 | } |
391 | } | 392 | } |
392 | 393 | ||
393 | static uint *verify_sun_starts; | 394 | static unsigned *verify_sun_starts; |
394 | 395 | ||
395 | static int | 396 | static int |
396 | verify_sun_cmp(int *a, int *b) | 397 | verify_sun_cmp(int *a, int *b) |
@@ -404,7 +405,7 @@ verify_sun_cmp(int *a, int *b) | |||
404 | static void | 405 | static void |
405 | verify_sun(void) | 406 | verify_sun(void) |
406 | { | 407 | { |
407 | uint starts[8], lens[8], start, stop; | 408 | unsigned starts[8], lens[8], start, stop; |
408 | int i,j,k,starto,endo; | 409 | int i,j,k,starto,endo; |
409 | int array[8]; | 410 | int array[8]; |
410 | 411 | ||
@@ -413,7 +414,7 @@ verify_sun(void) | |||
413 | for (k = 0; k < 7; k++) { | 414 | for (k = 0; k < 7; k++) { |
414 | for (i = 0; i < 8; i++) { | 415 | for (i = 0; i < 8; i++) { |
415 | if (k && (lens[i] % (g_heads * g_sectors))) { | 416 | if (k && (lens[i] % (g_heads * g_sectors))) { |
416 | printf("Partition %d doesn't end on cylinder boundary\n", i+1); | 417 | printf("Partition %u doesn't end on cylinder boundary\n", i+1); |
417 | } | 418 | } |
418 | if (lens[i]) { | 419 | if (lens[i]) { |
419 | for (j = 0; j < i; j++) | 420 | for (j = 0; j < i; j++) |
@@ -433,8 +434,8 @@ verify_sun(void) | |||
433 | endo = starts[i]+lens[i]; | 434 | endo = starts[i]+lens[i]; |
434 | if (starts[j]+lens[j] < endo) | 435 | if (starts[j]+lens[j] < endo) |
435 | endo = starts[j]+lens[j]; | 436 | endo = starts[j]+lens[j]; |
436 | printf("Partition %d overlaps with others in " | 437 | printf("Partition %u overlaps with others in " |
437 | "sectors %d-%d\n", i+1, starto, endo); | 438 | "sectors %u-%u\n", i+1, starto, endo); |
438 | } | 439 | } |
439 | } | 440 | } |
440 | } | 441 | } |
@@ -455,20 +456,20 @@ verify_sun(void) | |||
455 | } | 456 | } |
456 | stop = g_cylinders * g_heads * g_sectors; | 457 | stop = g_cylinders * g_heads * g_sectors; |
457 | if (starts[array[0]]) | 458 | if (starts[array[0]]) |
458 | printf("Unused gap - sectors 0-%d\n", starts[array[0]]); | 459 | printf("Unused gap - sectors %u-%u\n", 0, starts[array[0]]); |
459 | for (i = 0; i < 7 && array[i+1] != -1; i++) { | 460 | for (i = 0; i < 7 && array[i+1] != -1; i++) { |
460 | printf("Unused gap - sectors %d-%d\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]); | 461 | printf("Unused gap - sectors %u-%u\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]); |
461 | } | 462 | } |
462 | start = starts[array[i]] + lens[array[i]]; | 463 | start = starts[array[i]] + lens[array[i]]; |
463 | if (start < stop) | 464 | if (start < stop) |
464 | printf("Unused gap - sectors %d-%d\n", start, stop); | 465 | printf("Unused gap - sectors %u-%u\n", start, stop); |
465 | } | 466 | } |
466 | 467 | ||
467 | static void | 468 | static void |
468 | add_sun_partition(int n, int sys) | 469 | add_sun_partition(int n, int sys) |
469 | { | 470 | { |
470 | uint start, stop, stop2; | 471 | unsigned start, stop, stop2; |
471 | uint starts[8], lens[8]; | 472 | unsigned starts[8], lens[8]; |
472 | int whole_disk = 0; | 473 | int whole_disk = 0; |
473 | 474 | ||
474 | char mesg[256]; | 475 | char mesg[256]; |
@@ -529,7 +530,7 @@ and is of type 'Whole disk'\n"); | |||
529 | whole_disk = 1; | 530 | whole_disk = 1; |
530 | break; | 531 | break; |
531 | } | 532 | } |
532 | printf("Sector %d is already allocated\n", first); | 533 | printf("Sector %u is already allocated\n", first); |
533 | } else | 534 | } else |
534 | break; | 535 | break; |
535 | } | 536 | } |
@@ -560,8 +561,8 @@ and is of type 'Whole disk'\n"); | |||
560 | } else if (last > stop) { | 561 | } else if (last > stop) { |
561 | printf( | 562 | printf( |
562 | "You haven't covered the whole disk with the 3rd partition,\n" | 563 | "You haven't covered the whole disk with the 3rd partition,\n" |
563 | "but your value %d %s covers some other partition.\n" | 564 | "but your value %u %s covers some other partition.\n" |
564 | "Your entry has been changed to %d %s\n", | 565 | "Your entry has been changed to %u %s\n", |
565 | scround(last), str_units(SINGULAR), | 566 | scround(last), str_units(SINGULAR), |
566 | scround(stop), str_units(SINGULAR)); | 567 | scround(stop), str_units(SINGULAR)); |
567 | last = stop; | 568 | last = stop; |
@@ -627,11 +628,11 @@ sun_list_table(int xtra) | |||
627 | w = strlen(disk_device); | 628 | w = strlen(disk_device); |
628 | if (xtra) | 629 | if (xtra) |
629 | printf( | 630 | printf( |
630 | "\nDisk %s (Sun disk label): %d heads, %d sectors, %d rpm\n" | 631 | "\nDisk %s (Sun disk label): %u heads, %u sectors, %u rpm\n" |
631 | "%d cylinders, %d alternate cylinders, %d physical cylinders\n" | 632 | "%u cylinders, %u alternate cylinders, %u physical cylinders\n" |
632 | "%d extra sects/cyl, interleave %d:1\n" | 633 | "%u extra sects/cyl, interleave %u:1\n" |
633 | "%s\n" | 634 | "%s\n" |
634 | "Units = %s of %d * 512 bytes\n\n", | 635 | "Units = %s of %u * 512 bytes\n\n", |
635 | disk_device, g_heads, g_sectors, SUN_SSWAP16(sunlabel->rspeed), | 636 | disk_device, g_heads, g_sectors, SUN_SSWAP16(sunlabel->rspeed), |
636 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), | 637 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), |
637 | SUN_SSWAP16(sunlabel->pcylcount), | 638 | SUN_SSWAP16(sunlabel->pcylcount), |
@@ -641,8 +642,8 @@ sun_list_table(int xtra) | |||
641 | str_units(PLURAL), units_per_sector); | 642 | str_units(PLURAL), units_per_sector); |
642 | else | 643 | else |
643 | printf( | 644 | printf( |
644 | "\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n" | 645 | "\nDisk %s (Sun disk label): %u heads, %u sectors, %u cylinders\n" |
645 | "Units = %s of %d * 512 bytes\n\n", | 646 | "Units = %s of %u * 512 bytes\n\n", |
646 | disk_device, g_heads, g_sectors, g_cylinders, | 647 | disk_device, g_heads, g_sectors, g_cylinders, |
647 | str_units(PLURAL), units_per_sector); | 648 | str_units(PLURAL), units_per_sector); |
648 | 649 | ||
@@ -652,7 +653,7 @@ sun_list_table(int xtra) | |||
652 | if (sunlabel->partitions[i].num_sectors) { | 653 | if (sunlabel->partitions[i].num_sectors) { |
653 | uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; | 654 | uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; |
654 | uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); | 655 | uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); |
655 | printf("%s %c%c %9ld %9ld %9ld%c %2x %s\n", | 656 | printf("%s %c%c %9lu %9lu %9lu%c %2x %s\n", |
656 | partname(disk_device, i+1, w), /* device */ | 657 | partname(disk_device, i+1, w), /* device */ |
657 | (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', /* flags */ | 658 | (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', /* flags */ |
658 | (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ', | 659 | (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ', |