Cosmetic changes to reduce diffs from arc.

This commit is contained in:
tsutsui 2005-04-21 13:59:14 +00:00
parent ab74ed35be
commit fa657c9ce8
6 changed files with 97 additions and 79 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: devopen.c,v 1.4 2003/09/28 08:21:08 tsutsui Exp $ */
/* $NetBSD: devopen.c,v 1.5 2005/04/21 13:59:14 tsutsui Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,13 +42,12 @@
* file name if any.
*/
int
devopen(f, fname, file)
struct open_file *f;
const char *fname;
char **file; /* out */
devopen(struct open_file *f, const char *fname, char **file)
{
/* int ctlr = 0, unit = 0, part = 0; */
int rc;
#if 0
int ctlr = 0, unit = 0, part = 0;
#endif
int error;
char namebuf[128];
char devtype[16];
const char *cp;
@ -61,7 +60,7 @@ devopen(f, fname, file)
cp = fname;
ncp = (char *)fname;
/*
/*
* If device starts with a PCI bus specifier, skip past it so the
* device-matching code below gets the actual device type. Leave
* fname as is, since it'll be passed back to ARCS to open the
@ -99,11 +98,11 @@ devopen(f, fname, file)
printf("devopen: %s type %s file %s\n", namebuf, devtype, cp);
#ifdef LIBSA_SINGLE_DEVICE
rc = DEV_OPEN(dp)(f, fname);
error = DEV_OPEN(dp)(f, fname);
#else /* !LIBSA_SINGLE_DEVICE */
for (dp = devsw, i = 0; i < ndevs; dp++, i++)
if (dp->dv_name && strcmp(devtype, dp->dv_name) == 0)
goto fnd;
goto found;
printf("Unknown device '%s'\nKnown devices are:", devtype);
for (dp = devsw, i = 0; i < ndevs; dp++, i++)
if (dp->dv_name)
@ -111,11 +110,11 @@ devopen(f, fname, file)
printf("\n");
return ENXIO;
fnd:
rc = (dp->dv_open)(f, namebuf);
found:
error = (dp->dv_open)(f, namebuf);
#endif /* !LIBSA_SINGLE_DEVICE */
if (rc)
return rc;
if (error)
return error;
#ifndef LIBSA_SINGLE_DEVICE
f->f_dev = dp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: disk.c,v 1.6 2005/04/18 15:38:00 tsutsui Exp $ */
/* $NetBSD: disk.c,v 1.7 2005/04/21 13:59:15 tsutsui Exp $ */
/*
* Copyright (c) 1992, 1993
@ -50,24 +50,19 @@
extern const struct arcbios_fv *ARCBIOS;
struct disk_softc {
u_long sc_fd; /* PROM file id */
u_long sc_fd; /* ARCBIOS file id */
int sc_part; /* disk partition number */
struct disklabel sc_label; /* disk label for this disk */
};
int
diskstrategy(devdata, rw, bn, reqcnt, addr, cnt)
void *devdata;
int rw;
daddr_t bn;
size_t reqcnt;
void *addr;
size_t *cnt; /* out: number of bytes transfered */
diskstrategy(void *devdata, int rw, daddr_t bn, size_t reqcnt, void *addr,
size_t *cnt)
{
struct disk_softc *sc = (struct disk_softc *)devdata;
int part = sc->sc_part;
struct partition *pp = &sc->sc_label.d_partitions[part];
int s;
long error;
int64_t offset;
u_long count;
@ -78,7 +73,7 @@ diskstrategy(devdata, rw, bn, reqcnt, addr, cnt)
*/
if (reqcnt & (DEV_BSIZE - 1)) {
*cnt = 0;
return (EINVAL);
return EINVAL;
}
offset += pp->p_offset;
@ -91,14 +86,15 @@ diskstrategy(devdata, rw, bn, reqcnt, addr, cnt)
*/
offset *= DEV_BSIZE;
s = ARCBIOS->Seek(sc->sc_fd, &offset, 0);
s = ARCBIOS->Read(sc->sc_fd, addr, reqcnt, &count);
if (s < 0)
return (EIO);
error = (*ARCBIOS->Seek)(sc->sc_fd, &offset, 0);
if (error != ARCBIOS_ESUCCESS)
return EIO;
error = (*ARCBIOS->Read)(sc->sc_fd, addr, reqcnt, &count);
if (error != ARCBIOS_ESUCCESS)
return EIO;
*cnt = count;
return (0);
return 0;
}
int
@ -110,7 +106,10 @@ diskopen(struct open_file *f, ...)
struct disklabel *lp;
#ifdef arc
char *msg, buf[DEV_BSIZE];
size_t cnt;
int mbrp_off, i;
#endif
int error;
u_long fd;
char *device;
va_list ap;
@ -131,12 +130,13 @@ diskopen(struct open_file *f, ...)
*/
part = 0;
if (part >= 16)
return (ENXIO);
if (part >= MAXPARTITIONS)
return ENXIO;
if (ARCBIOS->Open(device, 0, &fd)) {
printf("open failed\n");
return (ENXIO);
error = (*ARCBIOS->Open)(device, 0, &fd);
if (error) {
printf("diskopen: open failed, errno = %d\n", error);
return ENXIO;
}
sc = alloc(sizeof(struct disk_softc));
@ -155,35 +155,51 @@ diskopen(struct open_file *f, ...)
lp->d_partitions[part].p_size = 0x7fffffff;
#ifdef arc
i = diskstrategy(sc, F_READ, (daddr_t)LABELSECTOR, DEV_BSIZE,
error = diskstrategy(sc, F_READ, (daddr_t)LABELSECTOR, DEV_BSIZE,
buf, &cnt);
if (i || cnt != DEV_BSIZE) {
printf("%s: error reading disk label\n", device);
if (error || cnt != DEV_BSIZE) {
printf("%s: can't read disklabel, errno = %d\n",
device, error);
free(sc, sizeof(struct disk_softc));
return (ENXIO);
return ENXIO;
}
msg = getdisklabel(buf, lp);
if (msg) {
/* If no label, just assume 0 and return */
return (0);
return 0;
}
/*
* On arc, we can't open whole disk, but can open each partition with
* OSLOADPARTITION like scsi(0)disk(0)rdisk()partition(1) etc.
* Thus, we don't have to add offset of the MBR partition.
*/
/* XXX magic: partition 2 is whole NetBSD partition */
mbrp_off = lp->d_partitions[2].p_offset;
for (i = 0; i < MAXPARTITIONS; i++) {
if (lp->d_partitions[i].p_fstype != FS_UNUSED &&
lp->d_partitions[i].p_offset >= mbrp_off)
lp->d_partitions[i].p_offset -= mbrp_off;
}
if (part >= lp->d_npartitions ||
lp->d_partitions[part].p_fstype == FS_UNUSED ||
lp->d_partitions[part].p_size == 0) {
free(sc, sizeof(struct disk_softc));
return ENXIO;
}
#endif
if (part >= lp->d_npartitions || lp->d_partitions[part].p_size == 0) {
free(sc, sizeof(struct disk_softc));
return (ENXIO);
}
return (0);
return 0;
}
#ifndef LIBSA_NO_DEV_CLOSE
int
diskclose(f)
struct open_file *f;
diskclose(struct open_file *f)
{
ARCBIOS->Close(((struct disk_softc *)(f->f_devdata))->sc_fd);
(*ARCBIOS->Close)(((struct disk_softc *)(f->f_devdata))->sc_fd);
free(f->f_devdata, sizeof(struct disk_softc));
f->f_devdata = (void *)0;
return (0);
f->f_devdata = NULL;
return 0;
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: disk.h,v 1.2 2004/02/08 13:15:42 sekiya Exp $ */
/* $NetBSD: disk.h,v 1.3 2005/04/21 13:59:15 tsutsui Exp $ */
/*
* Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
@ -32,7 +32,7 @@
* SUCH DAMAGE.
*/
int diskstrategy (void *, int, daddr_t, size_t, void *, size_t *);
int diskopen (struct open_file *, ...);
int diskclose (struct open_file *);
int diskioctl (struct open_file *, u_long, void *);
int diskstrategy(void *, int, daddr_t, size_t, void *, size_t *);
int diskopen(struct open_file *, ...);
int diskclose(struct open_file *);
int diskioctl(struct open_file *, u_long, void *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: getchar.c,v 1.4 2005/04/18 15:38:00 tsutsui Exp $ */
/* $NetBSD: getchar.c,v 1.5 2005/04/21 13:59:15 tsutsui Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -42,11 +42,13 @@
extern const struct arcbios_fv *ARCBIOS;
int
getchar()
getchar(void)
{
char ch;
u_long count;
(*ARCBIOS->Read)(0, &ch, 1, &count);
return(ch);
if ((*ARCBIOS->Read)(0, &ch, 1, &count) != ARCBIOS_ESUCCESS)
return -1;
return ch;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: getopt.c,v 1.1 2003/11/11 06:28:15 sekiya Exp $ */
/* $NetBSD: getopt.c,v 1.2 2005/04/21 13:59:15 tsutsui Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@ -49,10 +49,7 @@ char *optarg; /* argument associated with option */
* Parse argc/argv argument vector.
*/
int
getopt(nargc, nargv, ostr)
int nargc;
char * const *nargv;
const char *ostr;
getopt(int nargc, char * const *nargv, const char *ostr)
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
@ -61,12 +58,12 @@ getopt(nargc, nargv, ostr)
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
return -1;
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
return -1;
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
@ -76,12 +73,12 @@ getopt(nargc, nargv, ostr)
* assume it means -1.
*/
if (optopt == (int)'-')
return (-1);
return -1;
if (!*place)
++optind;
if (opterr && *ostr != ':')
printf("illegal option -- %c\n", optopt);
return (BADCH);
return BADCH;
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
@ -94,16 +91,16 @@ getopt(nargc, nargv, ostr)
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
return BADARG;
if (opterr)
printf("option requires an argument -- %c\n",
optopt);
return (BADCH);
return BADCH;
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
return optopt; /* dump back option letter */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: putchar.c,v 1.4 2005/04/18 15:38:00 tsutsui Exp $ */
/* $NetBSD: putchar.c,v 1.5 2005/04/21 13:59:15 tsutsui Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -42,12 +42,16 @@
extern const struct arcbios_fv *ARCBIOS;
void
putchar(c)
int c;
putchar(int c)
{
static char ch[2] = "?\r";
char ch;
u_long count;
ch[0] = c;
(*ARCBIOS->Write)(1, &ch, c == '\n' ? 2 : 1, &count);
if (c == '\n') {
ch = '\r';
(*ARCBIOS->Write)(1, &ch, 1, &count);
}
ch = c;
(*ARCBIOS->Write)(1, &ch, 1, &count);
}