From 980b7c95739ca0b618bbb06146ec5659cbb50c63 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Tue, 10 Sep 1996 21:18:40 +0000 Subject: [PATCH] Rather than adding more gunk here, clean some of it up: devread() had a bogus interface, cleaned up. Bread() did an unneeded bcopy(), don't. Saves 80 bytes and some time. --- sys/i386/boot/biosboot/boot.h | 6 +++--- sys/i386/boot/biosboot/disk.c | 38 +++++++++++++++++------------------ sys/i386/boot/biosboot/sys.c | 38 +++++++++++------------------------ 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/sys/i386/boot/biosboot/boot.h b/sys/i386/boot/biosboot/boot.h index e054257d4d5..44c821cb492 100644 --- a/sys/i386/boot/biosboot/boot.h +++ b/sys/i386/boot/biosboot/boot.h @@ -24,7 +24,7 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:35:03 rpd - * $Id: boot.h,v 1.10 1995/05/30 07:58:29 rgrimes Exp $ + * $Id: boot.h,v 1.11 1995/06/25 14:02:52 joerg Exp $ */ #include @@ -69,8 +69,8 @@ void boot2(void); /* disk.c */ int devopen(void); -void devread(void); -void Bread(int dosdev, int sector); +void devread(char *iodest, int sector, int cnt); +char * Bread(int dosdev, int sector); int badsect(int dosdev, int sector); /* io.c */ diff --git a/sys/i386/boot/biosboot/disk.c b/sys/i386/boot/biosboot/disk.c index f64c3980f33..d99c36e6a88 100644 --- a/sys/i386/boot/biosboot/disk.c +++ b/sys/i386/boot/biosboot/disk.c @@ -24,7 +24,7 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:35:49 rpd - * $Id: disk.c,v 1.16 1995/09/16 13:03:59 bde Exp $ + * $Id: disk.c,v 1.17 1996/07/12 05:35:47 bde Exp $ */ /* @@ -59,15 +59,12 @@ int bsize; int spt, spc; -char *iodest; struct fs *fs; struct inode inode; -int dosdev, unit, slice, part, maj, boff, poff, bnum, cnt; +int dosdev, unit, slice, part, maj, boff, poff; /*#define EMBEDDED_DISKLABEL 1*/ -#define I_ADDR ((void *) 0) /* XXX where all reads go */ - /* Read ahead buffer large enough for one track on a 1440K floppy. 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. @@ -84,7 +81,7 @@ devopen(void) { struct dos_partition *dptr; struct disklabel *dl; - int dosdev = inode.i_dev; + char *p; int i, sector = 0, di; #if 0 /* Save space, already have hard error for cyl > 1023 in Bread */ u_long bend; @@ -111,8 +108,8 @@ devopen(void) #ifdef EMBEDDED_DISKLABEL dl = &disklabel; #else EMBEDDED_DISKLABEL - Bread(dosdev, 0); - dptr = (struct dos_partition *)(((char *)0)+DOSPARTOFF); + p = Bread(dosdev, 0); + dptr = (struct dos_partition *)(p+DOSPARTOFF); slice = WHOLE_DISK_SLICE; for (i = 0; i < NDOSPART; i++, dptr++) if (dptr->dp_typ == DOSPTYP_386BSD) { @@ -120,8 +117,8 @@ devopen(void) sector = dptr->dp_start; break; } - Bread(dosdev, sector + LABELSECTOR); - dl=((struct disklabel *)0); + p = Bread(dosdev, sector + LABELSECTOR); + dl=((struct disklabel *)p); disklabel = *dl; /* structure copy (maybe useful later)*/ #endif EMBEDDED_DISKLABEL if (dl->d_magic != DISKMAGIC) { @@ -180,8 +177,8 @@ devopen(void) do_bad144 = 0; do { /* XXX: what if the "DOS sector" < 512 bytes ??? */ - Bread(dosdev, dkbbnum + i); - dkbptr = (struct dkbad *) 0; + p = Bread(dosdev, dkbbnum + i); + dkbptr = (struct dkbad *) p; /* XXX why is this not in ??? */ #define DKBAD_MAGIC 0x4321 if (dkbptr->bt_mbz == 0 && @@ -202,19 +199,22 @@ devopen(void) return 0; } + void -devread(void) +devread(char *iodest, int sector, int cnt) { - int offset, sector = bnum; - int dosdev = inode.i_dev; + int offset; + char *p; + for (offset = 0; offset < cnt; offset += BPS) { - Bread(dosdev, badsect(dosdev, sector++)); - bcopy(0, iodest+offset, BPS); + p = Bread(dosdev, badsect(dosdev, sector++)); + bcopy(p, iodest+offset, BPS); } } -void + +char * Bread(int dosdev, int sector) { if (dosdev != ra_dev || sector < ra_first || sector >= ra_end) @@ -245,7 +245,7 @@ Bread(int dosdev, int sector) ra_first = sector; ra_end = sector + nsec; } - bcopy(ra_buf + (sector - ra_first) * BPS, I_ADDR, BPS); + return (ra_buf + (sector - ra_first) * BPS); } int diff --git a/sys/i386/boot/biosboot/sys.c b/sys/i386/boot/biosboot/sys.c index 6aab84a7748..acd4b10ebb9 100644 --- a/sys/i386/boot/biosboot/sys.c +++ b/sys/i386/boot/biosboot/sys.c @@ -24,7 +24,7 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:36:34 rpd - * $Id: sys.c,v 1.11 1996/04/07 14:28:03 bde Exp $ + * $Id: sys.c,v 1.12 1996/09/07 21:06:43 bde Exp $ */ #include "boot.h" @@ -72,21 +72,17 @@ read(char *buffer, int count) logno = lblkno(fs, poff); cnt2 = size = blksize(fs, &inode, logno); bnum2 = fsbtodb(fs, block_map(logno)) + boff; - cnt = cnt2; - bnum = bnum2; if ( (!off) && (size <= count)) { - iodest = buffer; - devread(); + devread(buffer, bnum2, cnt2); } else { - iodest = iobuf; size -= off; if (size > count) size = count; - devread(); - bcopy(iodest+off,buffer,size); + devread(iobuf, bnum2, cnt2); + bcopy(iobuf+off, buffer, size); } buffer += size; count -= size; @@ -104,11 +100,8 @@ find(char *path) list_only = (path[0] == '?' && path[1] == '\0'); loop: - iodest = iobuf; - cnt = fs->fs_bsize; - bnum = fsbtodb(fs,ino_to_fsba(fs,ino)) + boff; - devread(); - bcopy((void *)&((struct dinode *)iodest)[ino % fs->fs_inopb], + devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize); + bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb], (void *)&inode.i_din, sizeof (struct dinode)); if (!*path) @@ -131,12 +124,10 @@ loop: } if (!(off = blkoff(fs, loc))) { block = lblkno(fs, loc); - cnt = blksize(fs, &inode, block); - bnum = fsbtodb(fs, block_map(block)) + boff; - iodest = iobuf; - devread(); + devread(iobuf, fsbtodb(fs, block_map(block)) + boff, + blksize(fs, &inode, block)); } - dp = (struct direct *)(iodest + off); + dp = (struct direct *)(iobuf + off); loc += dp->d_reclen; if (dp->d_ino && list_only) printf("%s ", dp->d_name); @@ -150,12 +141,11 @@ loop: int block_map(int file_block) { + int bnum; if (file_block < NDADDR) return(inode.i_db[file_block]); if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) { - iodest = mapbuf; - cnt = fs->fs_bsize; - devread(); + devread(mapbuf, bnum, fs->fs_bsize); mapblock = bnum; } return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]); @@ -247,7 +237,6 @@ openrd(void) } printf("dosdev = %x, biosdrive = %d, unit = %d, maj = %d\n", dosdev, biosdrive, unit, maj); - inode.i_dev = dosdev; /***********************************************\ * Now we know the disk unit and part, * @@ -259,10 +248,7 @@ openrd(void) /***********************************************\ * Load Filesystem info (mount the device) * \***********************************************/ - iodest = (char *)(fs = (struct fs *)fsbuf); - cnt = SBSIZE; - bnum = SBLOCK + boff; - devread(); + devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE); /***********************************************\ * Find the actual FILE on the mounted device * \***********************************************/