inode.c revision 1.6 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1980, 1986 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.5 mycroft /*static char sccsid[] = "from: @(#)inode.c 5.18 (Berkeley) 3/19/91";*/
36 1.6 cgd static char rcsid[] = "$Id: inode.c,v 1.6 1994/04/18 06:08:27 cgd Exp $";
37 1.1 cgd #endif /* not lint */
38 1.1 cgd
39 1.1 cgd #include <sys/param.h>
40 1.1 cgd #include <ufs/dinode.h>
41 1.1 cgd #include <ufs/fs.h>
42 1.1 cgd #include <ufs/dir.h>
43 1.6 cgd #ifndef SMALL
44 1.1 cgd #include <pwd.h>
45 1.6 cgd #endif
46 1.1 cgd #include <stdlib.h>
47 1.1 cgd #include <string.h>
48 1.1 cgd #include "fsck.h"
49 1.1 cgd
50 1.1 cgd static ino_t startinum;
51 1.1 cgd
52 1.1 cgd ckinode(dp, idesc)
53 1.1 cgd struct dinode *dp;
54 1.1 cgd register struct inodesc *idesc;
55 1.1 cgd {
56 1.1 cgd register daddr_t *ap;
57 1.1 cgd long ret, n, ndb, offset;
58 1.1 cgd struct dinode dino;
59 1.1 cgd
60 1.1 cgd if (idesc->id_fix != IGNORE)
61 1.1 cgd idesc->id_fix = DONTKNOW;
62 1.1 cgd idesc->id_entryno = 0;
63 1.1 cgd idesc->id_filesize = dp->di_size;
64 1.4 mycroft if ((dp->di_mode & IFMT) == IFBLK || (dp->di_mode & IFMT) == IFCHR ||
65 1.4 mycroft DFASTLINK(*dp))
66 1.1 cgd return (KEEPON);
67 1.1 cgd dino = *dp;
68 1.1 cgd ndb = howmany(dino.di_size, sblock.fs_bsize);
69 1.1 cgd for (ap = &dino.di_db[0]; ap < &dino.di_db[NDADDR]; ap++) {
70 1.1 cgd if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0)
71 1.1 cgd idesc->id_numfrags =
72 1.1 cgd numfrags(&sblock, fragroundup(&sblock, offset));
73 1.1 cgd else
74 1.1 cgd idesc->id_numfrags = sblock.fs_frag;
75 1.1 cgd if (*ap == 0)
76 1.1 cgd continue;
77 1.1 cgd idesc->id_blkno = *ap;
78 1.1 cgd if (idesc->id_type == ADDR)
79 1.1 cgd ret = (*idesc->id_func)(idesc);
80 1.1 cgd else
81 1.1 cgd ret = dirscan(idesc);
82 1.1 cgd if (ret & STOP)
83 1.1 cgd return (ret);
84 1.1 cgd }
85 1.1 cgd idesc->id_numfrags = sblock.fs_frag;
86 1.1 cgd for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
87 1.1 cgd if (*ap) {
88 1.1 cgd idesc->id_blkno = *ap;
89 1.1 cgd ret = iblock(idesc, n,
90 1.1 cgd dino.di_size - sblock.fs_bsize * NDADDR);
91 1.1 cgd if (ret & STOP)
92 1.1 cgd return (ret);
93 1.1 cgd }
94 1.1 cgd }
95 1.1 cgd return (KEEPON);
96 1.1 cgd }
97 1.1 cgd
98 1.1 cgd iblock(idesc, ilevel, isize)
99 1.1 cgd struct inodesc *idesc;
100 1.1 cgd register long ilevel;
101 1.1 cgd u_long isize;
102 1.1 cgd {
103 1.1 cgd register daddr_t *ap;
104 1.1 cgd register daddr_t *aplim;
105 1.1 cgd int i, n, (*func)(), nif, sizepb;
106 1.1 cgd register struct bufarea *bp;
107 1.1 cgd char buf[BUFSIZ];
108 1.1 cgd extern int dirscan(), pass1check();
109 1.1 cgd
110 1.1 cgd if (idesc->id_type == ADDR) {
111 1.1 cgd func = idesc->id_func;
112 1.1 cgd if (((n = (*func)(idesc)) & KEEPON) == 0)
113 1.1 cgd return (n);
114 1.1 cgd } else
115 1.1 cgd func = dirscan;
116 1.1 cgd if (chkrange(idesc->id_blkno, idesc->id_numfrags))
117 1.1 cgd return (SKIP);
118 1.1 cgd bp = getdatablk(idesc->id_blkno, sblock.fs_bsize);
119 1.1 cgd ilevel--;
120 1.1 cgd for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
121 1.1 cgd sizepb *= NINDIR(&sblock);
122 1.1 cgd nif = isize / sizepb + 1;
123 1.1 cgd if (nif > NINDIR(&sblock))
124 1.1 cgd nif = NINDIR(&sblock);
125 1.1 cgd if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
126 1.1 cgd aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
127 1.1 cgd for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
128 1.1 cgd if (*ap == 0)
129 1.1 cgd continue;
130 1.1 cgd (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%lu",
131 1.1 cgd idesc->id_number);
132 1.1 cgd if (dofix(idesc, buf)) {
133 1.1 cgd *ap = 0;
134 1.1 cgd dirty(bp);
135 1.1 cgd }
136 1.1 cgd }
137 1.1 cgd flush(fswritefd, bp);
138 1.1 cgd }
139 1.1 cgd aplim = &bp->b_un.b_indir[nif];
140 1.1 cgd for (ap = bp->b_un.b_indir, i = 1; ap < aplim; ap++, i++) {
141 1.1 cgd if (*ap) {
142 1.1 cgd idesc->id_blkno = *ap;
143 1.1 cgd if (ilevel > 0)
144 1.1 cgd n = iblock(idesc, ilevel, isize - i * sizepb);
145 1.1 cgd else
146 1.1 cgd n = (*func)(idesc);
147 1.1 cgd if (n & STOP) {
148 1.1 cgd bp->b_flags &= ~B_INUSE;
149 1.1 cgd return (n);
150 1.1 cgd }
151 1.1 cgd }
152 1.1 cgd }
153 1.1 cgd bp->b_flags &= ~B_INUSE;
154 1.1 cgd return (KEEPON);
155 1.1 cgd }
156 1.1 cgd
157 1.1 cgd /*
158 1.1 cgd * Check that a block in a legal block number.
159 1.1 cgd * Return 0 if in range, 1 if out of range.
160 1.1 cgd */
161 1.1 cgd chkrange(blk, cnt)
162 1.1 cgd daddr_t blk;
163 1.1 cgd int cnt;
164 1.1 cgd {
165 1.1 cgd register int c;
166 1.1 cgd
167 1.1 cgd if ((unsigned)(blk + cnt) > maxfsblock)
168 1.1 cgd return (1);
169 1.1 cgd c = dtog(&sblock, blk);
170 1.1 cgd if (blk < cgdmin(&sblock, c)) {
171 1.1 cgd if ((blk + cnt) > cgsblock(&sblock, c)) {
172 1.1 cgd if (debug) {
173 1.1 cgd printf("blk %ld < cgdmin %ld;",
174 1.1 cgd blk, cgdmin(&sblock, c));
175 1.1 cgd printf(" blk + cnt %ld > cgsbase %ld\n",
176 1.1 cgd blk + cnt, cgsblock(&sblock, c));
177 1.1 cgd }
178 1.1 cgd return (1);
179 1.1 cgd }
180 1.1 cgd } else {
181 1.1 cgd if ((blk + cnt) > cgbase(&sblock, c+1)) {
182 1.1 cgd if (debug) {
183 1.1 cgd printf("blk %ld >= cgdmin %ld;",
184 1.1 cgd blk, cgdmin(&sblock, c));
185 1.1 cgd printf(" blk + cnt %ld > sblock.fs_fpg %ld\n",
186 1.1 cgd blk+cnt, sblock.fs_fpg);
187 1.1 cgd }
188 1.1 cgd return (1);
189 1.1 cgd }
190 1.1 cgd }
191 1.1 cgd return (0);
192 1.1 cgd }
193 1.1 cgd
194 1.1 cgd /*
195 1.1 cgd * General purpose interface for reading inodes.
196 1.1 cgd */
197 1.1 cgd struct dinode *
198 1.1 cgd ginode(inumber)
199 1.1 cgd ino_t inumber;
200 1.1 cgd {
201 1.1 cgd daddr_t iblk;
202 1.1 cgd
203 1.1 cgd if (inumber < ROOTINO || inumber > maxino)
204 1.1 cgd errexit("bad inode number %d to ginode\n", inumber);
205 1.1 cgd if (startinum == 0 ||
206 1.1 cgd inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
207 1.1 cgd iblk = itod(&sblock, inumber);
208 1.1 cgd if (pbp != 0)
209 1.1 cgd pbp->b_flags &= ~B_INUSE;
210 1.1 cgd pbp = getdatablk(iblk, sblock.fs_bsize);
211 1.1 cgd startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
212 1.1 cgd }
213 1.1 cgd return (&pbp->b_un.b_dinode[inumber % INOPB(&sblock)]);
214 1.1 cgd }
215 1.1 cgd
216 1.1 cgd /*
217 1.1 cgd * Special purpose version of ginode used to optimize first pass
218 1.1 cgd * over all the inodes in numerical order.
219 1.1 cgd */
220 1.1 cgd ino_t nextino, lastinum;
221 1.1 cgd long readcnt, readpercg, fullcnt, inobufsize, partialcnt, partialsize;
222 1.1 cgd struct dinode *inodebuf;
223 1.1 cgd
224 1.1 cgd struct dinode *
225 1.1 cgd getnextinode(inumber)
226 1.1 cgd ino_t inumber;
227 1.1 cgd {
228 1.1 cgd long size;
229 1.1 cgd daddr_t dblk;
230 1.1 cgd static struct dinode *dp;
231 1.1 cgd
232 1.1 cgd if (inumber != nextino++ || inumber > maxino)
233 1.1 cgd errexit("bad inode number %d to nextinode\n", inumber);
234 1.1 cgd if (inumber >= lastinum) {
235 1.1 cgd readcnt++;
236 1.1 cgd dblk = fsbtodb(&sblock, itod(&sblock, lastinum));
237 1.1 cgd if (readcnt % readpercg == 0) {
238 1.1 cgd size = partialsize;
239 1.1 cgd lastinum += partialcnt;
240 1.1 cgd } else {
241 1.1 cgd size = inobufsize;
242 1.1 cgd lastinum += fullcnt;
243 1.1 cgd }
244 1.1 cgd (void)bread(fsreadfd, (char *)inodebuf, dblk, size); /* ??? */
245 1.1 cgd dp = inodebuf;
246 1.1 cgd }
247 1.1 cgd return (dp++);
248 1.1 cgd }
249 1.1 cgd
250 1.1 cgd resetinodebuf()
251 1.1 cgd {
252 1.1 cgd
253 1.1 cgd startinum = 0;
254 1.1 cgd nextino = 0;
255 1.1 cgd lastinum = 0;
256 1.1 cgd readcnt = 0;
257 1.1 cgd inobufsize = blkroundup(&sblock, INOBUFSIZE);
258 1.1 cgd fullcnt = inobufsize / sizeof(struct dinode);
259 1.1 cgd readpercg = sblock.fs_ipg / fullcnt;
260 1.1 cgd partialcnt = sblock.fs_ipg % fullcnt;
261 1.1 cgd partialsize = partialcnt * sizeof(struct dinode);
262 1.1 cgd if (partialcnt != 0) {
263 1.1 cgd readpercg++;
264 1.1 cgd } else {
265 1.1 cgd partialcnt = fullcnt;
266 1.1 cgd partialsize = inobufsize;
267 1.1 cgd }
268 1.1 cgd if (inodebuf == NULL &&
269 1.1 cgd (inodebuf = (struct dinode *)malloc((unsigned)inobufsize)) == NULL)
270 1.1 cgd errexit("Cannot allocate space for inode buffer\n");
271 1.1 cgd while (nextino < ROOTINO)
272 1.1 cgd (void)getnextinode(nextino);
273 1.1 cgd }
274 1.1 cgd
275 1.1 cgd freeinodebuf()
276 1.1 cgd {
277 1.1 cgd
278 1.1 cgd if (inodebuf != NULL)
279 1.1 cgd free((char *)inodebuf);
280 1.1 cgd inodebuf = NULL;
281 1.1 cgd }
282 1.1 cgd
283 1.1 cgd /*
284 1.1 cgd * Routines to maintain information about directory inodes.
285 1.1 cgd * This is built during the first pass and used during the
286 1.1 cgd * second and third passes.
287 1.1 cgd *
288 1.1 cgd * Enter inodes into the cache.
289 1.1 cgd */
290 1.1 cgd cacheino(dp, inumber)
291 1.1 cgd register struct dinode *dp;
292 1.1 cgd ino_t inumber;
293 1.1 cgd {
294 1.1 cgd register struct inoinfo *inp;
295 1.1 cgd struct inoinfo **inpp;
296 1.1 cgd unsigned int blks;
297 1.1 cgd
298 1.1 cgd blks = howmany(dp->di_size, sblock.fs_bsize);
299 1.1 cgd if (blks > NDADDR)
300 1.1 cgd blks = NDADDR + NIADDR;
301 1.1 cgd inp = (struct inoinfo *)
302 1.1 cgd malloc(sizeof(*inp) + (blks - 1) * sizeof(daddr_t));
303 1.1 cgd if (inp == NULL)
304 1.1 cgd return;
305 1.1 cgd inpp = &inphead[inumber % numdirs];
306 1.1 cgd inp->i_nexthash = *inpp;
307 1.1 cgd *inpp = inp;
308 1.1 cgd inp->i_parent = (ino_t)0;
309 1.1 cgd inp->i_dotdot = (ino_t)0;
310 1.1 cgd inp->i_number = inumber;
311 1.1 cgd inp->i_isize = dp->di_size;
312 1.1 cgd inp->i_numblks = blks * sizeof(daddr_t);
313 1.1 cgd bcopy((char *)&dp->di_db[0], (char *)&inp->i_blks[0],
314 1.1 cgd (size_t)inp->i_numblks);
315 1.1 cgd if (inplast == listmax) {
316 1.1 cgd listmax += 100;
317 1.1 cgd inpsort = (struct inoinfo **)realloc((char *)inpsort,
318 1.1 cgd (unsigned)listmax * sizeof(struct inoinfo *));
319 1.1 cgd if (inpsort == NULL)
320 1.1 cgd errexit("cannot increase directory list");
321 1.1 cgd }
322 1.1 cgd inpsort[inplast++] = inp;
323 1.1 cgd }
324 1.1 cgd
325 1.1 cgd /*
326 1.1 cgd * Look up an inode cache structure.
327 1.1 cgd */
328 1.1 cgd struct inoinfo *
329 1.1 cgd getinoinfo(inumber)
330 1.1 cgd ino_t inumber;
331 1.1 cgd {
332 1.1 cgd register struct inoinfo *inp;
333 1.1 cgd
334 1.1 cgd for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
335 1.1 cgd if (inp->i_number != inumber)
336 1.1 cgd continue;
337 1.1 cgd return (inp);
338 1.1 cgd }
339 1.1 cgd errexit("cannot find inode %d\n", inumber);
340 1.1 cgd return ((struct inoinfo *)0);
341 1.1 cgd }
342 1.1 cgd
343 1.1 cgd /*
344 1.1 cgd * Clean up all the inode cache structure.
345 1.1 cgd */
346 1.1 cgd inocleanup()
347 1.1 cgd {
348 1.1 cgd register struct inoinfo **inpp;
349 1.1 cgd
350 1.1 cgd if (inphead == NULL)
351 1.1 cgd return;
352 1.1 cgd for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
353 1.1 cgd free((char *)(*inpp));
354 1.1 cgd free((char *)inphead);
355 1.1 cgd free((char *)inpsort);
356 1.1 cgd inphead = inpsort = NULL;
357 1.1 cgd }
358 1.1 cgd
359 1.1 cgd inodirty()
360 1.1 cgd {
361 1.1 cgd
362 1.1 cgd dirty(pbp);
363 1.1 cgd }
364 1.1 cgd
365 1.1 cgd clri(idesc, type, flag)
366 1.1 cgd register struct inodesc *idesc;
367 1.1 cgd char *type;
368 1.1 cgd int flag;
369 1.1 cgd {
370 1.1 cgd register struct dinode *dp;
371 1.1 cgd
372 1.1 cgd dp = ginode(idesc->id_number);
373 1.1 cgd if (flag == 1) {
374 1.1 cgd pwarn("%s %s", type,
375 1.1 cgd (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE");
376 1.1 cgd pinode(idesc->id_number);
377 1.1 cgd }
378 1.1 cgd if (preen || reply("CLEAR") == 1) {
379 1.1 cgd if (preen)
380 1.1 cgd printf(" (CLEARED)\n");
381 1.1 cgd n_files--;
382 1.1 cgd (void)ckinode(dp, idesc);
383 1.1 cgd clearinode(dp);
384 1.1 cgd statemap[idesc->id_number] = USTATE;
385 1.1 cgd inodirty();
386 1.1 cgd }
387 1.1 cgd }
388 1.1 cgd
389 1.1 cgd findname(idesc)
390 1.1 cgd struct inodesc *idesc;
391 1.1 cgd {
392 1.1 cgd register struct direct *dirp = idesc->id_dirp;
393 1.1 cgd
394 1.1 cgd if (dirp->d_ino != idesc->id_parent)
395 1.1 cgd return (KEEPON);
396 1.1 cgd bcopy(dirp->d_name, idesc->id_name, (size_t)dirp->d_namlen + 1);
397 1.1 cgd return (STOP|FOUND);
398 1.1 cgd }
399 1.1 cgd
400 1.1 cgd findino(idesc)
401 1.1 cgd struct inodesc *idesc;
402 1.1 cgd {
403 1.1 cgd register struct direct *dirp = idesc->id_dirp;
404 1.1 cgd
405 1.1 cgd if (dirp->d_ino == 0)
406 1.1 cgd return (KEEPON);
407 1.1 cgd if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
408 1.1 cgd dirp->d_ino >= ROOTINO && dirp->d_ino <= maxino) {
409 1.1 cgd idesc->id_parent = dirp->d_ino;
410 1.1 cgd return (STOP|FOUND);
411 1.1 cgd }
412 1.1 cgd return (KEEPON);
413 1.1 cgd }
414 1.1 cgd
415 1.1 cgd pinode(ino)
416 1.1 cgd ino_t ino;
417 1.1 cgd {
418 1.1 cgd register struct dinode *dp;
419 1.1 cgd register char *p;
420 1.1 cgd struct passwd *pw;
421 1.1 cgd char *ctime();
422 1.1 cgd
423 1.1 cgd printf(" I=%lu ", ino);
424 1.1 cgd if (ino < ROOTINO || ino > maxino)
425 1.1 cgd return;
426 1.1 cgd dp = ginode(ino);
427 1.1 cgd printf(" OWNER=");
428 1.6 cgd #ifndef SMALL
429 1.1 cgd if ((pw = getpwuid((int)dp->di_uid)) != 0)
430 1.1 cgd printf("%s ", pw->pw_name);
431 1.1 cgd else
432 1.6 cgd #endif
433 1.1 cgd printf("%u ", (unsigned)dp->di_uid);
434 1.1 cgd printf("MODE=%o\n", dp->di_mode);
435 1.1 cgd if (preen)
436 1.1 cgd printf("%s: ", devname);
437 1.1 cgd printf("SIZE=%lu ", dp->di_size);
438 1.1 cgd p = ctime(&dp->di_mtime);
439 1.1 cgd printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
440 1.1 cgd }
441 1.1 cgd
442 1.1 cgd blkerror(ino, type, blk)
443 1.1 cgd ino_t ino;
444 1.1 cgd char *type;
445 1.1 cgd daddr_t blk;
446 1.1 cgd {
447 1.1 cgd
448 1.1 cgd pfatal("%ld %s I=%lu", blk, type, ino);
449 1.1 cgd printf("\n");
450 1.1 cgd switch (statemap[ino]) {
451 1.1 cgd
452 1.1 cgd case FSTATE:
453 1.1 cgd statemap[ino] = FCLEAR;
454 1.1 cgd return;
455 1.1 cgd
456 1.1 cgd case DSTATE:
457 1.1 cgd statemap[ino] = DCLEAR;
458 1.1 cgd return;
459 1.1 cgd
460 1.1 cgd case FCLEAR:
461 1.1 cgd case DCLEAR:
462 1.1 cgd return;
463 1.1 cgd
464 1.1 cgd default:
465 1.1 cgd errexit("BAD STATE %d TO BLKERR", statemap[ino]);
466 1.1 cgd /* NOTREACHED */
467 1.1 cgd }
468 1.1 cgd }
469 1.1 cgd
470 1.1 cgd /*
471 1.1 cgd * allocate an unused inode
472 1.1 cgd */
473 1.1 cgd ino_t
474 1.1 cgd allocino(request, type)
475 1.1 cgd ino_t request;
476 1.1 cgd int type;
477 1.1 cgd {
478 1.1 cgd register ino_t ino;
479 1.1 cgd register struct dinode *dp;
480 1.1 cgd
481 1.1 cgd if (request == 0)
482 1.1 cgd request = ROOTINO;
483 1.1 cgd else if (statemap[request] != USTATE)
484 1.1 cgd return (0);
485 1.1 cgd for (ino = request; ino < maxino; ino++)
486 1.1 cgd if (statemap[ino] == USTATE)
487 1.1 cgd break;
488 1.1 cgd if (ino == maxino)
489 1.1 cgd return (0);
490 1.1 cgd switch (type & IFMT) {
491 1.1 cgd case IFDIR:
492 1.1 cgd statemap[ino] = DSTATE;
493 1.1 cgd break;
494 1.1 cgd case IFREG:
495 1.1 cgd case IFLNK:
496 1.1 cgd statemap[ino] = FSTATE;
497 1.1 cgd break;
498 1.1 cgd default:
499 1.1 cgd return (0);
500 1.1 cgd }
501 1.1 cgd dp = ginode(ino);
502 1.1 cgd dp->di_db[0] = allocblk((long)1);
503 1.1 cgd if (dp->di_db[0] == 0) {
504 1.1 cgd statemap[ino] = USTATE;
505 1.1 cgd return (0);
506 1.1 cgd }
507 1.1 cgd dp->di_mode = type;
508 1.1 cgd (void)time(&dp->di_atime);
509 1.1 cgd dp->di_mtime = dp->di_ctime = dp->di_atime;
510 1.1 cgd dp->di_size = sblock.fs_fsize;
511 1.1 cgd dp->di_blocks = btodb(sblock.fs_fsize);
512 1.1 cgd n_files++;
513 1.1 cgd inodirty();
514 1.1 cgd return (ino);
515 1.1 cgd }
516 1.1 cgd
517 1.1 cgd /*
518 1.1 cgd * deallocate an inode
519 1.1 cgd */
520 1.1 cgd freeino(ino)
521 1.1 cgd ino_t ino;
522 1.1 cgd {
523 1.1 cgd struct inodesc idesc;
524 1.1 cgd extern int pass4check();
525 1.1 cgd struct dinode *dp;
526 1.1 cgd
527 1.1 cgd bzero((char *)&idesc, sizeof(struct inodesc));
528 1.1 cgd idesc.id_type = ADDR;
529 1.1 cgd idesc.id_func = pass4check;
530 1.1 cgd idesc.id_number = ino;
531 1.1 cgd dp = ginode(ino);
532 1.1 cgd (void)ckinode(dp, &idesc);
533 1.1 cgd clearinode(dp);
534 1.1 cgd inodirty();
535 1.1 cgd statemap[ino] = USTATE;
536 1.1 cgd n_files--;
537 1.1 cgd }
538