pass2.c revision 1.26 1 1.26 dholland /* $NetBSD: pass2.c,v 1.26 2015/08/12 18:28:00 dholland 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.10 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 perseant * may be used to endorse or promote products derived from this software
17 1.1 perseant * without specific prior written permission.
18 1.1 perseant *
19 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 perseant * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 perseant * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 perseant * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 perseant * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 perseant * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 perseant * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 perseant * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 perseant * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 perseant * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 perseant * SUCH DAMAGE.
30 1.1 perseant */
31 1.1 perseant
32 1.7 perseant #include <sys/types.h>
33 1.1 perseant #include <sys/param.h>
34 1.1 perseant #include <sys/time.h>
35 1.7 perseant #include <sys/mount.h>
36 1.7 perseant #include <sys/buf.h>
37 1.7 perseant
38 1.1 perseant #include <ufs/lfs/lfs.h>
39 1.26 dholland #include <ufs/lfs/lfs_accessors.h>
40 1.23 dholland #include <ufs/lfs/lfs_inode.h>
41 1.1 perseant
42 1.7 perseant #include <err.h>
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.7 perseant #include "bufcache.h"
48 1.7 perseant #include "vnode.h"
49 1.15 christos #include "lfs_user.h"
50 1.7 perseant
51 1.1 perseant #include "fsck.h"
52 1.1 perseant #include "fsutil.h"
53 1.1 perseant #include "extern.h"
54 1.1 perseant
55 1.21 dholland #define MINDIRSIZE (sizeof (struct lfs_dirtemplate))
56 1.1 perseant
57 1.7 perseant static int pass2check(struct inodesc *);
58 1.7 perseant static int blksort(const void *, const void *);
59 1.1 perseant
60 1.1 perseant void
61 1.11 xtraeme pass2(void)
62 1.1 perseant {
63 1.26 dholland union lfs_dinode *dp;
64 1.7 perseant struct uvnode *vp;
65 1.7 perseant struct inoinfo **inpp, *inp;
66 1.1 perseant struct inoinfo **inpend;
67 1.7 perseant struct inodesc curino;
68 1.26 dholland union lfs_dinode dino;
69 1.7 perseant char pathbuf[MAXPATHLEN + 1];
70 1.26 dholland uint16_t mode;
71 1.26 dholland unsigned ii;
72 1.1 perseant
73 1.19 dholland switch (statemap[ULFS_ROOTINO]) {
74 1.1 perseant
75 1.1 perseant case USTATE:
76 1.1 perseant pfatal("ROOT INODE UNALLOCATED");
77 1.1 perseant if (reply("ALLOCATE") == 0)
78 1.17 christos err(EEXIT, "%s", "");
79 1.19 dholland if (allocdir(ULFS_ROOTINO, ULFS_ROOTINO, 0755) != ULFS_ROOTINO)
80 1.25 christos err(EEXIT, "CANNOT ALLOCATE ROOT INODE");
81 1.1 perseant break;
82 1.1 perseant
83 1.1 perseant case DCLEAR:
84 1.1 perseant pfatal("DUPS/BAD IN ROOT INODE");
85 1.1 perseant if (reply("REALLOCATE")) {
86 1.19 dholland freeino(ULFS_ROOTINO);
87 1.19 dholland if (allocdir(ULFS_ROOTINO, ULFS_ROOTINO, 0755) != ULFS_ROOTINO)
88 1.24 christos err(EEXIT, "CANNOT ALLOCATE ROOT INODE");
89 1.1 perseant break;
90 1.1 perseant }
91 1.1 perseant if (reply("CONTINUE") == 0)
92 1.17 christos err(EEXIT, "%s", "");
93 1.1 perseant break;
94 1.1 perseant
95 1.1 perseant case FSTATE:
96 1.1 perseant case FCLEAR:
97 1.1 perseant pfatal("ROOT INODE NOT DIRECTORY");
98 1.1 perseant if (reply("REALLOCATE")) {
99 1.19 dholland freeino(ULFS_ROOTINO);
100 1.19 dholland if (allocdir(ULFS_ROOTINO, ULFS_ROOTINO, 0755) != ULFS_ROOTINO)
101 1.24 christos err(EEXIT, "CANNOT ALLOCATE ROOT INODE");
102 1.1 perseant break;
103 1.1 perseant }
104 1.1 perseant if (reply("FIX") == 0)
105 1.17 christos errx(EEXIT, "%s", "");
106 1.19 dholland vp = vget(fs, ULFS_ROOTINO);
107 1.7 perseant dp = VTOD(vp);
108 1.26 dholland mode = lfs_dino_getmode(fs, dp);
109 1.26 dholland mode &= ~LFS_IFMT;
110 1.26 dholland mode |= LFS_IFDIR;
111 1.26 dholland lfs_dino_setmode(fs, dp, mode);
112 1.7 perseant inodirty(VTOI(vp));
113 1.1 perseant break;
114 1.1 perseant
115 1.1 perseant case DSTATE:
116 1.1 perseant break;
117 1.1 perseant
118 1.1 perseant default:
119 1.24 christos errx(EEXIT, "BAD STATE %d FOR ROOT INODE", statemap[ULFS_ROOTINO]);
120 1.1 perseant }
121 1.19 dholland statemap[ULFS_WINO] = FSTATE;
122 1.21 dholland typemap[ULFS_WINO] = LFS_DT_WHT;
123 1.1 perseant /*
124 1.1 perseant * Sort the directory list into disk block order.
125 1.1 perseant */
126 1.7 perseant qsort((char *) inpsort, (size_t) inplast, sizeof *inpsort, blksort);
127 1.1 perseant /*
128 1.1 perseant * Check the integrity of each directory.
129 1.1 perseant */
130 1.1 perseant memset(&curino, 0, sizeof(struct inodesc));
131 1.1 perseant curino.id_type = DATA;
132 1.1 perseant curino.id_func = pass2check;
133 1.1 perseant inpend = &inpsort[inplast];
134 1.1 perseant for (inpp = inpsort; inpp < inpend; inpp++) {
135 1.1 perseant inp = *inpp;
136 1.1 perseant if (inp->i_isize == 0)
137 1.1 perseant continue;
138 1.1 perseant if (inp->i_isize < MINDIRSIZE) {
139 1.1 perseant direrror(inp->i_number, "DIRECTORY TOO SHORT");
140 1.22 dholland inp->i_isize = roundup(MINDIRSIZE, LFS_DIRBLKSIZ);
141 1.1 perseant if (reply("FIX") == 1) {
142 1.7 perseant vp = vget(fs, inp->i_number);
143 1.7 perseant dp = VTOD(vp);
144 1.26 dholland lfs_dino_setsize(fs, dp, inp->i_isize);
145 1.7 perseant inodirty(VTOI(vp));
146 1.1 perseant }
147 1.22 dholland } else if ((inp->i_isize & (LFS_DIRBLKSIZ - 1)) != 0) {
148 1.9 itojun getpathname(pathbuf, sizeof(pathbuf), inp->i_number,
149 1.9 itojun inp->i_number);
150 1.2 nathanw pwarn("DIRECTORY %s: LENGTH %lu NOT MULTIPLE OF %d",
151 1.22 dholland pathbuf, (unsigned long) inp->i_isize, LFS_DIRBLKSIZ);
152 1.1 perseant if (preen)
153 1.1 perseant printf(" (ADJUSTED)\n");
154 1.22 dholland inp->i_isize = roundup(inp->i_isize, LFS_DIRBLKSIZ);
155 1.1 perseant if (preen || reply("ADJUST") == 1) {
156 1.7 perseant vp = vget(fs, inp->i_number);
157 1.7 perseant dp = VTOD(vp);
158 1.26 dholland lfs_dino_setsize(fs, dp, inp->i_isize);
159 1.7 perseant inodirty(VTOI(vp));
160 1.1 perseant }
161 1.1 perseant }
162 1.26 dholland memset(&dino, 0, sizeof(dino));
163 1.26 dholland lfs_dino_setmode(fs, &dino, LFS_IFDIR);
164 1.26 dholland lfs_dino_setsize(fs, &dino, inp->i_isize);
165 1.26 dholland for (ii = 0; ii < inp->i_numblks / sizeof(inp->i_blks[0]) &&
166 1.26 dholland ii < ULFS_NDADDR; ii++) {
167 1.26 dholland lfs_dino_setdb(fs, &dino, ii, inp->i_blks[ii]);
168 1.26 dholland }
169 1.26 dholland for (; ii < inp->i_numblks / sizeof(inp->i_blks[0]); ii++) {
170 1.26 dholland lfs_dino_setib(fs, &dino, ii - ULFS_NDADDR,
171 1.26 dholland inp->i_blks[ii]);
172 1.26 dholland }
173 1.1 perseant curino.id_number = inp->i_number;
174 1.1 perseant curino.id_parent = inp->i_parent;
175 1.7 perseant (void) ckinode(&dino, &curino);
176 1.1 perseant }
177 1.1 perseant /*
178 1.1 perseant * Now that the parents of all directories have been found,
179 1.1 perseant * make another pass to verify the value of `..'
180 1.1 perseant */
181 1.1 perseant for (inpp = inpsort; inpp < inpend; inpp++) {
182 1.1 perseant inp = *inpp;
183 1.1 perseant if (inp->i_parent == 0 || inp->i_isize == 0)
184 1.1 perseant continue;
185 1.1 perseant if (inp->i_dotdot == inp->i_parent ||
186 1.7 perseant inp->i_dotdot == (ino_t) - 1)
187 1.1 perseant continue;
188 1.1 perseant if (inp->i_dotdot == 0) {
189 1.1 perseant inp->i_dotdot = inp->i_parent;
190 1.1 perseant fileerror(inp->i_parent, inp->i_number, "MISSING '..'");
191 1.1 perseant if (reply("FIX") == 0)
192 1.1 perseant continue;
193 1.7 perseant (void) makeentry(inp->i_number, inp->i_parent, "..");
194 1.1 perseant lncntp[inp->i_parent]--;
195 1.1 perseant continue;
196 1.1 perseant }
197 1.1 perseant fileerror(inp->i_parent, inp->i_number,
198 1.7 perseant "BAD INODE NUMBER FOR '..'");
199 1.1 perseant if (reply("FIX") == 0)
200 1.1 perseant continue;
201 1.1 perseant lncntp[inp->i_dotdot]++;
202 1.1 perseant lncntp[inp->i_parent]--;
203 1.1 perseant inp->i_dotdot = inp->i_parent;
204 1.7 perseant (void) changeino(inp->i_number, "..", inp->i_parent);
205 1.1 perseant }
206 1.1 perseant /*
207 1.1 perseant * Mark all the directories that can be found from the root.
208 1.1 perseant */
209 1.1 perseant propagate();
210 1.1 perseant }
211 1.1 perseant
212 1.1 perseant static int
213 1.4 perseant pass2check(struct inodesc * idesc)
214 1.1 perseant {
215 1.21 dholland struct lfs_direct *dirp = idesc->id_dirp;
216 1.12 perry struct inoinfo *inp;
217 1.7 perseant int n, entrysize, ret = 0;
218 1.26 dholland union lfs_dinode *dp;
219 1.14 christos const char *errmsg;
220 1.21 dholland struct lfs_direct proto;
221 1.7 perseant char namebuf[MAXPATHLEN + 1];
222 1.7 perseant char pathbuf[MAXPATHLEN + 1];
223 1.1 perseant
224 1.1 perseant /*
225 1.1 perseant * check for "."
226 1.1 perseant */
227 1.1 perseant if (idesc->id_entryno != 0)
228 1.1 perseant goto chk1;
229 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
230 1.1 perseant if (dirp->d_ino != idesc->id_number) {
231 1.1 perseant direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
232 1.1 perseant dirp->d_ino = idesc->id_number;
233 1.1 perseant if (reply("FIX") == 1)
234 1.1 perseant ret |= ALTERED;
235 1.1 perseant }
236 1.21 dholland if (dirp->d_type != LFS_DT_DIR) {
237 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
238 1.21 dholland dirp->d_type = LFS_DT_DIR;
239 1.1 perseant if (reply("FIX") == 1)
240 1.1 perseant ret |= ALTERED;
241 1.1 perseant }
242 1.1 perseant goto chk1;
243 1.1 perseant }
244 1.1 perseant direrror(idesc->id_number, "MISSING '.'");
245 1.1 perseant proto.d_ino = idesc->id_number;
246 1.21 dholland proto.d_type = LFS_DT_DIR;
247 1.1 perseant proto.d_namlen = 1;
248 1.9 itojun (void) strlcpy(proto.d_name, ".", sizeof(proto.d_name));
249 1.22 dholland entrysize = LFS_DIRSIZ(0, &proto, 0);
250 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
251 1.1 perseant pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
252 1.7 perseant dirp->d_name);
253 1.1 perseant } else if (dirp->d_reclen < entrysize) {
254 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
255 1.1 perseant } else if (dirp->d_reclen < 2 * entrysize) {
256 1.1 perseant proto.d_reclen = dirp->d_reclen;
257 1.7 perseant memcpy(dirp, &proto, (size_t) entrysize);
258 1.1 perseant if (reply("FIX") == 1)
259 1.1 perseant ret |= ALTERED;
260 1.1 perseant } else {
261 1.1 perseant n = dirp->d_reclen - entrysize;
262 1.1 perseant proto.d_reclen = entrysize;
263 1.7 perseant memcpy(dirp, &proto, (size_t) entrysize);
264 1.1 perseant idesc->id_entryno++;
265 1.1 perseant lncntp[dirp->d_ino]--;
266 1.21 dholland dirp = (struct lfs_direct *) ((char *) (dirp) + entrysize);
267 1.7 perseant memset(dirp, 0, (size_t) n);
268 1.1 perseant dirp->d_reclen = n;
269 1.1 perseant if (reply("FIX") == 1)
270 1.1 perseant ret |= ALTERED;
271 1.1 perseant }
272 1.1 perseant chk1:
273 1.1 perseant if (idesc->id_entryno > 1)
274 1.1 perseant goto chk2;
275 1.1 perseant inp = getinoinfo(idesc->id_number);
276 1.1 perseant proto.d_ino = inp->i_parent;
277 1.21 dholland proto.d_type = LFS_DT_DIR;
278 1.1 perseant proto.d_namlen = 2;
279 1.9 itojun (void) strlcpy(proto.d_name, "..", sizeof(proto.d_name));
280 1.22 dholland entrysize = LFS_DIRSIZ(0, &proto, 0);
281 1.1 perseant if (idesc->id_entryno == 0) {
282 1.22 dholland n = LFS_DIRSIZ(0, dirp, 0);
283 1.1 perseant if (dirp->d_reclen < n + entrysize)
284 1.1 perseant goto chk2;
285 1.1 perseant proto.d_reclen = dirp->d_reclen - n;
286 1.1 perseant dirp->d_reclen = n;
287 1.1 perseant idesc->id_entryno++;
288 1.1 perseant lncntp[dirp->d_ino]--;
289 1.21 dholland dirp = (struct lfs_direct *) ((char *) (dirp) + n);
290 1.7 perseant memset(dirp, 0, (size_t) proto.d_reclen);
291 1.1 perseant dirp->d_reclen = proto.d_reclen;
292 1.1 perseant }
293 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
294 1.1 perseant inp->i_dotdot = dirp->d_ino;
295 1.21 dholland if (dirp->d_type != LFS_DT_DIR) {
296 1.1 perseant direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
297 1.21 dholland dirp->d_type = LFS_DT_DIR;
298 1.1 perseant if (reply("FIX") == 1)
299 1.1 perseant ret |= ALTERED;
300 1.1 perseant }
301 1.1 perseant goto chk2;
302 1.1 perseant }
303 1.1 perseant if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
304 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
305 1.1 perseant pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
306 1.7 perseant dirp->d_name);
307 1.7 perseant inp->i_dotdot = (ino_t) - 1;
308 1.1 perseant } else if (dirp->d_reclen < entrysize) {
309 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
310 1.1 perseant pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
311 1.7 perseant inp->i_dotdot = (ino_t) - 1;
312 1.1 perseant } else if (inp->i_parent != 0) {
313 1.1 perseant /*
314 1.1 perseant * We know the parent, so fix now.
315 1.1 perseant */
316 1.1 perseant inp->i_dotdot = inp->i_parent;
317 1.1 perseant fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
318 1.1 perseant proto.d_reclen = dirp->d_reclen;
319 1.7 perseant memcpy(dirp, &proto, (size_t) entrysize);
320 1.1 perseant if (reply("FIX") == 1)
321 1.1 perseant ret |= ALTERED;
322 1.1 perseant }
323 1.1 perseant idesc->id_entryno++;
324 1.1 perseant if (dirp->d_ino != 0)
325 1.1 perseant lncntp[dirp->d_ino]--;
326 1.4 perseant return (ret | KEEPON);
327 1.1 perseant chk2:
328 1.1 perseant if (dirp->d_ino == 0)
329 1.4 perseant return (ret | KEEPON);
330 1.1 perseant if (dirp->d_namlen <= 2 &&
331 1.1 perseant dirp->d_name[0] == '.' &&
332 1.1 perseant idesc->id_entryno >= 2) {
333 1.1 perseant if (dirp->d_namlen == 1) {
334 1.1 perseant direrror(idesc->id_number, "EXTRA '.' ENTRY");
335 1.1 perseant dirp->d_ino = 0;
336 1.1 perseant if (reply("FIX") == 1)
337 1.1 perseant ret |= ALTERED;
338 1.1 perseant return (KEEPON | ret);
339 1.1 perseant }
340 1.1 perseant if (dirp->d_name[1] == '.') {
341 1.1 perseant direrror(idesc->id_number, "EXTRA '..' ENTRY");
342 1.1 perseant dirp->d_ino = 0;
343 1.1 perseant if (reply("FIX") == 1)
344 1.1 perseant ret |= ALTERED;
345 1.1 perseant return (KEEPON | ret);
346 1.1 perseant }
347 1.1 perseant }
348 1.1 perseant idesc->id_entryno++;
349 1.1 perseant n = 0;
350 1.5 perseant if (dirp->d_ino >= maxino) {
351 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
352 1.1 perseant n = reply("REMOVE");
353 1.4 perseant } else if (dirp->d_ino == LFS_IFILE_INUM &&
354 1.19 dholland idesc->id_number == ULFS_ROOTINO) {
355 1.21 dholland if (dirp->d_type != LFS_DT_REG) {
356 1.4 perseant fileerror(idesc->id_number, dirp->d_ino,
357 1.7 perseant "BAD TYPE FOR IFILE");
358 1.21 dholland dirp->d_type = LFS_DT_REG;
359 1.4 perseant if (reply("FIX") == 1)
360 1.4 perseant ret |= ALTERED;
361 1.4 perseant }
362 1.21 dholland } else if (((dirp->d_ino == ULFS_WINO && (dirp->d_type != LFS_DT_WHT)) ||
363 1.21 dholland (dirp->d_ino != ULFS_WINO && dirp->d_type == LFS_DT_WHT))) {
364 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
365 1.19 dholland dirp->d_ino = ULFS_WINO;
366 1.21 dholland dirp->d_type = LFS_DT_WHT;
367 1.1 perseant if (reply("FIX") == 1)
368 1.1 perseant ret |= ALTERED;
369 1.1 perseant } else {
370 1.1 perseant again:
371 1.1 perseant switch (statemap[dirp->d_ino]) {
372 1.1 perseant case USTATE:
373 1.1 perseant if (idesc->id_entryno <= 2)
374 1.1 perseant break;
375 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED");
376 1.1 perseant n = reply("REMOVE");
377 1.1 perseant break;
378 1.1 perseant
379 1.1 perseant case DCLEAR:
380 1.1 perseant case FCLEAR:
381 1.1 perseant if (idesc->id_entryno <= 2)
382 1.1 perseant break;
383 1.1 perseant if (statemap[dirp->d_ino] == FCLEAR)
384 1.1 perseant errmsg = "DUP/BAD";
385 1.1 perseant else if (!preen)
386 1.1 perseant errmsg = "ZERO LENGTH DIRECTORY";
387 1.1 perseant else {
388 1.1 perseant n = 1;
389 1.1 perseant break;
390 1.1 perseant }
391 1.1 perseant fileerror(idesc->id_number, dirp->d_ino, errmsg);
392 1.1 perseant if ((n = reply("REMOVE")) == 1)
393 1.1 perseant break;
394 1.1 perseant dp = ginode(dirp->d_ino);
395 1.1 perseant statemap[dirp->d_ino] =
396 1.26 dholland (lfs_dino_getmode(fs, dp) & LFS_IFMT) == LFS_IFDIR ? DSTATE : FSTATE;
397 1.26 dholland lncntp[dirp->d_ino] = lfs_dino_getnlink(fs, dp);
398 1.1 perseant goto again;
399 1.1 perseant
400 1.1 perseant case DSTATE:
401 1.1 perseant case DFOUND:
402 1.1 perseant inp = getinoinfo(dirp->d_ino);
403 1.1 perseant if (inp->i_parent != 0 && idesc->id_entryno > 2) {
404 1.9 itojun getpathname(pathbuf, sizeof(pathbuf),
405 1.9 itojun idesc->id_number, idesc->id_number);
406 1.9 itojun getpathname(namebuf, sizeof(namebuf),
407 1.9 itojun dirp->d_ino, dirp->d_ino);
408 1.1 perseant pwarn("%s %s %s\n", pathbuf,
409 1.7 perseant "IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
410 1.7 perseant namebuf);
411 1.1 perseant if (preen)
412 1.1 perseant printf(" (IGNORED)\n");
413 1.1 perseant else if ((n = reply("REMOVE")) == 1)
414 1.1 perseant break;
415 1.1 perseant }
416 1.1 perseant if (idesc->id_entryno > 2)
417 1.1 perseant inp->i_parent = idesc->id_number;
418 1.1 perseant /* fall through */
419 1.1 perseant
420 1.1 perseant case FSTATE:
421 1.7 perseant if (dirp->d_type != typemap[dirp->d_ino]) {
422 1.1 perseant fileerror(idesc->id_number, dirp->d_ino,
423 1.7 perseant "BAD TYPE VALUE");
424 1.13 perseant if (debug)
425 1.13 perseant pwarn("dir has %d, typemap has %d\n",
426 1.13 perseant dirp->d_type, typemap[dirp->d_ino]);
427 1.1 perseant dirp->d_type = typemap[dirp->d_ino];
428 1.1 perseant if (reply("FIX") == 1)
429 1.1 perseant ret |= ALTERED;
430 1.1 perseant }
431 1.1 perseant lncntp[dirp->d_ino]--;
432 1.1 perseant break;
433 1.1 perseant
434 1.1 perseant default:
435 1.17 christos errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
436 1.7 perseant statemap[dirp->d_ino], dirp->d_ino);
437 1.1 perseant }
438 1.1 perseant }
439 1.1 perseant if (n == 0)
440 1.4 perseant return (ret | KEEPON);
441 1.1 perseant dirp->d_ino = 0;
442 1.4 perseant return (ret | KEEPON | ALTERED);
443 1.1 perseant }
444 1.1 perseant /*
445 1.1 perseant * Routine to sort disk blocks.
446 1.1 perseant */
447 1.1 perseant static int
448 1.4 perseant blksort(const void *inpp1, const void *inpp2)
449 1.1 perseant {
450 1.14 christos return ((*(const struct inoinfo *const *) inpp1)->i_blks[0] -
451 1.14 christos (*(const struct inoinfo *const *) inpp2)->i_blks[0]);
452 1.1 perseant }
453