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:36:34 rpd
27 * $FreeBSD: src/sys/i386/boot/biosboot/sys.c,v 1.22 1999/08/28 00:43:14 peter Exp $
31 #include <sys/dirent.h>
32 #include <sys/reboot.h>
35 /* #define BUFSIZE 4096 */
36 #define BUFSIZE MAXBSIZE
38 static char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
41 static char biosdrivedigit;
44 #define MAPBUFSIZE BUFSIZE
45 static char buf[BUFSIZE], fsbuf[BUFSIZE], iobuf[BUFSIZE];
47 static char mapbuf[MAPBUFSIZE];
53 #define STARTBYTE 8192 /* Where on the media the kernel starts */
56 static int block_map(int file_block);
57 static int find(char *path);
60 xread(char *addr, int size)
67 pcpy(buf, addr, count);
75 read(char *buffer, int count)
81 while (count > 0 && poff < inode.i_size) {
83 off = blkoff(fs_copy, poff);
84 logno = lblkno(fs_copy, poff);
85 cnt2 = size = blksize(fs_copy, &inode, logno);
86 bnum2 = fsbtodb(fs_copy, block_map(logno)) + boff;
87 if ( (!off) && (size <= count)) {
88 devread(buffer, bnum2, cnt2);
93 devread(iobuf, bnum2, cnt2);
94 bcopy(iobuf+off, buffer, size);
103 read(char *buffer, int count)
105 int cnt, bnum, off, size;
107 off = STARTBYTE + poff;
110 /* Read any unaligned bit at the front */
116 devread(iobuf, off >> 9, 512);
117 bcopy(iobuf+cnt, buffer, size);
122 size = count & (~511);
123 if (size && (off & (~511))) {
124 devread(buffer, off >> 9, size);
130 devread(iobuf, off >> 9, 512);
131 bcopy(iobuf, buffer, count);
140 int block, off, loc, ino = ROOTINO;
144 list_only = (path[0] == '?' && path[1] == '\0');
146 devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize);
147 bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb],
148 (void *)&inode.i_din,
149 sizeof (struct dinode));
154 if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
156 for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
160 if (loc >= inode.i_size) {
168 if (!(off = blkoff(fs, loc))) {
169 block = lblkno(fs, loc);
170 devread(iobuf, fsbtodb(fs, block_map(block)) + boff,
171 blksize(fs, &inode, block));
173 dp = (struct dirent *)(iobuf + off);
175 if (dp->d_fileno && list_only)
176 printf("%s ", dp->d_name);
177 } while (!dp->d_fileno || strcmp(path, dp->d_name));
185 block_map(int file_block)
188 if (file_block < NDADDR)
189 return(inode.i_db[file_block]);
190 if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
191 devread(mapbuf, bnum, fs->fs_bsize);
194 return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
201 char **devp, *name0 = name, *cp = name0;
202 int biosdrive, dosdev_copy, ret;
204 /*******************************************************\
205 * If bracket given look for preceding device name *
206 \*******************************************************/
207 while (*cp && *cp!='(')
216 * Look for a BIOS drive number (a leading digit followed
219 biosdrivedigit = '\0';
220 if (*(name0 + 1) == ':' && *name0 >= '0' && *name0 <= '9') {
221 biosdrivedigit = *name0;
227 for (devp = devs; *devp; devp++)
228 if (name0[0] == (*devp)[0] &&
229 name0[1] == (*devp)[1])
233 printf("Unknown device\n");
238 /*******************************************************\
239 * Look inside brackets for unit number, and partition *
240 \*******************************************************/
242 * Allow any valid digit as the unit number, as the BIOS
243 * will complain if the unit number is out of range.
244 * Restricting the range here prevents the possibilty of using
245 * BIOSes that support more than 2 units.
246 * XXX Bad values may cause strange errors, need to check if
247 * what happens when a value out of range is supplied.
249 if (*cp >= '0' && *cp <= '9')
251 if (!*cp || (*cp == ',' && !*++cp))
253 if (*cp >= 'a' && *cp <= 'p')
255 while (*cp && *cp++!=')') ;
259 biosdrive = biosdrivedigit - '0';
260 if (biosdrivedigit == '\0') {
265 biosdrive += BOOT_HD_BIAS;
272 dosdev_copy = biosdrive | 0x80;
275 dosdev_copy = biosdrive;
278 printf("Unknown device\n");
281 dosdev = dosdev_copy;
283 /* XXX this is useful, but misplaced. */
284 printf("dosdev= %x, biosdrive = %d, unit = %d, maj = %d\n",
285 dosdev_copy, biosdrive, unit, maj);
288 /***********************************************\
289 * Now we know the disk unit and part, *
290 * Load disk info, (open the device) *
291 \***********************************************/
296 /***********************************************\
297 * Load Filesystem info (mount the device) *
298 \***********************************************/
299 devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE);
300 /***********************************************\
301 * Find the actual FILE on the mounted device *
302 \***********************************************/