1 /* 2 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 7 /* All Rights Reserved */ 8 9 /* 10 * Copyright (c) 1980, 1986, 1990 The Regents of the University of California. 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms are permitted 14 * provided that: (1) source distributions retain this entire copyright 15 * notice and comment, and (2) distributions including binaries display 16 * the following acknowledgement: ``This product includes software 17 * developed by the University of California, Berkeley and its contributors'' 18 * in the documentation or other materials provided with the distribution 19 * and in all advertising materials mentioning features or use of this 20 * software. Neither the name of the University nor the names of its 21 * contributors may be used to endorse or promote products derived 22 * from this software without specific prior written permission. 23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26 */ 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 29 30 #include <sys/param.h> 31 #include <sys/types.h> 32 #include <sys/mntent.h> 33 34 #define bcopy(f, t, n) memcpy(t, f, n) 35 #define bzero(s, n) memset(s, 0, n) 36 #define bcmp(s, d, n) memcmp(s, d, n) 37 38 #define index(s, r) strchr(s, r) 39 #define rindex(s, r) strrchr(s, r) 40 41 #include <sys/fs/ufs_fs.h> 42 #include <sys/vnode.h> 43 #include <sys/fs/ufs_inode.h> 44 #include "fsck.h" 45 46 int pass4check(); 47 48 pass4() 49 { 50 ino_t inumber; 51 struct zlncnt *zlnp; 52 struct dinode *dp; 53 struct inodesc idesc; 54 int n; 55 56 bzero((char *)&idesc, sizeof (struct inodesc)); 57 idesc.id_type = ADDR; 58 idesc.id_func = pass4check; 59 for (inumber = UFSROOTINO; inumber <= lastino; inumber++) { 60 idesc.id_number = inumber; 61 idesc.id_fix = DONTKNOW; 62 switch (statemap[inumber]) { 63 64 case FSTATE: 65 case SSTATE: 66 case DFOUND: 67 n = lncntp[inumber]; 68 if (n) 69 adjust(&idesc, (short)n); 70 else { 71 for (zlnp = zlnhead; zlnp; zlnp = zlnp->next) 72 if (zlnp->zlncnt == inumber) { 73 zlnp->zlncnt = zlnhead->zlncnt; 74 zlnp = zlnhead; 75 zlnhead = zlnhead->next; 76 free((char *)zlnp); 77 if (!willreclaim) 78 clri(&idesc, "UNREF", 1); 79 break; 80 } 81 } 82 break; 83 84 case DSTATE: 85 if (!willreclaim) 86 clri(&idesc, "UNREF", 1); 87 break; 88 89 case DCLEAR: 90 dp = ginode(inumber); 91 if (dp->di_size == 0) { 92 if (!willreclaim) 93 clri(&idesc, "ZERO LENGTH", 1); 94 break; 95 } 96 /* fall through */ 97 case FCLEAR: 98 clri(&idesc, "BAD/DUP", 1); 99 break; 100 101 case SCLEAR: 102 clri(&idesc, "BAD", 1); 103 break; 104 105 case USTATE: 106 break; 107 108 default: 109 errexit("BAD STATE %d FOR INODE I=%d", 110 statemap[inumber], inumber); 111 } 112 } 113 } 114 115 pass4check(idesc) 116 struct inodesc *idesc; 117 { 118 struct dups *dlp; 119 int nfrags; 120 int res = KEEPON; 121 daddr32_t blkno = idesc->id_blkno; 122 123 for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { 124 if (chkrange(blkno, 1)) { 125 res = SKIP; 126 } else if (testbmap(blkno)) { 127 for (dlp = duplist; dlp; dlp = dlp->next) { 128 if (dlp->dup != blkno) 129 continue; 130 dlp->dup = duplist->dup; 131 dlp = duplist; 132 duplist = duplist->next; 133 free((char *)dlp); 134 break; 135 } 136 if (dlp == 0) { 137 clrbmap(blkno); 138 n_blks--; 139 } 140 } 141 } 142 return (res); 143 } 144