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