Cleanup usr.sbin/fd* so they can compile under WARNS=6.

fdcontrol/fdcontrol.c:
	- Add const constraint to an intermediate value
	  which is not supposed to be changed elsewhere.
fdread/fdread.c:
	- Use _devname in favor of devname to avoid name
	  conflicit.
	- -1 is less than any positive number so in order
	  to get the block to function, we should get the
	  block a little earlier.
	- Cast to remove signed when we are sure that a
	  return value is positive, or is compared with
	  an positive number (tracknumber of a floppy
	  disk is not likely to have UINT_MAX/2 anyway)
fdread/fdutil.c:
	- Use more specific initializer
fdwrite/fdwrite.c:
	- Use static on format_track since it's not
	  referenced in other places.
	- Use const char* to represent string constant.

Bump WARNS accordingly.
This commit is contained in:
Xin LI 2005-01-08 15:46:06 +00:00
parent e152198a83
commit 4c1f1c62ca
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139905
8 changed files with 39 additions and 35 deletions

View File

@ -4,7 +4,7 @@
PROG= fdcontrol PROG= fdcontrol
SRCS= fdcontrol.c fdutil.c SRCS= fdcontrol.c fdutil.c
WARNS?= 2 WARNS?= 6
CFLAGS+= -I${.CURDIR}/../fdread CFLAGS+= -I${.CURDIR}/../fdread
MAN= fdcontrol.8 MAN= fdcontrol.8

View File

