2 * Mach Operating System
\r
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
\r
4 * All Rights Reserved.
\r
6 * Permission to use, copy, modify and distribute this software and its
\r
7 * documentation is hereby granted, provided that both the copyright
\r
8 * notice and this permission notice appear in all copies of the
\r
9 * software, derivative works or modified versions, and any portions
\r
10 * thereof, and that both notices appear in supporting documentation.
\r
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
\r
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
\r
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
\r
16 * Carnegie Mellon requests users of this software to return to
\r
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
\r
19 * School of Computer Science
\r
20 * Carnegie Mellon University
\r
21 * Pittsburgh PA 15213-3890
\r
23 * any improvements or extensions that they make and grant Carnegie Mellon
\r
24 * the rights to redistribute these changes.
\r
26 * from: Mach, Revision 2.2 92/04/04 11:36:34 rpd
\r
27 * $FreeBSD: src/sys/i386/boot/dosboot/sys.c,v 1.5 1999/08/28 00:43:25 peter Exp $
\r
28 * $DragonFly: src/sys/i386/boot/dosboot/Attic/sys.c,v 1.2 2003/06/17 04:28:34 dillon Exp $
\r
34 #define bcopy(a,b,c) memcpy(b,a,c)
\r
36 #include "protmod.h"
\r
40 #define BUFSIZE 4096
\r
42 #define MAXBSIZE 8192
\r
44 void ufs_read(char *buffer, long count);
\r
45 static long block_map(long file_block);
\r
47 char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
\r
48 char mapbuf[MAXBSIZE];
\r
51 void xread(unsigned long addr, long size)
\r
53 long count = BUFSIZE;
\r
57 ufs_read(buf, count);
\r
58 pm_copy(buf, addr, count);
\r
64 void ufs_read(char *buffer, long count)
\r
66 long logno, off, size;
\r
70 off = blkoff(fs, poff);
\r
71 logno = lblkno(fs, poff);
\r
72 cnt2 = size = blksize(fs, &inode, logno);
\r
73 bnum2 = fsbtodb(fs, block_map(logno)) + boff;
\r
76 if ( (!off) && (size <= count))
\r
88 bcopy(iodest+off,buffer,size);
\r
96 static int find(char *path)
\r
99 long block, off, loc, ino = ROOTINO;
\r
101 loop: iodest = iobuf;
\r
102 cnt = fs->fs_bsize;
\r
103 bnum = fsbtodb(fs,itod(fs,ino)) + boff;
\r
105 bcopy(&((struct dinode *)iodest)[ino % fs->fs_inopb],
\r
107 sizeof (struct dinode));
\r
110 while (*path == '/')
\r
112 if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
\r
114 for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
\r
118 if (loc >= inode.i_size)
\r
120 if (!(off = blkoff(fs, loc))) {
\r
121 block = lblkno(fs, loc);
\r
122 cnt = blksize(fs, &inode, block);
\r
123 bnum = fsbtodb(fs, block_map(block)) + boff;
\r
127 dp = (struct direct *)(iodest + off);
\r
128 loc += dp->d_reclen;
\r
129 } while (!dp->d_ino || strcmp(path, dp->d_name));
\r
131 *(path = rest) = ch;
\r
135 static long block_map(long file_block)
\r
137 if (file_block < NDADDR)
\r
138 return(inode.i_db[file_block]);
\r
139 if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
\r
141 cnt = fs->fs_bsize;
\r
145 return (((long *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
\r
148 int openrd(char *name)
\r
152 dosdev = 0x80; /* only 1st HD supported yet */
\r
153 inode.i_dev = dosdev;
\r
154 /***********************************************\
\r
155 * Now we know the disk unit and part, *
\r
156 * Load disk info, (open the device) *
\r
157 \***********************************************/
\r
158 if (devopen()) return 1;
\r
160 /***********************************************\
\r
161 * Load Filesystem info (mount the device) *
\r
162 \***********************************************/
\r
163 iodest = (char *)(fs = (struct fs *)fsbuf);
\r
165 bnum = SBLOCK + boff;
\r
167 /***********************************************\
\r
168 * Find the actual FILE on the mounted device *
\r
169 \***********************************************/
\r
170 if (!find(cp)) return 1;
\r