pass2.c (96483) | pass2.c (98542) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static const char sccsid[] = "@(#)pass2.c 8.9 (Berkeley) 4/28/95"; 37#endif 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static const char sccsid[] = "@(#)pass2.c 8.9 (Berkeley) 4/28/95"; 37#endif 38static const char rcsid[] = |
39 "$FreeBSD: head/sbin/fsck_ffs/pass2.c 96483 2002-05-12 23:44:15Z phk $"; | 39 "$FreeBSD: head/sbin/fsck_ffs/pass2.c 98542 2002-06-21 06:18:05Z mckusick $"; |
40#endif /* not lint */ 41 42#include <sys/param.h> 43 44#include <ufs/ufs/dinode.h> 45#include <ufs/ufs/dir.h> 46#include <ufs/ffs/fs.h> 47 --- 5 unchanged lines hidden (view full) --- 53#define MINDIRSIZE (sizeof (struct dirtemplate)) 54 55static int blksort(const void *, const void *); 56static int pass2check(struct inodesc *); 57 58void 59pass2(void) 60{ | 40#endif /* not lint */ 41 42#include <sys/param.h> 43 44#include <ufs/ufs/dinode.h> 45#include <ufs/ufs/dir.h> 46#include <ufs/ffs/fs.h> 47 --- 5 unchanged lines hidden (view full) --- 53#define MINDIRSIZE (sizeof (struct dirtemplate)) 54 55static int blksort(const void *, const void *); 56static int pass2check(struct inodesc *); 57 58void 59pass2(void) 60{ |
61 struct dinode *dp; | 61 union dinode *dp; |
62 struct inoinfo **inpp, *inp; 63 struct inoinfo **inpend; 64 struct inodesc curino; | 62 struct inoinfo **inpp, *inp; 63 struct inoinfo **inpend; 64 struct inodesc curino; |
65 struct dinode dino; | 65 union dinode dino; 66 int i; |
66 char pathbuf[MAXPATHLEN + 1]; 67 68 switch (inoinfo(ROOTINO)->ino_state) { 69 70 case USTATE: 71 pfatal("ROOT INODE UNALLOCATED"); 72 if (reply("ALLOCATE") == 0) { 73 ckfini(0); --- 26 unchanged lines hidden (view full) --- 100 errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); 101 break; 102 } 103 if (reply("FIX") == 0) { 104 ckfini(0); 105 exit(EEXIT); 106 } 107 dp = ginode(ROOTINO); | 67 char pathbuf[MAXPATHLEN + 1]; 68 69 switch (inoinfo(ROOTINO)->ino_state) { 70 71 case USTATE: 72 pfatal("ROOT INODE UNALLOCATED"); 73 if (reply("ALLOCATE") == 0) { 74 ckfini(0); --- 26 unchanged lines hidden (view full) --- 101 errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); 102 break; 103 } 104 if (reply("FIX") == 0) { 105 ckfini(0); 106 exit(EEXIT); 107 } 108 dp = ginode(ROOTINO); |
108 dp->di_mode &= ~IFMT; 109 dp->di_mode |= IFDIR; | 109 DIP(dp, di_mode) &= ~IFMT; 110 DIP(dp, di_mode) |= IFDIR; |
110 inodirty(); 111 break; 112 113 case DSTATE: 114 break; 115 116 default: 117 errx(EEXIT, "BAD STATE %d FOR ROOT INODE", --- 7 unchanged lines hidden (view full) --- 125 */ 126 qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); 127 /* 128 * Check the integrity of each directory. 129 */ 130 memset(&curino, 0, sizeof(struct inodesc)); 131 curino.id_type = DATA; 132 curino.id_func = pass2check; | 111 inodirty(); 112 break; 113 114 case DSTATE: 115 break; 116 117 default: 118 errx(EEXIT, "BAD STATE %d FOR ROOT INODE", --- 7 unchanged lines hidden (view full) --- 126 */ 127 qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); 128 /* 129 * Check the integrity of each directory. 130 */ 131 memset(&curino, 0, sizeof(struct inodesc)); 132 curino.id_type = DATA; 133 curino.id_func = pass2check; |
133 dp = &dino; | |
134 inpend = &inpsort[inplast]; 135 for (inpp = inpsort; inpp < inpend; inpp++) { 136 if (got_siginfo) { 137 printf("%s: phase 2: dir %d of %d (%d%%)\n", cdevname, 138 inpp - inpsort, (int)inplast, 139 (int)((inpp - inpsort) * 100 / inplast)); 140 got_siginfo = 0; 141 } 142 inp = *inpp; 143 if (inp->i_isize == 0) 144 continue; 145 if (inp->i_isize < MINDIRSIZE) { 146 direrror(inp->i_number, "DIRECTORY TOO SHORT"); 147 inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); 148 if (reply("FIX") == 1) { 149 dp = ginode(inp->i_number); | 134 inpend = &inpsort[inplast]; 135 for (inpp = inpsort; inpp < inpend; inpp++) { 136 if (got_siginfo) { 137 printf("%s: phase 2: dir %d of %d (%d%%)\n", cdevname, 138 inpp - inpsort, (int)inplast, 139 (int)((inpp - inpsort) * 100 / inplast)); 140 got_siginfo = 0; 141 } 142 inp = *inpp; 143 if (inp->i_isize == 0) 144 continue; 145 if (inp->i_isize < MINDIRSIZE) { 146 direrror(inp->i_number, "DIRECTORY TOO SHORT"); 147 inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); 148 if (reply("FIX") == 1) { 149 dp = ginode(inp->i_number); |
150 dp->di_size = inp->i_isize; | 150 DIP(dp, di_size) = inp->i_isize; |
151 inodirty(); | 151 inodirty(); |
152 dp = &dino; | |
153 } 154 } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { 155 getpathname(pathbuf, inp->i_number, inp->i_number); 156 if (usedsoftdep) 157 pfatal("%s %s: LENGTH %d NOT MULTIPLE OF %d", 158 "DIRECTORY", pathbuf, inp->i_isize, 159 DIRBLKSIZ); 160 else 161 pwarn("%s %s: LENGTH %d NOT MULTIPLE OF %d", 162 "DIRECTORY", pathbuf, inp->i_isize, 163 DIRBLKSIZ); 164 if (preen) 165 printf(" (ADJUSTED)\n"); 166 inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); 167 if (preen || reply("ADJUST") == 1) { 168 dp = ginode(inp->i_number); | 152 } 153 } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { 154 getpathname(pathbuf, inp->i_number, inp->i_number); 155 if (usedsoftdep) 156 pfatal("%s %s: LENGTH %d NOT MULTIPLE OF %d", 157 "DIRECTORY", pathbuf, inp->i_isize, 158 DIRBLKSIZ); 159 else 160 pwarn("%s %s: LENGTH %d NOT MULTIPLE OF %d", 161 "DIRECTORY", pathbuf, inp->i_isize, 162 DIRBLKSIZ); 163 if (preen) 164 printf(" (ADJUSTED)\n"); 165 inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); 166 if (preen || reply("ADJUST") == 1) { 167 dp = ginode(inp->i_number); |
169 dp->di_size = roundup(inp->i_isize, DIRBLKSIZ); | 168 DIP(dp, di_size) = 169 roundup(inp->i_isize, DIRBLKSIZ); |
170 inodirty(); | 170 inodirty(); |
171 dp = &dino; | |
172 } 173 } | 171 } 172 } |
174 memset(&dino, 0, sizeof(struct dinode)); 175 dino.di_mode = IFDIR; 176 dp->di_size = inp->i_isize; 177 memmove(&dp->di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks); | 173 dp = &dino; 174 memset(dp, 0, sizeof(struct ufs2_dinode)); 175 DIP(dp, di_mode) = IFDIR; 176 DIP(dp, di_size) = inp->i_isize; 177 for (i = 0; 178 i < (inp->i_numblks<NDADDR ? inp->i_numblks : NDADDR); 179 i++) 180 DIP(dp, di_db[i]) = inp->i_blks[i]; 181 if (inp->i_numblks > NDADDR) 182 for (i = 0; i < NIADDR; i++) 183 DIP(dp, di_ib[i]) = inp->i_blks[NDADDR + i]; |
178 curino.id_number = inp->i_number; 179 curino.id_parent = inp->i_parent; 180 (void)ckinode(dp, &curino); 181 } 182 /* 183 * Now that the parents of all directories have been found, 184 * make another pass to verify the value of `..' 185 */ --- 32 unchanged lines hidden (view full) --- 218} 219 220static int 221pass2check(struct inodesc *idesc) 222{ 223 struct direct *dirp = idesc->id_dirp; 224 struct inoinfo *inp; 225 int n, entrysize, ret = 0; | 184 curino.id_number = inp->i_number; 185 curino.id_parent = inp->i_parent; 186 (void)ckinode(dp, &curino); 187 } 188 /* 189 * Now that the parents of all directories have been found, 190 * make another pass to verify the value of `..' 191 */ --- 32 unchanged lines hidden (view full) --- 224} 225 226static int 227pass2check(struct inodesc *idesc) 228{ 229 struct direct *dirp = idesc->id_dirp; 230 struct inoinfo *inp; 231 int n, entrysize, ret = 0; |
226 struct dinode *dp; | 232 union dinode *dp; |
227 char *errmsg; 228 struct direct proto; 229 char namebuf[MAXPATHLEN + 1]; 230 char pathbuf[MAXPATHLEN + 1]; 231 232 /* 233 * check for "." 234 */ --- 152 unchanged lines hidden (view full) --- 387 n = 1; 388 break; 389 } 390 fileerror(idesc->id_number, dirp->d_ino, errmsg); 391 if ((n = reply("REMOVE")) == 1) 392 break; 393 dp = ginode(dirp->d_ino); 394 inoinfo(dirp->d_ino)->ino_state = | 233 char *errmsg; 234 struct direct proto; 235 char namebuf[MAXPATHLEN + 1]; 236 char pathbuf[MAXPATHLEN + 1]; 237 238 /* 239 * check for "." 240 */ --- 152 unchanged lines hidden (view full) --- 393 n = 1; 394 break; 395 } 396 fileerror(idesc->id_number, dirp->d_ino, errmsg); 397 if ((n = reply("REMOVE")) == 1) 398 break; 399 dp = ginode(dirp->d_ino); 400 inoinfo(dirp->d_ino)->ino_state = |
395 (dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE; 396 inoinfo(dirp->d_ino)->ino_linkcnt = dp->di_nlink; | 401 (DIP(dp, di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE; 402 inoinfo(dirp->d_ino)->ino_linkcnt = DIP(dp, di_nlink); |
397 goto again; 398 399 case DSTATE: 400 if (inoinfo(idesc->id_number)->ino_state == DFOUND) 401 inoinfo(dirp->d_ino)->ino_state = DFOUND; 402 /* fall through */ 403 404 case DFOUND: --- 56 unchanged lines hidden --- | 403 goto again; 404 405 case DSTATE: 406 if (inoinfo(idesc->id_number)->ino_state == DFOUND) 407 inoinfo(dirp->d_ino)->ino_state = DFOUND; 408 /* fall through */ 409 410 case DFOUND: --- 56 unchanged lines hidden --- |