aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-19 20:32:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-19 20:32:02 +0000
commit28703015ab71784f40bc97f720ed900e26bd03ca (patch)
treeff0f9a21d1822c9a2f35819db4156d9555f56116 /util-linux
parentf58906b6463436f6a19f72d43c3ab4ba69d79104 (diff)
downloadbusybox-w32-28703015ab71784f40bc97f720ed900e26bd03ca.tar.gz
busybox-w32-28703015ab71784f40bc97f720ed900e26bd03ca.tar.bz2
busybox-w32-28703015ab71784f40bc97f720ed900e26bd03ca.zip
u_short, ulong exterminated
fdiskXXX: add a bit of sanity (not enough by far)
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/fdisk.c68
-rw-r--r--util-linux/fdisk_osf.c53
-rw-r--r--util-linux/fdisk_sgi.c4
-rw-r--r--util-linux/fdisk_sun.c4
-rw-r--r--util-linux/mount.c2
5 files changed, 64 insertions, 67 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 2af5a41b9..e4f7e5455 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -220,8 +220,8 @@ static int get_boot(enum action what);
220 } 220 }
221 221
222 222
223static int32_t get_start_sect(const struct partition *p); 223static unsigned get_start_sect(const struct partition *p);
224static int32_t get_nr_sects(const struct partition *p); 224static unsigned get_nr_sects(const struct partition *p);
225 225
226/* 226/*
227 * per partition table entry data 227 * per partition table entry data
@@ -338,7 +338,9 @@ read_hex(const struct systypes *sys)
338 continue; 338 continue;
339 } 339 }
340 v = bb_strtoul(line_ptr, NULL, 16); 340 v = bb_strtoul(line_ptr, NULL, 16);
341 if (errno || v > 0xff) continue; 341 if (v > 0xff)
342 /* Bad input also triggers this */
343 continue;
342 return v; 344 return v;
343 } 345 }
344} 346}
@@ -393,15 +395,15 @@ STATIC_OSF void xbsd_print_disklabel(int);
393#define SGI_XLV 0x0c 395#define SGI_XLV 0x0c
394#define SGI_XVM 0x0d 396#define SGI_XVM 0x0d
395#define SGI_ENTIRE_DISK SGI_VOLUME 397#define SGI_ENTIRE_DISK SGI_VOLUME
396#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) 398#if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL
397static uint16_t 399static uint16_t
398__swap16(uint16_t x) 400fdisk_swap16(uint16_t x)
399{ 401{
400 return (x << 8) | (x >> 8); 402 return (x << 8) | (x >> 8);
401} 403}
402 404
403static uint32_t 405static uint32_t
404__swap32(uint32_t x) 406fdisk_swap32(uint32_t x)
405{ 407{
406 return (x << 24) | 408 return (x << 24) |
407 ((x & 0xFF00) << 8) | 409 ((x & 0xFF00) << 8) |
@@ -578,7 +580,7 @@ set_start_sect(struct partition *p, unsigned start_sect)
578} 580}
579#endif 581#endif
580 582
581static int32_t 583static unsigned
582get_start_sect(const struct partition *p) 584get_start_sect(const struct partition *p)
583{ 585{
584 return read4_little_endian(p->start4); 586 return read4_little_endian(p->start4);
@@ -586,13 +588,13 @@ get_start_sect(const struct partition *p)
586 588
587#if ENABLE_FEATURE_FDISK_WRITABLE 589#if ENABLE_FEATURE_FDISK_WRITABLE
588static void 590static void
589set_nr_sects(struct partition *p, int32_t nr_sects) 591set_nr_sects(struct partition *p, unsigned nr_sects)
590{ 592{
591 store4_little_endian(p->size4, nr_sects); 593 store4_little_endian(p->size4, nr_sects);
592} 594}
593#endif 595#endif
594 596
595static int32_t 597static unsigned
596get_nr_sects(const struct partition *p) 598get_nr_sects(const struct partition *p)
597{ 599{
598 return read4_little_endian(p->size4); 600 return read4_little_endian(p->size4);
@@ -1770,13 +1772,13 @@ change_sysid(void)
1770#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 1772#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
1771 1773
1772 1774
1773/* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993, 1775/* check_consistency() and linear2chs() added Sat Mar 6 12:28:16 1993,
1774 * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross, 1776 * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross,
1775 * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S. 1777 * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S.
1776 * Lubkin Oct. 1991). */ 1778 * Lubkin Oct. 1991). */
1777 1779
1778static void 1780static void
1779long2chs(ulong ls, unsigned *c, unsigned *h, unsigned *s) 1781linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s)
1780{ 1782{
1781 int spc = heads * sectors; 1783 int spc = heads * sectors;
1782 1784
@@ -1808,10 +1810,10 @@ check_consistency(const struct partition *p, int partition)
1808 pes = p->end_sector & 0x3f; 1810 pes = p->end_sector & 0x3f;
1809 1811
1810/* compute logical beginning (c, h, s) */ 1812/* compute logical beginning (c, h, s) */
1811 long2chs(get_start_sect(p), &lbc, &lbh, &lbs); 1813 linear2chs(get_start_sect(p), &lbc, &lbh, &lbs);
1812 1814
1813/* compute logical ending (c, h, s) */ 1815/* compute logical ending (c, h, s) */
1814 long2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); 1816 linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les);
1815 1817
1816/* Same physical / logical beginning? */ 1818/* Same physical / logical beginning? */
1817 if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { 1819 if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) {
@@ -2479,46 +2481,40 @@ write_table(void)
2479static void 2481static void
2480reread_partition_table(int leave) 2482reread_partition_table(int leave)
2481{ 2483{
2482 int error = 0;
2483 int i; 2484 int i;
2484 2485
2485 printf(_("Calling ioctl() to re-read partition table.\n")); 2486 printf(_("Calling ioctl() to re-read partition table\n"));
2486 sync(); 2487 sync();
2487 sleep(2); 2488 sleep(2); /* Huh? */
2488 if ((i = ioctl(fd, BLKRRPART)) != 0) { 2489 i = ioctl(fd, BLKRRPART);
2489 error = errno; 2490#if 0
2490 } else { 2491 else {
2491 /* some kernel versions (1.2.x) seem to have trouble 2492 /* some kernel versions (1.2.x) seem to have trouble
2492 rereading the partition table, but if asked to do it 2493 rereading the partition table, but if asked to do it
2493 twice, the second time works. - biro@yggdrasil.com */ 2494 twice, the second time works. - biro@yggdrasil.com */
2494 sync(); 2495 sync();
2495 sleep(2); 2496 sleep(2);
2496 if ((i = ioctl(fd, BLKRRPART)) != 0) 2497 i = ioctl(fd, BLKRRPART);
2497 error = errno;
2498 } 2498 }
2499#endif
2499 2500
2500 if (i) { 2501 if (i) {
2501 printf(_("\nWARNING: Re-reading the partition table " 2502 bb_perror_msg("WARNING: rereading partition table "
2502 "failed with error %d: %s.\n" 2503 "failed, kernel still uses old table");
2503 "The kernel still uses the old table.\n"
2504 "The new table will be used "
2505 "at the next reboot.\n"),
2506 error, strerror(error));
2507 } 2504 }
2508 2505
2506#if 0
2509 if (dos_changed) 2507 if (dos_changed)
2510 printf( 2508 printf(
2511 _("\nWARNING: If you have created or modified any DOS 6.x\n" 2509 _("\nWARNING: If you have created or modified any DOS 6.x\n"
2512 "partitions, please see the fdisk manual page for additional\n" 2510 "partitions, please see the fdisk manual page for additional\n"
2513 "information.\n")); 2511 "information.\n"));
2512#endif
2514 2513
2515 if (leave) { 2514 if (leave) {
2516 close(fd); 2515 if (ENABLE_FEATURE_CLEAN_UP)
2517 2516 close(fd);
2518 printf(_("Syncing disks.\n")); 2517 exit(i != 0);
2519 sync();
2520 sleep(4); /* for sync() */
2521 exit(!!i);
2522 } 2518 }
2523} 2519}
2524#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 2520#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
@@ -2544,7 +2540,6 @@ print_buffer(char *pbuffer)
2544 puts(""); 2540 puts("");
2545} 2541}
2546 2542
2547
2548static void 2543static void
2549print_raw(void) 2544print_raw(void)
2550{ 2545{
@@ -2728,7 +2723,8 @@ try(const char *device, int user_specified)
2728 if (!user_specified) 2723 if (!user_specified)
2729 if (is_ide_cdrom_or_tape(device)) 2724 if (is_ide_cdrom_or_tape(device))
2730 return; 2725 return;
2731 if ((fd = open(disk_device, type_open)) >= 0) { 2726 fd = open(disk_device, type_open);
2727 if (fd >= 0) {
2732 gb = get_boot(try_only); 2728 gb = get_boot(try_only);
2733 if (gb > 0) { /* I/O error */ 2729 if (gb > 0) { /* I/O error */
2734 close(fd); 2730 close(fd);
@@ -2861,7 +2857,7 @@ int fdisk_main(int argc, char **argv)
2861 type_open = O_RDONLY; 2857 type_open = O_RDONLY;
2862 if (argc > 0) { 2858 if (argc > 0) {
2863 int k; 2859 int k;
2864#if __GNUC__ 2860#if defined(__GNUC__)
2865 /* avoid gcc warning: 2861 /* avoid gcc warning:
2866 variable `k' might be clobbered by `longjmp' */ 2862 variable `k' might be clobbered by `longjmp' */
2867 (void)&k; 2863 (void)&k;
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c
index bff2371e4..3d654d392 100644
--- a/util-linux/fdisk_osf.c
+++ b/util-linux/fdisk_osf.c
@@ -253,7 +253,7 @@ static void xbsd_change_fstype(void);
253static int xbsd_get_part_index(int max); 253static int xbsd_get_part_index(int max);
254static int xbsd_check_new_partition(int *i); 254static int xbsd_check_new_partition(int *i);
255static void xbsd_list_types(void); 255static void xbsd_list_types(void);
256static u_short xbsd_dkcksum(struct xbsd_disklabel *lp); 256static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp);
257static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d); 257static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d);
258static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d); 258static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d);
259static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d); 259static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d);
@@ -650,37 +650,38 @@ xbsd_edit_disklabel(void)
650 d = &xbsd_dlabel; 650 d = &xbsd_dlabel;
651 651
652#if defined (__alpha__) || defined (__ia64__) 652#if defined (__alpha__) || defined (__ia64__)
653 d->d_secsize = (u_long) edit_int((u_long) d->d_secsize ,_("bytes/sector")); 653 d->d_secsize = edit_int(d->d_secsize ,_("bytes/sector"));
654 d->d_nsectors = (u_long) edit_int((u_long) d->d_nsectors ,_("sectors/track")); 654 d->d_nsectors = edit_int(d->d_nsectors ,_("sectors/track"));
655 d->d_ntracks = (u_long) edit_int((u_long) d->d_ntracks ,_("tracks/cylinder")); 655 d->d_ntracks = edit_int(d->d_ntracks ,_("tracks/cylinder"));
656 d->d_ncylinders = (u_long) edit_int((u_long) d->d_ncylinders ,_("cylinders")); 656 d->d_ncylinders = edit_int(d->d_ncylinders ,_("cylinders"));
657#endif 657#endif
658 658
659 /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */ 659 /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */
660 while (1) { 660 while (1) {
661 d->d_secpercyl = (u_long) edit_int((u_long) d->d_nsectors * d->d_ntracks, 661 d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks,
662 _("sectors/cylinder")); 662 _("sectors/cylinder"));
663 if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks) 663 if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)
664 break; 664 break;
665 665
666 printf(_("Must be <= sectors/track * tracks/cylinder (default).\n")); 666 printf(_("Must be <= sectors/track * tracks/cylinder (default).\n"));
667 } 667 }
668 d->d_rpm = (u_short) edit_int((u_short) d->d_rpm ,_("rpm")); 668 d->d_rpm = edit_int(d->d_rpm ,_("rpm"));
669 d->d_interleave = (u_short) edit_int((u_short) d->d_interleave,_("interleave")); 669 d->d_interleave = edit_int(d->d_interleave,_("interleave"));
670 d->d_trackskew = (u_short) edit_int((u_short) d->d_trackskew ,_("trackskew")); 670 d->d_trackskew = edit_int(d->d_trackskew ,_("trackskew"));
671 d->d_cylskew = (u_short) edit_int((u_short) d->d_cylskew ,_("cylinderskew")); 671 d->d_cylskew = edit_int(d->d_cylskew ,_("cylinderskew"));
672 d->d_headswitch = (u_long) edit_int((u_long) d->d_headswitch ,_("headswitch")); 672 d->d_headswitch = edit_int(d->d_headswitch,_("headswitch"));
673 d->d_trkseek = (u_long) edit_int((u_long) d->d_trkseek ,_("track-to-track seek")); 673 d->d_trkseek = edit_int(d->d_trkseek ,_("track-to-track seek"));
674 674
675 d->d_secperunit = d->d_secpercyl * d->d_ncylinders; 675 d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
676} 676}
677 677
678static int 678static int
679xbsd_get_bootstrap (char *path, void *ptr, int size) 679xbsd_get_bootstrap(char *path, void *ptr, int size)
680{ 680{
681 int fdb; 681 int fdb;
682 682
683 if ((fdb = open (path, O_RDONLY)) < 0) { 683 fdb = open(path, O_RDONLY);
684 if (fdb < 0) {
684 perror(path); 685 perror(path);
685 return 0; 686 return 0;
686 } 687 }
@@ -736,7 +737,7 @@ xbsd_write_bootstrap(void)
736 737
737 snprintf(path, sizeof(path), "%s/boot%s", bootdir, dkbasename); 738 snprintf(path, sizeof(path), "%s/boot%s", bootdir, dkbasename);
738 if (!xbsd_get_bootstrap(path, &disklabelbuffer[xbsd_dlabel.d_secsize], 739 if (!xbsd_get_bootstrap(path, &disklabelbuffer[xbsd_dlabel.d_secsize],
739 (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) 740 (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize))
740 return; 741 return;
741 742
742 e = d + sizeof(struct xbsd_disklabel); 743 e = d + sizeof(struct xbsd_disklabel);
@@ -748,9 +749,9 @@ xbsd_write_bootstrap(void)
748 749
749 memmove(d, &dl, sizeof(struct xbsd_disklabel)); 750 memmove(d, &dl, sizeof(struct xbsd_disklabel));
750 751
751#if defined (__powerpc__) || defined (__hppa__) 752#if defined(__powerpc__) || defined(__hppa__)
752 sector = 0; 753 sector = 0;
753#elif defined (__alpha__) 754#elif defined(__alpha__)
754 sector = 0; 755 sector = 0;
755 alpha_bootblock_checksum(disklabelbuffer); 756 alpha_bootblock_checksum(disklabelbuffer);
756#else 757#else
@@ -762,11 +763,11 @@ xbsd_write_bootstrap(void)
762 if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE)) 763 if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE))
763 fdisk_fatal(unable_to_write); 764 fdisk_fatal(unable_to_write);
764 765
765#if defined (__alpha__) 766#if defined(__alpha__)
766 printf(_("Bootstrap installed on %s.\n"), disk_device); 767 printf(_("Bootstrap installed on %s.\n"), disk_device);
767#else 768#else
768 printf(_("Bootstrap installed on %s.\n"), 769 printf(_("Bootstrap installed on %s.\n"),
769 partname (disk_device, xbsd_part_index+1, 0)); 770 partname(disk_device, xbsd_part_index+1, 0));
770#endif 771#endif
771 772
772 sync_disks(); 773 sync_disks();
@@ -812,7 +813,7 @@ xbsd_check_new_partition(int *i)
812 } 813 }
813 } 814 }
814 815
815 *i = xbsd_get_part_index (BSD_MAXPARTITIONS); 816 *i = xbsd_get_part_index(BSD_MAXPARTITIONS);
816 817
817 if (*i >= xbsd_dlabel.d_npartitions) 818 if (*i >= xbsd_dlabel.d_npartitions)
818 xbsd_dlabel.d_npartitions = (*i) + 1; 819 xbsd_dlabel.d_npartitions = (*i) + 1;
@@ -831,14 +832,14 @@ xbsd_list_types(void)
831 list_types(xbsd_fstypes); 832 list_types(xbsd_fstypes);
832} 833}
833 834
834static u_short 835static uint16_t
835xbsd_dkcksum(struct xbsd_disklabel *lp) 836xbsd_dkcksum(struct xbsd_disklabel *lp)
836{ 837{
837 u_short *start, *end; 838 uint16_t *start, *end;
838 u_short sum = 0; 839 uint16_t sum = 0;
839 840
840 start = (u_short *) lp; 841 start = (uint16_t *) lp;
841 end = (u_short *) &lp->d_partitions[lp->d_npartitions]; 842 end = (uint16_t *) &lp->d_partitions[lp->d_npartitions];
842 while (start < end) 843 while (start < end)
843 sum ^= *start++; 844 sum ^= *start++;
844 return sum; 845 return sum;
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c
index 548a70bdc..7687103c9 100644
--- a/util-linux/fdisk_sgi.c
+++ b/util-linux/fdisk_sgi.c
@@ -84,8 +84,8 @@ typedef struct {
84#define SGI_INFO_MAGIC 0x00072959 84#define SGI_INFO_MAGIC 0x00072959
85#define SGI_INFO_MAGIC_SWAPPED 0x59290700 85#define SGI_INFO_MAGIC_SWAPPED 0x59290700
86 86
87#define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) : (uint16_t)(x)) 87#define SGI_SSWAP16(x) (sgi_other_endian ? fdisk_swap16(x) : (uint16_t)(x))
88#define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) : (uint32_t)(x)) 88#define SGI_SSWAP32(x) (sgi_other_endian ? fdisk_swap32(x) : (uint32_t)(x))
89 89
90#define sgilabel ((sgi_partition *)MBRbuffer) 90#define sgilabel ((sgi_partition *)MBRbuffer)
91#define sgiparam (sgilabel->devparam) 91#define sgiparam (sgilabel->devparam)
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c
index 1e8f2e525..af85fb2c4 100644
--- a/util-linux/fdisk_sun.c
+++ b/util-linux/fdisk_sun.c
@@ -2,8 +2,8 @@
2 2
3#define SUN_LABEL_MAGIC 0xDABE 3#define SUN_LABEL_MAGIC 0xDABE
4#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA 4#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
5#define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) : (uint16_t)(x)) 5#define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x))
6#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) : (uint32_t)(x)) 6#define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x))
7 7
8/* Copied from linux/major.h */ 8/* Copied from linux/major.h */
9#define FLOPPY_MAJOR 2 9#define FLOPPY_MAJOR 2
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 35665a2b5..661e26f19 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -439,7 +439,7 @@ struct ppathcnf {
439 short pc_name_max; 439 short pc_name_max;
440 short pc_path_max; 440 short pc_path_max;
441 short pc_pipe_buf; 441 short pc_pipe_buf;
442 u_char pc_vdisable; 442 uint8_t pc_vdisable;
443 char pc_xxx; 443 char pc_xxx;
444 short pc_mask[2]; 444 short pc_mask[2];
445}; 445};