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>
22 #define VICE /* control whether AFS changes are present */
26 #include <sys/param.h>
29 #include <sys/mount.h>
30 #include <sys/vnode.h>
31 #include <ufs/inode.h>
38 #else /* AFS_OSF_ENV */
39 #ifdef AFS_VFSINCL_ENV
41 #include <sys/vnode.h>
43 #include <sys/fs/ufs_inode.h>
44 #include <sys/fs/ufs_fs.h>
46 #include <sys/fs/ufs_fsdir.h>
49 #include <ufs/inode.h>
51 #include <ufs/fsdir.h>
55 #else /* AFS_VFSINCL_ENV */
56 #include <sys/inode.h>
59 #define LONGFILENAMES 1
60 #include <sys/sysmacros.h>
63 #ifdef HAVE_USR_OLD_USR_INCLUDE_NDIR_H
64 #include </usr/old/usr/include/ndir.h>
72 #endif /* AFS_VFSINCL_ENV */
73 #endif /* AFS_OSF_ENV */
75 #include <afs/osi_inode.h>
81 #include <sys/mnttab.h>
82 #include <sys/mntent.h>
86 #endif /* AFS_SUN_ENV */
88 struct bufarea *pbp = 0;
92 register struct inodesc *idesc;
95 long ret, n, ndb, offset;
97 UOFF_T indir_data_blks;
98 extern int pass1check();
104 idesc->id_fix = DONTKNOW;
105 idesc->id_entryno = 0;
106 idesc->id_filesize = dp->di_size;
107 if ((dp->di_mode & IFMT) == IFBLK || (dp->di_mode & IFMT) == IFCHR)
110 if ((dp->di_flags & IC_FASTLINK) != 0) {
113 #endif /* AFS_OSF_ENV */
115 ndb = howmany(dino.di_size, (UOFF_T) sblock.fs_bsize);
119 * Check property lists on pass1
121 if (idesc->id_func == pass1check && dino.di_flags & IC_PROPLIST && *ap) {
122 ret = proplist_scan(dp, idesc);
126 #endif /* AFS_OSF_ENV */
127 for (; ap < &dino.di_db[NDADDR]; ap++) {
128 if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0)
130 numfrags(&sblock, fragroundup(&sblock, offset));
132 idesc->id_numfrags = sblock.fs_frag;
135 idesc->id_blkno = *ap;
136 if (idesc->id_type == ADDR)
137 ret = (*idesc->id_func) (idesc);
139 ret = dirscan(idesc);
143 idesc->id_numfrags = sblock.fs_frag;
144 #if defined(AFS_SUN56_ENV)
146 * indir_data_blks determine the no. of data blocks
147 * in the previous levels. ie., at level 3 it
148 * is the number of data blocks at level 2, 1, and 0.
150 for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
153 indir_data_blks = NDADDR;
156 indir_data_blks = NDADDR + NINDIR(&sblock);
160 NDADDR + NINDIR(&sblock) +
161 (NINDIR(&sblock) * NINDIR(&sblock));
164 idesc->id_blkno = *ap;
167 (u_offset_t) howmany(dino.di_size,
168 (u_offset_t) sblock.fs_bsize) -
175 for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
177 idesc->id_blkno = *ap;
178 ret = iblock(idesc, n, dino.di_size - sblock.fs_bsize * NDADDR);
187 iblock(idesc, ilevel, isize)
188 struct inodesc *idesc;
189 register long ilevel;
192 register daddr_t *ap;
193 register daddr_t *aplim;
194 int i, n, (*func) ();
197 register struct bufarea *bp;
199 extern int dirscan(), pass1check();
201 if (idesc->id_type == ADDR) {
202 func = idesc->id_func;
203 if (((n = (*func) (idesc)) & KEEPON) == 0)
207 if (chkrange(idesc->id_blkno, idesc->id_numfrags))
209 bp = getdatablk(idesc->id_blkno, sblock.fs_bsize);
211 #if defined(AFS_SUN56_ENV)
212 for (sizepb = 1, i = 0; i < ilevel; i++) {
213 sizepb *= (u_offset_t) NINDIR(&sblock);
217 * nif indicates the next "free" pointer (as an array index) in this
218 * indirect block, based on counting the blocks remaining in the
219 * file after subtracting all previously processed blocks.
220 * This figure is based on the size field of the inode.
222 * Note that in normal operation, nif may initially calculated to
223 * be larger than the number of pointers in this block; if that is
224 * the case, nif is limited to the max number of pointers per
227 * Also note that if an inode is inconsistant (has more blocks
228 * allocated to it than the size field would indicate), the sweep
229 * through any indirect blocks directly pointed at by the inode
230 * continues. Since the block offset of any data blocks referenced
231 * by these indirect blocks is greater than the size of the file,
232 * the index nif may be computed as a negative value.
233 * In this case, we reset nif to indicate that all pointers in
234 * this retrieval block should be zeroed and the resulting
235 * unreferenced data and/or retrieval blocks be recovered
236 * through garbage collection later.
238 nif = (offset_t) howmany(isize, sizepb);
239 if (nif > NINDIR(&sblock))
240 nif = NINDIR(&sblock);
244 for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
245 sizepb *= (UOFF_T) NINDIR(&sblock);
246 nif = isize / sizepb + 1;
247 if (nif > NINDIR(&sblock))
248 nif = NINDIR(&sblock);
250 if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
251 aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
252 for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
255 (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%d",
257 if (dofix(idesc, buf)) {
262 flush(fswritefd, bp);
264 aplim = &bp->b_un.b_indir[nif];
265 for (ap = bp->b_un.b_indir, i = 1; ap < aplim; ap++, i++) {
267 idesc->id_blkno = *ap;
269 #if defined(AFS_SUN56_ENV)
270 n = iblock(idesc, ilevel, isize);
272 * each iteration decrease "remaining block
273 * count" by however many blocks were accessible
274 * by a pointer at this indirect block level.
278 n = iblock(idesc, ilevel, isize - i * sizepb);
283 bp->b_flags &= ~B_INUSE;
288 bp->b_flags &= ~B_INUSE;
293 * Check that a block in a legal block number.
294 * Return 0 if in range, 1 if out of range.
302 if ((unsigned)(blk + cnt) > maxfsblock)
304 c = dtog(&sblock, blk);
305 if (blk < cgdmin(&sblock, c)) {
306 if ((blk + cnt) > cgsblock(&sblock, c)) {
308 printf("blk %d < cgdmin %d;", blk, cgdmin(&sblock, c));
309 printf(" blk + cnt %d > cgsbase %d\n", blk + cnt,
310 cgsblock(&sblock, c));
315 if ((blk + cnt) > cgbase(&sblock, c + 1)) {
317 printf("blk %d >= cgdmin %d;", blk, cgdmin(&sblock, c));
318 printf(" blk + cnt %d > sblock.fs_fpg %d\n", blk + cnt,
333 if (inumber < ROOTINO || inumber > maxino)
334 errexit("bad inode number %d to ginode\n", inumber);
335 if (mlk_startinum == 0 || inumber < mlk_startinum
336 || inumber >= mlk_startinum + INOPB(&sblock)) {
337 iblk = itod(&sblock, inumber);
339 pbp->b_flags &= ~B_INUSE;
340 pbp = getdatablk(iblk, sblock.fs_bsize);
341 mlk_startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
343 return (&pbp->b_un.b_dinode[inumber % INOPB(&sblock)]);
349 register struct inoinfo **inpp;
353 for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
354 free((char *)(*inpp));
355 free((char *)inphead);
356 free((char *)inpsort);
357 inphead = inpsort = NULL;
367 clri(idesc, type, flag)
368 register struct inodesc *idesc;
372 register struct dinode *dp;
373 #if defined(ACLS) && defined(AFS_HPUX_ENV)
374 struct inodesc cidesc;
377 dp = ginode(idesc->id_number);
379 pwarn("%s %s", type, (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE");
380 pinode(idesc->id_number);
381 #if defined(ACLS) && defined(AFS_HPUX_ENV)
382 } else if (flag == 2) {
383 pwarn("%s %s", type, "CONTINUATION INODE ");
384 printf(" I=%u ", idesc->id_number);
387 if (preen || reply("CLEAR") == 1) {
389 printf(" (CLEARED)\n");
390 #if defined(ACLS) && defined(AFS_HPUX_ENV)
397 * If there is a CI associated with this inode, we must
400 if (statemap[idesc->id_number] & HASCINODE) {
401 if (!(dp->di_contin < ROOTINO || dp->di_contin > maxino))
402 cidesc.id_number = dp->di_contin;
403 clri(&cidesc, "UNREF", 2);
408 (void)ckinode(dp, idesc);
414 statemap[idesc->id_number] = USTATE;
420 struct inodesc *idesc;
422 register struct direct *dirp = idesc->id_dirp;
424 if (dirp->d_ino != idesc->id_parent)
426 memcpy(idesc->id_name, dirp->d_name, (int)dirp->d_namlen + 1);
427 return (STOP | FOUND);
431 struct inodesc *idesc;
433 register struct direct *dirp = idesc->id_dirp;
435 if (dirp->d_ino == 0)
437 if (strcmp(dirp->d_name, idesc->id_name) == 0 && dirp->d_ino >= ROOTINO
438 && dirp->d_ino <= maxino) {
439 idesc->id_parent = dirp->d_ino;
440 return (STOP | FOUND);
448 register struct dinode *dp;
453 printf(" I=%u ", ino);
454 if (ino < ROOTINO || ino > maxino)
458 #if defined(AFS_HPUX110_ENV)
464 pwarn("Could not getinode(%d) in pinode.", ino);
467 uid = _GET_D_UID(dp);
468 if (getpw(uid, uidbuf) == 0) {
469 for (p = uidbuf; *p != ':'; p++);
471 printf("%s ", uidbuf);
476 #else /* AFS_HPUX110_ENV */
477 #if defined(AFS_HPUX102_ENV)
478 if ((pw = getpwuid(_GET_D_UID(dp))) != 0)
479 printf("%s ", pw->pw_name);
481 printf("%d ", _GET_D_UID(dp));
482 #else /* AFS_HPUX102_ENV */
483 if ((pw = getpwuid((int)dp->di_uid)) != 0)
484 printf("%s ", pw->pw_name);
486 printf("%d ", dp->di_uid);
487 #endif /* else AFS_HPUX102_ENV */
488 #endif /* else AFS_HPUX110_ENV */
489 printf("MODE=%o\n", dp->di_mode);
491 printf("%s: ", devname);
492 #if defined(AFS_SUN56_ENV)
493 printf("SIZE=%" AFS_INT64_FMT " ", dp->di_size);
495 printf("SIZE=%ld ", dp->di_size);
497 p = ctime(&dp->di_mtime);
498 printf("MTIME=%12.12s %4.4s ", p + 4, p + 20);
501 blkerror(ino, type, blk)
507 pfatal("%ld %s I=%u", blk, type, ino);
509 switch (statemap[ino]) {
515 #if defined(ACLS) && defined(AFS_HPUX_ENV)
517 * Keep the continuation inode info
519 if (statemap[ino] & HASCINODE)
520 statemap[ino] = FCLEAR | HASCINODE;
522 statemap[ino] = FCLEAR;
524 statemap[ino] = FCLEAR;
529 #if defined(ACLS) && defined(AFS_HPUX_ENV)
531 * Keep the continuation inode info
533 if (statemap[ino] & HASCINODE)
534 statemap[ino] = DCLEAR | HASCINODE;
536 statemap[ino] = DCLEAR;
538 statemap[ino] = DCLEAR;
547 errexit("BAD STATE %d TO BLKERR", statemap[ino]);
553 * allocate an unused inode
556 allocino(request, type)
561 register struct dinode *dp;
565 else if (statemap[request] != USTATE)
567 for (ino = request; ino < maxino; ino++)
568 if (statemap[ino] == USTATE)
572 switch (type & IFMT) {
574 statemap[ino] = DSTATE;
578 statemap[ino] = FSTATE;
584 dp->di_db[0] = allocblk((long)1);
585 if (dp->di_db[0] == 0) {
586 statemap[ino] = USTATE;
591 dp->di_mtime = dp->di_ctime = dp->di_atime;
592 dp->di_size = sblock.fs_fsize;
593 dp->di_blocks = btodb(sblock.fs_fsize);
601 * deallocate an inode
606 struct inodesc idesc;
607 extern int pass4check();
610 memset((char *)&idesc, 0, sizeof(struct inodesc));
611 idesc.id_type = ADDR;
612 idesc.id_func = pass4check;
613 idesc.id_number = ino;
615 (void)ckinode(dp, &idesc);
622 statemap[ino] = USTATE;