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/boot/pc98/boot2/sys.c,v 1.5 2003/09/08 09:11:20 obrien Exp $
28 * $DragonFly: src/sys/boot/pc98/boot2/Attic/sys.c,v 1.3 2003/11/10 06:08:38 dillon Exp $
32 * Ported to PC-9801 by Yoshio Kimura
36 #include <sys/dirent.h>
39 /* #define BUFSIZE 4096 */
40 #define BUFSIZE MAXBSIZE
41 static char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
44 static char biosdrivedigit;
47 #define MAPBUFSIZE BUFSIZE
48 static char buf[BUFSIZE], fsbuf[BUFSIZE], iobuf[BUFSIZE];
50 static char mapbuf[MAPBUFSIZE];
56 #define STARTBYTE 8192 /* Where on the media the kernel starts */
59 static int block_map(int file_block);
60 static int find(char *path);
63 xread(char *addr, int size)
70 pcpy(buf, addr, count);
78 read(char *buffer, int count)
84 while (count > 0 && poff < inode.i_size) {
86 off = blkoff(fs_copy, poff);
87 logno = lblkno(fs_copy, poff);
88 cnt2 = size = blksize(fs_copy, &inode, logno);
89 bnum2 = fsbtodb(fs_copy, block_map(logno)) + boff;
90 if ( (!off) && (size <= count)) {
91 devread(buffer, bnum2, cnt2);
96 devread(iobuf, bnum2, cnt2);
97 bcopy(iobuf+off, buffer, size);
106 read(char *buffer, int count)
108 int cnt, bnum, off, size;
110 off = STARTBYTE + poff;
113 /* Read any unaligned bit at the front */
119 devread(iobuf, off >> 9, 512);
120 bcopy(iobuf+cnt, buffer, size);
125 size = count & (~511);
126 if (size && (off & (~511))) {
127 devread(buffer, off >> 9, size);
133 devread(iobuf, off >> 9, 512);
134 bcopy(iobuf, buffer, count);
143 int block, off, loc, ino = ROOTINO;
147 list_only = (path[0] == '?' && path[1] == '\0');
149 devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize);
150 bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb],
151 (void *)&inode.i_din,
152 sizeof (struct dinode));
157 if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
159 for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
163 if (loc >= inode.i_size) {
171 if (!(off = blkoff(fs, loc))) {
172 block = lblkno(fs, loc);
173 devread(iobuf, fsbtodb(fs, block_map(block)) + boff,
174 blksize(fs, &inode, block));
176 dp = (struct dirent *)(iobuf + off);
178 if (dp->d_fileno && list_only)
179 printf("%s ", dp->d_name);
180 } while (!dp->d_fileno || strcmp(path, dp->d_name));
188 block_map(int file_block)
191 if (file_block < NDADDR)
192 return(inode.i_db[file_block]);
193 if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
194 devread(mapbuf, bnum, fs->fs_bsize);
197 return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
204 char **devp, *name0 = name, *cp = name0;
205 int biosdrive, dosdev_copy, ret;
207 /*******************************************************\
208 * If bracket given look for preceding device name *
209 \*******************************************************/
210 while (*cp && *cp!='(')
219 * Look for a BIOS drive number (a leading digit followed
222 biosdrivedigit = '\0';
223 if (*(name0 + 1) == ':' && *name0 >= '0' && *name0 <= '9') {
224 biosdrivedigit = *name0;
230 for (devp = devs; *devp; devp++)
231 if (name0[0] == (*devp)[0] &&
232 name0[1] == (*devp)[1])
236 printf("Unknown device\n");
241 /*******************************************************\
242 * Look inside brackets for unit number, and partition *
243 \*******************************************************/
245 * Allow any valid digit as the unit number, as the BIOS
246 * will complain if the unit number is out of range.
247 * Restricting the range here prevents the possibilty of using
248 * BIOSes that support more than 2 units.
249 * XXX Bad values may cause strange errors, need to check if
250 * what happens when a value out of range is supplied.
252 if (*cp >= '0' && *cp <= '9')
254 if (!*cp || (*cp == ',' && !*++cp))
256 if (*cp >= 'a' && *cp <= 'p')
258 while (*cp && *cp++!=')') ;
262 biosdrive = biosdrivedigit - '0';
263 if (biosdrivedigit == '\0') {
265 biosdrive = dosdev & 0x0f;
272 biosdrive += BOOT_HD_BIAS;
279 dosdev_copy = biosdrive | 0xA0; /* SCSI HD or MO */
283 dosdev_copy = biosdrive | 0x80;
288 case 2: /* 1200KB fd */
289 dosdev_copy = (maj << 3) | unit | 0x80;
292 dosdev_copy = biosdrive;
296 case 6: /* 1440KB fd */
297 dosdev_copy = (maj << 3) | unit;
301 printf("Unknown device\n");
304 dosdev = dosdev_copy;
306 /* XXX this is useful, but misplaced. */
307 printf("dosdev= %x, biosdrive = %d, unit = %d, maj = %d\n",
308 dosdev_copy, biosdrive, unit, maj);
311 /***********************************************\
312 * Now we know the disk unit and part, *
313 * Load disk info, (open the device) *
314 \***********************************************/
319 /***********************************************\
320 * Load Filesystem info (mount the device) *
321 \***********************************************/
322 devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE);
323 /***********************************************\
324 * Find the actual FILE on the mounted device *
325 \***********************************************/