Purely cosmetic whitespace/indentation changes (mmm, indent(1))

This commit is contained in:
thorpej 1997-03-22 01:41:34 +00:00
parent ddf4bc9113
commit 5e82fddd43
4 changed files with 228 additions and 223 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: biosdisk.c,v 1.2 1997/03/22 01:33:10 thorpej Exp $ */
/* $NetBSD: biosdisk.c,v 1.3 1997/03/22 01:41:34 thorpej Exp $ */
/*
* Copyright (c) 1996
@ -32,11 +32,10 @@
*
*/
/* raw BIOS disk device for libsa.
needs lowlevel parts from bios_disk.S and biosdisk_ll.c
partly from netbsd:sys/arch/i386/boot/disk.c
no bad144 handling!
/*
* raw BIOS disk device for libsa. needs lowlevel parts from bios_disk.S and
* biosdisk_ll.c partly from netbsd:sys/arch/i386/boot/disk.c no bad144
* handling!
*/
/*
@ -45,24 +44,24 @@
* Mach Operating System
* Copyright (c) 1992, 1991 Carnegie Mellon University
* All Rights Reserved.
*
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
*
* Carnegie Mellon requests users of this software to return to
*
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
@ -79,181 +78,184 @@
#define BUFSIZE (1 * BIOSDISK_SECSIZE)
struct biosdisk {
struct biosdisk_ll ll;
struct biosdisk {
struct biosdisk_ll ll;
#ifdef COMPAT_OLDBOOT
int disktype;
int disktype;
#endif
int boff;
char buf[BUFSIZE];
int boff;
char buf[BUFSIZE];
};
int biosdiskstrategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
size_t size;
void *buf;
size_t *rsize;
int
biosdiskstrategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
size_t size;
void *buf;
size_t *rsize;
{
struct biosdisk *d;
int blks, frag;
struct biosdisk *d;
int blks, frag;
if(flag != F_READ) return(EROFS);
if (flag != F_READ)
return (EROFS);
d = (struct biosdisk*)devdata;
d = (struct biosdisk *) devdata;
dblk += d->boff;
dblk += d->boff;
blks = size / BIOSDISK_SECSIZE;
if(blks && readsects(&d->ll, dblk, blks, buf, 0)){
if(rsize) *rsize = 0;
return(EIO);
}
/* do we really need this? */
frag = size % BIOSDISK_SECSIZE;
if(frag) {
if(readsects(&d->ll, dblk + blks, 1, d->buf, 0)){
if(rsize) *rsize = blks * BIOSDISK_SECSIZE;
return(EIO);
}
bcopy(d->buf, buf + blks * BIOSDISK_SECSIZE, frag);
}
if(rsize) *rsize = size;
return(0);
blks = size / BIOSDISK_SECSIZE;
if (blks && readsects(&d->ll, dblk, blks, buf, 0)) {
if (rsize)
*rsize = 0;
return (EIO);
}
/* do we really need this? */
frag = size % BIOSDISK_SECSIZE;
if (frag) {
if (readsects(&d->ll, dblk + blks, 1, d->buf, 0)) {
if (rsize)
*rsize = blks * BIOSDISK_SECSIZE;
return (EIO);
}
bcopy(d->buf, buf + blks * BIOSDISK_SECSIZE, frag);
}
if (rsize)
*rsize = size;
return (0);
}
#ifdef COMPAT_OLDBOOT
int biosdisk_gettype(f)
struct open_file *f;
int
biosdisk_gettype(f)
struct open_file *f;
{
struct biosdisk *d = f->f_devdata;
return(d->disktype);
struct biosdisk *d = f->f_devdata;
return (d->disktype);
}
#endif
int biosdiskopen(f, biosdev, partition)
struct open_file *f;
int biosdev;
unsigned int partition;
int
biosdiskopen(f, biosdev, partition)
struct open_file *f;
int biosdev;
unsigned int partition;
{
struct biosdisk *d;
struct dos_partition *dptr;
int sector;
int error = 0, i;
struct biosdisk *d;
struct dos_partition *dptr;
int sector;
int error = 0, i;
#ifndef NO_DISKLABEL
struct disklabel *lp;
struct disklabel *lp;
#endif
d = (struct biosdisk*)alloc(sizeof(struct biosdisk));
if(!d) {
d = (struct biosdisk *) alloc(sizeof(struct biosdisk));
if (!d) {
#ifdef DEBUG
printf("biosdiskopen: no memory\n");
printf("biosdiskopen: no memory\n");
#endif
return(ENOMEM);
}
d->ll.dev = biosdev;
if(set_geometry(&d->ll)) {
return (ENOMEM);
}
d->ll.dev = biosdev;
if (set_geometry(&d->ll)) {
#ifdef DISK_DEBUG
printf("no geometry information\n");
printf("no geometry information\n");
#endif
error = ENXIO;
goto out;
}
/* find NetBSD Partition in DOS partition table
XXX check magic??? */
if(readsects(&d->ll, 0, 1, d->buf, 0)){
error = ENXIO;
goto out;
}
/*
* find NetBSD Partition in DOS partition table XXX check magic???
*/
if (readsects(&d->ll, 0, 1, d->buf, 0)) {
#ifdef DISK_DEBUG
printf("error reading mbr\n");
printf("error reading mbr\n");
#endif
error = EIO;
goto out;
}
dptr = (struct dos_partition *)&d->buf[DOSPARTOFF];
sector = -1;
for (i = 0; i < NDOSPART; i++, dptr++)
if (dptr->dp_typ == DOSPTYP_NETBSD) {
sector = dptr->dp_start;
break;
}
if (sector == -1) {
/*
* One of two things:
* 1. no MBR
* 2. no NetBSD partition in MBR
*
* We simply default to "start of disk" in this case and press on.
*/
sector = 0;
}
error = EIO;
goto out;
}
dptr = (struct dos_partition *) & d->buf[DOSPARTOFF];
sector = -1;
for (i = 0; i < NDOSPART; i++, dptr++)
if (dptr->dp_typ == DOSPTYP_NETBSD) {
sector = dptr->dp_start;
break;
}
if (sector == -1) {
/*
* One of two things:
* 1. no MBR
* 2. no NetBSD partition in MBR
*
* We simply default to "start of disk" in this case and
* press on.
*/
sector = 0;
}
#ifdef NO_DISKLABEL
d->boff = sector;
d->boff = sector;
#else
/* find partition in NetBSD disklabel */
if(readsects(&d->ll, sector + LABELSECTOR, 1, d->buf, 0)){
/* find partition in NetBSD disklabel */
if (readsects(&d->ll, sector + LABELSECTOR, 1, d->buf, 0)) {
#ifdef DISK_DEBUG
printf("Error reading disklabel\n");
printf("Error reading disklabel\n");
#endif
error = EIO;
goto out;
}
lp = (struct disklabel *)(d->buf + LABELOFFSET);
if(lp->d_magic != DISKMAGIC) {
error = EIO;
goto out;
}
lp = (struct disklabel *) (d->buf + LABELOFFSET);
if (lp->d_magic != DISKMAGIC) {
#ifdef DISK_DEBUG
printf("warning: no disklabel\n");
printf("warning: no disklabel\n");
#endif
d->boff = sector;
} else if(partition >= lp->d_npartitions ||
lp->d_partitions[partition].p_fstype == FS_UNUSED) {
d->boff = sector;
} else if (partition >= lp->d_npartitions ||
lp->d_partitions[partition].p_fstype == FS_UNUSED) {
#ifdef DISK_DEBUG
printf("illegal partition\n");
printf("illegal partition\n");
#endif
error = EPART;
goto out;
} else {
d->boff = lp->d_partitions[partition].p_offset;
error = EPART;
goto out;
} else {
d->boff = lp->d_partitions[partition].p_offset;
#ifdef COMPAT_OLDBOOT
d->disktype = lp->d_type;
d->disktype = lp->d_type;
#endif
}
#endif /* NO_DISKLABEL */
}
#endif /* NO_DISKLABEL */
#ifdef DISK_DEBUG
printf("partition @%d\n", d->boff);
printf("partition @%d\n", d->boff);
#endif
f->f_devdata = d;
f->f_devdata = d;
out:
if(error)
free(d, sizeof(struct biosdisk));
return(error);
if (error)
free(d, sizeof(struct biosdisk));
return (error);
}
int biosdiskclose(f)
struct open_file *f;
int
biosdiskclose(f)
struct open_file *f;
{
struct biosdisk *d = f->f_devdata;
struct biosdisk *d = f->f_devdata;
if(!(d->ll.dev & 0x80)) /* let the floppy drive go off */
delay(3000000); /* 2s is enough on all PCs I found */
if (!(d->ll.dev & 0x80))/* let the floppy drive go off */
delay(3000000); /* 2s is enough on all PCs I found */
free(d, sizeof(struct biosdisk));
f->f_devdata = NULL;
return(0);
free(d, sizeof(struct biosdisk));
f->f_devdata = NULL;
return (0);
}
int biosdiskioctl(f, cmd, arg)
struct open_file *f;
u_long cmd;
void *arg;
int
biosdiskioctl(f, cmd, arg)
struct open_file *f;
u_long cmd;
void *arg;
{
return EIO;
return EIO;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: biosdisk.h,v 1.1.1.1 1997/03/14 02:40:32 perry Exp $ */
/* $NetBSD: biosdisk.h,v 1.2 1997/03/22 01:41:35 thorpej Exp $ */
/*
* Copyright (c) 1996
@ -29,10 +29,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
int biosdiskstrategy __P((void*, int, daddr_t, size_t, void*, size_t*));
int biosdiskopen __P((struct open_file*, ...));
int biosdiskclose __P((struct open_file*));

View File

@ -1,4 +1,4 @@
/* $NetBSD: biosdisk_ll.c,v 1.1.1.1 1997/03/14 02:40:32 perry Exp $ */
/* $NetBSD: biosdisk_ll.c,v 1.2 1997/03/22 01:41:36 thorpej Exp $ */
/*
* Copyright (c) 1996
@ -33,13 +33,12 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* shared by bootsector startup (bootsectmain)
and biosdisk.c
needs lowlevel parts from bios_disk.S
*/
/*
* shared by bootsector startup (bootsectmain) and biosdisk.c needs lowlevel
* parts from bios_disk.S
*/
#include <lib/libsa/stand.h>
@ -47,92 +46,100 @@
#include "diskbuf.h"
extern int get_diskinfo __P((int));
extern int biosread __P((int, int, int, int, int, char*));
extern int biosread __P((int, int, int, int, int, char *));
#define SPT(di) ((di)&0xff)
#define HEADS(di) ((((di)>>8)&0xff)+1)
int set_geometry(d)
struct biosdisk_ll *d;
int
set_geometry(d)
struct biosdisk_ll *d;
{
int diskinfo;
int diskinfo;
diskinfo = get_diskinfo(d->dev);
diskinfo = get_diskinfo(d->dev);
d->spc = (d->spt = SPT(diskinfo)) * HEADS(diskinfo);
d->spc = (d->spt = SPT(diskinfo)) * HEADS(diskinfo);
/* get_diskinfo assumes floppy if BIOS call
fails. Check at least "valid" geometry. */
return(!d->spc || !d->spt);
/*
* get_diskinfo assumes floppy if BIOS call fails. Check at least
* "valid" geometry.
*/
return (!d->spc || !d->spt);
}
/* Global shared "diskbuf" is used as read ahead buffer. For
* reading from floppies, the bootstrap has to be loaded on a 64K boundary
* to ensure that this buffer doesn't cross a 64K DMA boundary.
/*
* Global shared "diskbuf" is used as read ahead buffer. For reading from
* floppies, the bootstrap has to be loaded on a 64K boundary to ensure that
* this buffer doesn't cross a 64K DMA boundary.
*/
#define RA_SECTORS (DISKBUFSIZE / BIOSDISK_SECSIZE)
static int ra_dev;
static int ra_end;
static int ra_first;
static int ra_dev;
static int ra_end;
static int ra_first;
int readsects(d, dblk, num, buf, cold) /* reads ahead if (!cold) */
struct biosdisk_ll *d;
int dblk, num;
char *buf;
int cold; /* don't use data segment or bss, don't call library functions */
int
readsects(d, dblk, num, buf, cold) /* reads ahead if (!cold) */
struct biosdisk_ll *d;
int dblk, num;
char *buf;
int cold; /* don't use data segment or bss, don't call
* library functions */
{
while(num) {
int nsec;
while (num) {
int nsec;
/* check for usable data in read-ahead buffer */
if (cold || diskbuf_user != &ra_dev || d->dev != ra_dev
|| dblk < ra_first || dblk >= ra_end) {
/* check for usable data in read-ahead buffer */
if (cold || diskbuf_user != &ra_dev || d->dev != ra_dev
|| dblk < ra_first || dblk >= ra_end) {
/* no, read from disk */
int cyl, head, sec;
char *trbuf;
/* no, read from disk */
int cyl, head, sec;
char *trbuf;
cyl = dblk / d->spc;
head = (dblk % d->spc) / d->spt;
sec = dblk % d->spt;
nsec = d->spt - sec;
cyl = dblk / d->spc;
head = (dblk % d->spc) / d->spt;
sec = dblk % d->spt;
nsec = d->spt - sec;
if(cold) {
/* transfer directly to buffer */
trbuf = buf;
if (nsec > num)
nsec = num;
} else {
/* fill read-ahead buffer */
trbuf = diskbuf;
if (nsec > RA_SECTORS)
nsec = RA_SECTORS;
if (cold) {
/* transfer directly to buffer */
trbuf = buf;
if (nsec > num)
nsec = num;
} else {
/* fill read-ahead buffer */
trbuf = diskbuf;
if (nsec > RA_SECTORS)
nsec = RA_SECTORS;
ra_dev = d->dev;
ra_first = dblk;
ra_end = dblk + nsec;
diskbuf_user = &ra_dev;
}
ra_dev = d->dev;
ra_first = dblk;
ra_end = dblk + nsec;
diskbuf_user = &ra_dev;
}
if (biosread(d->dev, cyl, head, sec, nsec, trbuf)) {
if(!cold) diskbuf_user = 0; /* mark invalid */
return(-1); /* XXX cannot output here if (cold) */
}
if (biosread(d->dev, cyl, head, sec, nsec, trbuf)) {
if (!cold)
diskbuf_user = 0; /* mark invalid */
return (-1); /* XXX cannot output here if
* (cold) */
}
} else /* can take blocks from end of read-ahead
* buffer */
nsec = ra_end - dblk;
} else /* can take blocks from end of read-ahead buffer */
nsec = ra_end - dblk;
if(!cold) {
/* copy data from read-ahead to user buffer */
if(nsec > num) nsec = num;
bcopy(diskbuf + (dblk - ra_first) * BIOSDISK_SECSIZE, buf,
nsec * BIOSDISK_SECSIZE);
if (!cold) {
/* copy data from read-ahead to user buffer */
if (nsec > num)
nsec = num;
bcopy(diskbuf + (dblk - ra_first) * BIOSDISK_SECSIZE,
buf, nsec * BIOSDISK_SECSIZE);
}
buf += nsec * BIOSDISK_SECSIZE;
num -= nsec;
dblk += nsec;
}
buf += nsec * BIOSDISK_SECSIZE;
num -= nsec;
dblk += nsec;
}
return(0);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: biosdisk_ll.h,v 1.1.1.1 1997/03/14 02:40:32 perry Exp $ */
/* $NetBSD: biosdisk_ll.h,v 1.2 1997/03/22 01:41:36 thorpej Exp $ */
/*
* Copyright (c) 1996
@ -33,21 +33,19 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* shared by bootsector startup (bootsectmain)
and biosdisk.c
needs lowlevel parts from bios_disk.S
/*
* shared by bootsector startup (bootsectmain) and biosdisk.c needs lowlevel
* parts from bios_disk.S
*/
struct biosdisk_ll {
int dev; /* BIOS device number */
int spt, spc; /* geometry */
int dev; /* BIOS device number */
int spt, spc; /* geometry */
};
#define BIOSDISK_SECSIZE 512
int set_geometry __P((struct biosdisk_ll*));
int readsects __P((struct biosdisk_ll*, int, int, char*, int));
int set_geometry __P((struct biosdisk_ll *));
int readsects __P((struct biosdisk_ll *, int, int, char *, int));