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.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 'util-linux/fdisk.c')
-rw-r--r-- | util-linux/fdisk.c | 293 |
1 files changed, 163 insertions, 130 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 441640831..e50ee77d1 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -53,8 +53,18 @@ enum { | |||
53 | }; | 53 | }; |
54 | 54 | ||
55 | 55 | ||
56 | /* Used for sector numbers. Today's disk sizes make it necessary */ | ||
57 | typedef unsigned long long ullong; | 56 | typedef unsigned long long ullong; |
57 | /* Used for sector numbers. Partition formats we know | ||
58 | * do not support more than 2^32 sectors | ||
59 | */ | ||
60 | typedef uint32_t sector_t; | ||
61 | #if UINT_MAX == 4294967295 | ||
62 | # define SECT_FMT "" | ||
63 | #elif ULONG_MAX == 4294967295 | ||
64 | # define SECT_FMT "l" | ||
65 | #else | ||
66 | # error Cant detect sizeof(uint32_t) | ||
67 | #endif | ||
58 | 68 | ||
59 | struct hd_geometry { | 69 | struct hd_geometry { |
60 | unsigned char heads; | 70 | unsigned char heads; |
@@ -71,7 +81,7 @@ static const char msg_building_new_label[] ALIGN1 = | |||
71 | "won't be recoverable.\n\n"; | 81 | "won't be recoverable.\n\n"; |
72 | 82 | ||
73 | static const char msg_part_already_defined[] ALIGN1 = | 83 | static const char msg_part_already_defined[] ALIGN1 = |
74 | "Partition %d is already defined, delete it before re-adding\n"; | 84 | "Partition %u is already defined, delete it before re-adding\n"; |
75 | 85 | ||
76 | 86 | ||
77 | struct partition { | 87 | struct partition { |
@@ -136,9 +146,9 @@ static void update_units(void); | |||
136 | static void change_units(void); | 146 | static void change_units(void); |
137 | static void reread_partition_table(int leave); | 147 | static void reread_partition_table(int leave); |
138 | static void delete_partition(int i); | 148 | static void delete_partition(int i); |
139 | static int get_partition(int warn, int max); | 149 | static unsigned get_partition(int warn, unsigned max); |
140 | static void list_types(const char *const *sys); | 150 | static void list_types(const char *const *sys); |
141 | static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg); | 151 | static sector_t read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char *mesg); |
142 | #endif | 152 | #endif |
143 | static const char *partition_type(unsigned char type); | 153 | static const char *partition_type(unsigned char type); |
144 | static void get_geometry(void); | 154 | static void get_geometry(void); |
@@ -151,8 +161,8 @@ static int get_boot(void); | |||
151 | #define PLURAL 0 | 161 | #define PLURAL 0 |
152 | #define SINGULAR 1 | 162 | #define SINGULAR 1 |
153 | 163 | ||
154 | static unsigned get_start_sect(const struct partition *p); | 164 | static sector_t get_start_sect(const struct partition *p); |
155 | static unsigned get_nr_sects(const struct partition *p); | 165 | static sector_t get_nr_sects(const struct partition *p); |
156 | 166 | ||
157 | /* | 167 | /* |
158 | * per partition table entry data | 168 | * per partition table entry data |
@@ -165,8 +175,8 @@ static unsigned get_nr_sects(const struct partition *p); | |||
165 | struct pte { | 175 | struct pte { |
166 | struct partition *part_table; /* points into sectorbuffer */ | 176 | struct partition *part_table; /* points into sectorbuffer */ |
167 | struct partition *ext_pointer; /* points into sectorbuffer */ | 177 | struct partition *ext_pointer; /* points into sectorbuffer */ |
168 | ullong offset; /* disk sector number */ | 178 | sector_t offset; /* disk sector number */ |
169 | char *sectorbuffer; /* disk sector contents */ | 179 | char *sectorbuffer; /* disk sector contents */ |
170 | #if ENABLE_FEATURE_FDISK_WRITABLE | 180 | #if ENABLE_FEATURE_FDISK_WRITABLE |
171 | char changed; /* boolean */ | 181 | char changed; /* boolean */ |
172 | #endif | 182 | #endif |
@@ -308,8 +318,8 @@ struct globals { | |||
308 | unsigned user_cylinders, user_heads, user_sectors; | 318 | unsigned user_cylinders, user_heads, user_sectors; |
309 | unsigned pt_heads, pt_sectors; | 319 | unsigned pt_heads, pt_sectors; |
310 | unsigned kern_heads, kern_sectors; | 320 | unsigned kern_heads, kern_sectors; |
311 | ullong extended_offset; /* offset of link pointers */ | 321 | sector_t extended_offset; /* offset of link pointers */ |
312 | ullong total_number_of_sectors; | 322 | sector_t total_number_of_sectors; |
313 | 323 | ||
314 | jmp_buf listingbuf; | 324 | jmp_buf listingbuf; |
315 | char line_buffer[80]; | 325 | char line_buffer[80]; |
@@ -364,18 +374,36 @@ struct globals { | |||
364 | 374 | ||
365 | 375 | ||
366 | /* TODO: move to libbb? */ | 376 | /* TODO: move to libbb? */ |
367 | static ullong bb_BLKGETSIZE_sectors(int fd) | 377 | /* TODO: return unsigned long long, FEATURE_FDISK_BLKSIZE _can_ handle |
378 | * disks > 2^32 sectors | ||
379 | */ | ||
380 | static sector_t bb_BLKGETSIZE_sectors(int fd) | ||
368 | { | 381 | { |
369 | uint64_t v64; | 382 | uint64_t v64; |
370 | unsigned long longsectors; | 383 | unsigned long longsectors; |
371 | 384 | ||
372 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { | 385 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { |
373 | /* Got bytes, convert to 512 byte sectors */ | 386 | /* Got bytes, convert to 512 byte sectors */ |
374 | return (v64 >> 9); | 387 | v64 >>= 9; |
388 | if (v64 != (sector_t)v64) { | ||
389 | ret_trunc: | ||
390 | /* Not only DOS, but all other partition tables | ||
391 | * we support can't record more than 32 bit | ||
392 | * sector counts or offsets | ||
393 | */ | ||
394 | bb_error_msg("device has more than 2^32 sectors, can't use all of them"); | ||
395 | v64 = (uint32_t)-1L; | ||
396 | } | ||
397 | return v64; | ||
375 | } | 398 | } |
376 | /* Needs temp of type long */ | 399 | /* Needs temp of type long */ |
377 | if (ioctl(fd, BLKGETSIZE, &longsectors)) | 400 | if (ioctl(fd, BLKGETSIZE, &longsectors)) |
378 | longsectors = 0; | 401 | longsectors = 0; |
402 | if (sizeof(long) > sizeof(sector_t) | ||
403 | && longsectors != (sector_t)longsectors | ||
404 | ) { | ||
405 | goto ret_trunc; | ||
406 | } | ||
379 | return longsectors; | 407 | return longsectors; |
380 | } | 408 | } |
381 | 409 | ||
@@ -566,15 +594,16 @@ static void fdisk_fatal(const char *why) | |||
566 | } | 594 | } |
567 | 595 | ||
568 | static void | 596 | static void |
569 | seek_sector(ullong secno) | 597 | seek_sector(sector_t secno) |
570 | { | 598 | { |
571 | secno *= sector_size; | ||
572 | #if ENABLE_FDISK_SUPPORT_LARGE_DISKS | 599 | #if ENABLE_FDISK_SUPPORT_LARGE_DISKS |
573 | if (lseek64(dev_fd, (off64_t)secno, SEEK_SET) == (off64_t) -1) | 600 | off64_t off = (off64_t)secno * sector_size; |
601 | if (lseek64(dev_fd, off, SEEK_SET) == (off64_t) -1) | ||
574 | fdisk_fatal(unable_to_seek); | 602 | fdisk_fatal(unable_to_seek); |
575 | #else | 603 | #else |
576 | if (secno > MAXINT(off_t) | 604 | uint64_t off = (uint64_t)secno * sector_size; |
577 | || lseek(dev_fd, (off_t)secno, SEEK_SET) == (off_t) -1 | 605 | if (off > MAXINT(off_t) |
606 | || lseek(dev_fd, (off_t)off, SEEK_SET) == (off_t) -1 | ||
578 | ) { | 607 | ) { |
579 | fdisk_fatal(unable_to_seek); | 608 | fdisk_fatal(unable_to_seek); |
580 | } | 609 | } |
@@ -583,7 +612,7 @@ seek_sector(ullong secno) | |||
583 | 612 | ||
584 | #if ENABLE_FEATURE_FDISK_WRITABLE | 613 | #if ENABLE_FEATURE_FDISK_WRITABLE |
585 | static void | 614 | static void |
586 | write_sector(ullong secno, const void *buf) | 615 | write_sector(sector_t secno, const void *buf) |
587 | { | 616 | { |
588 | seek_sector(secno); | 617 | seek_sector(secno); |
589 | xwrite(dev_fd, buf, sector_size); | 618 | xwrite(dev_fd, buf, sector_size); |
@@ -707,7 +736,7 @@ set_start_sect(struct partition *p, unsigned start_sect) | |||
707 | } | 736 | } |
708 | #endif | 737 | #endif |
709 | 738 | ||
710 | static unsigned | 739 | static sector_t |
711 | get_start_sect(const struct partition *p) | 740 | get_start_sect(const struct partition *p) |
712 | { | 741 | { |
713 | return read4_little_endian(p->start4); | 742 | return read4_little_endian(p->start4); |
@@ -721,7 +750,7 @@ set_nr_sects(struct partition *p, unsigned nr_sects) | |||
721 | } | 750 | } |
722 | #endif | 751 | #endif |
723 | 752 | ||
724 | static unsigned | 753 | static sector_t |
725 | get_nr_sects(const struct partition *p) | 754 | get_nr_sects(const struct partition *p) |
726 | { | 755 | { |
727 | return read4_little_endian(p->size4); | 756 | return read4_little_endian(p->size4); |
@@ -729,7 +758,7 @@ get_nr_sects(const struct partition *p) | |||
729 | 758 | ||
730 | /* Allocate a buffer and read a partition table sector */ | 759 | /* Allocate a buffer and read a partition table sector */ |
731 | static void | 760 | static void |
732 | read_pte(struct pte *pe, ullong offset) | 761 | read_pte(struct pte *pe, sector_t offset) |
733 | { | 762 | { |
734 | pe->offset = offset; | 763 | pe->offset = offset; |
735 | pe->sectorbuffer = xzalloc(sector_size); | 764 | pe->sectorbuffer = xzalloc(sector_size); |
@@ -743,7 +772,7 @@ read_pte(struct pte *pe, ullong offset) | |||
743 | pe->part_table = pe->ext_pointer = NULL; | 772 | pe->part_table = pe->ext_pointer = NULL; |
744 | } | 773 | } |
745 | 774 | ||
746 | static unsigned | 775 | static sector_t |
747 | get_partition_start(const struct pte *pe) | 776 | get_partition_start(const struct pte *pe) |
748 | { | 777 | { |
749 | return pe->offset + get_start_sect(pe->part_table); | 778 | return pe->offset + get_start_sect(pe->part_table); |
@@ -985,10 +1014,10 @@ clear_partition(struct partition *p) | |||
985 | 1014 | ||
986 | #if ENABLE_FEATURE_FDISK_WRITABLE | 1015 | #if ENABLE_FEATURE_FDISK_WRITABLE |
987 | static void | 1016 | static void |
988 | set_partition(int i, int doext, ullong start, ullong stop, int sysid) | 1017 | set_partition(int i, int doext, sector_t start, sector_t stop, int sysid) |
989 | { | 1018 | { |
990 | struct partition *p; | 1019 | struct partition *p; |
991 | ullong offset; | 1020 | sector_t offset; |
992 | 1021 | ||
993 | if (doext) { | 1022 | if (doext) { |
994 | p = ptes[i].ext_pointer; | 1023 | p = ptes[i].ext_pointer; |
@@ -1049,7 +1078,7 @@ warn_cylinders(void) | |||
1049 | { | 1078 | { |
1050 | if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn) | 1079 | if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn) |
1051 | printf("\n" | 1080 | printf("\n" |
1052 | "The number of cylinders for this disk is set to %d.\n" | 1081 | "The number of cylinders for this disk is set to %u.\n" |
1053 | "There is nothing wrong with that, but this is larger than 1024,\n" | 1082 | "There is nothing wrong with that, but this is larger than 1024,\n" |
1054 | "and could in certain setups cause problems with:\n" | 1083 | "and could in certain setups cause problems with:\n" |
1055 | "1) software that runs at boot time (e.g., old versions of LILO)\n" | 1084 | "1) software that runs at boot time (e.g., old versions of LILO)\n" |
@@ -1085,7 +1114,7 @@ read_extended(int ext) | |||
1085 | Do not try to 'improve' this test. */ | 1114 | Do not try to 'improve' this test. */ |
1086 | struct pte *pre = &ptes[g_partitions - 1]; | 1115 | struct pte *pre = &ptes[g_partitions - 1]; |
1087 | #if ENABLE_FEATURE_FDISK_WRITABLE | 1116 | #if ENABLE_FEATURE_FDISK_WRITABLE |
1088 | printf("Warning: deleting partitions after %d\n", | 1117 | printf("Warning: deleting partitions after %u\n", |
1089 | g_partitions); | 1118 | g_partitions); |
1090 | pre->changed = 1; | 1119 | pre->changed = 1; |
1091 | #endif | 1120 | #endif |
@@ -1104,14 +1133,14 @@ read_extended(int ext) | |||
1104 | if (pe->ext_pointer) | 1133 | if (pe->ext_pointer) |
1105 | printf("Warning: extra link " | 1134 | printf("Warning: extra link " |
1106 | "pointer in partition table" | 1135 | "pointer in partition table" |
1107 | " %d\n", g_partitions + 1); | 1136 | " %u\n", g_partitions + 1); |
1108 | else | 1137 | else |
1109 | pe->ext_pointer = p; | 1138 | pe->ext_pointer = p; |
1110 | } else if (p->sys_ind) { | 1139 | } else if (p->sys_ind) { |
1111 | if (pe->part_table) | 1140 | if (pe->part_table) |
1112 | printf("Warning: ignoring extra " | 1141 | printf("Warning: ignoring extra " |
1113 | "data in partition table" | 1142 | "data in partition table" |
1114 | " %d\n", g_partitions + 1); | 1143 | " %u\n", g_partitions + 1); |
1115 | else | 1144 | else |
1116 | pe->part_table = p; | 1145 | pe->part_table = p; |
1117 | } | 1146 | } |
@@ -1144,7 +1173,7 @@ read_extended(int ext) | |||
1144 | if (!get_nr_sects(pe->part_table) | 1173 | if (!get_nr_sects(pe->part_table) |
1145 | && (g_partitions > 5 || ptes[4].part_table->sys_ind) | 1174 | && (g_partitions > 5 || ptes[4].part_table->sys_ind) |
1146 | ) { | 1175 | ) { |
1147 | printf("Omitting empty partition (%d)\n", i+1); | 1176 | printf("Omitting empty partition (%u)\n", i+1); |
1148 | delete_partition(i); | 1177 | delete_partition(i); |
1149 | goto remove; /* numbering changed */ | 1178 | goto remove; /* numbering changed */ |
1150 | } | 1179 | } |
@@ -1185,7 +1214,7 @@ get_sectorsize(void) | |||
1185 | if (ioctl(dev_fd, BLKSSZGET, &arg) == 0) | 1214 | if (ioctl(dev_fd, BLKSSZGET, &arg) == 0) |
1186 | sector_size = arg; | 1215 | sector_size = arg; |
1187 | if (sector_size != DEFAULT_SECTOR_SIZE) | 1216 | if (sector_size != DEFAULT_SECTOR_SIZE) |
1188 | printf("Note: sector size is %d " | 1217 | printf("Note: sector size is %u " |
1189 | "(not " DEFAULT_SECTOR_SIZE_STR ")\n", | 1218 | "(not " DEFAULT_SECTOR_SIZE_STR ")\n", |
1190 | sector_size); | 1219 | sector_size); |
1191 | } | 1220 | } |
@@ -1396,7 +1425,7 @@ static int get_boot(void) | |||
1396 | if (IS_EXTENDED(ptes[i].part_table->sys_ind)) { | 1425 | if (IS_EXTENDED(ptes[i].part_table->sys_ind)) { |
1397 | if (g_partitions != 4) | 1426 | if (g_partitions != 4) |
1398 | printf("Ignoring extra extended " | 1427 | printf("Ignoring extra extended " |
1399 | "partition %d\n", i + 1); | 1428 | "partition %u\n", i + 1); |
1400 | else | 1429 | else |
1401 | read_extended(i); | 1430 | read_extended(i); |
1402 | } | 1431 | } |
@@ -1406,7 +1435,7 @@ static int get_boot(void) | |||
1406 | struct pte *pe = &ptes[i]; | 1435 | struct pte *pe = &ptes[i]; |
1407 | if (!valid_part_table_flag(pe->sectorbuffer)) { | 1436 | if (!valid_part_table_flag(pe->sectorbuffer)) { |
1408 | printf("Warning: invalid flag 0x%02x,0x%02x of partition " | 1437 | printf("Warning: invalid flag 0x%02x,0x%02x of partition " |
1409 | "table %d will be corrected by w(rite)\n", | 1438 | "table %u will be corrected by w(rite)\n", |
1410 | pe->sectorbuffer[510], | 1439 | pe->sectorbuffer[510], |
1411 | pe->sectorbuffer[511], | 1440 | pe->sectorbuffer[511], |
1412 | i + 1); | 1441 | i + 1); |
@@ -1425,10 +1454,10 @@ static int get_boot(void) | |||
1425 | * | 1454 | * |
1426 | * There is no default if DFLT is not between LOW and HIGH. | 1455 | * There is no default if DFLT is not between LOW and HIGH. |
1427 | */ | 1456 | */ |
1428 | static unsigned | 1457 | static sector_t |
1429 | read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg) | 1458 | read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char *mesg) |
1430 | { | 1459 | { |
1431 | unsigned i; | 1460 | sector_t value; |
1432 | int default_ok = 1; | 1461 | int default_ok = 1; |
1433 | const char *fmt = "%s (%u-%u, default %u): "; | 1462 | const char *fmt = "%s (%u-%u, default %u): "; |
1434 | 1463 | ||
@@ -1451,8 +1480,10 @@ read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char * | |||
1451 | int minus = (*line_ptr == '-'); | 1480 | int minus = (*line_ptr == '-'); |
1452 | int absolute = 0; | 1481 | int absolute = 0; |
1453 | 1482 | ||
1454 | i = atoi(line_ptr + 1); | 1483 | value = atoi(line_ptr + 1); |
1455 | 1484 | ||
1485 | /* (1) if 2nd char is digit, use_default = 0. | ||
1486 | * (2) move line_ptr to first non-digit. */ | ||
1456 | while (isdigit(*++line_ptr)) | 1487 | while (isdigit(*++line_ptr)) |
1457 | use_default = 0; | 1488 | use_default = 0; |
1458 | 1489 | ||
@@ -1460,7 +1491,7 @@ read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char * | |||
1460 | case 'c': | 1491 | case 'c': |
1461 | case 'C': | 1492 | case 'C': |
1462 | if (!display_in_cyl_units) | 1493 | if (!display_in_cyl_units) |
1463 | i *= g_heads * g_sectors; | 1494 | value *= g_heads * g_sectors; |
1464 | break; | 1495 | break; |
1465 | case 'K': | 1496 | case 'K': |
1466 | absolute = 1024; | 1497 | absolute = 1024; |
@@ -1483,38 +1514,38 @@ read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char * | |||
1483 | ullong bytes; | 1514 | ullong bytes; |
1484 | unsigned long unit; | 1515 | unsigned long unit; |
1485 | 1516 | ||
1486 | bytes = (ullong) i * absolute; | 1517 | bytes = (ullong) value * absolute; |
1487 | unit = sector_size * units_per_sector; | 1518 | unit = sector_size * units_per_sector; |
1488 | bytes += unit/2; /* round */ | 1519 | bytes += unit/2; /* round */ |
1489 | bytes /= unit; | 1520 | bytes /= unit; |
1490 | i = bytes; | 1521 | value = bytes; |
1491 | } | 1522 | } |
1492 | if (minus) | 1523 | if (minus) |
1493 | i = -i; | 1524 | value = -value; |
1494 | i += base; | 1525 | value += base; |
1495 | } else { | 1526 | } else { |
1496 | i = atoi(line_ptr); | 1527 | value = atoi(line_ptr); |
1497 | while (isdigit(*line_ptr)) { | 1528 | while (isdigit(*line_ptr)) { |
1498 | line_ptr++; | 1529 | line_ptr++; |
1499 | use_default = 0; | 1530 | use_default = 0; |
1500 | } | 1531 | } |
1501 | } | 1532 | } |
1502 | if (use_default) { | 1533 | if (use_default) { |
1503 | i = dflt; | 1534 | value = dflt; |
1504 | printf("Using default value %u\n", i); | 1535 | printf("Using default value %u\n", value); |
1505 | } | 1536 | } |
1506 | if (i >= low && i <= high) | 1537 | if (value >= low && value <= high) |
1507 | break; | 1538 | break; |
1508 | printf("Value is out of range\n"); | 1539 | printf("Value is out of range\n"); |
1509 | } | 1540 | } |
1510 | return i; | 1541 | return value; |
1511 | } | 1542 | } |
1512 | 1543 | ||
1513 | static int | 1544 | static unsigned |
1514 | get_partition(int warn, int max) | 1545 | get_partition(int warn, unsigned max) |
1515 | { | 1546 | { |
1516 | struct pte *pe; | 1547 | struct pte *pe; |
1517 | int i; | 1548 | unsigned i; |
1518 | 1549 | ||
1519 | i = read_int(1, 0, max, 0, "Partition number") - 1; | 1550 | i = read_int(1, 0, max, 0, "Partition number") - 1; |
1520 | pe = &ptes[i]; | 1551 | pe = &ptes[i]; |
@@ -1524,17 +1555,17 @@ get_partition(int warn, int max) | |||
1524 | || (LABEL_IS_SUN && (!sunlabel->partitions[i].num_sectors || !sunlabel->infos[i].id)) | 1555 | || (LABEL_IS_SUN && (!sunlabel->partitions[i].num_sectors || !sunlabel->infos[i].id)) |
1525 | || (LABEL_IS_SGI && !sgi_get_num_sectors(i)) | 1556 | || (LABEL_IS_SGI && !sgi_get_num_sectors(i)) |
1526 | ) { | 1557 | ) { |
1527 | printf("Warning: partition %d has empty type\n", i+1); | 1558 | printf("Warning: partition %u has empty type\n", i+1); |
1528 | } | 1559 | } |
1529 | } | 1560 | } |
1530 | return i; | 1561 | return i; |
1531 | } | 1562 | } |
1532 | 1563 | ||
1533 | static int | 1564 | static int |
1534 | get_existing_partition(int warn, int max) | 1565 | get_existing_partition(int warn, unsigned max) |
1535 | { | 1566 | { |
1536 | int pno = -1; | 1567 | int pno = -1; |
1537 | int i; | 1568 | unsigned i; |
1538 | 1569 | ||
1539 | for (i = 0; i < max; i++) { | 1570 | for (i = 0; i < max; i++) { |
1540 | struct pte *pe = &ptes[i]; | 1571 | struct pte *pe = &ptes[i]; |
@@ -1547,7 +1578,7 @@ get_existing_partition(int warn, int max) | |||
1547 | } | 1578 | } |
1548 | } | 1579 | } |
1549 | if (pno >= 0) { | 1580 | if (pno >= 0) { |
1550 | printf("Selected partition %d\n", pno+1); | 1581 | printf("Selected partition %u\n", pno+1); |
1551 | return pno; | 1582 | return pno; |
1552 | } | 1583 | } |
1553 | printf("No partition is defined yet!\n"); | 1584 | printf("No partition is defined yet!\n"); |
@@ -1558,10 +1589,10 @@ get_existing_partition(int warn, int max) | |||
1558 | } | 1589 | } |
1559 | 1590 | ||
1560 | static int | 1591 | static int |
1561 | get_nonexisting_partition(int warn, int max) | 1592 | get_nonexisting_partition(int warn, unsigned max) |
1562 | { | 1593 | { |
1563 | int pno = -1; | 1594 | int pno = -1; |
1564 | int i; | 1595 | unsigned i; |
1565 | 1596 | ||
1566 | for (i = 0; i < max; i++) { | 1597 | for (i = 0; i < max; i++) { |
1567 | struct pte *pe = &ptes[i]; | 1598 | struct pte *pe = &ptes[i]; |
@@ -1574,7 +1605,7 @@ get_nonexisting_partition(int warn, int max) | |||
1574 | } | 1605 | } |
1575 | } | 1606 | } |
1576 | if (pno >= 0) { | 1607 | if (pno >= 0) { |
1577 | printf("Selected partition %d\n", pno+1); | 1608 | printf("Selected partition %u\n", pno+1); |
1578 | return pno; | 1609 | return pno; |
1579 | } | 1610 | } |
1580 | printf("All primary partitions have been defined already!\n"); | 1611 | printf("All primary partitions have been defined already!\n"); |
@@ -1601,7 +1632,7 @@ toggle_active(int i) | |||
1601 | struct partition *p = pe->part_table; | 1632 | struct partition *p = pe->part_table; |
1602 | 1633 | ||
1603 | if (IS_EXTENDED(p->sys_ind) && !p->boot_ind) | 1634 | if (IS_EXTENDED(p->sys_ind) && !p->boot_ind) |
1604 | printf("WARNING: Partition %d is an extended partition\n", i + 1); | 1635 | printf("WARNING: Partition %u is an extended partition\n", i + 1); |
1605 | p->boot_ind = (p->boot_ind ? 0 : ACTIVE_FLAG); | 1636 | p->boot_ind = (p->boot_ind ? 0 : ACTIVE_FLAG); |
1606 | pe->changed = 1; | 1637 | pe->changed = 1; |
1607 | } | 1638 | } |
@@ -1674,8 +1705,8 @@ delete_partition(int i) | |||
1674 | 1705 | ||
1675 | if (pe->part_table) /* prevent SEGFAULT */ | 1706 | if (pe->part_table) /* prevent SEGFAULT */ |
1676 | set_start_sect(pe->part_table, | 1707 | set_start_sect(pe->part_table, |
1677 | get_partition_start(pe) - | 1708 | get_partition_start(pe) - |
1678 | extended_offset); | 1709 | extended_offset); |
1679 | pe->offset = extended_offset; | 1710 | pe->offset = extended_offset; |
1680 | pe->changed = 1; | 1711 | pe->changed = 1; |
1681 | } | 1712 | } |
@@ -1714,7 +1745,7 @@ change_sysid(void) | |||
1714 | /* if changing types T to 0 is allowed, then | 1745 | /* if changing types T to 0 is allowed, then |
1715 | the reverse change must be allowed, too */ | 1746 | the reverse change must be allowed, too */ |
1716 | if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN && !get_nr_sects(p)) { | 1747 | if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN && !get_nr_sects(p)) { |
1717 | printf("Partition %d does not exist yet!\n", i + 1); | 1748 | printf("Partition %u does not exist yet!\n", i + 1); |
1718 | return; | 1749 | return; |
1719 | } | 1750 | } |
1720 | while (1) { | 1751 | while (1) { |
@@ -1765,7 +1796,7 @@ change_sysid(void) | |||
1765 | } else | 1796 | } else |
1766 | p->sys_ind = sys; | 1797 | p->sys_ind = sys; |
1767 | 1798 | ||
1768 | printf("Changed system type of partition %d " | 1799 | printf("Changed system type of partition %u " |
1769 | "to %x (%s)\n", i + 1, sys, | 1800 | "to %x (%s)\n", i + 1, sys, |
1770 | partition_type(sys)); | 1801 | partition_type(sys)); |
1771 | ptes[i].changed = 1; | 1802 | ptes[i].changed = 1; |
@@ -1823,23 +1854,23 @@ check_consistency(const struct partition *p, int partition) | |||
1823 | 1854 | ||
1824 | /* Same physical / logical beginning? */ | 1855 | /* Same physical / logical beginning? */ |
1825 | if (g_cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { | 1856 | if (g_cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { |
1826 | printf("Partition %d has different physical/logical " | 1857 | printf("Partition %u has different physical/logical " |
1827 | "beginnings (non-Linux?):\n", partition + 1); | 1858 | "beginnings (non-Linux?):\n", partition + 1); |
1828 | printf(" phys=(%d, %d, %d) ", pbc, pbh, pbs); | 1859 | printf(" phys=(%u, %u, %u) ", pbc, pbh, pbs); |
1829 | printf("logical=(%d, %d, %d)\n", lbc, lbh, lbs); | 1860 | printf("logical=(%u, %u, %u)\n", lbc, lbh, lbs); |
1830 | } | 1861 | } |
1831 | 1862 | ||
1832 | /* Same physical / logical ending? */ | 1863 | /* Same physical / logical ending? */ |
1833 | if (g_cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) { | 1864 | if (g_cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) { |
1834 | printf("Partition %d has different physical/logical " | 1865 | printf("Partition %u has different physical/logical " |
1835 | "endings:\n", partition + 1); | 1866 | "endings:\n", partition + 1); |
1836 | printf(" phys=(%d, %d, %d) ", pec, peh, pes); | 1867 | printf(" phys=(%u, %u, %u) ", pec, peh, pes); |
1837 | printf("logical=(%d, %d, %d)\n", lec, leh, les); | 1868 | printf("logical=(%u, %u, %u)\n", lec, leh, les); |
1838 | } | 1869 | } |
1839 | 1870 | ||
1840 | /* Ending on cylinder boundary? */ | 1871 | /* Ending on cylinder boundary? */ |
1841 | if (peh != (g_heads - 1) || pes != g_sectors) { | 1872 | if (peh != (g_heads - 1) || pes != g_sectors) { |
1842 | printf("Partition %i does not end on cylinder boundary\n", | 1873 | printf("Partition %u does not end on cylinder boundary\n", |
1843 | partition + 1); | 1874 | partition + 1); |
1844 | } | 1875 | } |
1845 | } | 1876 | } |
@@ -1847,23 +1878,23 @@ check_consistency(const struct partition *p, int partition) | |||
1847 | static void | 1878 | static void |
1848 | list_disk_geometry(void) | 1879 | list_disk_geometry(void) |
1849 | { | 1880 | { |
1850 | long long bytes = (total_number_of_sectors << 9); | 1881 | ullong bytes = ((ullong)total_number_of_sectors << 9); |
1851 | long megabytes = bytes/1000000; | 1882 | long megabytes = bytes / 1000000; |
1852 | 1883 | ||
1853 | if (megabytes < 10000) | 1884 | if (megabytes < 10000) |
1854 | printf("\nDisk %s: %ld MB, %lld bytes\n", | 1885 | printf("\nDisk %s: %lu MB, %llu bytes\n", |
1855 | disk_device, megabytes, bytes); | 1886 | disk_device, megabytes, bytes); |
1856 | else | 1887 | else |
1857 | printf("\nDisk %s: %ld.%ld GB, %lld bytes\n", | 1888 | printf("\nDisk %s: %lu.%lu GB, %llu bytes\n", |
1858 | disk_device, megabytes/1000, (megabytes/100)%10, bytes); | 1889 | disk_device, megabytes/1000, (megabytes/100)%10, bytes); |
1859 | printf("%d heads, %d sectors/track, %d cylinders", | 1890 | printf("%u heads, %u sectors/track, %u cylinders", |
1860 | g_heads, g_sectors, g_cylinders); | 1891 | g_heads, g_sectors, g_cylinders); |
1861 | if (units_per_sector == 1) | 1892 | if (units_per_sector == 1) |
1862 | printf(", total %llu sectors", | 1893 | printf(", total %"SECT_FMT"u sectors", |
1863 | total_number_of_sectors / (sector_size/512)); | 1894 | total_number_of_sectors / (sector_size/512)); |
1864 | printf("\nUnits = %s of %d * %d = %d bytes\n\n", | 1895 | printf("\nUnits = %s of %u * %u = %u bytes\n\n", |
1865 | str_units(PLURAL), | 1896 | str_units(PLURAL), |
1866 | units_per_sector, sector_size, units_per_sector * sector_size); | 1897 | units_per_sector, sector_size, units_per_sector * sector_size); |
1867 | } | 1898 | } |
1868 | 1899 | ||
1869 | /* | 1900 | /* |
@@ -1876,8 +1907,8 @@ wrong_p_order(int *prev) | |||
1876 | { | 1907 | { |
1877 | const struct pte *pe; | 1908 | const struct pte *pe; |
1878 | const struct partition *p; | 1909 | const struct partition *p; |
1879 | ullong last_p_start_pos = 0, p_start_pos; | 1910 | sector_t last_p_start_pos = 0, p_start_pos; |
1880 | int i, last_i = 0; | 1911 | unsigned i, last_i = 0; |
1881 | 1912 | ||
1882 | for (i = 0; i < g_partitions; i++) { | 1913 | for (i = 0; i < g_partitions; i++) { |
1883 | if (i == 4) { | 1914 | if (i == 4) { |
@@ -2045,8 +2076,8 @@ list_table(int xtra) | |||
2045 | 2076 | ||
2046 | for (i = 0; i < g_partitions; i++) { | 2077 | for (i = 0; i < g_partitions; i++) { |
2047 | const struct pte *pe = &ptes[i]; | 2078 | const struct pte *pe = &ptes[i]; |
2048 | ullong psects; | 2079 | sector_t psects; |
2049 | ullong pblocks; | 2080 | sector_t pblocks; |
2050 | unsigned podd; | 2081 | unsigned podd; |
2051 | 2082 | ||
2052 | p = pe->part_table; | 2083 | p = pe->part_table; |
@@ -2064,14 +2095,14 @@ list_table(int xtra) | |||
2064 | if (sector_size > 1024) | 2095 | if (sector_size > 1024) |
2065 | pblocks *= (sector_size / 1024); | 2096 | pblocks *= (sector_size / 1024); |
2066 | 2097 | ||
2067 | printf("%s %c %11llu %11llu %11llu%c %2x %s\n", | 2098 | printf("%s %c %11"SECT_FMT"u %11"SECT_FMT"u %11"SECT_FMT"u%c %2x %s\n", |
2068 | partname(disk_device, i+1, w+2), | 2099 | partname(disk_device, i+1, w+2), |
2069 | !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG /* boot flag */ | 2100 | !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG /* boot flag */ |
2070 | ? '*' : '?', | 2101 | ? '*' : '?', |
2071 | (ullong) cround(get_partition_start(pe)), /* start */ | 2102 | cround(get_partition_start(pe)), /* start */ |
2072 | (ullong) cround(get_partition_start(pe) + psects /* end */ | 2103 | cround(get_partition_start(pe) + psects /* end */ |
2073 | - (psects ? 1 : 0)), | 2104 | - (psects ? 1 : 0)), |
2074 | (ullong) pblocks, podd ? '+' : ' ', /* odd flag on end */ | 2105 | pblocks, podd ? '+' : ' ', /* odd flag on end */ |
2075 | p->sys_ind, /* type id */ | 2106 | p->sys_ind, /* type id */ |
2076 | partition_type(p->sys_ind)); /* type name */ | 2107 | partition_type(p->sys_ind)); /* type name */ |
2077 | 2108 | ||
@@ -2079,8 +2110,8 @@ list_table(int xtra) | |||
2079 | } | 2110 | } |
2080 | 2111 | ||
2081 | /* Is partition table in disk order? It need not be, but... */ | 2112 | /* Is partition table in disk order? It need not be, but... */ |
2082 | /* partition table entries are not checked for correct order if this | 2113 | /* partition table entries are not checked for correct order |
2083 | is a sgi, sun or aix labeled disk... */ | 2114 | * if this is a sgi, sun or aix labeled disk... */ |
2084 | if (LABEL_IS_DOS && wrong_p_order(NULL)) { | 2115 | if (LABEL_IS_DOS && wrong_p_order(NULL)) { |
2085 | /* FIXME */ | 2116 | /* FIXME */ |
2086 | printf("\nPartition table entries are not in disk order\n"); | 2117 | printf("\nPartition table entries are not in disk order\n"); |
@@ -2095,20 +2126,21 @@ x_list_table(int extend) | |||
2095 | const struct partition *p; | 2126 | const struct partition *p; |
2096 | int i; | 2127 | int i; |
2097 | 2128 | ||
2098 | printf("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n", | 2129 | printf("\nDisk %s: %u heads, %u sectors, %u cylinders\n\n", |
2099 | disk_device, g_heads, g_sectors, g_cylinders); | 2130 | disk_device, g_heads, g_sectors, g_cylinders); |
2100 | printf("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n"); | 2131 | printf("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n"); |
2101 | for (i = 0; i < g_partitions; i++) { | 2132 | for (i = 0; i < g_partitions; i++) { |
2102 | pe = &ptes[i]; | 2133 | pe = &ptes[i]; |
2103 | p = (extend ? pe->ext_pointer : pe->part_table); | 2134 | p = (extend ? pe->ext_pointer : pe->part_table); |
2104 | if (p != NULL) { | 2135 | if (p != NULL) { |
2105 | printf("%2d %02x%4d%4d%5d%4d%4d%5d%11u%11u %02x\n", | 2136 | printf("%2u %02x%4u%4u%5u%4u%4u%5u%11"SECT_FMT"u%11"SECT_FMT"u %02x\n", |
2106 | i + 1, p->boot_ind, p->head, | 2137 | i + 1, p->boot_ind, p->head, |
2107 | sector(p->sector), | 2138 | sector(p->sector), |
2108 | cylinder(p->sector, p->cyl), p->end_head, | 2139 | cylinder(p->sector, p->cyl), p->end_head, |
2109 | sector(p->end_sector), | 2140 | sector(p->end_sector), |
2110 | cylinder(p->end_sector, p->end_cyl), | 2141 | cylinder(p->end_sector, p->end_cyl), |
2111 | get_start_sect(p), get_nr_sects(p), p->sys_ind); | 2142 | get_start_sect(p), get_nr_sects(p), |
2143 | p->sys_ind); | ||
2112 | if (p->sys_ind) | 2144 | if (p->sys_ind) |
2113 | check_consistency(p, i); | 2145 | check_consistency(p, i); |
2114 | } | 2146 | } |
@@ -2118,9 +2150,9 @@ x_list_table(int extend) | |||
2118 | 2150 | ||
2119 | #if ENABLE_FEATURE_FDISK_WRITABLE | 2151 | #if ENABLE_FEATURE_FDISK_WRITABLE |
2120 | static void | 2152 | static void |
2121 | fill_bounds(ullong *first, ullong *last) | 2153 | fill_bounds(sector_t *first, sector_t *last) |
2122 | { | 2154 | { |
2123 | int i; | 2155 | unsigned i; |
2124 | const struct pte *pe = &ptes[0]; | 2156 | const struct pte *pe = &ptes[0]; |
2125 | const struct partition *p; | 2157 | const struct partition *p; |
2126 | 2158 | ||
@@ -2137,35 +2169,35 @@ fill_bounds(ullong *first, ullong *last) | |||
2137 | } | 2169 | } |
2138 | 2170 | ||
2139 | static void | 2171 | static void |
2140 | check(int n, unsigned h, unsigned s, unsigned c, ullong start) | 2172 | check(int n, unsigned h, unsigned s, unsigned c, sector_t start) |
2141 | { | 2173 | { |
2142 | ullong total, real_s, real_c; | 2174 | sector_t total, real_s, real_c; |
2143 | 2175 | ||
2144 | real_s = sector(s) - 1; | 2176 | real_s = sector(s) - 1; |
2145 | real_c = cylinder(s, c); | 2177 | real_c = cylinder(s, c); |
2146 | total = (real_c * g_sectors + real_s) * g_heads + h; | 2178 | total = (real_c * g_sectors + real_s) * g_heads + h; |
2147 | if (!total) | 2179 | if (!total) |
2148 | printf("Partition %d contains sector 0\n", n); | 2180 | printf("Partition %u contains sector 0\n", n); |
2149 | if (h >= g_heads) | 2181 | if (h >= g_heads) |
2150 | printf("Partition %d: head %d greater than maximum %d\n", | 2182 | printf("Partition %u: head %u greater than maximum %u\n", |
2151 | n, h + 1, g_heads); | 2183 | n, h + 1, g_heads); |
2152 | if (real_s >= g_sectors) | 2184 | if (real_s >= g_sectors) |
2153 | printf("Partition %d: sector %d greater than " | 2185 | printf("Partition %u: sector %u greater than " |
2154 | "maximum %d\n", n, s, g_sectors); | 2186 | "maximum %u\n", n, s, g_sectors); |
2155 | if (real_c >= g_cylinders) | 2187 | if (real_c >= g_cylinders) |
2156 | printf("Partition %d: cylinder %llu greater than " | 2188 | printf("Partition %u: cylinder %"SECT_FMT"u greater than " |
2157 | "maximum %d\n", n, real_c + 1, g_cylinders); | 2189 | "maximum %u\n", n, real_c + 1, g_cylinders); |
2158 | if (g_cylinders <= 1024 && start != total) | 2190 | if (g_cylinders <= 1024 && start != total) |
2159 | printf("Partition %d: previous sectors %llu disagrees with " | 2191 | printf("Partition %u: previous sectors %"SECT_FMT"u disagrees with " |
2160 | "total %llu\n", n, start, total); | 2192 | "total %"SECT_FMT"u\n", n, start, total); |
2161 | } | 2193 | } |
2162 | 2194 | ||
2163 | static void | 2195 | static void |
2164 | verify(void) | 2196 | verify(void) |
2165 | { | 2197 | { |
2166 | int i, j; | 2198 | int i, j; |
2167 | unsigned total = 1; | 2199 | sector_t total = 1; |
2168 | ullong first[g_partitions], last[g_partitions]; | 2200 | sector_t first[g_partitions], last[g_partitions]; |
2169 | struct partition *p; | 2201 | struct partition *p; |
2170 | 2202 | ||
2171 | if (warn_geometry()) | 2203 | if (warn_geometry()) |
@@ -2189,15 +2221,15 @@ verify(void) | |||
2189 | check_consistency(p, i); | 2221 | check_consistency(p, i); |
2190 | if (get_partition_start(pe) < first[i]) | 2222 | if (get_partition_start(pe) < first[i]) |
2191 | printf("Warning: bad start-of-data in " | 2223 | printf("Warning: bad start-of-data in " |
2192 | "partition %d\n", i + 1); | 2224 | "partition %u\n", i + 1); |
2193 | check(i + 1, p->end_head, p->end_sector, p->end_cyl, | 2225 | check(i + 1, p->end_head, p->end_sector, p->end_cyl, |
2194 | last[i]); | 2226 | last[i]); |
2195 | total += last[i] + 1 - first[i]; | 2227 | total += last[i] + 1 - first[i]; |
2196 | for (j = 0; j < i; j++) { | 2228 | for (j = 0; j < i; j++) { |
2197 | if ((first[i] >= first[j] && first[i] <= last[j]) | 2229 | if ((first[i] >= first[j] && first[i] <= last[j]) |
2198 | || ((last[i] <= last[j] && last[i] >= first[j]))) { | 2230 | || ((last[i] <= last[j] && last[i] >= first[j]))) { |
2199 | printf("Warning: partition %d overlaps " | 2231 | printf("Warning: partition %u overlaps " |
2200 | "partition %d\n", j + 1, i + 1); | 2232 | "partition %u\n", j + 1, i + 1); |
2201 | total += first[i] >= first[j] ? | 2233 | total += first[i] >= first[j] ? |
2202 | first[i] : first[j]; | 2234 | first[i] : first[j]; |
2203 | total -= last[i] <= last[j] ? | 2235 | total -= last[i] <= last[j] ? |
@@ -2209,7 +2241,7 @@ verify(void) | |||
2209 | 2241 | ||
2210 | if (extended_offset) { | 2242 | if (extended_offset) { |
2211 | struct pte *pex = &ptes[ext_index]; | 2243 | struct pte *pex = &ptes[ext_index]; |
2212 | ullong e_last = get_start_sect(pex->part_table) + | 2244 | sector_t e_last = get_start_sect(pex->part_table) + |
2213 | get_nr_sects(pex->part_table) - 1; | 2245 | get_nr_sects(pex->part_table) - 1; |
2214 | 2246 | ||
2215 | for (i = 4; i < g_partitions; i++) { | 2247 | for (i = 4; i < g_partitions; i++) { |
@@ -2217,22 +2249,22 @@ verify(void) | |||
2217 | p = ptes[i].part_table; | 2249 | p = ptes[i].part_table; |
2218 | if (!p->sys_ind) { | 2250 | if (!p->sys_ind) { |
2219 | if (i != 4 || i + 1 < g_partitions) | 2251 | if (i != 4 || i + 1 < g_partitions) |
2220 | printf("Warning: partition %d " | 2252 | printf("Warning: partition %u " |
2221 | "is empty\n", i + 1); | 2253 | "is empty\n", i + 1); |
2222 | } else if (first[i] < extended_offset || last[i] > e_last) { | 2254 | } else if (first[i] < extended_offset || last[i] > e_last) { |
2223 | printf("Logical partition %d not entirely in " | 2255 | printf("Logical partition %u not entirely in " |
2224 | "partition %d\n", i + 1, ext_index + 1); | 2256 | "partition %u\n", i + 1, ext_index + 1); |
2225 | } | 2257 | } |
2226 | } | 2258 | } |
2227 | } | 2259 | } |
2228 | 2260 | ||
2229 | if (total > g_heads * g_sectors * g_cylinders) | 2261 | if (total > g_heads * g_sectors * g_cylinders) |
2230 | printf("Total allocated sectors %d greater than the maximum " | 2262 | printf("Total allocated sectors %u greater than the maximum " |
2231 | "%d\n", total, g_heads * g_sectors * g_cylinders); | 2263 | "%u\n", total, g_heads * g_sectors * g_cylinders); |
2232 | else { | 2264 | else { |
2233 | total = g_heads * g_sectors * g_cylinders - total; | 2265 | total = g_heads * g_sectors * g_cylinders - total; |
2234 | if (total != 0) | 2266 | if (total != 0) |
2235 | printf("%d unallocated sectors\n", total); | 2267 | printf("%"SECT_FMT"u unallocated sectors\n", total); |
2236 | } | 2268 | } |
2237 | } | 2269 | } |
2238 | 2270 | ||
@@ -2243,9 +2275,9 @@ add_partition(int n, int sys) | |||
2243 | int i, num_read = 0; | 2275 | int i, num_read = 0; |
2244 | struct partition *p = ptes[n].part_table; | 2276 | struct partition *p = ptes[n].part_table; |
2245 | struct partition *q = ptes[ext_index].part_table; | 2277 | struct partition *q = ptes[ext_index].part_table; |
2246 | ullong limit, temp; | 2278 | sector_t limit, temp; |
2247 | ullong start, stop = 0; | 2279 | sector_t start, stop = 0; |
2248 | ullong first[g_partitions], last[g_partitions]; | 2280 | sector_t first[g_partitions], last[g_partitions]; |
2249 | 2281 | ||
2250 | if (p && p->sys_ind) { | 2282 | if (p && p->sys_ind) { |
2251 | printf(msg_part_already_defined, n + 1); | 2283 | printf(msg_part_already_defined, n + 1); |
@@ -2255,7 +2287,7 @@ add_partition(int n, int sys) | |||
2255 | if (n < 4) { | 2287 | if (n < 4) { |
2256 | start = sector_offset; | 2288 | start = sector_offset; |
2257 | if (display_in_cyl_units || !total_number_of_sectors) | 2289 | if (display_in_cyl_units || !total_number_of_sectors) |
2258 | limit = (ullong) g_heads * g_sectors * g_cylinders - 1; | 2290 | limit = (sector_t) g_heads * g_sectors * g_cylinders - 1; |
2259 | else | 2291 | else |
2260 | limit = total_number_of_sectors - 1; | 2292 | limit = total_number_of_sectors - 1; |
2261 | if (extended_offset) { | 2293 | if (extended_offset) { |
@@ -2286,19 +2318,20 @@ add_partition(int n, int sys) | |||
2286 | if (start > limit) | 2318 | if (start > limit) |
2287 | break; | 2319 | break; |
2288 | if (start >= temp+units_per_sector && num_read) { | 2320 | if (start >= temp+units_per_sector && num_read) { |
2289 | printf("Sector %lld is already allocated\n", temp); | 2321 | printf("Sector %"SECT_FMT"u is already allocated\n", temp); |
2290 | temp = start; | 2322 | temp = start; |
2291 | num_read = 0; | 2323 | num_read = 0; |
2292 | } | 2324 | } |
2293 | if (!num_read && start == temp) { | 2325 | if (!num_read && start == temp) { |
2294 | ullong saved_start; | 2326 | sector_t saved_start; |
2295 | 2327 | ||
2296 | saved_start = start; | 2328 | saved_start = start; |
2297 | start = read_int(cround(saved_start), cround(saved_start), cround(limit), | 2329 | start = read_int(cround(saved_start), cround(saved_start), cround(limit), |
2298 | 0, mesg); | 2330 | 0, mesg); |
2299 | if (display_in_cyl_units) { | 2331 | if (display_in_cyl_units) { |
2300 | start = (start - 1) * units_per_sector; | 2332 | start = (start - 1) * units_per_sector; |
2301 | if (start < saved_start) start = saved_start; | 2333 | if (start < saved_start) |
2334 | start = saved_start; | ||
2302 | } | 2335 | } |
2303 | num_read = 1; | 2336 | num_read = 1; |
2304 | } | 2337 | } |
@@ -2546,16 +2579,16 @@ print_raw(void) | |||
2546 | } | 2579 | } |
2547 | 2580 | ||
2548 | static void | 2581 | static void |
2549 | move_begin(int i) | 2582 | move_begin(unsigned i) |
2550 | { | 2583 | { |
2551 | struct pte *pe = &ptes[i]; | 2584 | struct pte *pe = &ptes[i]; |
2552 | struct partition *p = pe->part_table; | 2585 | struct partition *p = pe->part_table; |
2553 | ullong new, first; | 2586 | sector_t new, first; |
2554 | 2587 | ||
2555 | if (warn_geometry()) | 2588 | if (warn_geometry()) |
2556 | return; | 2589 | return; |
2557 | if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED(p->sys_ind)) { | 2590 | if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED(p->sys_ind)) { |
2558 | printf("Partition %d has no data area\n", i + 1); | 2591 | printf("Partition %u has no data area\n", i + 1); |
2559 | return; | 2592 | return; |
2560 | } | 2593 | } |
2561 | first = get_partition_start(pe); | 2594 | first = get_partition_start(pe); |
@@ -2761,7 +2794,7 @@ list_devs_in_proc_partititons(void) | |||
2761 | procpt = fopen_or_warn("/proc/partitions", "r"); | 2794 | procpt = fopen_or_warn("/proc/partitions", "r"); |
2762 | 2795 | ||
2763 | while (fgets(line, sizeof(line), procpt)) { | 2796 | while (fgets(line, sizeof(line), procpt)) { |
2764 | if (sscanf(line, " %d %d %d %[^\n ]", | 2797 | if (sscanf(line, " %u %u %u %[^\n ]", |
2765 | &ma, &mi, &sz, ptname) != 4) | 2798 | &ma, &mi, &sz, ptname) != 4) |
2766 | continue; | 2799 | continue; |
2767 | for (s = ptname; *s; s++) | 2800 | for (s = ptname; *s; s++) |
@@ -2855,9 +2888,9 @@ int fdisk_main(int argc, char **argv) | |||
2855 | size = bb_BLKGETSIZE_sectors(fd) / 2; | 2888 | size = bb_BLKGETSIZE_sectors(fd) / 2; |
2856 | close(fd); | 2889 | close(fd); |
2857 | if (argc == 1) | 2890 | if (argc == 1) |
2858 | printf("%lld\n", size); | 2891 | printf("%llu\n", size); |
2859 | else | 2892 | else |
2860 | printf("%s: %lld\n", argv[j], size); | 2893 | printf("%s: %llu\n", argv[j], size); |
2861 | } | 2894 | } |
2862 | return 0; | 2895 | return 0; |
2863 | } | 2896 | } |