2 * Copyright (c) 1980, 1986 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <afsconfig.h>
19 #include <afs/param.h>
24 #define VICE /* control whether AFS changes are present */
28 #include <sys/param.h>
31 #include <sys/mount.h>
32 #include <sys/vnode.h>
33 #include <ufs/inode.h>
40 #else /* AFS_OSF_ENV */
41 #ifdef AFS_VFSINCL_ENV
43 #include <sys/vnode.h>
45 #include <sys/fs/ufs_inode.h>
46 #include <sys/fs/ufs_fs.h>
48 #include <sys/fs/ufs_fsdir.h>
51 #include <ufs/inode.h>
53 #include <ufs/fsdir.h>
57 #else /* AFS_VFSINCL_ENV */
58 #include <sys/inode.h>
61 #define LONGFILENAMES 1
62 #include <sys/sysmacros.h>
65 #ifdef HAVE_USR_OLD_USR_INCLUDE_NDIR_H
66 #include </usr/old/usr/include/ndir.h>
74 #endif /* AFS_VFSINCL_ENV */
75 #endif /* AFS_OSF_ENV */
77 #include <afs/osi_inode.h>
83 #include <sys/mnttab.h>
84 #include <sys/mntent.h>
88 #endif /* AFS_SUN_ENV */
90 struct bufarea *pbp = 0;
94 register struct inodesc *idesc;
97 long ret, n, ndb, offset;
99 UOFF_T indir_data_blks;
100 extern int pass1check();
106 idesc->id_fix = DONTKNOW;
107 idesc->id_entryno = 0;
108 idesc->id_filesize = dp->di_size;
109 if ((dp->di_mode & IFMT) == IFBLK || (dp->di_mode & IFMT) == IFCHR)
112 if ((dp->di_flags & IC_FASTLINK) != 0) {
115 #endif /* AFS_OSF_ENV */
117 ndb = howmany(dino.di_size, (UOFF_T) sblock.fs_bsize);
121 * Check property lists on pass1
123 if (idesc->id_func == pass1check && dino.di_flags & IC_PROPLIST && *ap) {
124 ret = proplist_scan(dp, idesc);
128 #endif /* AFS_OSF_ENV */
129 for (; ap < &dino.di_db[NDADDR]; ap++) {
130 if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0)
132 numfrags(&sblock, fragroundup(&sblock, offset));
134 idesc->id_numfrags = sblock.fs_frag;
137 idesc->id_blkno = *ap;
138 if (idesc->id_type == ADDR)
139 ret = (*idesc->id_func) (idesc);
141 ret = dirscan(idesc);
145 idesc->id_numfrags = sblock.fs_frag;
146 #if defined(AFS_SUN56_ENV)
148 * indir_data_blks determine the no. of data blocks
149 * in the previous levels. ie., at level 3 it
150 * is the number of data blocks at level 2, 1, and 0.
152 for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
155 indir_data_blks = NDADDR;
158 indir_data_blks = NDADDR + NINDIR(&sblock);
162 NDADDR + NINDIR(&sblock) +
163 (NINDIR(&sblock) * NINDIR(&sblock));
166 idesc->id_blkno = *ap;
169 (u_offset_t) howmany(dino.di_size,
170 (u_offset_t) sblock.fs_bsize) -
177 for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
179 idesc->id_blkno = *ap;
180 ret = iblock(idesc, n, dino.di_size - sblock.fs_bsize * NDADDR);
189 iblock(idesc, ilevel, isize)
190 struct inodesc *idesc;
191 register long ilevel;
194 register daddr_t *ap;
195 register daddr_t *aplim;
196 int i, n, (*func) ();
199 register struct bufarea *bp;
201 extern int dirscan(), pass1check();
203 if (idesc->id_type == ADDR) {
204 func = idesc->id_func;
205 if (((n = (*func) (idesc)) & KEEPON) == 0)
209 if (chkrange(idesc->id_blkno, idesc->id_numfrags))
211 bp = getdatablk(idesc->id_blkno, sblock.fs_bsize);
213 #if defined(AFS_SUN56_ENV)
214 for (sizepb = 1, i = 0; i < ilevel; i++) {
215 sizepb *= (u_offset_t) NINDIR(&sblock);
219 * nif indicates the next "free" pointer (as an array index) in this
220 * indirect block, based on counting the blocks remaining in the
221 * file after subtracting all previously processed blocks.
222 * This figure is based on the size field of the inode.
224 * Note that in normal operation, nif may initially calculated to
225 * be larger than the number of pointers in this block; if that is
226 * the case, nif is limited to the max number of pointers per
229 * Also note that if an inode is inconsistant (has more blocks
230 * allocated to it than the size field would indicate), the sweep
231 * through any indirect blocks directly pointed at by the inode
232 * continues. Since the block offset of any data blocks referenced
233 * by these indirect blocks is greater than the size of the file,
234 * the index nif may be computed as a negative value.
235 * In this case, we reset nif to indicate that all pointers in
236 * this retrieval block should be zeroed and the resulting
237 * unreferenced data and/or retrieval blocks be recovered
238 * through garbage collection later.
240 nif = (offset_t) howmany(isize, sizepb);
241 if (nif > NINDIR(&sblock))
242 nif = NINDIR(&sblock);
246 for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
247 sizepb *= (UOFF_T) NINDIR(&sblock);
248 nif = isize / sizepb + 1;
249 if (nif > NINDIR(&sblock))
250 nif = NINDIR(&sblock);
252 if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
253 aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
254 for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
257 (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%d",
259 if (dofix(idesc, buf)) {
264 flush(fswritefd, bp);
266 aplim = &bp->b_un.b_indir[nif];
267 for (ap = bp->b_un.b_indir, i = 1; ap < aplim; ap++, i++) {
269 idesc->id_blkno = *ap;
271 #if defined(AFS_SUN56_ENV)
272 n = iblock(idesc, ilevel, isize);
274 * each iteration decrease "remaining block
275 * count" by however many blocks were accessible
276 * by a pointer at this indirect block level.
280 n = iblock(idesc, ilevel, isize - i * sizepb);
285 bp->b_flags &= ~B_INUSE;
290 bp->b_flags &= ~B_INUSE;
295 * Check that a block in a legal block number.
296 * Return 0 if in range, 1 if out of range.
304 if ((unsigned)(blk + cnt) > maxfsblock)
306 c = dtog(&sblock, blk);
307 if (blk < cgdmin(&sblock, c)) {
308 if ((blk + cnt) > cgsblock(&sblock, c)) {
310 printf("blk %d < cgdmin %d;", blk, cgdmin(&sblock, c));
311 printf(" blk + cnt %d > cgsbase %d\n", blk + cnt,
312 cgsblock(&sblock, c));
317 if ((blk + cnt) > cgbase(&sblock, c + 1)) {
319 printf("blk %d >= cgdmin %d;", blk, cgdmin(&sblock, c));
320 printf(" blk + cnt %d > sblock.fs_fpg %d\n", blk + cnt,
335 if (inumber < ROOTINO || inumber > maxino)
336 errexit("bad inode number %d to ginode\n", inumber);
337 if (mlk_startinum == 0 || inumber < mlk_startinum
338 || inumber >= mlk_startinum + INOPB(&sblock)) {
339 iblk = itod(&sblock, inumber);
341 pbp->b_flags &= ~B_INUSE;
342 pbp = getdatablk(iblk, sblock.fs_bsize);
343 mlk_startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
345 return (&pbp->b_un.b_dinode[inumber % INOPB(&sblock)]);
351 register struct inoinfo **inpp;
355 for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
356 free((char *)(*inpp));
357 free((char *)inphead);
358 free((char *)inpsort);
359 inphead = inpsort = NULL;
369 clri(idesc, type, flag)
370 register struct inodesc *idesc;
374 register struct dinode *dp;
375 #if defined(ACLS) && defined(AFS_HPUX_ENV)
376 struct inodesc cidesc;
379 dp = ginode(idesc->id_number);
381 pwarn("%s %s", type, (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE");
382 pinode(idesc->id_number);
383 #if defined(ACLS) && defined(AFS_HPUX_ENV)
384 } else if (flag == 2) {
385 pwarn("%s %s", type, "CONTINUATION INODE ");
386 printf(" I=%u ", idesc->id_number);
389 if (preen || reply("CLEAR") == 1) {
391 printf(" (CLEARED)\n");
392 #if defined(ACLS) && defined(AFS_HPUX_ENV)
399 * If there is a CI associated with this inode, we must
402 if (statemap[idesc->id_number] & HASCINODE) {
403 if (!(dp->di_contin < ROOTINO || dp->di_contin > maxino))
404 cidesc.id_number = dp->di_contin;
405 clri(&cidesc, "UNREF", 2);
410 (void)ckinode(dp, idesc);
416 statemap[idesc->id_number] = USTATE;
422 struct inodesc *idesc;
424 register struct direct *dirp = idesc->id_dirp;
426 if (dirp->d_ino != idesc->id_parent)
428 memcpy(idesc->id_name, dirp->d_name, (int)dirp->d_namlen + 1);
429 return (STOP | FOUND);
433 struct inodesc *idesc;
435 register struct direct *dirp = idesc->id_dirp;
437 if (dirp->d_ino == 0)
439 if (strcmp(dirp->d_name, idesc->id_name) == 0 && dirp->d_ino >= ROOTINO
440 && dirp->d_ino <= maxino) {
441 idesc->id_parent = dirp->d_ino;
442 return (STOP | FOUND);
450 register struct dinode *dp;
455 printf(" I=%u ", ino);
456 if (ino < ROOTINO || ino > maxino)
460 #if defined(AFS_HPUX110_ENV)
466 pwarn("Could not getinode(%d) in pinode.", ino);
469 uid = _GET_D_UID(dp);
470 if (getpw(uid, uidbuf) == 0) {
471 for (p = uidbuf; *p != ':'; p++);
473 printf("%s ", uidbuf);
478 #else /* AFS_HPUX110_ENV */
479 #if defined(AFS_HPUX102_ENV)
480 if ((pw = getpwuid(_GET_D_UID(dp))) != 0)
481 printf("%s ", pw->pw_name);
483 printf("%d ", _GET_D_UID(dp));
484 #else /* AFS_HPUX102_ENV */
485 if ((pw = getpwuid((int)dp->di_uid)) != 0)
486 printf("%s ", pw->pw_name);
488 printf("%d ", dp->di_uid);
489 #endif /* else AFS_HPUX102_ENV */
490 #endif /* else AFS_HPUX110_ENV */
491 printf("MODE=%o\n", dp->di_mode);
493 printf("%s: ", devname);
494 #if defined(AFS_SUN56_ENV)
495 printf("SIZE=%" AFS_INT64_FMT " ", dp->di_size);
497 printf("SIZE=%ld ", dp->di_size);
499 p = ctime(&dp->di_mtime);
500 printf("MTIME=%12.12s %4.4s ", p + 4, p + 20);
503 blkerror(ino, type, blk)
509 pfatal("%ld %s I=%u", blk, type, ino);
511 switch (statemap[ino]) {
517 #if defined(ACLS) && defined(AFS_HPUX_ENV)
519 * Keep the continuation inode info
521 if (statemap[ino] & HASCINODE)
522 statemap[ino] = FCLEAR | HASCINODE;
524 statemap[ino] = FCLEAR;
526 statemap[ino] = FCLEAR;
531 #if defined(ACLS) && defined(AFS_HPUX_ENV)
533 * Keep the continuation inode info
535 if (statemap[ino] & HASCINODE)
536 statemap[ino] = DCLEAR | HASCINODE;
538 statemap[ino] = DCLEAR;
540 statemap[ino] = DCLEAR;
549 errexit("BAD STATE %d TO BLKERR", statemap[ino]);
555 * allocate an unused inode
558 allocino(request, type)
563 register struct dinode *dp;
567 else if (statemap[request] != USTATE)
569 for (ino = request; ino < maxino; ino++)
570 if (statemap[ino] == USTATE)
574 switch (type & IFMT) {
576 statemap[ino] = DSTATE;
580 statemap[ino] = FSTATE;
586 dp->di_db[0] = allocblk((long)1);
587 if (dp->di_db[0] == 0) {
588 statemap[ino] = USTATE;
593 dp->di_mtime = dp->di_ctime = dp->di_atime;
594 dp->di_size = sblock.fs_fsize;
595 dp->di_blocks = btodb(sblock.fs_fsize);
603 * deallocate an inode
608 struct inodesc idesc;
609 extern int pass4check();
612 memset((char *)&idesc, 0, sizeof(struct inodesc));
613 idesc.id_type = ADDR;
614 idesc.id_func = pass4check;
615 idesc.id_number = ino;
617 (void)ckinode(dp, &idesc);
624 statemap[ino] = USTATE;