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 $
28 * $DragonFly: src/sys/i386/boot/biosboot/Attic/sys.c,v 1.2 2003/06/17 04:28:34 dillon Exp $
32 #include <sys/dirent.h>
33 #include <sys/reboot.h>
36 /* #define BUFSIZE 4096 */
37 #define BUFSIZE MAXBSIZE
39 static char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
42 static char biosdrivedigit;
45 #define MAPBUFSIZE BUFSIZE
46 static char buf[BUFSIZE], fsbuf[BUFSIZE], iobuf[BUFSIZE];
48 static char mapbuf[MAPBUFSIZE];
54 #define STARTBYTE 8192 /* Where on the media the kernel starts */
57 static int block_map(int file_block);
58 static int find(char *path);
61 xread(char *addr, int size)
68 pcpy(buf, addr, count);
76 read(char *buffer, int count)
82 while (count > 0 && poff < inode.i_size) {
84 off = blkoff(fs_copy, poff);
85 logno = lblkno(fs_copy, poff);
86 cnt2 = size = blksize(fs_copy, &inode, logno);
87 bnum2 = fsbtodb(fs_copy, block_map(logno)) + boff;
88 if ( (!off) && (size <= count)) {
89 devread(buffer, bnum2, cnt2);
94 devread(iobuf, bnum2, cnt2);
95 bcopy(iobuf+off, buffer, size);
104 read(char *buffer, int count)
106 int cnt, bnum, off, size;
108 off = STARTBYTE + poff;
111 /* Read any unaligned bit at the front */
117 devread(iobuf, off >> 9, 512);
118 bcopy(iobuf+cnt, buffer, size);
123 size = count & (~511);
124 if (size && (off & (~511))) {
125 devread(buffer, off >> 9, size);
131 devread(iobuf, off >> 9, 512);
132 bcopy(iobuf, buffer, count);
141 int block, off, loc, ino = ROOTINO;
145 list_only = (path[0] == '?' && path[1] == '\0');
147 devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize);
148 bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb],
149 (void *)&inode.i_din,
150 sizeof (struct dinode));
155 if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
157 for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
161 if (loc >= inode.i_size) {
169 if (!(off = blkoff(fs, loc))) {
170 block = lblkno(fs, loc);
171 devread(iobuf, fsbtodb(fs, block_map(block)) + boff,
172 blksize(fs, &inode, block));
174 dp = (struct dirent *)(iobuf + off);
176 if (dp->d_fileno && list_only)
177 printf("%s ", dp->d_name);
178 } while (!dp->d_fileno || strcmp(path, dp->d_name));
186 block_map(int file_block)
189 if (file_block < NDADDR)
190 return(inode.i_db[file_block]);
191 if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
192 devread(mapbuf, bnum, fs->fs_bsize);
195 return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
202 char **devp, *name0 = name, *cp = name0;
203 int biosdrive, dosdev_copy, ret;
205 /*******************************************************\
206 * If bracket given look for preceding device name *
207 \*******************************************************/
208 while (*cp && *cp!='(')
217 * Look for a BIOS drive number (a leading digit followed
220 biosdrivedigit = '\0';
221 if (*(name0 + 1) == ':' && *name0 >= '0' && *name0 <= '9') {
222 biosdrivedigit = *name0;
228 for (devp = devs; *devp; devp++)
229 if (name0[0] == (*devp)[0] &&
230 name0[1] == (*devp)[1])
234 printf("Unknown device\n");
239 /*******************************************************\
240 * Look inside brackets for unit number, and partition *
241 \*******************************************************/
243 * Allow any valid digit as the unit number, as the BIOS
244 * will complain if the unit number is out of range.
245 * Restricting the range here prevents the possibilty of using
246 * BIOSes that support more than 2 units.
247 * XXX Bad values may cause strange errors, need to check if
248 * what happens when a value out of range is supplied.
250 if (*cp >= '0' && *cp <= '9')
252 if (!*cp || (*cp == ',' && !*++cp))
254 if (*cp >= 'a' && *cp <= 'p')
256 while (*cp && *cp++!=')') ;
260 biosdrive = biosdrivedigit - '0';
261 if (biosdrivedigit == '\0') {
266 biosdrive += BOOT_HD_BIAS;
273 dosdev_copy = biosdrive | 0x80;
276 dosdev_copy = biosdrive;
279 printf("Unknown device\n");
282 dosdev = dosdev_copy;
284 /* XXX this is useful, but misplaced. */
285 printf("dosdev= %x, biosdrive = %d, unit = %d, maj = %d\n",
286 dosdev_copy, biosdrive, unit, maj);
289 /***********************************************\
290 * Now we know the disk unit and part, *
291 * Load disk info, (open the device) *
292 \***********************************************/
297 /***********************************************\
298 * Load Filesystem info (mount the device) *
299 \***********************************************/
300 devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE);
301 /***********************************************\
302 * Find the actual FILE on the mounted device *
303 \***********************************************/