utilities.c revision 1.1 1 1.1 perseant /* $Id: utilities.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 #include <stdio.h>
43 1.1 perseant #include <stdlib.h>
44 1.1 perseant #include <string.h>
45 1.1 perseant #include <ctype.h>
46 1.1 perseant #include <unistd.h>
47 1.1 perseant
48 1.1 perseant #include <signal.h>
49 1.1 perseant
50 1.1 perseant #include "fsutil.h"
51 1.1 perseant #include "fsck.h"
52 1.1 perseant #include "extern.h"
53 1.1 perseant
54 1.1 perseant long diskreads, totalreads; /* Disk cache statistics */
55 1.1 perseant
56 1.1 perseant static void rwerror __P((char *, daddr_t));
57 1.1 perseant
58 1.1 perseant int
59 1.1 perseant ftypeok(dp)
60 1.1 perseant struct dinode *dp;
61 1.1 perseant {
62 1.1 perseant switch (dp->di_mode & IFMT) {
63 1.1 perseant
64 1.1 perseant case IFDIR:
65 1.1 perseant case IFREG:
66 1.1 perseant case IFBLK:
67 1.1 perseant case IFCHR:
68 1.1 perseant case IFLNK:
69 1.1 perseant case IFSOCK:
70 1.1 perseant case IFIFO:
71 1.1 perseant return (1);
72 1.1 perseant
73 1.1 perseant default:
74 1.1 perseant if (debug)
75 1.1 perseant printf("bad file type 0%o\n", dp->di_mode);
76 1.1 perseant return (0);
77 1.1 perseant }
78 1.1 perseant }
79 1.1 perseant
80 1.1 perseant int
81 1.1 perseant reply(question)
82 1.1 perseant char *question;
83 1.1 perseant {
84 1.1 perseant int persevere;
85 1.1 perseant char c;
86 1.1 perseant
87 1.1 perseant if (preen)
88 1.1 perseant pfatal("INTERNAL ERROR: GOT TO reply()");
89 1.1 perseant persevere = !strcmp(question, "CONTINUE");
90 1.1 perseant printf("\n");
91 1.1 perseant if (!persevere && (nflag || fswritefd < 0)) {
92 1.1 perseant printf("%s? no\n\n", question);
93 1.1 perseant return (0);
94 1.1 perseant }
95 1.1 perseant if (yflag || (persevere && nflag)) {
96 1.1 perseant printf("%s? yes\n\n", question);
97 1.1 perseant return (1);
98 1.1 perseant }
99 1.1 perseant do {
100 1.1 perseant printf("%s? [yn] ", question);
101 1.1 perseant (void) fflush(stdout);
102 1.1 perseant c = getc(stdin);
103 1.1 perseant while (c != '\n' && getc(stdin) != '\n')
104 1.1 perseant if (feof(stdin))
105 1.1 perseant return (0);
106 1.1 perseant } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
107 1.1 perseant printf("\n");
108 1.1 perseant if (c == 'y' || c == 'Y')
109 1.1 perseant return (1);
110 1.1 perseant return (0);
111 1.1 perseant }
112 1.1 perseant
113 1.1 perseant /*
114 1.1 perseant * Malloc buffers and set up cache.
115 1.1 perseant */
116 1.1 perseant void
117 1.1 perseant bufinit()
118 1.1 perseant {
119 1.1 perseant register struct bufarea *bp;
120 1.1 perseant long bufcnt, i;
121 1.1 perseant char *bufp;
122 1.1 perseant
123 1.1 perseant pbp = pdirbp = (struct bufarea *)0;
124 1.1 perseant bufp = malloc((unsigned int)sblock.lfs_bsize);
125 1.1 perseant if (bufp == 0)
126 1.1 perseant errexit("cannot allocate buffer pool\n");
127 1.1 perseant /* cgblk.b_un.b_buf = bufp; */
128 1.1 perseant /* initbarea(&cgblk); */
129 1.1 perseant bufhead.b_next = bufhead.b_prev = &bufhead;
130 1.1 perseant bufcnt = MAXBUFSPACE / sblock.lfs_bsize;
131 1.1 perseant if (bufcnt < MINBUFS)
132 1.1 perseant bufcnt = MINBUFS;
133 1.1 perseant for (i = 0; i < bufcnt; i++) {
134 1.1 perseant bp = (struct bufarea *)malloc(sizeof(struct bufarea));
135 1.1 perseant bufp = malloc((unsigned int)sblock.lfs_bsize);
136 1.1 perseant if (bp == NULL || bufp == NULL) {
137 1.1 perseant if (i >= MINBUFS)
138 1.1 perseant break;
139 1.1 perseant errexit("cannot allocate buffer pool\n");
140 1.1 perseant }
141 1.1 perseant bp->b_un.b_buf = bufp;
142 1.1 perseant bp->b_prev = &bufhead;
143 1.1 perseant bp->b_next = bufhead.b_next;
144 1.1 perseant bufhead.b_next->b_prev = bp;
145 1.1 perseant bufhead.b_next = bp;
146 1.1 perseant initbarea(bp);
147 1.1 perseant }
148 1.1 perseant bufhead.b_size = i; /* save number of buffers */
149 1.1 perseant }
150 1.1 perseant
151 1.1 perseant /*
152 1.1 perseant * Manage a cache of directory blocks.
153 1.1 perseant */
154 1.1 perseant struct bufarea *
155 1.1 perseant getddblk(blkno,size)
156 1.1 perseant daddr_t blkno;
157 1.1 perseant long size;
158 1.1 perseant {
159 1.1 perseant register struct bufarea *bp;
160 1.1 perseant
161 1.1 perseant for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
162 1.1 perseant if (bp->b_bno == blkno) {
163 1.1 perseant if(bp->b_size <= size)
164 1.1 perseant getdblk(bp,blkno,size);
165 1.1 perseant goto foundit;
166 1.1 perseant }
167 1.1 perseant for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
168 1.1 perseant if ((bp->b_flags & B_INUSE) == 0)
169 1.1 perseant break;
170 1.1 perseant if (bp == &bufhead)
171 1.1 perseant errexit("deadlocked buffer pool\n");
172 1.1 perseant getdblk(bp, blkno, size);
173 1.1 perseant /* fall through */
174 1.1 perseant foundit:
175 1.1 perseant totalreads++;
176 1.1 perseant bp->b_prev->b_next = bp->b_next;
177 1.1 perseant bp->b_next->b_prev = bp->b_prev;
178 1.1 perseant bp->b_prev = &bufhead;
179 1.1 perseant bp->b_next = bufhead.b_next;
180 1.1 perseant bufhead.b_next->b_prev = bp;
181 1.1 perseant bufhead.b_next = bp;
182 1.1 perseant bp->b_flags |= B_INUSE;
183 1.1 perseant return (bp);
184 1.1 perseant }
185 1.1 perseant
186 1.1 perseant struct bufarea *
187 1.1 perseant getdatablk(blkno, size)
188 1.1 perseant daddr_t blkno;
189 1.1 perseant long size;
190 1.1 perseant {
191 1.1 perseant return getddblk(fsbtodb(&sblock,blkno),size);
192 1.1 perseant }
193 1.1 perseant
194 1.1 perseant void
195 1.1 perseant getdblk(bp, blk, size)
196 1.1 perseant register struct bufarea *bp;
197 1.1 perseant daddr_t blk;
198 1.1 perseant long size;
199 1.1 perseant {
200 1.1 perseant if (bp->b_bno != blk) {
201 1.1 perseant flush(fswritefd, bp);
202 1.1 perseant diskreads++;
203 1.1 perseant bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, blk, size);
204 1.1 perseant bp->b_bno = blk;
205 1.1 perseant bp->b_size = size;
206 1.1 perseant }
207 1.1 perseant }
208 1.1 perseant
209 1.1 perseant void
210 1.1 perseant getblk(bp, blk, size)
211 1.1 perseant register struct bufarea *bp;
212 1.1 perseant daddr_t blk;
213 1.1 perseant long size;
214 1.1 perseant {
215 1.1 perseant getdblk(bp, fsbtodb(&sblock,blk), size);
216 1.1 perseant }
217 1.1 perseant
218 1.1 perseant void
219 1.1 perseant flush(fd, bp)
220 1.1 perseant int fd;
221 1.1 perseant register struct bufarea *bp;
222 1.1 perseant {
223 1.1 perseant if (!bp->b_dirty)
224 1.1 perseant return;
225 1.1 perseant if (bp->b_errs != 0)
226 1.1 perseant pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
227 1.1 perseant (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
228 1.1 perseant bp->b_bno);
229 1.1 perseant bp->b_dirty = 0;
230 1.1 perseant bp->b_errs = 0;
231 1.1 perseant bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
232 1.1 perseant if (bp != &sblk)
233 1.1 perseant return;
234 1.1 perseant #if 0 /* XXX - FFS */
235 1.1 perseant for (i = 0, j = 0; i < sblock.lfs_cssize; i += sblock.lfs_bsize, j++) {
236 1.1 perseant bwrite(fswritefd, (char *)sblock.lfs_csp[j],
237 1.1 perseant fsbtodb(&sblock, sblock.lfs_csaddr + j * sblock.lfs_frag),
238 1.1 perseant sblock.lfs_cssize - i < sblock.lfs_bsize ?
239 1.1 perseant sblock.lfs_cssize - i : sblock.lfs_bsize);
240 1.1 perseant }
241 1.1 perseant #endif
242 1.1 perseant }
243 1.1 perseant
244 1.1 perseant static void
245 1.1 perseant rwerror(mesg, blk)
246 1.1 perseant char *mesg;
247 1.1 perseant daddr_t blk;
248 1.1 perseant {
249 1.1 perseant
250 1.1 perseant if (preen == 0)
251 1.1 perseant printf("\n");
252 1.1 perseant pfatal("CANNOT %s: BLK %d", mesg, blk);
253 1.1 perseant if (reply("CONTINUE") == 0)
254 1.1 perseant errexit("Program terminated\n");
255 1.1 perseant }
256 1.1 perseant
257 1.1 perseant void
258 1.1 perseant ckfini(markclean)
259 1.1 perseant int markclean;
260 1.1 perseant {
261 1.1 perseant register struct bufarea *bp, *nbp;
262 1.1 perseant int cnt = 0;
263 1.1 perseant
264 1.1 perseant if (fswritefd < 0) {
265 1.1 perseant (void)close(fsreadfd);
266 1.1 perseant return;
267 1.1 perseant }
268 1.1 perseant flush(fswritefd, &sblk);
269 1.1 perseant if (havesb && sblk.b_bno != LFS_SBPAD / dev_bsize &&
270 1.1 perseant !preen && reply("UPDATE STANDARD SUPERBLOCK")) {
271 1.1 perseant sblk.b_bno = LFS_SBPAD / dev_bsize;
272 1.1 perseant sbdirty();
273 1.1 perseant flush(fswritefd, &sblk);
274 1.1 perseant }
275 1.1 perseant /* flush(fswritefd, &cgblk); */
276 1.1 perseant /* free(cgblk.b_un.b_buf); */
277 1.1 perseant for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
278 1.1 perseant cnt++;
279 1.1 perseant flush(fswritefd, bp);
280 1.1 perseant nbp = bp->b_prev;
281 1.1 perseant free(bp->b_un.b_buf);
282 1.1 perseant free((char *)bp);
283 1.1 perseant }
284 1.1 perseant if (bufhead.b_size != cnt)
285 1.1 perseant errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
286 1.1 perseant pbp = pdirbp = (struct bufarea *)0;
287 1.1 perseant #if 0 /* FFS */
288 1.1 perseant if (markclean && (sblock.lfs_clean & FS_ISCLEAN) == 0) {
289 1.1 perseant /*
290 1.1 perseant * Mark the file system as clean, and sync the superblock.
291 1.1 perseant */
292 1.1 perseant if (preen)
293 1.1 perseant pwarn("MARKING FILE SYSTEM CLEAN\n");
294 1.1 perseant else if (!reply("MARK FILE SYSTEM CLEAN"))
295 1.1 perseant markclean = 0;
296 1.1 perseant if (markclean) {
297 1.1 perseant sblock.lfs_clean = FS_ISCLEAN;
298 1.1 perseant sbdirty();
299 1.1 perseant flush(fswritefd, &sblk);
300 1.1 perseant }
301 1.1 perseant }
302 1.1 perseant #endif
303 1.1 perseant if (debug)
304 1.1 perseant printf("cache missed %ld of %ld (%d%%)\n", diskreads,
305 1.1 perseant totalreads, (int)(diskreads * 100 / totalreads));
306 1.1 perseant (void)close(fsreadfd);
307 1.1 perseant (void)close(fswritefd);
308 1.1 perseant }
309 1.1 perseant
310 1.1 perseant int
311 1.1 perseant bread(fd, buf, blk, size)
312 1.1 perseant int fd;
313 1.1 perseant char *buf;
314 1.1 perseant daddr_t blk;
315 1.1 perseant long size;
316 1.1 perseant {
317 1.1 perseant char *cp;
318 1.1 perseant int i, errs;
319 1.1 perseant off_t offset;
320 1.1 perseant
321 1.1 perseant offset = blk;
322 1.1 perseant offset *= dev_bsize;
323 1.1 perseant if (lseek(fd, offset, 0) < 0) {
324 1.1 perseant rwerror("SEEK", blk);
325 1.1 perseant raise(1);
326 1.1 perseant }
327 1.1 perseant else if (read(fd, buf, (int)size) == size)
328 1.1 perseant return (0);
329 1.1 perseant rwerror("READ", blk);
330 1.1 perseant if (lseek(fd, offset, 0) < 0)
331 1.1 perseant rwerror("SEEK", blk);
332 1.1 perseant errs = 0;
333 1.1 perseant memset(buf, 0, (size_t)size);
334 1.1 perseant printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
335 1.1 perseant for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
336 1.1 perseant if (read(fd, cp, (int)secsize) != secsize) {
337 1.1 perseant (void)lseek(fd, offset + i + secsize, 0);
338 1.1 perseant if (secsize != dev_bsize && dev_bsize != 1)
339 1.1 perseant printf(" %ld (%ld),",
340 1.1 perseant (blk * dev_bsize + i) / secsize,
341 1.1 perseant blk + i / dev_bsize);
342 1.1 perseant else
343 1.1 perseant printf(" %ld,", blk + i / dev_bsize);
344 1.1 perseant errs++;
345 1.1 perseant }
346 1.1 perseant }
347 1.1 perseant printf("\n");
348 1.1 perseant return (errs);
349 1.1 perseant }
350 1.1 perseant
351 1.1 perseant void
352 1.1 perseant bwrite(fd, buf, blk, size)
353 1.1 perseant int fd;
354 1.1 perseant char *buf;
355 1.1 perseant daddr_t blk;
356 1.1 perseant long size;
357 1.1 perseant {
358 1.1 perseant int i;
359 1.1 perseant char *cp;
360 1.1 perseant off_t offset;
361 1.1 perseant
362 1.1 perseant if (fd < 0)
363 1.1 perseant return;
364 1.1 perseant offset = blk;
365 1.1 perseant offset *= dev_bsize;
366 1.1 perseant if (lseek(fd, offset, 0) < 0)
367 1.1 perseant rwerror("SEEK", blk);
368 1.1 perseant else if (write(fd, buf, (int)size) == size) {
369 1.1 perseant fsmodified = 1;
370 1.1 perseant return;
371 1.1 perseant }
372 1.1 perseant rwerror("WRITE", blk);
373 1.1 perseant if (lseek(fd, offset, 0) < 0)
374 1.1 perseant rwerror("SEEK", blk);
375 1.1 perseant printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
376 1.1 perseant for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
377 1.1 perseant if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
378 1.1 perseant (void)lseek(fd, offset + i + dev_bsize, 0);
379 1.1 perseant printf(" %ld,", blk + i / dev_bsize);
380 1.1 perseant }
381 1.1 perseant printf("\n");
382 1.1 perseant return;
383 1.1 perseant }
384 1.1 perseant
385 1.1 perseant /*
386 1.1 perseant * allocate a data block with the specified number of fragments
387 1.1 perseant */
388 1.1 perseant int
389 1.1 perseant allocblk(frags)
390 1.1 perseant long frags;
391 1.1 perseant {
392 1.1 perseant register int i, j, k;
393 1.1 perseant
394 1.1 perseant if (frags <= 0 || frags > sblock.lfs_frag)
395 1.1 perseant return (0);
396 1.1 perseant for (i = 0; i < maxfsblock - sblock.lfs_frag; i += sblock.lfs_frag) {
397 1.1 perseant for (j = 0; j <= sblock.lfs_frag - frags; j++) {
398 1.1 perseant if (testbmap(i + j))
399 1.1 perseant continue;
400 1.1 perseant for (k = 1; k < frags; k++)
401 1.1 perseant if (testbmap(i + j + k))
402 1.1 perseant break;
403 1.1 perseant if (k < frags) {
404 1.1 perseant j += k;
405 1.1 perseant continue;
406 1.1 perseant }
407 1.1 perseant for (k = 0; k < frags; k++) {
408 1.1 perseant #ifndef VERBOSE_BLOCKMAP
409 1.1 perseant setbmap(i + j + k);
410 1.1 perseant #else
411 1.1 perseant setbmap(i + j + k, -1);
412 1.1 perseant #endif
413 1.1 perseant }
414 1.1 perseant n_blks += frags;
415 1.1 perseant return (i + j);
416 1.1 perseant }
417 1.1 perseant }
418 1.1 perseant return (0);
419 1.1 perseant }
420 1.1 perseant
421 1.1 perseant /*
422 1.1 perseant * Free a previously allocated block
423 1.1 perseant */
424 1.1 perseant void
425 1.1 perseant freeblk(blkno, frags)
426 1.1 perseant daddr_t blkno;
427 1.1 perseant long frags;
428 1.1 perseant {
429 1.1 perseant struct inodesc idesc;
430 1.1 perseant
431 1.1 perseant idesc.id_blkno = blkno;
432 1.1 perseant idesc.id_numfrags = frags;
433 1.1 perseant (void)pass4check(&idesc);
434 1.1 perseant }
435 1.1 perseant
436 1.1 perseant /*
437 1.1 perseant * Find a pathname
438 1.1 perseant */
439 1.1 perseant void
440 1.1 perseant getpathname(namebuf, curdir, ino)
441 1.1 perseant char *namebuf;
442 1.1 perseant ino_t curdir, ino;
443 1.1 perseant {
444 1.1 perseant int len;
445 1.1 perseant register char *cp;
446 1.1 perseant struct inodesc idesc;
447 1.1 perseant static int busy = 0;
448 1.1 perseant
449 1.1 perseant if (curdir == ino && ino == ROOTINO) {
450 1.1 perseant (void)strcpy(namebuf, "/");
451 1.1 perseant return;
452 1.1 perseant }
453 1.1 perseant if (busy ||
454 1.1 perseant (statemap[curdir] != DSTATE && statemap[curdir] != DFOUND)) {
455 1.1 perseant (void)strcpy(namebuf, "?");
456 1.1 perseant return;
457 1.1 perseant }
458 1.1 perseant busy = 1;
459 1.1 perseant memset(&idesc, 0, sizeof(struct inodesc));
460 1.1 perseant idesc.id_type = DATA;
461 1.1 perseant idesc.id_fix = IGNORE;
462 1.1 perseant cp = &namebuf[MAXPATHLEN - 1];
463 1.1 perseant *cp = '\0';
464 1.1 perseant if (curdir != ino) {
465 1.1 perseant idesc.id_parent = curdir;
466 1.1 perseant goto namelookup;
467 1.1 perseant }
468 1.1 perseant while (ino != ROOTINO) {
469 1.1 perseant idesc.id_number = ino;
470 1.1 perseant idesc.id_func = findino;
471 1.1 perseant idesc.id_name = "..";
472 1.1 perseant if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
473 1.1 perseant break;
474 1.1 perseant namelookup:
475 1.1 perseant idesc.id_number = idesc.id_parent;
476 1.1 perseant idesc.id_parent = ino;
477 1.1 perseant idesc.id_func = findname;
478 1.1 perseant idesc.id_name = namebuf;
479 1.1 perseant if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0)
480 1.1 perseant break;
481 1.1 perseant len = strlen(namebuf);
482 1.1 perseant cp -= len;
483 1.1 perseant memcpy(cp, namebuf, (size_t)len);
484 1.1 perseant *--cp = '/';
485 1.1 perseant if (cp < &namebuf[MAXNAMLEN])
486 1.1 perseant break;
487 1.1 perseant ino = idesc.id_number;
488 1.1 perseant }
489 1.1 perseant busy = 0;
490 1.1 perseant if (ino != ROOTINO)
491 1.1 perseant *--cp = '?';
492 1.1 perseant memcpy(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
493 1.1 perseant }
494 1.1 perseant
495 1.1 perseant void
496 1.1 perseant catch(n)
497 1.1 perseant int n;
498 1.1 perseant {
499 1.1 perseant if (!doinglevel2)
500 1.1 perseant ckfini(0);
501 1.1 perseant exit(12);
502 1.1 perseant }
503 1.1 perseant
504 1.1 perseant /*
505 1.1 perseant * When preening, allow a single quit to signal
506 1.1 perseant * a special exit after filesystem checks complete
507 1.1 perseant * so that reboot sequence may be interrupted.
508 1.1 perseant */
509 1.1 perseant void
510 1.1 perseant catchquit(n)
511 1.1 perseant int n;
512 1.1 perseant {
513 1.1 perseant extern int returntosingle;
514 1.1 perseant
515 1.1 perseant printf("returning to single-user after filesystem check\n");
516 1.1 perseant returntosingle = 1;
517 1.1 perseant (void)signal(SIGQUIT, SIG_DFL);
518 1.1 perseant }
519 1.1 perseant
520 1.1 perseant /*
521 1.1 perseant * Ignore a single quit signal; wait and flush just in case.
522 1.1 perseant * Used by child processes in preen.
523 1.1 perseant */
524 1.1 perseant void
525 1.1 perseant voidquit(n)
526 1.1 perseant int n;
527 1.1 perseant {
528 1.1 perseant
529 1.1 perseant sleep(1);
530 1.1 perseant (void)signal(SIGQUIT, SIG_IGN);
531 1.1 perseant (void)signal(SIGQUIT, SIG_DFL);
532 1.1 perseant }
533 1.1 perseant
534 1.1 perseant /*
535 1.1 perseant * determine whether an inode should be fixed.
536 1.1 perseant */
537 1.1 perseant int
538 1.1 perseant dofix(idesc, msg)
539 1.1 perseant register struct inodesc *idesc;
540 1.1 perseant char *msg;
541 1.1 perseant {
542 1.1 perseant
543 1.1 perseant switch (idesc->id_fix) {
544 1.1 perseant
545 1.1 perseant case DONTKNOW:
546 1.1 perseant if (idesc->id_type == DATA)
547 1.1 perseant direrror(idesc->id_number, msg);
548 1.1 perseant else
549 1.1 perseant pwarn(msg);
550 1.1 perseant if (preen) {
551 1.1 perseant printf(" (SALVAGED)\n");
552 1.1 perseant idesc->id_fix = FIX;
553 1.1 perseant return (ALTERED);
554 1.1 perseant }
555 1.1 perseant if (reply("SALVAGE") == 0) {
556 1.1 perseant idesc->id_fix = NOFIX;
557 1.1 perseant return (0);
558 1.1 perseant }
559 1.1 perseant idesc->id_fix = FIX;
560 1.1 perseant return (ALTERED);
561 1.1 perseant
562 1.1 perseant case FIX:
563 1.1 perseant return (ALTERED);
564 1.1 perseant
565 1.1 perseant case NOFIX:
566 1.1 perseant case IGNORE:
567 1.1 perseant return (0);
568 1.1 perseant
569 1.1 perseant default:
570 1.1 perseant errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
571 1.1 perseant }
572 1.1 perseant /* NOTREACHED */
573 1.1 perseant }
574