@ -157,7 +157,7 @@ mode = O_RDONLY | O_NONBLOCK;
if (showfmt) { if (showfmt) {
if (verbose) { if (verbose) {
char *s; const char *s;
printf("%s: %d KB media type\n", argv[0], printf("%s: %d KB media type\n", argv[0],
(128 << ft.secsize) * ft.size / 1024); (128 << ft.secsize) * ft.size / 1024);

View File

@ -5,7 +5,7 @@
PROG= fdformat PROG= fdformat
SRCS= fdformat.c fdutil.c SRCS= fdformat.c fdutil.c
WARNS?= 2 WARNS?= 6
CFLAGS+= -I${.CURDIR}/../fdread CFLAGS+= -I${.CURDIR}/../fdread
.if ${MACHINE} == "pc98" .if ${MACHINE} == "pc98"

View File

@ -3,6 +3,8 @@
PROG= fdread PROG= fdread
SRCS= fdread.c fdutil.c SRCS= fdread.c fdutil.c
WARNS?= 6
.if ${MACHINE} == "pc98" .if ${MACHINE} == "pc98"
CFLAGS+= -DPC98 CFLAGS+= -DPC98
.endif .endif

View File

@ -47,7 +47,7 @@
int quiet, recover; int quiet, recover;
unsigned char fillbyte = 0xf0; /* "foo" */ unsigned char fillbyte = 0xf0; /* "foo" */
int doread(int fd, FILE *of, const char *devname); int doread(int fd, FILE *of, const char *_devname);
int doreadid(int fd, unsigned int numids, unsigned int trackno); int doreadid(int fd, unsigned int numids, unsigned int trackno);
void usage(void); void usage(void);
@ -66,7 +66,7 @@ main(int argc, char **argv)
{ {
int c, errs = 0; int c, errs = 0;
unsigned int numids = 0, trackno = 0; unsigned int numids = 0, trackno = 0;
const char *fname = 0, *devname = "/dev/fd0"; const char *fname = 0, *_devname = "/dev/fd0";
char *cp; char *cp;
FILE *of = stdout; FILE *of = stdout;
int fd; int fd;
@ -75,7 +75,7 @@ main(int argc, char **argv)
while ((c = getopt(argc, argv, "d:f:I:o:qrt:")) != -1) while ((c = getopt(argc, argv, "d:f:I:o:qrt:")) != -1)
switch (c) { switch (c) {
case 'd': case 'd':
devname = optarg; _devname = optarg;
break; break;
case 'f': case 'f':
@ -149,14 +149,14 @@ main(int argc, char **argv)
err(EX_OSERR, "cannot create output file %s", fname); err(EX_OSERR, "cannot create output file %s", fname);
} }
if ((fd = open(devname, O_RDONLY)) == -1) if ((fd = open(_devname, O_RDONLY)) == -1)
err(EX_OSERR, "cannot open device %s", devname); err(EX_OSERR, "cannot open device %s", _devname);
return (numids? doreadid(fd, numids, trackno): doread(fd, of, devname)); return (numids? doreadid(fd, numids, trackno): doread(fd, of, _devname));
} }
int int
doread(int fd, FILE *of, const char *devname) doread(int fd, FILE *of, const char *_devname)
{ {
char *trackbuf; char *trackbuf;
int rv, fdopts, recoverable, nerrs = 0; int rv, fdopts, recoverable, nerrs = 0;
@ -178,7 +178,7 @@ doread(int fd, FILE *of, const char *devname)
if (!quiet) if (!quiet)
fprintf(stderr, "Reading %d * %d * %d * %d medium at %s\n", fprintf(stderr, "Reading %d * %d * %d * %d medium at %s\n",
fdt.tracks, fdt.heads, fdt.sectrac, secsize, devname); fdt.tracks, fdt.heads, fdt.sectrac, secsize, _devname);
for (nbytes = 0; nbytes < mediasize;) { for (nbytes = 0; nbytes < mediasize;) {
if (lseek(fd, nbytes, SEEK_SET) != nbytes) if (lseek(fd, nbytes, SEEK_SET) != nbytes)
@ -189,7 +189,7 @@ doread(int fd, FILE *of, const char *devname)
warnx("premature EOF after %u bytes", nbytes); warnx("premature EOF after %u bytes", nbytes);
return (EX_OK); return (EX_OK);
} }
if (rv == tracksize) { if ((unsigned)rv == tracksize) {
nbytes += rv; nbytes += rv;
if (!quiet) if (!quiet)
fprintf(stderr, "%5d KB\r", nbytes / 1024); fprintf(stderr, "%5d KB\r", nbytes / 1024);
@ -197,23 +197,13 @@ doread(int fd, FILE *of, const char *devname)
fflush(of); fflush(of);
continue; continue;
} }
if (rv < tracksize) {
/* should not happen */
nbytes += rv;
if (!quiet)
fprintf(stderr, "\nshort after %5d KB\r",
nbytes / 1024);
fwrite(trackbuf, sizeof(unsigned char), rv, of);
fflush(of);
continue;
}
if (rv == -1) { if (rv == -1) {
/* fall back reading one sector at a time */ /* fall back reading one sector at a time */
for (n = 0; n < tracksize; n += secsize) { for (n = 0; n < tracksize; n += secsize) {
if (lseek(fd, nbytes, SEEK_SET) != nbytes) if (lseek(fd, nbytes, SEEK_SET) != nbytes)
err(EX_OSERR, "cannot lseek()"); err(EX_OSERR, "cannot lseek()");
rv = read(fd, trackbuf, secsize); rv = read(fd, trackbuf, secsize);
if (rv == secsize) { if ((unsigned) rv == secsize) {
nbytes += rv; nbytes += rv;
if (!quiet) if (!quiet)
fprintf(stderr, "%5d KB\r", fprintf(stderr, "%5d KB\r",
@ -257,7 +247,7 @@ doread(int fd, FILE *of, const char *devname)
"ioctl(fd, FD_SOPTS, FDOPT_NOERROR)"); "ioctl(fd, FD_SOPTS, FDOPT_NOERROR)");
rv = read(fd, trackbuf, rv = read(fd, trackbuf,
secsize); secsize);
if (rv != secsize) if ((unsigned)rv != secsize)
err(EX_IOERR, err(EX_IOERR,
"read() with FDOPT_NOERROR still fails"); "read() with FDOPT_NOERROR still fails");
fdopts &= ~FDOPT_NOERROR; fdopts &= ~FDOPT_NOERROR;
@ -286,6 +276,16 @@ doread(int fd, FILE *of, const char *devname)
rv); rv);
} }
} }
if ((unsigned)rv < tracksize) {
/* should not happen */
nbytes += rv;
if (!quiet)
fprintf(stderr, "\nshort after %5d KB\r",
nbytes / 1024);
fwrite(trackbuf, sizeof(unsigned char), rv, of);
fflush(of);
continue;
}
} }
if (!quiet) { if (!quiet) {
putc('\n', stderr); putc('\n', stderr);

View File

@ -102,7 +102,7 @@ static struct fd_type fd_types_288m[] = {
{ FDF_3_820 }, { FDF_3_820 },
{ FDF_3_800 }, { FDF_3_800 },
{ FDF_3_720 }, { FDF_3_720 },
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
}; };
static struct fd_type fd_types_144m[] = { static struct fd_type fd_types_144m[] = {
@ -126,7 +126,7 @@ static struct fd_type fd_types_144m[] = {
{ FDF_3_1480 }, { FDF_3_1480 },
{ FDF_3_1640 }, { FDF_3_1640 },
#endif #endif
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
#else #else
{ FDF_3_1722 }, { FDF_3_1722 },
{ FDF_3_1476 }, { FDF_3_1476 },
@ -135,7 +135,7 @@ static struct fd_type fd_types_144m[] = {
{ FDF_3_820 }, { FDF_3_820 },
{ FDF_3_800 }, { FDF_3_800 },
{ FDF_3_720 }, { FDF_3_720 },
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
#endif #endif
}; };
@ -153,7 +153,7 @@ static struct fd_type fd_types_12m[] = {
#if 0 #if 0
{ FDF_5_1280 }, { FDF_5_1280 },
#endif #endif
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
#else #else
{ FDF_5_1200 }, { FDF_5_1200 },
{ FDF_5_1230 }, { FDF_5_1230 },
@ -164,20 +164,20 @@ static struct fd_type fd_types_12m[] = {
{ FDF_5_720 }, { FDF_5_720 },
{ FDF_5_360 | FL_2STEP }, { FDF_5_360 | FL_2STEP },
{ FDF_5_640 }, { FDF_5_640 },
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
#endif #endif
}; };
static struct fd_type fd_types_720k[] = static struct fd_type fd_types_720k[] =
{ {
{ FDF_3_720 }, { FDF_3_720 },
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
}; };
static struct fd_type fd_types_360k[] = static struct fd_type fd_types_360k[] =
{ {
{ FDF_5_360 }, { FDF_5_360 },
{ 0 } { 0,0,0,0,0,0,0,0,0,0,0,0 }
}; };

View File

@ -8,5 +8,6 @@
# $FreeBSD$ # $FreeBSD$
PROG= fdwrite PROG= fdwrite
WARNS?= 6
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -21,9 +21,9 @@
#include <sys/fdcio.h> #include <sys/fdcio.h>
int static int
format_track(int fd, int cyl, int secs, int head, int rate, format_track(int fd, int cyl, int secs, int head, int rate,
int gaplen, int secsize, int fill,int interleave) int gaplen, int secsize, int fill, int interleave)
{ {
struct fd_formb f; struct fd_formb f;
register int i,j; register int i,j;
@ -55,7 +55,7 @@ format_track(int fd, int cyl, int secs, int head, int rate,
} }
static void static void
usage() usage(void)
{ {
fprintf(stderr, "usage: fdwrite [-v] [-y] [-f inputfile] [-d device]\n"); fprintf(stderr, "usage: fdwrite [-v] [-y] [-f inputfile] [-d device]\n");
exit(2); exit(2);
@ -67,7 +67,8 @@ main(int argc, char **argv)
int inputfd = -1, c, fdn = 0, i,j,fd; int inputfd = -1, c, fdn = 0, i,j,fd;
int bpt, verbose=1, nbytes=0, track; int bpt, verbose=1, nbytes=0, track;
int interactive = 1, fdopts; int interactive = 1, fdopts;
char *device= "/dev/fd0", *trackbuf = 0,*vrfybuf = 0; const char *device= "/dev/fd0";
char *trackbuf = 0,*vrfybuf = 0;
struct fd_type fdt; struct fd_type fdt;
FILE *tty; FILE *tty;