u_short, ulong exterminated fdiskXXX: add a bit of sanity (not enough by far)
No binary (build failed)
—
(log yok)
| @@ -81,14 +81,14 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) | |
| struct unipair *up; | |
| int ct = 0, maxct; | |
| int glyph; | |
| - | u_short unicode; |
| + | uint16_t unicode; |
| maxct = tailsz; /* more than enough */ | |
| up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair)); | |
| for (glyph = 0; glyph < fontsize; glyph++) { | |
| while (tailsz >= 2) { | |
| - | unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; |
| + | unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0]; |
| tailsz -= 2; | |
| inbuf += 2; | |
| if (unicode == PSF_SEPARATOR) | |
| @@ -29,7 +29,7 @@ int loadkmap_main(int argc, char **argv) | |
| { | |
| struct kbentry ke; | |
| int i, j, fd; | |
| - | u_short ibuff[NR_KEYS]; |
| + | uint16_t ibuff[NR_KEYS]; |
| char flags[MAX_NR_KEYMAPS]; | |
| char buff[7]; | |
| @@ -46,7 +46,7 @@ int loadkmap_main(int argc, char **argv) | |
| for (i = 0; i < MAX_NR_KEYMAPS; i++) { | |
| if (flags[i] == 1) { | |
| - | xread(0, ibuff, NR_KEYS * sizeof(u_short)); |
| + | xread(0, ibuff, NR_KEYS * sizeof(uint16_t)); |
| for (j = 0; j < NR_KEYS; j++) { | |
| ke.kb_index = j; | |
| ke.kb_table = i; | |
| @@ -985,7 +985,7 @@ static void config(int sig ATTRIBUTE_UNUSED) | |
| } else | |
| #endif | |
| { | |
| - | u_short port = htons(atoi(sep->se_service)); |
| + | uint16_t port = htons(atoi(sep->se_service)); |
| // FIXME: atoi_or_else(str, 0) would be handy here | |
| if (!port) { | |
| /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); | |
| @@ -1037,8 +1037,8 @@ static void config(int sig ATTRIBUTE_UNUSED) | |
| register_rpc(sep); | |
| } else | |
| #endif | |
| - | { |
| - | u_short port = htons(atoi(sep->se_service)); |
| + | { |
| + | uint16_t port = htons(atoi(sep->se_service)); |
| if (!port) { | |
| /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); | |
| @@ -316,8 +316,8 @@ static int pmtu; /* Path MTU Discovery (RFC1191) */ | |
| static char *hostname; | |
| - | static u_short ident; |
| - | static u_short port = 32768 + 666; /* start udp dest port # for probe packets */ |
| + | static uint16_t ident; |
| + | static uint16_t port = 32768 + 666; /* start udp dest port # for probe packets */ |
| static int waittime = 5; /* time to wait for response (in seconds) */ | |
| static int nflag; /* print addresses numerically */ | |
| @@ -539,12 +539,12 @@ wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) | |
| /* | |
| * Checksum routine for Internet Protocol family headers (C Version) | |
| */ | |
| - | static u_short |
| - | in_cksum(u_short *addr, int len) |
| + | static uint16_t |
| + | in_cksum(uint16_t *addr, int len) |
| { | |
| int nleft = len; | |
| - | u_short *w = addr; |
| - | u_short answer; |
| + | uint16_t *w = addr; |
| + | uint16_t answer; |
| int sum = 0; | |
| /* | |
| @@ -589,7 +589,7 @@ send_probe(int seq, int ttl, struct timeval *tp) | |
| */ | |
| if (doipcksum) { | |
| outip->ip_sum = | |
| - | in_cksum((u_short *)outip, sizeof(*outip) + optlen); |
| + | in_cksum((uint16_t *)outip, sizeof(*outip) + optlen); |
| if (outip->ip_sum == 0) | |
| outip->ip_sum = 0xffff; | |
| } | |
| @@ -610,7 +610,7 @@ send_probe(int seq, int ttl, struct timeval *tp) | |
| if (useicmp) { | |
| /* Always calculate checksum for icmp packets */ | |
| outicmp->icmp_cksum = 0; | |
| - | outicmp->icmp_cksum = in_cksum((u_short *)outicmp, |
| + | outicmp->icmp_cksum = in_cksum((uint16_t *)outicmp, |
| packlen - (sizeof(*outip) + optlen)); | |
| if (outicmp->icmp_cksum == 0) | |
| outicmp->icmp_cksum = 0xffff; | |
| @@ -628,7 +628,7 @@ send_probe(int seq, int ttl, struct timeval *tp) | |
| ui->ui_pr = oui->ui_pr; | |
| ui->ui_len = outudp->len; | |
| outudp->check = 0; | |
| - | outudp->check = in_cksum((u_short *)ui, packlen); |
| + | outudp->check = in_cksum((uint16_t *)ui, packlen); |
| if (outudp->check == 0) | |
| outudp->check = 0xffff; | |
| *outip = tip; | |
| @@ -637,11 +637,11 @@ send_probe(int seq, int ttl, struct timeval *tp) | |
| #if ENABLE_FEATURE_TRACEROUTE_VERBOSE | |
| /* XXX undocumented debugging hack */ | |
| if (verbose > 1) { | |
| - | const u_short *sp; |
| + | const uint16_t *sp; |
| int nshorts, i; | |
| - | sp = (u_short *)outip; |
| - | nshorts = (u_int)packlen / sizeof(u_short); |
| + | sp = (uint16_t *)outip; |
| + | nshorts = (u_int)packlen / sizeof(uint16_t); |
| i = 0; | |
| printf("[ %d bytes", packlen); | |
| while (--nshorts >= 0) { | |
| @@ -906,7 +906,7 @@ traceroute_main(int argc, char *argv[]) | |
| #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE | |
| int lsrr = 0; | |
| #endif | |
| - | u_short off = 0; |
| + | uint16_t off = 0; |
| struct IFADDRLIST *al; | |
| char *device = NULL; | |
| int max_ttl = 30; | |
| @@ -1137,17 +1137,15 @@ traceroute_main(int argc, char *argv[]) | |
| outicmp = (struct icmp *)outp; | |
| outicmp->icmp_type = ICMP_ECHO; | |
| outicmp->icmp_id = htons(ident); | |
| - | |
| outdata = (struct outdata *)(outp + 8); /* XXX magic number */ | |
| } else | |
| #endif | |
| - | { |
| + | { |
| outip->ip_p = IPPROTO_UDP; | |
| outudp = (struct udphdr *)outp; | |
| outudp->source = htons(ident); | |
| - | outudp->len = |
| - | htons((u_short)(packlen - (sizeof(*outip) + optlen))); |
| + | outudp->len = htons((uint16_t)(packlen - (sizeof(*outip) + optlen))); |
| outdata = (struct outdata *)(outudp + 1); | |
| } | |
| @@ -15,9 +15,9 @@ | |
| struct arpMsg { | |
| /* Ethernet header */ | |
| - | u_char h_dest[6]; /* destination ether addr */ |
| - | u_char h_source[6]; /* source ether addr */ |
| - | u_short h_proto; /* packet type ID field */ |
| + | uint8_t h_dest[6]; /* destination ether addr */ |
| + | uint8_t h_source[6]; /* source ether addr */ |
| + | uint16_t h_proto; /* packet type ID field */ |
| /* ARP packet */ | |
| uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */ | |
| @@ -103,7 +103,7 @@ static void xid_del(u_int32_t xid) | |
| */ | |
| static int get_dhcp_packet_type(struct dhcpMessage *p) | |
| { | |
| - | u_char *op; |
| + | uint8_t *op; |
| /* it must be either a BOOTREQUEST or a BOOTREPLY */ | |
| if (p->op != BOOTREQUEST && p->op != BOOTREPLY) | |
| @@ -220,8 +220,8 @@ static int get_boot(enum action what); | |
| } | |
| - | static int32_t get_start_sect(const struct partition *p); |
| - | static int32_t get_nr_sects(const struct partition *p); |
| + | static unsigned get_start_sect(const struct partition *p); |
| + | static unsigned get_nr_sects(const struct partition *p); |
| /* | |
| * per partition table entry data | |
| @@ -338,7 +338,9 @@ read_hex(const struct systypes *sys) | |
| continue; | |
| } | |
| v = bb_strtoul(line_ptr, NULL, 16); | |
| - | if (errno || v > 0xff) continue; |
| + | if (v > 0xff) |
| + | /* Bad input also triggers this */ |
| + | continue; |
| return v; | |
| } | |
| } | |
| @@ -393,15 +395,15 @@ STATIC_OSF void xbsd_print_disklabel(int); | |
| #define SGI_XLV 0x0c | |
| #define SGI_XVM 0x0d | |
| #define SGI_ENTIRE_DISK SGI_VOLUME | |
| - | #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) |
| + | #if ENABLE_FEATURE_SGI_LABEL || ENABLE_FEATURE_SUN_LABEL |
| static uint16_t | |
| - | __swap16(uint16_t x) |
| + | fdisk_swap16(uint16_t x) |
| { | |
| return (x << 8) | (x >> 8); | |
| } | |
| static uint32_t | |
| - | __swap32(uint32_t x) |
| + | fdisk_swap32(uint32_t x) |
| { | |
| return (x << 24) | | |
| ((x & 0xFF00) << 8) | | |
| @@ -578,7 +580,7 @@ set_start_sect(struct partition *p, unsigned start_sect) | |
| } | |
| #endif | |
| - | static int32_t |
| + | static unsigned |
| get_start_sect(const struct partition *p) | |
| { | |
| return read4_little_endian(p->start4); | |
| @@ -586,13 +588,13 @@ get_start_sect(const struct partition *p) | |
| #if ENABLE_FEATURE_FDISK_WRITABLE | |
| static void | |
| - | set_nr_sects(struct partition *p, int32_t nr_sects) |
| + | set_nr_sects(struct partition *p, unsigned nr_sects) |
| { | |
| store4_little_endian(p->size4, nr_sects); | |
| } | |
| #endif | |
| - | static int32_t |
| + | static unsigned |
| get_nr_sects(const struct partition *p) | |
| { | |
| return read4_little_endian(p->size4); | |
| @@ -1770,13 +1772,13 @@ change_sysid(void) | |
| #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | |
| - | /* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993, |
| + | /* check_consistency() and linear2chs() added Sat Mar 6 12:28:16 1993, |
| * [email protected], based on code fragments from pfdisk by Gordon W. Ross, | |
| * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S. | |
| * Lubkin Oct. 1991). */ | |
| static void | |
| - | long2chs(ulong ls, unsigned *c, unsigned *h, unsigned *s) |
| + | linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s) |
| { | |
| int spc = heads * sectors; | |
| @@ -1808,10 +1810,10 @@ check_consistency(const struct partition *p, int partition) | |
| pes = p->end_sector & 0x3f; | |
| /* compute logical beginning (c, h, s) */ | |
| - | long2chs(get_start_sect(p), &lbc, &lbh, &lbs); |
| + | linear2chs(get_start_sect(p), &lbc, &lbh, &lbs); |
| /* compute logical ending (c, h, s) */ | |
| - | long2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); |
| + | linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); |
| /* Same physical / logical beginning? */ | |
| if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { | |
| @@ -2479,46 +2481,40 @@ write_table(void) | |
| static void | |
| reread_partition_table(int leave) | |
| { | |
| - | int error = 0; |
| int i; | |
| - | printf(_("Calling ioctl() to re-read partition table.\n")); |
| + | printf(_("Calling ioctl() to re-read partition table\n")); |
| sync(); | |
| - | sleep(2); |
| - | if ((i = ioctl(fd, BLKRRPART)) != 0) { |
| - | error = errno; |
| - | } else { |
| + | sleep(2); /* Huh? */ |
| + | i = ioctl(fd, BLKRRPART); |
| + | #if 0 |
| + | else { |
| /* some kernel versions (1.2.x) seem to have trouble | |
| rereading the partition table, but if asked to do it | |
| twice, the second time works. - [email protected] */ | |
| sync(); | |
| sleep(2); | |
| - | if ((i = ioctl(fd, BLKRRPART)) != 0) |
| - | error = errno; |
| + | i = ioctl(fd, BLKRRPART); |
| } | |
| + | #endif |
| if (i) { | |
| - | printf(_("\nWARNING: Re-reading the partition table " |
| - | "failed with error %d: %s.\n" |
| - | "The kernel still uses the old table.\n" |
| - | "The new table will be used " |
| - | "at the next reboot.\n"), |
| - | error, strerror(error)); |
| + | bb_perror_msg("WARNING: rereading partition table " |
| + | "failed, kernel still uses old table"); |
| } | |
| + | #if 0 |
| if (dos_changed) | |
| printf( | |
| _("\nWARNING: If you have created or modified any DOS 6.x\n" | |
| "partitions, please see the fdisk manual page for additional\n" | |
| "information.\n")); | |
| + | #endif |
| if (leave) { | |
| - | close(fd); |
| - | |
| - | printf(_("Syncing disks.\n")); |
| - | sync(); |
| - | sleep(4); /* for sync() */ |
| - | exit(!!i); |
| + | if (ENABLE_FEATURE_CLEAN_UP) |
| + | close(fd); |
| + | exit(i != 0); |
| } | |
| } | |
| #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | |
| @@ -2544,7 +2540,6 @@ print_buffer(char *pbuffer) | |
| puts(""); | |
| } | |
| - | |
| static void | |
| print_raw(void) | |
| { | |
| @@ -2728,7 +2723,8 @@ try(const char *device, int user_specified) | |
| if (!user_specified) | |
| if (is_ide_cdrom_or_tape(device)) | |
| return; | |
| - | if ((fd = open(disk_device, type_open)) >= 0) { |
| + | fd = open(disk_device, type_open); |
| + | if (fd >= 0) { |
| gb = get_boot(try_only); | |
| if (gb > 0) { /* I/O error */ | |
| close(fd); | |
| @@ -2861,7 +2857,7 @@ int fdisk_main(int argc, char **argv) | |
| type_open = O_RDONLY; | |
| if (argc > 0) { | |
| int k; | |
| - | #if __GNUC__ |
| + | #if defined(__GNUC__) |
| /* avoid gcc warning: | |
| variable `k' might be clobbered by `longjmp' */ | |
| (void)&k; | |
| @@ -253,7 +253,7 @@ static void xbsd_change_fstype(void); | |
| static int xbsd_get_part_index(int max); | |
| static int xbsd_check_new_partition(int *i); | |
| static void xbsd_list_types(void); | |
| - | static u_short xbsd_dkcksum(struct xbsd_disklabel *lp); |
| + | static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp); |
| static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d); | |
| static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d); | |
| static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d); | |
| @@ -650,37 +650,38 @@ xbsd_edit_disklabel(void) | |
| d = &xbsd_dlabel; | |
| #if defined (__alpha__) || defined (__ia64__) | |
| - | d->d_secsize = (u_long) edit_int((u_long) d->d_secsize ,_("bytes/sector")); |
| - | d->d_nsectors = (u_long) edit_int((u_long) d->d_nsectors ,_("sectors/track")); |
| - | d->d_ntracks = (u_long) edit_int((u_long) d->d_ntracks ,_("tracks/cylinder")); |
| - | d->d_ncylinders = (u_long) edit_int((u_long) d->d_ncylinders ,_("cylinders")); |
| + | d->d_secsize = edit_int(d->d_secsize ,_("bytes/sector")); |
| + | d->d_nsectors = edit_int(d->d_nsectors ,_("sectors/track")); |
| + | d->d_ntracks = edit_int(d->d_ntracks ,_("tracks/cylinder")); |
| + | d->d_ncylinders = edit_int(d->d_ncylinders ,_("cylinders")); |
| #endif | |
| - | /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */ |
| + | /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */ |
| while (1) { | |
| - | d->d_secpercyl = (u_long) edit_int((u_long) d->d_nsectors * d->d_ntracks, |
| + | d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks, |
| _("sectors/cylinder")); | |
| if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks) | |
| break; | |
| printf(_("Must be <= sectors/track * tracks/cylinder (default).\n")); | |
| } | |
| - | d->d_rpm = (u_short) edit_int((u_short) d->d_rpm ,_("rpm")); |
| - | d->d_interleave = (u_short) edit_int((u_short) d->d_interleave,_("interleave")); |
| - | d->d_trackskew = (u_short) edit_int((u_short) d->d_trackskew ,_("trackskew")); |
| - | d->d_cylskew = (u_short) edit_int((u_short) d->d_cylskew ,_("cylinderskew")); |
| - | d->d_headswitch = (u_long) edit_int((u_long) d->d_headswitch ,_("headswitch")); |
| - | d->d_trkseek = (u_long) edit_int((u_long) d->d_trkseek ,_("track-to-track seek")); |
| + | d->d_rpm = edit_int(d->d_rpm ,_("rpm")); |
| + | d->d_interleave = edit_int(d->d_interleave,_("interleave")); |
| + | d->d_trackskew = edit_int(d->d_trackskew ,_("trackskew")); |
| + | d->d_cylskew = edit_int(d->d_cylskew ,_("cylinderskew")); |
| + | d->d_headswitch = edit_int(d->d_headswitch,_("headswitch")); |
| + | d->d_trkseek = edit_int(d->d_trkseek ,_("track-to-track seek")); |
| d->d_secperunit = d->d_secpercyl * d->d_ncylinders; | |
| } | |
| static int | |
| - | xbsd_get_bootstrap (char *path, void *ptr, int size) |
| + | xbsd_get_bootstrap(char *path, void *ptr, int size) |
| { | |
| int fdb; | |
| - | if ((fdb = open (path, O_RDONLY)) < 0) { |
| + | fdb = open(path, O_RDONLY); |
| + | if (fdb < 0) { |
| perror(path); | |
| return 0; | |
| } | |
| @@ -736,7 +737,7 @@ xbsd_write_bootstrap(void) | |
| snprintf(path, sizeof(path), "%s/boot%s", bootdir, dkbasename); | |
| if (!xbsd_get_bootstrap(path, &disklabelbuffer[xbsd_dlabel.d_secsize], | |
| - | (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) |
| + | (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) |
| return; | |
| e = d + sizeof(struct xbsd_disklabel); | |
| @@ -748,9 +749,9 @@ xbsd_write_bootstrap(void) | |
| memmove(d, &dl, sizeof(struct xbsd_disklabel)); | |
| - | #if defined (__powerpc__) || defined (__hppa__) |
| + | #if defined(__powerpc__) || defined(__hppa__) |
| sector = 0; | |
| - | #elif defined (__alpha__) |
| + | #elif defined(__alpha__) |
| sector = 0; | |
| alpha_bootblock_checksum(disklabelbuffer); | |
| #else | |
| @@ -762,11 +763,11 @@ xbsd_write_bootstrap(void) | |
| if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE)) | |
| fdisk_fatal(unable_to_write); | |
| - | #if defined (__alpha__) |
| + | #if defined(__alpha__) |
| printf(_("Bootstrap installed on %s.\n"), disk_device); | |
| #else | |
| printf(_("Bootstrap installed on %s.\n"), | |
| - | partname (disk_device, xbsd_part_index+1, 0)); |
| + | partname(disk_device, xbsd_part_index+1, 0)); |
| #endif | |
| sync_disks(); | |
| @@ -812,7 +813,7 @@ xbsd_check_new_partition(int *i) | |
| } | |
| } | |
| - | *i = xbsd_get_part_index (BSD_MAXPARTITIONS); |
| + | *i = xbsd_get_part_index(BSD_MAXPARTITIONS); |
| if (*i >= xbsd_dlabel.d_npartitions) | |
| xbsd_dlabel.d_npartitions = (*i) + 1; | |
| @@ -831,14 +832,14 @@ xbsd_list_types(void) | |
| list_types(xbsd_fstypes); | |
| } | |
| - | static u_short |
| + | static uint16_t |
| xbsd_dkcksum(struct xbsd_disklabel *lp) | |
| { | |
| - | u_short *start, *end; |
| - | u_short sum = 0; |
| + | uint16_t *start, *end; |
| + | uint16_t sum = 0; |
| - | start = (u_short *) lp; |
| - | end = (u_short *) &lp->d_partitions[lp->d_npartitions]; |
| + | start = (uint16_t *) lp; |
| + | end = (uint16_t *) &lp->d_partitions[lp->d_npartitions]; |
| while (start < end) | |
| sum ^= *start++; | |
| return sum; | |
| @@ -84,8 +84,8 @@ typedef struct { | |
| #define SGI_INFO_MAGIC 0x00072959 | |
| #define SGI_INFO_MAGIC_SWAPPED 0x59290700 | |
| - | #define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) : (uint16_t)(x)) |
| - | #define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) : (uint32_t)(x)) |
| + | #define SGI_SSWAP16(x) (sgi_other_endian ? fdisk_swap16(x) : (uint16_t)(x)) |
| + | #define SGI_SSWAP32(x) (sgi_other_endian ? fdisk_swap32(x) : (uint32_t)(x)) |
| #define sgilabel ((sgi_partition *)MBRbuffer) | |
| #define sgiparam (sgilabel->devparam) | |
| @@ -2,8 +2,8 @@ | |
| #define SUN_LABEL_MAGIC 0xDABE | |
| #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA | |
| - | #define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) : (uint16_t)(x)) |
| - | #define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) : (uint32_t)(x)) |
| + | #define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x)) |
| + | #define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x)) |
| /* Copied from linux/major.h */ | |
| #define FLOPPY_MAJOR 2 | |
| @@ -439,7 +439,7 @@ struct ppathcnf { | |
| short pc_name_max; | |
| short pc_path_max; | |
| short pc_pipe_buf; | |
| - | u_char pc_vdisable; |
| + | uint8_t pc_vdisable; |
| char pc_xxx; | |
| short pc_mask[2]; | |
| }; | |