pass2.c revision 1.1 1 1.1 perseant /* $Id: pass2.c,v 1.1 1999/03/18 02:02:19 perseant Exp $ */
2 1.1 perseant
3 1.1 perseant /*
4 1.1 perseant * Copyright (c) 1980, 1986, 1993
5 1.1 perseant * The Regents of the University of California. All rights reserved.
6 1.1 perseant *
7 1.1 perseant * Redistribution and use in source and binary forms, with or without
8 1.1 perseant * modification, are permitted provided that the following conditions
9 1.1 perseant * are met:
10 1.1 perseant * 1. Redistributions of source code must retain the above copyright
11 1.1 perseant * notice, this list of conditions and the following disclaimer.
12 1.1 perseant * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 perseant * notice, this list of conditions and the following disclaimer in the
14 1.1 perseant * documentation and/or other materials provided with the distribution.
15 1.1 perseant * 3. All advertising materials mentioning features or use of this software
16 1.1 perseant * must display the following acknowledgement:
17 1.1 perseant * This product includes software developed by the University of
18 1.1 perseant * California, Berkeley and its contributors.
19 1.1 perseant * 4. Neither the name of the University nor the names of its contributors
20 1.1 perseant * may be used to endorse or promote products derived from this software
21 1.1 perseant * without specific prior written permission.
22 1.1 perseant *
23 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 perseant * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 perseant * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 perseant * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 perseant * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 perseant * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 perseant * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 perseant * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 perseant * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 perseant * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 perseant * SUCH DAMAGE.
34 1.1 perseant */
35 1.1 perseant
36 1.1 perseant #include <sys/param.h>
37 1.1 perseant #include <sys/time.h>
38 1.1 perseant #include <ufs/ufs/dinode.h>
39 1.1 perseant #include <ufs/ufs/dir.h>
40 1.1 perseant #include <sys/mount.h>
41 1.1 perseant #include <ufs/lfs/lfs.h>
42 1.1 perseant
43 1.1 perseant #include <stdio.h>
44 1.1 perseant #include <stdlib.h>
45 1.1 perseant #include <string.h>
46 1.1 perseant
47 1.1 perseant #include "fsck.h"
48 1.1 perseant #include "fsutil.h"
49 1.1 perseant #include "extern.h"
50 1.1 perseant
51 1.1 perseant #define MINDIRSIZE (sizeof (struct dirtemplate))
52 1.1 perseant
53 1.1 perseant static int pass2check __P((struct inodesc *));
54 1.1 perseant static int blksort __P((const void *, const void *));
55 1.1 perseant
56 1.1 perseant void
57 1.1 perseant pass2()
58 1.1 perseant {
59 1.1 perseant register struct dinode *dp;
60 1.1 perseant register struct inoinfo **inpp, *inp;
61 1.1 perseant struct inoinfo **inpend;
62 1.1 perseant struct inodesc curino;
63 1.1 perseant struct dinode dino;
64 1.1 perseant char pathbuf[MAXPATHLEN + 1];
65 1.1 perseant
66 1.1 perseant switch (statemap[ROOTINO]) {
67 1.1 perseant
68 1.1 perseant case USTATE:
69 1.1 perseant pfatal("ROOT INODE UNALLOCATED");
70 1.1 perseant if (reply("ALLOCATE") == 0)
71 1.1 perseant errexit("%s", "");
72 1.1 perseant if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
73 1.1 perseant errexit("CANNOT ALLOCATE ROOT INODE\n");
74 1.1 perseant break;
75 1.1 perseant
76 1.1 perseant case DCLEAR:
77 1.1 perseant pfatal("DUPS/BAD IN ROOT INODE");
78 1.1 perseant if (reply("REALLOCATE")) {
79 1.1 perseant freeino(ROOTINO);
80 1.1 perseant if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
81 1.1 perseant errexit("CANNOT ALLOCATE ROOT INODE\n");
82 1.1 perseant break;
83 1.1 perseant }
84 1.1 perseant if (reply("CONTINUE") == 0)
85 1.1 perseant errexit("%s", "");
86 1.1 perseant break;
87 1.1 perseant
88 1.1 perseant case FSTATE:
89 1.1 perseant case FCLEAR:
90 1.1 perseant pfatal("ROOT INODE NOT DIRECTORY");
91 1.1 perseant if (reply("REALLOCATE")) {
92 1.1 perseant freeino(ROOTINO);
93 1.1 perseant if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
94 1.1 perseant errexit("CANNOT ALLOCATE ROOT INODE\n");
95 1.1 perseant break;
96 1.1 perseant }
97 1.1 perseant if (reply("FIX") == 0)
98 1.1 perseant errexit("%s", "");
99 1.1 perseant dp = ginode(ROOTINO);
100 1.1 perseant dp->di_mode &= ~IFMT;
101 1.1 perseant dp->di_mode |= IFDIR;
102 1.1 perseant inodirty();
103 1.1 perseant break;
104 1.1 perseant
105 1.1 perseant case DSTATE:
106 1.1 perseant break;
107 1.1 perseant
108 1.1 perseant default:
109 1.1 perseant errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
110 1.1 perseant }
111 1.1 perseant if (newinofmt) {
112 1.1 perseant statemap[WINO] = FSTATE;
113 1.1 perseant typemap[WINO] = DT_WHT;
114 1.1 perseant }
115 1.1 perseant /*
116 1.1 perseant * Sort the directory list into disk block order.
117 1.1 perseant */
118 1.1 perseant qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
119 1.1 perseant /*
120 1.1 perseant * Check the integrity of each directory.
121 1.1 perseant */
122 1.1 perseant memset(&curino, 0, sizeof(struct inodesc));
123 1.1 perseant curino.id_type = DATA;
124 1.1 perseant curino.id_func = pass2check;
125 1.1 perseant inpend = &inpsort[inplast];
126 1.1 perseant for (inpp = inpsort; inpp < inpend; inpp++) {
127 1.1 perseant inp = *inpp;
128 1.1 perseant if (inp->i_isize == 0)
129 1.1 perseant continue;
130 1.1 perseant if (inp->i_isize < MINDIRSIZE) {
131 1.1 perseant direrror(inp->i_number, "DIRECTORY TOO SHORT");
132 1.1 perseant inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ);
133 1.1 perseant if (reply("FIX") == 1) {
134 1.1 perseant dp = ginode(inp->i_number);
135 1.1 perseant dp->di_size = inp->i_isize;
136 1.1 perseant inodirty();
137 1.1 perseant }
138 1.1 perseant } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
139 1.1 perseant getpathname(pathbuf, inp->i_number, inp->i_number);
140 1.1 perseant pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d",
141 1.1 perseant pathbuf, inp->i_isize, DIRBLKSIZ);
142 1.1 perseant if (preen)
143 1.1 perseant printf(" (ADJUSTED)\n");
144 1.1 perseant inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
145 1.1 perseant if (preen || reply("ADJUST") == 1) {
146 1.1 perseant dp = ginode(inp->i_number);
147 1.1 perseant dp->di_size = inp->i_isize;
148 1.1 perseant inodirty();
149 1.1 perseant }
150 1.1 perseant }
151 1.1 perseant memset(&dino, 0, sizeof(struct dinode));
152 1.1 perseant dino.di_mode = IFDIR;
153 1.1 perseant dino.di_size = inp->i_isize;
154 1.1 perseant memcpy(&dino.di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks);
155 1.1 perseant curino.id_number = inp->i_number;
156 1.1 perseant curino.id_parent = inp->i_parent;
157 1.1 perseant #if 0
158 1.1 perseant printf("checking %ld against %ld\n",
159 1.1 perseant (long)dino.di_inumber,
160 1.1 perseant (long)inp->i_number);
161 1.1 perseant #endif
162 1.1 perseant (void)ckinode(&dino, &curino);
163 1.1 perseant }
164 1.1 perseant /*
165 1.1 perseant * Now that the parents of all directories have been found,
166 1.1 perseant * make another pass to verify the value of `..'
167 1.1 perseant */
168 1.1 perseant for (inpp = inpsort; inpp < inpend; inpp++) {
169 1.1 perseant inp = *inpp;
170 1.1 perseant if (inp->i_parent == 0 || inp->i_isize == 0)
171 1.1 perseant continue;
172 1.1 perseant if (inp->i_dotdot == inp->i_parent ||
173 1.1 perseant inp->i_dotdot == (ino_t)-1)
174 1.1 perseant continue;
175 1.1 perseant if (inp->i_dotdot == 0) {
176 1.1 perseant inp->i_dotdot = inp->i_parent;
177 1.1 perseant fileerror(inp->i_parent, inp->i_number, "MISSING '..'");
178 1.1 perseant if (reply("FIX") == 0)
179 1.1 perseant continue;
180 1.1 perseant (void)makeentry(inp->i_number, inp->i_parent, "..");
181 1.1 perseant lncntp[inp->i_parent]--;
182 1.1 perseant continue;
183 1.1 perseant }
184 1.1 perseant fileerror(inp->i_parent, inp->i_number,
185 1.1 perseant "BAD INODE NUMBER FOR '..'");
186 1.1 perseant if (reply("FIX") == 0)
187 1.1 perseant continue;
188 1.1 perseant lncntp[inp->i_dotdot]++;
189 1.1 perseant lncntp[inp->i_parent]--;
190 1.1 perseant inp->i_dotdot = inp->i_parent;
191 1.1 perseant (void)changeino(inp->i_number, "..", inp->i_parent);
192 1.1 perseant }
193 1.1 perseant /*
194 1.1 perseant * Mark all the directories that can be found from the root.
195 1.1 perseant */
196 1.1 perseant propagate();
197 1.1 perseant }
198 1.1 perseant
199 1.1 perseant static int
200 1.1 perseant pass2check(idesc)
201 1.1 perseant struct inodesc *idesc;
202 1.1 perseant {
203 1.1 perseant register struct direct *dirp = idesc->id_dirp;
204 1.1 perseant register struct inoinfo *inp;
205 1.1 perseant int n, entrysize, ret = 0;
206 1.1 perseant struct dinode *dp;
207 1.1 perseant char *errmsg;
208 1.1 perseant struct direct proto;
209 1.1 perseant char namebuf[MAXPATHLEN + 1];
210 1.1 perseant char pathbuf[MAXPATHLEN + 1];
211 1.1 perseant
212 1.1 perseant /*
213 1.1 perseant * If converting, set directory entry type.
214 1.1 perseant */
215 1.1 perseant if (doinglevel2 && dirp->d_ino > 0 && dirp->d_ino < maxino) {
216 1.1 perseant dirp->d_type = typemap[dirp->d_ino];
217 1.1 perseant ret |= ALTERED;
218 1.1 perseant }
219 1.1 perseant /*
220 1.1 perseant * check for "."
221 1.1 perseant */
222 1.1 perseant if (idesc->id_entryno != 0)
223 1.1 perseant goto chk1;
224 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
225 1.1 perseant if (dirp->d_ino != idesc->id_number) {
226 1.1 perseant direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
227 1.1 perseant dirp->d_ino = idesc->id_number;
228 1.1 perseant if (reply("FIX") == 1)
229 1.1 perseant ret |= ALTERED;
230 1.1 perseant }
231 1.1 perseant if (newinofmt && dirp->d_type != DT_DIR) {
232 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
233 1.1 perseant dirp->d_type = DT_DIR;
234 1.1 perseant if (reply("FIX") == 1)
235 1.1 perseant ret |= ALTERED;
236 1.1 perseant }
237 1.1 perseant goto chk1;
238 1.1 perseant }
239 1.1 perseant direrror(idesc->id_number, "MISSING '.'");
240 1.1 perseant proto.d_ino = idesc->id_number;
241 1.1 perseant if (newinofmt)
242 1.1 perseant proto.d_type = DT_DIR;
243 1.1 perseant else
244 1.1 perseant proto.d_type = 0;
245 1.1 perseant proto.d_namlen = 1;
246 1.1 perseant (void)strcpy(proto.d_name, ".");
247 1.1 perseant # if BYTE_ORDER == LITTLE_ENDIAN
248 1.1 perseant if (!newinofmt) {
249 1.1 perseant u_char tmp;
250 1.1 perseant
251 1.1 perseant tmp = proto.d_type;
252 1.1 perseant proto.d_type = proto.d_namlen;
253 1.1 perseant proto.d_namlen = tmp;
254 1.1 perseant }
255 1.1 perseant # endif
256 1.1 perseant entrysize = DIRSIZ(0, &proto, 0);
257 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
258 1.1 perseant pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
259 1.1 perseant dirp->d_name);
260 1.1 perseant } else if (dirp->d_reclen < entrysize) {
261 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
262 1.1 perseant } else if (dirp->d_reclen < 2 * entrysize) {
263 1.1 perseant proto.d_reclen = dirp->d_reclen;
264 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
265 1.1 perseant if (reply("FIX") == 1)
266 1.1 perseant ret |= ALTERED;
267 1.1 perseant } else {
268 1.1 perseant n = dirp->d_reclen - entrysize;
269 1.1 perseant proto.d_reclen = entrysize;
270 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
271 1.1 perseant idesc->id_entryno++;
272 1.1 perseant lncntp[dirp->d_ino]--;
273 1.1 perseant dirp = (struct direct *)((char *)(dirp) + entrysize);
274 1.1 perseant memset(dirp, 0, (size_t)n);
275 1.1 perseant dirp->d_reclen = n;
276 1.1 perseant if (reply("FIX") == 1)
277 1.1 perseant ret |= ALTERED;
278 1.1 perseant }
279 1.1 perseant chk1:
280 1.1 perseant if (idesc->id_entryno > 1)
281 1.1 perseant goto chk2;
282 1.1 perseant inp = getinoinfo(idesc->id_number);
283 1.1 perseant proto.d_ino = inp->i_parent;
284 1.1 perseant if (newinofmt)
285 1.1 perseant proto.d_type = DT_DIR;
286 1.1 perseant else
287 1.1 perseant proto.d_type = 0;
288 1.1 perseant proto.d_namlen = 2;
289 1.1 perseant (void)strcpy(proto.d_name, "..");
290 1.1 perseant # if BYTE_ORDER == LITTLE_ENDIAN
291 1.1 perseant if (!newinofmt) {
292 1.1 perseant u_char tmp;
293 1.1 perseant
294 1.1 perseant tmp = proto.d_type;
295 1.1 perseant proto.d_type = proto.d_namlen;
296 1.1 perseant proto.d_namlen = tmp;
297 1.1 perseant }
298 1.1 perseant # endif
299 1.1 perseant entrysize = DIRSIZ(0, &proto, 0);
300 1.1 perseant if (idesc->id_entryno == 0) {
301 1.1 perseant n = DIRSIZ(0, dirp, 0);
302 1.1 perseant if (dirp->d_reclen < n + entrysize)
303 1.1 perseant goto chk2;
304 1.1 perseant proto.d_reclen = dirp->d_reclen - n;
305 1.1 perseant dirp->d_reclen = n;
306 1.1 perseant idesc->id_entryno++;
307 1.1 perseant lncntp[dirp->d_ino]--;
308 1.1 perseant dirp = (struct direct *)((char *)(dirp) + n);
309 1.1 perseant memset(dirp, 0, (size_t)proto.d_reclen);
310 1.1 perseant dirp->d_reclen = proto.d_reclen;
311 1.1 perseant }
312 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
313 1.1 perseant inp->i_dotdot = dirp->d_ino;
314 1.1 perseant if (newinofmt && dirp->d_type != DT_DIR) {
315 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
316 1.1 perseant dirp->d_type = DT_DIR;
317 1.1 perseant if (reply("FIX") == 1)
318 1.1 perseant ret |= ALTERED;
319 1.1 perseant }
320 1.1 perseant goto chk2;
321 1.1 perseant }
322 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
323 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
324 1.1 perseant pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
325 1.1 perseant dirp->d_name);
326 1.1 perseant inp->i_dotdot = (ino_t)-1;
327 1.1 perseant } else if (dirp->d_reclen < entrysize) {
328 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
329 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
330 1.1 perseant inp->i_dotdot = (ino_t)-1;
331 1.1 perseant } else if (inp->i_parent != 0) {
332 1.1 perseant /*
333 1.1 perseant * We know the parent, so fix now.
334 1.1 perseant */
335 1.1 perseant inp->i_dotdot = inp->i_parent;
336 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
337 1.1 perseant proto.d_reclen = dirp->d_reclen;
338 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
339 1.1 perseant if (reply("FIX") == 1)
340 1.1 perseant ret |= ALTERED;
341 1.1 perseant }
342 1.1 perseant idesc->id_entryno++;
343 1.1 perseant if (dirp->d_ino != 0)
344 1.1 perseant lncntp[dirp->d_ino]--;
345 1.1 perseant return (ret|KEEPON);
346 1.1 perseant chk2:
347 1.1 perseant if (dirp->d_ino == 0)
348 1.1 perseant return (ret|KEEPON);
349 1.1 perseant if (dirp->d_namlen <= 2 &&
350 1.1 perseant dirp->d_name[0] == '.' &&
351 1.1 perseant idesc->id_entryno >= 2) {
352 1.1 perseant if (dirp->d_namlen == 1) {
353 1.1 perseant direrror(idesc->id_number, "EXTRA '.' ENTRY");
354 1.1 perseant dirp->d_ino = 0;
355 1.1 perseant if (reply("FIX") == 1)
356 1.1 perseant ret |= ALTERED;
357 1.1 perseant return (KEEPON | ret);
358 1.1 perseant }
359 1.1 perseant if (dirp->d_name[1] == '.') {
360 1.1 perseant direrror(idesc->id_number, "EXTRA '..' ENTRY");
361 1.1 perseant dirp->d_ino = 0;
362 1.1 perseant if (reply("FIX") == 1)
363 1.1 perseant ret |= ALTERED;
364 1.1 perseant return (KEEPON | ret);
365 1.1 perseant }
366 1.1 perseant }
367 1.1 perseant idesc->id_entryno++;
368 1.1 perseant n = 0;
369 1.1 perseant if (dirp->d_ino > maxino) {
370 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
371 1.1 perseant n = reply("REMOVE");
372 1.1 perseant } else if(dirp->d_ino == LFS_IFILE_INUM
373 1.1 perseant && idesc->id_number==ROOTINO) {
374 1.1 perseant if(dirp->d_type != DT_REG) {
375 1.1 perseant fileerror(idesc->id_number, dirp->d_ino,
376 1.1 perseant "BAD TYPE FOR IFILE");
377 1.1 perseant dirp->d_type = DT_REG;
378 1.1 perseant if(reply("FIX") == 1)
379 1.1 perseant ret |= ALTERED;
380 1.1 perseant }
381 1.1 perseant } else if (newinofmt &&
382 1.1 perseant ((dirp->d_ino == WINO && (dirp->d_type != DT_WHT))
383 1.1 perseant || (dirp->d_ino != WINO && dirp->d_type == DT_WHT))) {
384 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
385 1.1 perseant dirp->d_ino = WINO;
386 1.1 perseant dirp->d_type = DT_WHT;
387 1.1 perseant if (reply("FIX") == 1)
388 1.1 perseant ret |= ALTERED;
389 1.1 perseant } else {
390 1.1 perseant again:
391 1.1 perseant switch (statemap[dirp->d_ino]) {
392 1.1 perseant case USTATE:
393 1.1 perseant if (idesc->id_entryno <= 2)
394 1.1 perseant break;
395 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED");
396 1.1 perseant n = reply("REMOVE");
397 1.1 perseant break;
398 1.1 perseant
399 1.1 perseant case DCLEAR:
400 1.1 perseant case FCLEAR:
401 1.1 perseant if (idesc->id_entryno <= 2)
402 1.1 perseant break;
403 1.1 perseant if (statemap[dirp->d_ino] == FCLEAR)
404 1.1 perseant errmsg = "DUP/BAD";
405 1.1 perseant else if (!preen)
406 1.1 perseant errmsg = "ZERO LENGTH DIRECTORY";
407 1.1 perseant else {
408 1.1 perseant n = 1;
409 1.1 perseant break;
410 1.1 perseant }
411 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, errmsg);
412 1.1 perseant if ((n = reply("REMOVE")) == 1)
413 1.1 perseant break;
414 1.1 perseant dp = ginode(dirp->d_ino);
415 1.1 perseant statemap[dirp->d_ino] =
416 1.1 perseant (dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE;
417 1.1 perseant lncntp[dirp->d_ino] = dp->di_nlink;
418 1.1 perseant goto again;
419 1.1 perseant
420 1.1 perseant case DSTATE:
421 1.1 perseant case DFOUND:
422 1.1 perseant inp = getinoinfo(dirp->d_ino);
423 1.1 perseant if (inp->i_parent != 0 && idesc->id_entryno > 2) {
424 1.1 perseant getpathname(pathbuf, idesc->id_number,
425 1.1 perseant idesc->id_number);
426 1.1 perseant getpathname(namebuf, dirp->d_ino, dirp->d_ino);
427 1.1 perseant pwarn("%s %s %s\n", pathbuf,
428 1.1 perseant "IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
429 1.1 perseant namebuf);
430 1.1 perseant if (preen)
431 1.1 perseant printf(" (IGNORED)\n");
432 1.1 perseant else if ((n = reply("REMOVE")) == 1)
433 1.1 perseant break;
434 1.1 perseant }
435 1.1 perseant if (idesc->id_entryno > 2)
436 1.1 perseant inp->i_parent = idesc->id_number;
437 1.1 perseant /* fall through */
438 1.1 perseant
439 1.1 perseant case FSTATE:
440 1.1 perseant if (newinofmt && dirp->d_type != typemap[dirp->d_ino]) {
441 1.1 perseant fileerror(idesc->id_number, dirp->d_ino,
442 1.1 perseant "BAD TYPE VALUE");
443 1.1 perseant dirp->d_type = typemap[dirp->d_ino];
444 1.1 perseant if (reply("FIX") == 1)
445 1.1 perseant ret |= ALTERED;
446 1.1 perseant }
447 1.1 perseant lncntp[dirp->d_ino]--;
448 1.1 perseant break;
449 1.1 perseant
450 1.1 perseant default:
451 1.1 perseant /* errexit */pwarn("BAD STATE %d FOR INODE I=%d",
452 1.1 perseant statemap[dirp->d_ino], dirp->d_ino);
453 1.1 perseant }
454 1.1 perseant }
455 1.1 perseant if (n == 0)
456 1.1 perseant return (ret|KEEPON);
457 1.1 perseant dirp->d_ino = 0;
458 1.1 perseant return (ret|KEEPON|ALTERED);
459 1.1 perseant }
460 1.1 perseant
461 1.1 perseant /*
462 1.1 perseant * Routine to sort disk blocks.
463 1.1 perseant */
464 1.1 perseant static int
465 1.1 perseant blksort(inpp1, inpp2)
466 1.1 perseant const void *inpp1, *inpp2;
467 1.1 perseant {
468 1.1 perseant return ((* (struct inoinfo **) inpp1)->i_blks[0] -
469 1.1 perseant (* (struct inoinfo **) inpp2)->i_blks[0]);
470 1.1 perseant }
471