aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-06-28 23:50:31 +0000
committerEric Andersen <andersen@codepoet.org>2004-06-28 23:50:31 +0000
commitd926149d26d08df1d9ee84104f002098d1ba9b28 (patch)
tree5b418a35c91b74e67e6b9bc7e6b92319fe87aab5
parent0373cf1396ad3c6906c7c4a12b90fb2685eda851 (diff)
downloadbusybox-w32-d926149d26d08df1d9ee84104f002098d1ba9b28.tar.gz
busybox-w32-d926149d26d08df1d9ee84104f002098d1ba9b28.tar.bz2
busybox-w32-d926149d26d08df1d9ee84104f002098d1ba9b28.zip
Avoid a number of places where large drives could wrap a uint, and
instead use off_t which will be automagically promoted to 64bit if compiled with support for large drives. -Erik
-rw-r--r--util-linux/fdisk.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index b27a8aa09..8580bec70 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -252,8 +252,8 @@ static int get_boot(enum action what);
252 } 252 }
253 253
254 254
255static unsigned int get_start_sect(const struct partition *p); 255static int32_t get_start_sect(const struct partition *p);
256static unsigned int get_nr_sects(const struct partition *p); 256static int32_t get_nr_sects(const struct partition *p);
257 257
258/* 258/*
259 * per partition table entry data 259 * per partition table entry data
@@ -269,7 +269,7 @@ static struct pte {
269#ifdef CONFIG_FEATURE_FDISK_WRITABLE 269#ifdef CONFIG_FEATURE_FDISK_WRITABLE
270 char changed; /* boolean */ 270 char changed; /* boolean */
271#endif 271#endif
272 uint offset; /* disk sector number */ 272 off_t offset; /* disk sector number */
273 char *sectorbuffer; /* disk sector contents */ 273 char *sectorbuffer; /* disk sector contents */
274} ptes[MAXIMUM_PARTS]; 274} ptes[MAXIMUM_PARTS];
275 275
@@ -1059,7 +1059,7 @@ xbsd_delete_part (void)
1059static void 1059static void
1060xbsd_new_part (void) 1060xbsd_new_part (void)
1061{ 1061{
1062 uint begin, end; 1062 off_t begin, end;
1063 char mesg[256]; 1063 char mesg[256];
1064 int i; 1064 int i;
1065 1065
@@ -3317,19 +3317,19 @@ set_start_sect(struct partition *p, unsigned int start_sect) {
3317} 3317}
3318#endif 3318#endif
3319 3319
3320static unsigned int 3320static int32_t
3321get_start_sect(const struct partition *p) { 3321get_start_sect(const struct partition *p) {
3322 return read4_little_endian(p->start4); 3322 return read4_little_endian(p->start4);
3323} 3323}
3324 3324
3325#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3325#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3326static void 3326static void
3327set_nr_sects(struct partition *p, unsigned int nr_sects) { 3327set_nr_sects(struct partition *p, int32_t nr_sects) {
3328 store4_little_endian(p->size4, nr_sects); 3328 store4_little_endian(p->size4, nr_sects);
3329} 3329}
3330#endif 3330#endif
3331 3331
3332static unsigned int 3332static int32_t
3333get_nr_sects(const struct partition *p) { 3333get_nr_sects(const struct partition *p) {
3334 return read4_little_endian(p->size4); 3334 return read4_little_endian(p->size4);
3335} 3335}
@@ -3352,7 +3352,7 @@ static uint user_cylinders, user_heads, user_sectors;
3352static uint pt_heads, pt_sectors; 3352static uint pt_heads, pt_sectors;
3353static uint kern_heads, kern_sectors; 3353static uint kern_heads, kern_sectors;
3354 3354
3355static uint extended_offset; /* offset of link pointers */ 3355static off_t extended_offset; /* offset of link pointers */
3356 3356
3357static unsigned long long total_number_of_sectors; 3357static unsigned long long total_number_of_sectors;
3358 3358
@@ -3393,7 +3393,7 @@ static void fdisk_fatal(enum failure why) {
3393} 3393}
3394 3394
3395static void 3395static void
3396seek_sector(uint secno) { 3396seek_sector(off_t secno) {
3397 off_t offset = secno * sector_size; 3397 off_t offset = secno * sector_size;
3398 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) 3398 if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
3399 fdisk_fatal(unable_to_seek); 3399 fdisk_fatal(unable_to_seek);
@@ -3401,7 +3401,7 @@ seek_sector(uint secno) {
3401 3401
3402#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3402#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3403static void 3403static void
3404write_sector(uint secno, char *buf) { 3404write_sector(off_t secno, char *buf) {
3405 seek_sector(secno); 3405 seek_sector(secno);
3406 if (write(fd, buf, sector_size) != sector_size) 3406 if (write(fd, buf, sector_size) != sector_size)
3407 fdisk_fatal(unable_to_write); 3407 fdisk_fatal(unable_to_write);
@@ -3410,7 +3410,7 @@ write_sector(uint secno, char *buf) {
3410 3410
3411/* Allocate a buffer and read a partition table sector */ 3411/* Allocate a buffer and read a partition table sector */
3412static void 3412static void
3413read_pte(struct pte *pe, uint offset) { 3413read_pte(struct pte *pe, off_t offset) {
3414 3414
3415 pe->offset = offset; 3415 pe->offset = offset;
3416 pe->sectorbuffer = (char *) xmalloc(sector_size); 3416 pe->sectorbuffer = (char *) xmalloc(sector_size);
@@ -3687,9 +3687,9 @@ clear_partition(struct partition *p) {
3687 3687
3688#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3688#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3689static void 3689static void
3690set_partition(int i, int doext, uint start, uint stop, int sysid) { 3690set_partition(int i, int doext, off_t start, off_t stop, int sysid) {
3691 struct partition *p; 3691 struct partition *p;
3692 uint offset; 3692 off_t offset;
3693 3693
3694 if (doext) { 3694 if (doext) {
3695 p = ptes[i].ext_pointer; 3695 p = ptes[i].ext_pointer;
@@ -4646,7 +4646,7 @@ static int
4646wrong_p_order(int *prev) { 4646wrong_p_order(int *prev) {
4647 const struct pte *pe; 4647 const struct pte *pe;
4648 const struct partition *p; 4648 const struct partition *p;
4649 uint last_p_start_pos = 0, p_start_pos; 4649 off_t last_p_start_pos = 0, p_start_pos;
4650 int i, last_i = 0; 4650 int i, last_i = 0;
4651 4651
4652 for (i = 0 ; i < partitions; i++) { 4652 for (i = 0 ; i < partitions; i++) {
@@ -4820,8 +4820,8 @@ list_table(int xtra) {
4820 4820
4821 p = pe->part_table; 4821 p = pe->part_table;
4822 if (p && !is_cleared_partition(p)) { 4822 if (p && !is_cleared_partition(p)) {
4823 unsigned int psects = get_nr_sects(p); 4823 off_t psects = get_nr_sects(p);
4824 unsigned int pblocks = psects; 4824 off_t pblocks = psects;
4825 unsigned int podd = 0; 4825 unsigned int podd = 0;
4826 4826
4827 if (sector_size < 1024) { 4827 if (sector_size < 1024) {
@@ -4831,14 +4831,14 @@ list_table(int xtra) {
4831 if (sector_size > 1024) 4831 if (sector_size > 1024)
4832 pblocks *= (sector_size / 1024); 4832 pblocks *= (sector_size / 1024);
4833 printf( 4833 printf(
4834 "%s %c %11lu %11lu %11lu%c %2x %s\n", 4834 "%s %c %11llu %11llu %11llu%c %2x %s\n",
4835 partname(disk_device, i+1, w+2), 4835 partname(disk_device, i+1, w+2),
4836/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG 4836/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG
4837 ? '*' : '?', 4837 ? '*' : '?',
4838/* start */ (unsigned long) cround(get_partition_start(pe)), 4838/* start */ (unsigned long long) cround(get_partition_start(pe)),
4839/* end */ (unsigned long) cround(get_partition_start(pe) + psects 4839/* end */ (unsigned long long) cround(get_partition_start(pe) + psects
4840 - (psects ? 1 : 0)), 4840 - (psects ? 1 : 0)),
4841/* odd flag on end */ (unsigned long) pblocks, podd ? '+' : ' ', 4841/* odd flag on end */ (unsigned long long) pblocks, podd ? '+' : ' ',
4842/* type id */ p->sys_ind, 4842/* type id */ p->sys_ind,
4843/* type name */ partition_type(p->sys_ind)); 4843/* type name */ partition_type(p->sys_ind));
4844 check_consistency(p, i); 4844 check_consistency(p, i);
@@ -4883,7 +4883,7 @@ x_list_table(int extend) {
4883 4883
4884#ifdef CONFIG_FEATURE_FDISK_WRITABLE 4884#ifdef CONFIG_FEATURE_FDISK_WRITABLE
4885static void 4885static void
4886fill_bounds(uint *first, uint *last) { 4886fill_bounds(off_t *first, off_t *last) {
4887 int i; 4887 int i;
4888 const struct pte *pe = &ptes[0]; 4888 const struct pte *pe = &ptes[0];
4889 const struct partition *p; 4889 const struct partition *p;
@@ -4901,8 +4901,8 @@ fill_bounds(uint *first, uint *last) {
4901} 4901}
4902 4902
4903static void 4903static void
4904check(int n, uint h, uint s, uint c, uint start) { 4904check(int n, uint h, uint s, uint c, off_t start) {
4905 uint total, real_s, real_c; 4905 off_t total, real_s, real_c;
4906 4906
4907 real_s = sector(s) - 1; 4907 real_s = sector(s) - 1;
4908 real_c = cylinder(s, c); 4908 real_c = cylinder(s, c);
@@ -4917,19 +4917,19 @@ check(int n, uint h, uint s, uint c, uint start) {
4917 fprintf(stderr, _("Partition %d: sector %d greater than " 4917 fprintf(stderr, _("Partition %d: sector %d greater than "
4918 "maximum %d\n"), n, s, sectors); 4918 "maximum %d\n"), n, s, sectors);
4919 if (real_c >= cylinders) 4919 if (real_c >= cylinders)
4920 fprintf(stderr, _("Partitions %d: cylinder %d greater than " 4920 fprintf(stderr, _("Partitions %d: cylinder %llu greater than "
4921 "maximum %d\n"), n, real_c + 1, cylinders); 4921 "maximum %d\n"), n, (unsigned long long)real_c + 1, cylinders);
4922 if (cylinders <= 1024 && start != total) 4922 if (cylinders <= 1024 && start != total)
4923 fprintf(stderr, 4923 fprintf(stderr,
4924 _("Partition %d: previous sectors %d disagrees with " 4924 _("Partition %d: previous sectors %llu disagrees with "
4925 "total %d\n"), n, start, total); 4925 "total %llu\n"), n, (unsigned long long)start, (unsigned long long)total);
4926} 4926}
4927 4927
4928static void 4928static void
4929verify(void) { 4929verify(void) {
4930 int i, j; 4930 int i, j;
4931 uint total = 1; 4931 uint total = 1;
4932 uint first[partitions], last[partitions]; 4932 off_t first[partitions], last[partitions];
4933 struct partition *p; 4933 struct partition *p;
4934 4934
4935 if (warn_geometry()) 4935 if (warn_geometry())
@@ -4976,7 +4976,7 @@ verify(void) {
4976 4976
4977 if (extended_offset) { 4977 if (extended_offset) {
4978 struct pte *pex = &ptes[ext_index]; 4978 struct pte *pex = &ptes[ext_index];
4979 uint e_last = get_start_sect(pex->part_table) + 4979 off_t e_last = get_start_sect(pex->part_table) +
4980 get_nr_sects(pex->part_table) - 1; 4980 get_nr_sects(pex->part_table) - 1;
4981 4981
4982 for (i = 4; i < partitions; i++) { 4982 for (i = 4; i < partitions; i++) {
@@ -5008,7 +5008,7 @@ add_partition(int n, int sys) {
5008 struct partition *p = ptes[n].part_table; 5008 struct partition *p = ptes[n].part_table;
5009 struct partition *q = ptes[ext_index].part_table; 5009 struct partition *q = ptes[ext_index].part_table;
5010 long long llimit; 5010 long long llimit;
5011 uint start, stop = 0, limit, temp, 5011 off_t start, stop = 0, limit, temp,
5012 first[partitions], last[partitions]; 5012 first[partitions], last[partitions];
5013 5013
5014 if (p && p->sys_ind) { 5014 if (p && p->sys_ind) {
@@ -5054,12 +5054,12 @@ add_partition(int n, int sys) {
5054 if (start > limit) 5054 if (start > limit)
5055 break; 5055 break;
5056 if (start >= temp+units_per_sector && readed) { 5056 if (start >= temp+units_per_sector && readed) {
5057 printf(_("Sector %d is already allocated\n"), temp); 5057 printf(_("Sector %llu is already allocated\n"), (unsigned long long)temp);
5058 temp = start; 5058 temp = start;
5059 readed = 0; 5059 readed = 0;
5060 } 5060 }
5061 if (!readed && start == temp) { 5061 if (!readed && start == temp) {
5062 uint saved_start; 5062 off_t saved_start;
5063 5063
5064 saved_start = start; 5064 saved_start = start;
5065 start = read_int(cround(saved_start), cround(saved_start), cround(limit), 5065 start = read_int(cround(saved_start), cround(saved_start), cround(limit),
@@ -5344,7 +5344,7 @@ static void
5344move_begin(int i) { 5344move_begin(int i) {
5345 struct pte *pe = &ptes[i]; 5345 struct pte *pe = &ptes[i];
5346 struct partition *p = pe->part_table; 5346 struct partition *p = pe->part_table;
5347 uint new, first; 5347 off_t new, first;
5348 5348
5349 if (warn_geometry()) 5349 if (warn_geometry())
5350 return; 5350 return;