pass2.c revision 1.5 1 1.5 perseant /* $NetBSD: pass2.c,v 1.5 2000/06/14 18:44:00 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.4 perseant static int pass2check(struct inodesc *);
54 1.4 perseant static int blksort(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.4 perseant struct inodesc curino;
63 1.4 perseant struct dinode dino;
64 1.4 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.4 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.2 nathanw pwarn("DIRECTORY %s: LENGTH %lu NOT MULTIPLE OF %d",
141 1.4 perseant pathbuf, (unsigned long)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.4 perseant printf("checking %ld against %ld\n",
159 1.4 perseant (long)dino.di_inumber,
160 1.4 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.4 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.4 perseant pass2check(struct inodesc * idesc)
201 1.1 perseant {
202 1.1 perseant register struct direct *dirp = idesc->id_dirp;
203 1.1 perseant register struct inoinfo *inp;
204 1.4 perseant int n, entrysize, ret = 0;
205 1.4 perseant struct dinode *dp;
206 1.4 perseant char *errmsg;
207 1.4 perseant struct direct proto;
208 1.4 perseant char namebuf[MAXPATHLEN + 1];
209 1.4 perseant char pathbuf[MAXPATHLEN + 1];
210 1.1 perseant
211 1.1 perseant /*
212 1.1 perseant * If converting, set directory entry type.
213 1.1 perseant */
214 1.1 perseant if (doinglevel2 && dirp->d_ino > 0 && dirp->d_ino < maxino) {
215 1.1 perseant dirp->d_type = typemap[dirp->d_ino];
216 1.1 perseant ret |= ALTERED;
217 1.1 perseant }
218 1.4 perseant /*
219 1.1 perseant * check for "."
220 1.1 perseant */
221 1.1 perseant if (idesc->id_entryno != 0)
222 1.1 perseant goto chk1;
223 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
224 1.1 perseant if (dirp->d_ino != idesc->id_number) {
225 1.1 perseant direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
226 1.1 perseant dirp->d_ino = idesc->id_number;
227 1.1 perseant if (reply("FIX") == 1)
228 1.1 perseant ret |= ALTERED;
229 1.1 perseant }
230 1.1 perseant if (newinofmt && dirp->d_type != DT_DIR) {
231 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
232 1.1 perseant dirp->d_type = DT_DIR;
233 1.1 perseant if (reply("FIX") == 1)
234 1.1 perseant ret |= ALTERED;
235 1.1 perseant }
236 1.1 perseant goto chk1;
237 1.1 perseant }
238 1.1 perseant direrror(idesc->id_number, "MISSING '.'");
239 1.1 perseant proto.d_ino = idesc->id_number;
240 1.1 perseant if (newinofmt)
241 1.1 perseant proto.d_type = DT_DIR;
242 1.1 perseant else
243 1.1 perseant proto.d_type = 0;
244 1.1 perseant proto.d_namlen = 1;
245 1.1 perseant (void)strcpy(proto.d_name, ".");
246 1.1 perseant # if BYTE_ORDER == LITTLE_ENDIAN
247 1.1 perseant if (!newinofmt) {
248 1.4 perseant u_char tmp;
249 1.1 perseant
250 1.1 perseant tmp = proto.d_type;
251 1.1 perseant proto.d_type = proto.d_namlen;
252 1.1 perseant proto.d_namlen = tmp;
253 1.1 perseant }
254 1.1 perseant # endif
255 1.1 perseant entrysize = DIRSIZ(0, &proto, 0);
256 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
257 1.1 perseant pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
258 1.4 perseant dirp->d_name);
259 1.1 perseant } else if (dirp->d_reclen < entrysize) {
260 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
261 1.1 perseant } else if (dirp->d_reclen < 2 * entrysize) {
262 1.1 perseant proto.d_reclen = dirp->d_reclen;
263 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
264 1.1 perseant if (reply("FIX") == 1)
265 1.1 perseant ret |= ALTERED;
266 1.1 perseant } else {
267 1.1 perseant n = dirp->d_reclen - entrysize;
268 1.1 perseant proto.d_reclen = entrysize;
269 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
270 1.1 perseant idesc->id_entryno++;
271 1.1 perseant lncntp[dirp->d_ino]--;
272 1.1 perseant dirp = (struct direct *)((char *)(dirp) + entrysize);
273 1.1 perseant memset(dirp, 0, (size_t)n);
274 1.1 perseant dirp->d_reclen = n;
275 1.1 perseant if (reply("FIX") == 1)
276 1.1 perseant ret |= ALTERED;
277 1.1 perseant }
278 1.1 perseant chk1:
279 1.1 perseant if (idesc->id_entryno > 1)
280 1.1 perseant goto chk2;
281 1.1 perseant inp = getinoinfo(idesc->id_number);
282 1.1 perseant proto.d_ino = inp->i_parent;
283 1.1 perseant if (newinofmt)
284 1.1 perseant proto.d_type = DT_DIR;
285 1.1 perseant else
286 1.1 perseant proto.d_type = 0;
287 1.1 perseant proto.d_namlen = 2;
288 1.1 perseant (void)strcpy(proto.d_name, "..");
289 1.1 perseant # if BYTE_ORDER == LITTLE_ENDIAN
290 1.1 perseant if (!newinofmt) {
291 1.4 perseant u_char tmp;
292 1.1 perseant
293 1.1 perseant tmp = proto.d_type;
294 1.1 perseant proto.d_type = proto.d_namlen;
295 1.1 perseant proto.d_namlen = tmp;
296 1.1 perseant }
297 1.1 perseant # endif
298 1.1 perseant entrysize = DIRSIZ(0, &proto, 0);
299 1.1 perseant if (idesc->id_entryno == 0) {
300 1.1 perseant n = DIRSIZ(0, dirp, 0);
301 1.1 perseant if (dirp->d_reclen < n + entrysize)
302 1.1 perseant goto chk2;
303 1.1 perseant proto.d_reclen = dirp->d_reclen - n;
304 1.1 perseant dirp->d_reclen = n;
305 1.1 perseant idesc->id_entryno++;
306 1.1 perseant lncntp[dirp->d_ino]--;
307 1.1 perseant dirp = (struct direct *)((char *)(dirp) + n);
308 1.1 perseant memset(dirp, 0, (size_t)proto.d_reclen);
309 1.1 perseant dirp->d_reclen = proto.d_reclen;
310 1.1 perseant }
311 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
312 1.1 perseant inp->i_dotdot = dirp->d_ino;
313 1.1 perseant if (newinofmt && dirp->d_type != DT_DIR) {
314 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
315 1.1 perseant dirp->d_type = DT_DIR;
316 1.1 perseant if (reply("FIX") == 1)
317 1.1 perseant ret |= ALTERED;
318 1.1 perseant }
319 1.1 perseant goto chk2;
320 1.1 perseant }
321 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
322 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
323 1.1 perseant pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
324 1.4 perseant dirp->d_name);
325 1.1 perseant inp->i_dotdot = (ino_t)-1;
326 1.1 perseant } else if (dirp->d_reclen < entrysize) {
327 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
328 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
329 1.1 perseant inp->i_dotdot = (ino_t)-1;
330 1.1 perseant } else if (inp->i_parent != 0) {
331 1.1 perseant /*
332 1.1 perseant * We know the parent, so fix now.
333 1.1 perseant */
334 1.1 perseant inp->i_dotdot = inp->i_parent;
335 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
336 1.1 perseant proto.d_reclen = dirp->d_reclen;
337 1.1 perseant memcpy(dirp, &proto, (size_t)entrysize);
338 1.1 perseant if (reply("FIX") == 1)
339 1.1 perseant ret |= ALTERED;
340 1.1 perseant }
341 1.1 perseant idesc->id_entryno++;
342 1.1 perseant if (dirp->d_ino != 0)
343 1.1 perseant lncntp[dirp->d_ino]--;
344 1.4 perseant return (ret | KEEPON);
345 1.1 perseant chk2:
346 1.1 perseant if (dirp->d_ino == 0)
347 1.4 perseant return (ret | KEEPON);
348 1.1 perseant if (dirp->d_namlen <= 2 &&
349 1.1 perseant dirp->d_name[0] == '.' &&
350 1.1 perseant idesc->id_entryno >= 2) {
351 1.1 perseant if (dirp->d_namlen == 1) {
352 1.1 perseant direrror(idesc->id_number, "EXTRA '.' ENTRY");
353 1.1 perseant dirp->d_ino = 0;
354 1.1 perseant if (reply("FIX") == 1)
355 1.1 perseant ret |= ALTERED;
356 1.1 perseant return (KEEPON | ret);
357 1.1 perseant }
358 1.1 perseant if (dirp->d_name[1] == '.') {
359 1.1 perseant direrror(idesc->id_number, "EXTRA '..' ENTRY");
360 1.1 perseant dirp->d_ino = 0;
361 1.1 perseant if (reply("FIX") == 1)
362 1.1 perseant ret |= ALTERED;
363 1.1 perseant return (KEEPON | ret);
364 1.1 perseant }
365 1.1 perseant }
366 1.1 perseant idesc->id_entryno++;
367 1.1 perseant n = 0;
368 1.5 perseant if (dirp->d_ino >= maxino) {
369 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
370 1.1 perseant n = reply("REMOVE");
371 1.4 perseant } else if (dirp->d_ino == LFS_IFILE_INUM &&
372 1.4 perseant idesc->id_number == ROOTINO) {
373 1.4 perseant if (dirp->d_type != DT_REG) {
374 1.4 perseant fileerror(idesc->id_number, dirp->d_ino,
375 1.4 perseant "BAD TYPE FOR IFILE");
376 1.4 perseant dirp->d_type = DT_REG;
377 1.4 perseant if (reply("FIX") == 1)
378 1.4 perseant ret |= ALTERED;
379 1.4 perseant }
380 1.1 perseant } else if (newinofmt &&
381 1.4 perseant ((dirp->d_ino == WINO && (dirp->d_type != DT_WHT)) ||
382 1.4 perseant (dirp->d_ino != WINO && dirp->d_type == DT_WHT))) {
383 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
384 1.1 perseant dirp->d_ino = WINO;
385 1.1 perseant dirp->d_type = DT_WHT;
386 1.1 perseant if (reply("FIX") == 1)
387 1.1 perseant ret |= ALTERED;
388 1.1 perseant } else {
389 1.1 perseant again:
390 1.1 perseant switch (statemap[dirp->d_ino]) {
391 1.1 perseant case USTATE:
392 1.1 perseant if (idesc->id_entryno <= 2)
393 1.1 perseant break;
394 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED");
395 1.1 perseant n = reply("REMOVE");
396 1.1 perseant break;
397 1.1 perseant
398 1.1 perseant case DCLEAR:
399 1.1 perseant case FCLEAR:
400 1.1 perseant if (idesc->id_entryno <= 2)
401 1.1 perseant break;
402 1.1 perseant if (statemap[dirp->d_ino] == FCLEAR)
403 1.1 perseant errmsg = "DUP/BAD";
404 1.1 perseant else if (!preen)
405 1.1 perseant errmsg = "ZERO LENGTH DIRECTORY";
406 1.1 perseant else {
407 1.1 perseant n = 1;
408 1.1 perseant break;
409 1.1 perseant }
410 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, errmsg);
411 1.1 perseant if ((n = reply("REMOVE")) == 1)
412 1.1 perseant break;
413 1.1 perseant dp = ginode(dirp->d_ino);
414 1.1 perseant statemap[dirp->d_ino] =
415 1.4 perseant (dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE;
416 1.1 perseant lncntp[dirp->d_ino] = dp->di_nlink;
417 1.1 perseant goto again;
418 1.1 perseant
419 1.1 perseant case DSTATE:
420 1.1 perseant case DFOUND:
421 1.1 perseant inp = getinoinfo(dirp->d_ino);
422 1.1 perseant if (inp->i_parent != 0 && idesc->id_entryno > 2) {
423 1.1 perseant getpathname(pathbuf, idesc->id_number,
424 1.4 perseant idesc->id_number);
425 1.1 perseant getpathname(namebuf, dirp->d_ino, dirp->d_ino);
426 1.1 perseant pwarn("%s %s %s\n", pathbuf,
427 1.4 perseant "IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
428 1.4 perseant namebuf);
429 1.1 perseant if (preen)
430 1.1 perseant printf(" (IGNORED)\n");
431 1.1 perseant else if ((n = reply("REMOVE")) == 1)
432 1.1 perseant break;
433 1.1 perseant }
434 1.1 perseant if (idesc->id_entryno > 2)
435 1.1 perseant inp->i_parent = idesc->id_number;
436 1.1 perseant /* fall through */
437 1.1 perseant
438 1.1 perseant case FSTATE:
439 1.1 perseant if (newinofmt && dirp->d_type != typemap[dirp->d_ino]) {
440 1.1 perseant fileerror(idesc->id_number, dirp->d_ino,
441 1.4 perseant "BAD TYPE VALUE");
442 1.1 perseant dirp->d_type = typemap[dirp->d_ino];
443 1.1 perseant if (reply("FIX") == 1)
444 1.1 perseant ret |= ALTERED;
445 1.1 perseant }
446 1.1 perseant lncntp[dirp->d_ino]--;
447 1.1 perseant break;
448 1.1 perseant
449 1.1 perseant default:
450 1.4 perseant /* errexit */ pwarn("BAD STATE %d FOR INODE I=%d",
451 1.4 perseant statemap[dirp->d_ino], dirp->d_ino);
452 1.1 perseant }
453 1.1 perseant }
454 1.1 perseant if (n == 0)
455 1.4 perseant return (ret | KEEPON);
456 1.1 perseant dirp->d_ino = 0;
457 1.4 perseant return (ret | KEEPON | ALTERED);
458 1.1 perseant }
459 1.1 perseant
460 1.1 perseant /*
461 1.1 perseant * Routine to sort disk blocks.
462 1.1 perseant */
463 1.1 perseant static int
464 1.4 perseant blksort(const void *inpp1, const void *inpp2)
465 1.1 perseant {
466 1.4 perseant return ((*(struct inoinfo **)inpp1)->i_blks[0] -
467 1.4 perseant (*(struct inoinfo **)inpp2)->i_blks[0]);
468 1.1 perseant }
469