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:
parent
e152198a83
commit
4c1f1c62ca
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139905
@ -4,7 +4,7 @@
|
||||
|
||||
PROG= fdcontrol
|
||||
SRCS= fdcontrol.c fdutil.c
|
||||
WARNS?= 2
|
||||
WARNS?= 6
|
||||
CFLAGS+= -I${.CURDIR}/../fdread
|
||||
MAN= fdcontrol.8
|
||||
|
||||
|
@ -157,7 +157,7 @@ mode = O_RDONLY | O_NONBLOCK;
|
||||
|
||||
if (showfmt) {
|
||||
if (verbose) {
|
||||
char *s;
|
||||
const char *s;
|
||||
|
||||
printf("%s: %d KB media type\n", argv[0],
|
||||
(128 << ft.secsize) * ft.size / 1024);
|
||||
|
@ -5,7 +5,7 @@
|
||||
PROG= fdformat
|
||||
SRCS= fdformat.c fdutil.c
|
||||
|
||||
WARNS?= 2
|
||||
WARNS?= 6
|
||||
CFLAGS+= -I${.CURDIR}/../fdread
|
||||
|
||||
.if ${MACHINE} == "pc98"
|
||||
|
@ -3,6 +3,8 @@
|
||||
PROG= fdread
|
||||
SRCS= fdread.c fdutil.c
|
||||
|
||||
WARNS?= 6
|
||||
|
||||
.if ${MACHINE} == "pc98"
|
||||
CFLAGS+= -DPC98
|
||||
.endif
|
||||
|
@ -47,7 +47,7 @@
|
||||
int quiet, recover;
|
||||
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);
|
||||
void usage(void);
|
||||
|
||||
@ -66,7 +66,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
int c, errs = 0;
|
||||
unsigned int numids = 0, trackno = 0;
|
||||
const char *fname = 0, *devname = "/dev/fd0";
|
||||
const char *fname = 0, *_devname = "/dev/fd0";
|
||||
char *cp;
|
||||
FILE *of = stdout;
|
||||
int fd;
|
||||
@ -75,7 +75,7 @@ main(int argc, char **argv)
|
||||
while ((c = getopt(argc, argv, "d:f:I:o:qrt:")) != -1)
|
||||
switch (c) {
|
||||
case 'd':
|
||||
devname = optarg;
|
||||
_devname = optarg;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
@ -149,14 +149,14 @@ main(int argc, char **argv)
|
||||
err(EX_OSERR, "cannot create output file %s", fname);
|
||||
}
|
||||
|
||||
if ((fd = open(devname, O_RDONLY)) == -1)
|
||||
err(EX_OSERR, "cannot open device %s", devname);
|
||||
if ((fd = open(_devname, O_RDONLY)) == -1)
|
||||
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
|
||||
doread(int fd, FILE *of, const char *devname)
|
||||
doread(int fd, FILE *of, const char *_devname)
|
||||
{
|
||||
char *trackbuf;
|
||||
int rv, fdopts, recoverable, nerrs = 0;
|
||||
@ -178,7 +178,7 @@ doread(int fd, FILE *of, const char *devname)
|
||||
|
||||
if (!quiet)
|
||||
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;) {
|
||||
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);
|
||||
return (EX_OK);
|
||||
}
|
||||
if (rv == tracksize) {
|
||||
if ((unsigned)rv == tracksize) {
|
||||
nbytes += rv;
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%5d KB\r", nbytes / 1024);
|
||||
@ -197,23 +197,13 @@ doread(int fd, FILE *of, const char *devname)
|
||||
fflush(of);
|
||||
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) {
|
||||
/* fall back reading one sector at a time */
|
||||
for (n = 0; n < tracksize; n += secsize) {
|
||||
if (lseek(fd, nbytes, SEEK_SET) != nbytes)
|
||||
err(EX_OSERR, "cannot lseek()");
|
||||
rv = read(fd, trackbuf, secsize);
|
||||
if (rv == secsize) {
|
||||
if ((unsigned) rv == secsize) {
|
||||
nbytes += rv;
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%5d KB\r",
|
||||
@ -257,7 +247,7 @@ doread(int fd, FILE *of, const char *devname)
|
||||
"ioctl(fd, FD_SOPTS, FDOPT_NOERROR)");
|
||||
rv = read(fd, trackbuf,
|
||||
secsize);
|
||||
if (rv != secsize)
|
||||
if ((unsigned)rv != secsize)
|
||||
err(EX_IOERR,
|
||||
"read() with FDOPT_NOERROR still fails");
|
||||
fdopts &= ~FDOPT_NOERROR;
|
||||
@ -286,6 +276,16 @@ doread(int fd, FILE *of, const char *devname)
|
||||
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) {
|
||||
putc('\n', stderr);
|
||||
|
@ -102,7 +102,7 @@ static struct fd_type fd_types_288m[] = {
|
||||
{ FDF_3_820 },
|
||||
{ FDF_3_800 },
|
||||
{ FDF_3_720 },
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
|
||||
static struct fd_type fd_types_144m[] = {
|
||||
@ -126,7 +126,7 @@ static struct fd_type fd_types_144m[] = {
|
||||
{ FDF_3_1480 },
|
||||
{ FDF_3_1640 },
|
||||
#endif
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
#else
|
||||
{ FDF_3_1722 },
|
||||
{ FDF_3_1476 },
|
||||
@ -135,7 +135,7 @@ static struct fd_type fd_types_144m[] = {
|
||||
{ FDF_3_820 },
|
||||
{ FDF_3_800 },
|
||||
{ FDF_3_720 },
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -153,7 +153,7 @@ static struct fd_type fd_types_12m[] = {
|
||||
#if 0
|
||||
{ FDF_5_1280 },
|
||||
#endif
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
#else
|
||||
{ FDF_5_1200 },
|
||||
{ FDF_5_1230 },
|
||||
@ -164,20 +164,20 @@ static struct fd_type fd_types_12m[] = {
|
||||
{ FDF_5_720 },
|
||||
{ FDF_5_360 | FL_2STEP },
|
||||
{ FDF_5_640 },
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct fd_type fd_types_720k[] =
|
||||
{
|
||||
{ FDF_3_720 },
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
|
||||
static struct fd_type fd_types_360k[] =
|
||||
{
|
||||
{ FDF_5_360 },
|
||||
{ 0 }
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
|
||||
|
||||
|
@ -8,5 +8,6 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fdwrite
|
||||
WARNS?= 6
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include <sys/fdcio.h>
|
||||
|
||||
int
|
||||
static int
|
||||
format_track(int fd, int cyl, int secs, int head, int rate,
|
||||
int gaplen, int secsize, int fill, int interleave)
|
||||
{
|
||||
@ -55,7 +55,7 @@ format_track(int fd, int cyl, int secs, int head, int rate,
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: fdwrite [-v] [-y] [-f inputfile] [-d device]\n");
|
||||
exit(2);
|
||||
@ -67,7 +67,8 @@ main(int argc, char **argv)
|
||||
int inputfd = -1, c, fdn = 0, i,j,fd;
|
||||
int bpt, verbose=1, nbytes=0, track;
|
||||
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;
|
||||
FILE *tty;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user