2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, Revision 2.2 92/04/04 11:35:49 rpd
29 * Ported to PC-9801 by Yoshio Kimura
34 * If there is no 386BSD partition, initialize the label sector with
35 * LABELSECTOR instead of with garbage.
38 * Fixed reading of bad sector table. It is at the end of the 'c'
39 * partition, which is not always at the end of the disk.
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
46 #include <sys/disklabel.h>
47 #include <sys/diskpc98.h>
48 #include <machine/bootinfo.h>
50 #define BIOS_DEV_FLOPPY 0x0
51 #define BIOS_DEV_WIN 0x80
54 #define SPT(di) ((di)&0xff)
55 #define HEADS(di) (((di)>>8)&0xff)
62 int dosdev, unit, slice, part, maj, boff;
64 /*#define EMBEDDED_DISKLABEL 1*/
66 /* Read ahead buffer large enough for one track on a 1440K floppy. For
67 * reading from floppies, the bootstrap has to be loaded on a 64K boundary
68 * to ensure that this buffer doesn't cross a 64K DMA boundary.
71 static char ra_buf[RA_SECTORS * BPS];
76 static char *Bread(int dosdev, int sector);
81 struct pc98_partition *dptr;
84 int i, sector = 0, di, dosdev_copy;
87 di = get_diskinfo(dosdev_copy);
88 spc = (spt = SPT(di)) * HEADS(di);
91 if ((dosdev_copy & 0xf0) == 0x90)
94 part = (spt == 15 ? 0 : 1);
98 #ifdef EMBEDDED_DISKLABEL
100 #else /* EMBEDDED_DISKLABEL */
101 p = Bread(dosdev_copy, 1);
102 dptr = (struct pc98_partition *)p;
103 slice = WHOLE_DISK_SLICE;
104 for (i = 0; i < NDOSPART; i++, dptr++)
105 if (dptr->dp_mid == DOSMID_386BSD) {
106 slice = BASE_SLICE + i;
107 sector = dptr->dp_scyl * spc;
110 p = Bread(dosdev, sector + LABELSECTOR);
111 dl=((struct disklabel *)p);
112 disklabel = *dl; /* structure copy (maybe useful later)*/
113 #endif /* EMBEDDED_DISKLABEL */
114 if (dl->d_magic != DISKMAGIC) {
115 printf("bad disklabel\n");
118 /* This little trick is for OnTrack DiskManager disks */
119 boff = dl->d_partitions[part].p_offset -
120 dl->d_partitions[2].p_offset + sector;
128 * Be aware that cnt is rounded up to N*BPS
131 devread(char *iodest, int sector, int cnt)
137 for (offset = 0; offset < cnt; offset += BPS)
139 dosdev_copy = dosdev;
140 p = Bread(dosdev_copy, sector++);
141 memcpy(p, iodest+offset, BPS);
147 Bread(int dosdev, int sector)
149 if (dosdev != ra_dev || sector < ra_first || sector >= ra_end)
151 int cyl, head, sec, nsec;
154 head = (sector % spc) / spt;
157 if (nsec > RA_SECTORS)
160 if (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0)
164 while (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0) {
165 printf("Error: D:0x%x C:%d H:%d S:%d\n",
166 dosdev, cyl, head, sec);
172 ra_end = sector + nsec;
174 return (ra_buf + (sector - ra_first) * BPS);