Commit | Line | Data |
---|---|---|
15637ed4 | 1 | /* |
15637ed4 RG |
2 | * Mach Operating System |
3 | * Copyright (c) 1992, 1991 Carnegie Mellon University | |
4 | * All Rights Reserved. | |
5 | * | |
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. | |
11 | * | |
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. | |
15 | * | |
16 | * Carnegie Mellon requests users of this software to return to | |
17 | * | |
18 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
19 | * School of Computer Science | |
20 | * Carnegie Mellon University | |
21 | * Pittsburgh PA 15213-3890 | |
22 | * | |
23 | * any improvements or extensions that they make and grant Carnegie Mellon | |
24 | * the rights to redistribute these changes. | |
a27f4645 | 25 | * |
e4270b63 RG |
26 | * from: Mach, Revision 2.2 92/04/04 11:36:34 rpd |
27 | * $Id$ | |
15637ed4 RG |
28 | */ |
29 | ||
30 | #include "boot.h" | |
31 | #include <sys/dir.h> | |
32 | #include <sys/reboot.h> | |
33 | ||
34 | /* #define BUFSIZE 4096 */ | |
35 | #define BUFSIZE MAXBSIZE | |
36 | ||
37 | char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE]; | |
38 | ||
39 | int xread(addr, size) | |
40 | char * addr; | |
41 | int size; | |
42 | { | |
43 | int count = BUFSIZE; | |
44 | while (size > 0) { | |
45 | if (BUFSIZE > size) | |
46 | count = size; | |
47 | read(buf, count); | |
48 | pcpy(buf, addr, count); | |
49 | size -= count; | |
50 | addr += count; | |
51 | } | |
52 | } | |
53 | ||
54 | read(buffer, count) | |
55 | int count; | |
56 | char *buffer; | |
57 | { | |
58 | int logno, off, size; | |
59 | int cnt2, bnum2; | |
60 | ||
61 | while (count) { | |
62 | off = blkoff(fs, poff); | |
63 | logno = lblkno(fs, poff); | |
64 | cnt2 = size = blksize(fs, &inode, logno); | |
65 | bnum2 = fsbtodb(fs, block_map(logno)) + boff; | |
66 | cnt = cnt2; | |
67 | bnum = bnum2; | |
68 | if ( (!off) && (size <= count)) | |
69 | { | |
70 | iodest = buffer; | |
71 | devread(); | |
72 | } | |
73 | else | |
74 | { | |
75 | iodest = iobuf; | |
76 | size -= off; | |
77 | if (size > count) | |
78 | size = count; | |
79 | devread(); | |
80 | bcopy(iodest+off,buffer,size); | |
81 | } | |
82 | buffer += size; | |
83 | count -= size; | |
84 | poff += size; | |
85 | } | |
86 | } | |
87 | ||
88 | find(path) | |
89 | char *path; | |
90 | { | |
91 | char *rest, ch; | |
92 | int block, off, loc, ino = ROOTINO; | |
93 | struct direct *dp; | |
94 | loop: iodest = iobuf; | |
95 | cnt = fs->fs_bsize; | |
96 | bnum = fsbtodb(fs,itod(fs,ino)) + boff; | |
97 | devread(); | |
98 | bcopy(&((struct dinode *)iodest)[ino % fs->fs_inopb], | |
99 | &inode.i_din, | |
100 | sizeof (struct dinode)); | |
101 | if (!*path) | |
102 | return 1; | |
103 | while (*path == '/') | |
104 | path++; | |
105 | if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR)) | |
106 | return 0; | |
107 | for (rest = path; (ch = *rest) && ch != '/'; rest++) ; | |
108 | *rest = 0; | |
109 | loc = 0; | |
110 | do { | |
111 | if (loc >= inode.i_size) | |
112 | return 0; | |
113 | if (!(off = blkoff(fs, loc))) { | |
114 | block = lblkno(fs, loc); | |
115 | cnt = blksize(fs, &inode, block); | |
116 | bnum = fsbtodb(fs, block_map(block)) + boff; | |
117 | iodest = iobuf; | |
118 | devread(); | |
119 | } | |
120 | dp = (struct direct *)(iodest + off); | |
121 | loc += dp->d_reclen; | |
122 | } while (!dp->d_ino || strcmp(path, dp->d_name)); | |
123 | ino = dp->d_ino; | |
124 | *(path = rest) = ch; | |
125 | goto loop; | |
126 | } | |
127 | ||
128 | char mapbuf[MAXBSIZE]; | |
129 | int mapblock = 0; | |
130 | ||
131 | block_map(file_block) | |
132 | int file_block; | |
133 | { | |
134 | if (file_block < NDADDR) | |
135 | return(inode.i_db[file_block]); | |
136 | if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) { | |
137 | iodest = mapbuf; | |
138 | cnt = fs->fs_bsize; | |
139 | devread(); | |
140 | mapblock = bnum; | |
141 | } | |
142 | return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]); | |
143 | } | |
144 | ||
145 | openrd() | |
146 | { | |
147 | char **devp, *cp = name; | |
148 | /*******************************************************\ | |
149 | * If bracket given look for preceding device name * | |
150 | \*******************************************************/ | |
151 | while (*cp && *cp!='(') | |
152 | cp++; | |
153 | if (!*cp) | |
154 | { | |
155 | cp = name; | |
156 | } | |
157 | else | |
158 | { | |
159 | if (cp++ != name) | |
160 | { | |
161 | for (devp = devs; *devp; devp++) | |
162 | if (name[0] == (*devp)[0] && | |
163 | name[1] == (*devp)[1]) | |
164 | break; | |
165 | if (!*devp) | |
166 | { | |
167 | printf("Unknown device\n"); | |
168 | return 1; | |
169 | } | |
170 | maj = devp-devs; | |
171 | } | |
172 | /*******************************************************\ | |
173 | * Look inside brackets for unit number, and partition * | |
174 | \*******************************************************/ | |
175 | if (*cp >= '0' && *cp <= '9') | |
176 | if ((unit = *cp++ - '0') > 1) | |
177 | { | |
178 | printf("Bad unit\n"); | |
179 | return 1; | |
180 | } | |
181 | if (!*cp || (*cp == ',' && !*++cp)) | |
182 | return 1; | |
183 | if (*cp >= 'a' && *cp <= 'p') | |
184 | part = *cp++ - 'a'; | |
185 | while (*cp && *cp++!=')') ; | |
186 | if (!*cp) | |
187 | return 1; | |
188 | } | |
189 | switch(maj) | |
190 | { | |
191 | case 1: | |
192 | dosdev = unit | 0x80; | |
193 | unit = 0; | |
194 | break; | |
195 | case 0: | |
196 | case 4: | |
197 | dosdev = unit | 0x80; | |
198 | break; | |
199 | case 2: | |
200 | dosdev = unit; | |
201 | break; | |
202 | case 3: | |
203 | printf("Wangtek unsupported\n"); | |
204 | return 1; | |
205 | break; | |
206 | } | |
207 | inode.i_dev = dosdev; | |
208 | /***********************************************\ | |
209 | * Now we know the disk unit and part, * | |
210 | * Load disk info, (open the device) * | |
211 | \***********************************************/ | |
212 | if (devopen()) | |
213 | return 1; | |
214 | ||
215 | /***********************************************\ | |
216 | * Load Filesystem info (mount the device) * | |
217 | \***********************************************/ | |
218 | iodest = (char *)(fs = (struct fs *)fsbuf); | |
219 | cnt = SBSIZE; | |
220 | bnum = SBLOCK + boff; | |
221 | devread(); | |
222 | /***********************************************\ | |
223 | * Find the actual FILE on the mounted device * | |
224 | \***********************************************/ | |
225 | if (!find(cp)) | |
226 | { | |
227 | return 1; | |
228 | } | |
229 | poff = 0; | |
230 | name = cp; | |
231 | return 0; | |
232 | } |