xref: /dragonfly/sbin/restore/interactive.c (revision 1bf4b486)
1 /*
2  * Copyright (c) 1985, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)interactive.c	8.5 (Berkeley) 5/1/95
34  * $FreeBSD: src/sbin/restore/interactive.c,v 1.8.2.1 2001/01/03 14:36:08 iedowse Exp $
35  * $DragonFly: src/sbin/restore/interactive.c,v 1.7 2004/12/18 21:43:40 swildner Exp $
36  */
37 
38 #include <sys/param.h>
39 #include <sys/stat.h>
40 
41 #include <vfs/ufs/dinode.h>
42 #include <vfs/ufs/dir.h>
43 #include <protocols/dumprestore.h>
44 
45 #include <setjmp.h>
46 #include <glob.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 
51 #include "restore.h"
52 #include "extern.h"
53 
54 #define round(a, b) (((a) + (b) - 1) / (b) * (b))
55 
56 /*
57  * Things to handle interruptions.
58  */
59 static int runshell;
60 static jmp_buf reset;
61 static char *nextarg = NULL;
62 
63 /*
64  * Structure and routines associated with listing directories.
65  */
66 struct afile {
67 	ino_t	fnum;		/* inode number of file */
68 	char	*fname;		/* file name */
69 	short	len;		/* name length */
70 	char	prefix;		/* prefix character */
71 	char	postfix;	/* postfix character */
72 };
73 struct arglist {
74 	int	freeglob;	/* glob structure needs to be freed */
75 	int	argcnt;		/* next globbed argument to return */
76 	glob_t	glob;		/* globbing information */
77 	char	*cmd;		/* the current command */
78 };
79 
80 static char	*copynext(char *, char *);
81 static int	 fcmp(const void *, const void *);
82 static void	 formatf(struct afile *, int);
83 static void	 getcmd(char *, char *, char *, int, struct arglist *);
84 struct dirent	*glob_readdir(RST_DIR *dirp);
85 static int	 glob_stat(const char *, struct stat *);
86 static void	 mkentry(char *, struct direct *, struct afile *);
87 static void	 printlist(char *, char *);
88 
89 /*
90  * Read and execute commands from the terminal.
91  */
92 void
93 runcmdshell(void)
94 {
95 	register struct entry *np;
96 	ino_t ino;
97 	struct arglist arglist;
98 	char curdir[MAXPATHLEN];
99 	char name[MAXPATHLEN];
100 	char cmd[BUFSIZ];
101 
102 	arglist.freeglob = 0;
103 	arglist.argcnt = 0;
104 	arglist.glob.gl_flags = GLOB_ALTDIRFUNC;
105 	arglist.glob.gl_opendir = (void *)rst_opendir;
106 	arglist.glob.gl_readdir = (void *)glob_readdir;
107 	arglist.glob.gl_closedir = (void *)rst_closedir;
108 	arglist.glob.gl_lstat = glob_stat;
109 	arglist.glob.gl_stat = glob_stat;
110 	canon("/", curdir, sizeof(curdir));
111 loop:
112 	if (setjmp(reset) != 0) {
113 		if (arglist.freeglob != 0) {
114 			arglist.freeglob = 0;
115 			arglist.argcnt = 0;
116 			globfree(&arglist.glob);
117 		}
118 		nextarg = NULL;
119 		volno = 0;
120 	}
121 	runshell = 1;
122 	getcmd(curdir, cmd, name, sizeof(name), &arglist);
123 	switch (cmd[0]) {
124 	/*
125 	 * Add elements to the extraction list.
126 	 */
127 	case 'a':
128 		if (strncmp(cmd, "add", strlen(cmd)) != 0)
129 			goto bad;
130 		ino = dirlookup(name);
131 		if (ino == 0)
132 			break;
133 		if (mflag)
134 			pathcheck(name);
135 		treescan(name, ino, addfile);
136 		break;
137 	/*
138 	 * Change working directory.
139 	 */
140 	case 'c':
141 		if (strncmp(cmd, "cd", strlen(cmd)) != 0)
142 			goto bad;
143 		ino = dirlookup(name);
144 		if (ino == 0)
145 			break;
146 		if (inodetype(ino) == LEAF) {
147 			fprintf(stderr, "%s: not a directory\n", name);
148 			break;
149 		}
150 		strcpy(curdir, name);
151 		break;
152 	/*
153 	 * Delete elements from the extraction list.
154 	 */
155 	case 'd':
156 		if (strncmp(cmd, "delete", strlen(cmd)) != 0)
157 			goto bad;
158 		np = lookupname(name);
159 		if (np == NULL || (np->e_flags & NEW) == 0) {
160 			fprintf(stderr, "%s: not on extraction list\n", name);
161 			break;
162 		}
163 		treescan(name, np->e_ino, deletefile);
164 		break;
165 	/*
166 	 * Extract the requested list.
167 	 */
168 	case 'e':
169 		if (strncmp(cmd, "extract", strlen(cmd)) != 0)
170 			goto bad;
171 		createfiles();
172 		createlinks();
173 		setdirmodes(0);
174 		if (dflag)
175 			checkrestore();
176 		volno = 0;
177 		break;
178 	/*
179 	 * List available commands.
180 	 */
181 	case 'h':
182 		if (strncmp(cmd, "help", strlen(cmd)) != 0)
183 			goto bad;
184 	case '?':
185 		fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
186 			"Available commands are:\n",
187 			"\tls [arg] - list directory\n",
188 			"\tcd arg - change directory\n",
189 			"\tpwd - print current directory\n",
190 			"\tadd [arg] - add `arg' to list of",
191 			" files to be extracted\n",
192 			"\tdelete [arg] - delete `arg' from",
193 			" list of files to be extracted\n",
194 			"\textract - extract requested files\n",
195 			"\tsetmodes - set modes of requested directories\n",
196 			"\tquit - immediately exit program\n",
197 			"\twhat - list dump header information\n",
198 			"\tverbose - toggle verbose flag",
199 			" (useful with ``ls'')\n",
200 			"\thelp or `?' - print this list\n",
201 			"If no `arg' is supplied, the current",
202 			" directory is used\n");
203 		break;
204 	/*
205 	 * List a directory.
206 	 */
207 	case 'l':
208 		if (strncmp(cmd, "ls", strlen(cmd)) != 0)
209 			goto bad;
210 		printlist(name, curdir);
211 		break;
212 	/*
213 	 * Print current directory.
214 	 */
215 	case 'p':
216 		if (strncmp(cmd, "pwd", strlen(cmd)) != 0)
217 			goto bad;
218 		if (curdir[1] == '\0')
219 			fprintf(stderr, "/\n");
220 		else
221 			fprintf(stderr, "%s\n", &curdir[1]);
222 		break;
223 	/*
224 	 * Quit.
225 	 */
226 	case 'q':
227 		if (strncmp(cmd, "quit", strlen(cmd)) != 0)
228 			goto bad;
229 		return;
230 	case 'x':
231 		if (strncmp(cmd, "xit", strlen(cmd)) != 0)
232 			goto bad;
233 		return;
234 	/*
235 	 * Toggle verbose mode.
236 	 */
237 	case 'v':
238 		if (strncmp(cmd, "verbose", strlen(cmd)) != 0)
239 			goto bad;
240 		if (vflag) {
241 			fprintf(stderr, "verbose mode off\n");
242 			vflag = 0;
243 			break;
244 		}
245 		fprintf(stderr, "verbose mode on\n");
246 		vflag++;
247 		break;
248 	/*
249 	 * Just restore requested directory modes.
250 	 */
251 	case 's':
252 		if (strncmp(cmd, "setmodes", strlen(cmd)) != 0)
253 			goto bad;
254 		setdirmodes(FORCE);
255 		break;
256 	/*
257 	 * Print out dump header information.
258 	 */
259 	case 'w':
260 		if (strncmp(cmd, "what", strlen(cmd)) != 0)
261 			goto bad;
262 		printdumpinfo();
263 		break;
264 	/*
265 	 * Turn on debugging.
266 	 */
267 	case 'D':
268 		if (strncmp(cmd, "Debug", strlen(cmd)) != 0)
269 			goto bad;
270 		if (dflag) {
271 			fprintf(stderr, "debugging mode off\n");
272 			dflag = 0;
273 			break;
274 		}
275 		fprintf(stderr, "debugging mode on\n");
276 		dflag++;
277 		break;
278 	/*
279 	 * Unknown command.
280 	 */
281 	default:
282 	bad:
283 		fprintf(stderr, "%s: unknown command; type ? for help\n", cmd);
284 		break;
285 	}
286 	goto loop;
287 }
288 
289 /*
290  * Read and parse an interactive command.
291  * The first word on the line is assigned to "cmd". If
292  * there are no arguments on the command line, then "curdir"
293  * is returned as the argument. If there are arguments
294  * on the line they are returned one at a time on each
295  * successive call to getcmd. Each argument is first assigned
296  * to "name". If it does not start with "/" the pathname in
297  * "curdir" is prepended to it. Finally "canon" is called to
298  * eliminate any embedded ".." components.
299  */
300 static void
301 getcmd(char *curdir, char *cmd, char *name, int size, struct arglist *ap)
302 {
303 	register char *cp;
304 	static char input[BUFSIZ];
305 	char output[BUFSIZ];
306 #	define rawname input	/* save space by reusing input buffer */
307 
308 	/*
309 	 * Check to see if still processing arguments.
310 	 */
311 	if (ap->argcnt > 0)
312 		goto retnext;
313 	if (nextarg != NULL)
314 		goto getnext;
315 	/*
316 	 * Read a command line and trim off trailing white space.
317 	 */
318 	do	{
319 		fprintf(stderr, "restore > ");
320 		fflush(stderr);
321 		if (fgets(input, BUFSIZ, terminal) == NULL) {
322 			strcpy(cmd, "quit");
323 			return;
324 		}
325 	} while (input[0] == '\n');
326 	for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--)
327 		/* trim off trailing white space and newline */;
328 	*++cp = '\0';
329 	/*
330 	 * Copy the command into "cmd".
331 	 */
332 	cp = copynext(input, cmd);
333 	ap->cmd = cmd;
334 	/*
335 	 * If no argument, use curdir as the default.
336 	 */
337 	if (*cp == '\0') {
338 		strncpy(name, curdir, size);
339 		name[size - 1] = '\0';
340 		return;
341 	}
342 	nextarg = cp;
343 	/*
344 	 * Find the next argument.
345 	 */
346 getnext:
347 	cp = copynext(nextarg, rawname);
348 	if (*cp == '\0')
349 		nextarg = NULL;
350 	else
351 		nextarg = cp;
352 	/*
353 	 * If it is an absolute pathname, canonicalize it and return it.
354 	 */
355 	if (rawname[0] == '/') {
356 		canon(rawname, name, size);
357 	} else {
358 		/*
359 		 * For relative pathnames, prepend the current directory to
360 		 * it then canonicalize and return it.
361 		 */
362 		snprintf(output, sizeof(output), "%s/%s", curdir, rawname);
363 		canon(output, name, size);
364 	}
365 	if (glob(name, GLOB_ALTDIRFUNC, NULL, &ap->glob) < 0)
366 		fprintf(stderr, "%s: out of memory\n", ap->cmd);
367 	if (ap->glob.gl_pathc == 0)
368 		return;
369 	ap->freeglob = 1;
370 	ap->argcnt = ap->glob.gl_pathc;
371 
372 retnext:
373 	strncpy(name, ap->glob.gl_pathv[ap->glob.gl_pathc - ap->argcnt], size);
374 	name[size - 1] = '\0';
375 	if (--ap->argcnt == 0) {
376 		ap->freeglob = 0;
377 		globfree(&ap->glob);
378 	}
379 #	undef rawname
380 }
381 
382 /*
383  * Strip off the next token of the input.
384  */
385 static char *
386 copynext(char *input, char *output)
387 {
388 	register char *cp, *bp;
389 	char quote;
390 
391 	for (cp = input; *cp == ' ' || *cp == '\t'; cp++)
392 		/* skip to argument */;
393 	bp = output;
394 	while (*cp != ' ' && *cp != '\t' && *cp != '\0') {
395 		/*
396 		 * Handle back slashes.
397 		 */
398 		if (*cp == '\\') {
399 			if (*++cp == '\0') {
400 				fprintf(stderr,
401 					"command lines cannot be continued\n");
402 				continue;
403 			}
404 			*bp++ = *cp++;
405 			continue;
406 		}
407 		/*
408 		 * The usual unquoted case.
409 		 */
410 		if (*cp != '\'' && *cp != '"') {
411 			*bp++ = *cp++;
412 			continue;
413 		}
414 		/*
415 		 * Handle single and double quotes.
416 		 */
417 		quote = *cp++;
418 		while (*cp != quote && *cp != '\0')
419 			*bp++ = *cp++ | 0200;
420 		if (*cp++ == '\0') {
421 			fprintf(stderr, "missing %c\n", quote);
422 			cp--;
423 			continue;
424 		}
425 	}
426 	*bp = '\0';
427 	return (cp);
428 }
429 
430 /*
431  * Canonicalize file names to always start with ``./'' and
432  * remove any embedded "." and ".." components.
433  */
434 void
435 canon(char *rawname, char *canonname, int len)
436 {
437 	register char *cp, *np;
438 
439 	if (strcmp(rawname, ".") == 0 || strncmp(rawname, "./", 2) == 0)
440 		strcpy(canonname, "");
441 	else if (rawname[0] == '/')
442 		strcpy(canonname, ".");
443 	else
444 		strcpy(canonname, "./");
445 	if (strlen(canonname) + strlen(rawname) >= len) {
446 		fprintf(stderr, "canonname: not enough buffer space\n");
447 		done(1);
448 	}
449 
450 	strcat(canonname, rawname);
451 	/*
452 	 * Eliminate multiple and trailing '/'s
453 	 */
454 	for (cp = np = canonname; *np != '\0'; cp++) {
455 		*cp = *np++;
456 		while (*cp == '/' && *np == '/')
457 			np++;
458 	}
459 	*cp = '\0';
460 	if (*--cp == '/')
461 		*cp = '\0';
462 	/*
463 	 * Eliminate extraneous "." and ".." from pathnames.
464 	 */
465 	for (np = canonname; *np != '\0'; ) {
466 		np++;
467 		cp = np;
468 		while (*np != '/' && *np != '\0')
469 			np++;
470 		if (np - cp == 1 && *cp == '.') {
471 			cp--;
472 			strcpy(cp, np);
473 			np = cp;
474 		}
475 		if (np - cp == 2 && strncmp(cp, "..", 2) == 0) {
476 			cp--;
477 			while (cp > &canonname[1] && *--cp != '/')
478 				/* find beginning of name */;
479 			strcpy(cp, np);
480 			np = cp;
481 		}
482 	}
483 }
484 
485 /*
486  * Do an "ls" style listing of a directory
487  */
488 static void
489 printlist(char *name, char *basename)
490 {
491 	register struct afile *fp, *list, *listp = NULL;
492 	register struct direct *dp;
493 	struct afile single;
494 	RST_DIR *dirp;
495 	int entries, len, namelen;
496 	char locname[MAXPATHLEN + 1];
497 
498 	dp = pathsearch(name);
499 	if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
500 	    (!vflag && dp->d_ino == WINO))
501 		return;
502 	if ((dirp = rst_opendir(name)) == NULL) {
503 		entries = 1;
504 		list = &single;
505 		mkentry(name, dp, list);
506 		len = strlen(basename) + 1;
507 		if (strlen(name) - len > single.len) {
508 			freename(single.fname);
509 			single.fname = savename(&name[len]);
510 			single.len = strlen(single.fname);
511 		}
512 	} else {
513 		entries = 0;
514 		while ((dp = rst_readdir(dirp)))
515 			entries++;
516 		rst_closedir(dirp);
517 		list = (struct afile *)malloc(entries * sizeof(struct afile));
518 		if (list == NULL) {
519 			fprintf(stderr, "ls: out of memory\n");
520 			return;
521 		}
522 		if ((dirp = rst_opendir(name)) == NULL)
523 			panic("directory reopen failed\n");
524 		fprintf(stderr, "%s:\n", name);
525 		entries = 0;
526 		listp = list;
527 		strncpy(locname, name, MAXPATHLEN);
528 		strncat(locname, "/", MAXPATHLEN);
529 		namelen = strlen(locname);
530 		while ((dp = rst_readdir(dirp))) {
531 			if (dp == NULL)
532 				break;
533 			if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)
534 				continue;
535 			if (!vflag && (dp->d_ino == WINO ||
536 			     strcmp(dp->d_name, ".") == 0 ||
537 			     strcmp(dp->d_name, "..") == 0))
538 				continue;
539 			locname[namelen] = '\0';
540 			if (namelen + dp->d_namlen >= MAXPATHLEN) {
541 				fprintf(stderr, "%s%s: name exceeds %d char\n",
542 					locname, dp->d_name, MAXPATHLEN);
543 			} else {
544 				strncat(locname, dp->d_name, (int)dp->d_namlen);
545 				mkentry(locname, dp, listp++);
546 				entries++;
547 			}
548 		}
549 		rst_closedir(dirp);
550 		if (entries == 0) {
551 			fprintf(stderr, "\n");
552 			free(list);
553 			return;
554 		}
555 		qsort((char *)list, entries, sizeof(struct afile), fcmp);
556 	}
557 	formatf(list, entries);
558 	if (dirp != NULL) {
559 		for (fp = listp - 1; fp >= list; fp--)
560 			freename(fp->fname);
561 		fprintf(stderr, "\n");
562 		free(list);
563 	}
564 }
565 
566 /*
567  * Read the contents of a directory.
568  */
569 static void
570 mkentry(char *name, struct direct *dp, register struct afile *fp)
571 {
572 	char *cp;
573 	struct entry *np;
574 
575 	fp->fnum = dp->d_ino;
576 	fp->fname = savename(dp->d_name);
577 	for (cp = fp->fname; *cp; cp++)
578 		if (!vflag && (*cp < ' ' || *cp >= 0177))
579 			*cp = '?';
580 	fp->len = cp - fp->fname;
581 	if (dflag && TSTINO(fp->fnum, dumpmap) == 0)
582 		fp->prefix = '^';
583 	else if ((np = lookupname(name)) != NULL && (np->e_flags & NEW))
584 		fp->prefix = '*';
585 	else
586 		fp->prefix = ' ';
587 	switch(dp->d_type) {
588 
589 	default:
590 		fprintf(stderr, "Warning: undefined file type %d\n",
591 		    dp->d_type);
592 		/* fall through */
593 	case DT_REG:
594 		fp->postfix = ' ';
595 		break;
596 
597 	case DT_LNK:
598 		fp->postfix = '@';
599 		break;
600 
601 	case DT_FIFO:
602 	case DT_SOCK:
603 		fp->postfix = '=';
604 		break;
605 
606 	case DT_CHR:
607 	case DT_BLK:
608 		fp->postfix = '#';
609 		break;
610 
611 	case DT_WHT:
612 		fp->postfix = '%';
613 		break;
614 
615 	case DT_UNKNOWN:
616 	case DT_DIR:
617 		if (inodetype(dp->d_ino) == NODE)
618 			fp->postfix = '/';
619 		else
620 			fp->postfix = ' ';
621 		break;
622 	}
623 	return;
624 }
625 
626 /*
627  * Print out a pretty listing of a directory
628  */
629 static void
630 formatf(register struct afile *list, int nentry)
631 {
632 	register struct afile *fp, *endlist;
633 	int width, bigino, haveprefix, havepostfix;
634 	int i, j, w, precision = 0, columns, lines;
635 
636 	width = 0;
637 	haveprefix = 0;
638 	havepostfix = 0;
639 	bigino = ROOTINO;
640 	endlist = &list[nentry];
641 	for (fp = &list[0]; fp < endlist; fp++) {
642 		if (bigino < fp->fnum)
643 			bigino = fp->fnum;
644 		if (width < fp->len)
645 			width = fp->len;
646 		if (fp->prefix != ' ')
647 			haveprefix = 1;
648 		if (fp->postfix != ' ')
649 			havepostfix = 1;
650 	}
651 	if (haveprefix)
652 		width++;
653 	if (havepostfix)
654 		width++;
655 	if (vflag) {
656 		for (precision = 0, i = bigino; i > 0; i /= 10)
657 			precision++;
658 		width += precision + 1;
659 	}
660 	width++;
661 	columns = 81 / width;
662 	if (columns == 0)
663 		columns = 1;
664 	lines = (nentry + columns - 1) / columns;
665 	for (i = 0; i < lines; i++) {
666 		for (j = 0; j < columns; j++) {
667 			fp = &list[j * lines + i];
668 			if (vflag) {
669 				fprintf(stderr, "%*d ", precision, fp->fnum);
670 				fp->len += precision + 1;
671 			}
672 			if (haveprefix) {
673 				putc(fp->prefix, stderr);
674 				fp->len++;
675 			}
676 			fprintf(stderr, "%s", fp->fname);
677 			if (havepostfix) {
678 				putc(fp->postfix, stderr);
679 				fp->len++;
680 			}
681 			if (fp + lines >= endlist) {
682 				fprintf(stderr, "\n");
683 				break;
684 			}
685 			for (w = fp->len; w < width; w++)
686 				putc(' ', stderr);
687 		}
688 	}
689 }
690 
691 /*
692  * Skip over directory entries that are not on the tape
693  *
694  * First have to get definition of a dirent.
695  */
696 #undef DIRBLKSIZ
697 #include <dirent.h>
698 #undef d_ino
699 
700 struct dirent *
701 glob_readdir(RST_DIR *dirp)
702 {
703 	struct direct *dp;
704 	static struct dirent adirent;
705 
706 	while ((dp = rst_readdir(dirp)) != NULL) {
707 		if (!vflag && dp->d_ino == WINO)
708 			continue;
709 		if (dflag || TSTINO(dp->d_ino, dumpmap))
710 			break;
711 	}
712 	if (dp == NULL)
713 		return (NULL);
714 	adirent.d_fileno = dp->d_ino;
715 	adirent.d_namlen = dp->d_namlen;
716 	memmove(adirent.d_name, dp->d_name, dp->d_namlen + 1);
717 	return (&adirent);
718 }
719 
720 /*
721  * Return st_mode information in response to stat or lstat calls
722  */
723 static int
724 glob_stat(const char *name, struct stat *stp)
725 {
726 	register struct direct *dp;
727 
728 	dp = pathsearch(name);
729 	if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
730 	    (!vflag && dp->d_ino == WINO))
731 		return (-1);
732 	if (inodetype(dp->d_ino) == NODE)
733 		stp->st_mode = IFDIR;
734 	else
735 		stp->st_mode = IFREG;
736 	return (0);
737 }
738 
739 /*
740  * Comparison routine for qsort.
741  */
742 static int
743 fcmp(register const void *f1, register const void *f2)
744 {
745 	return (strcmp(((struct afile *)f1)->fname,
746 	    ((struct afile *)f2)->fname));
747 }
748 
749 /*
750  * respond to interrupts
751  */
752 void
753 onintr(int signo)
754 {
755 	if (command == 'i' && runshell)
756 		longjmp(reset, 1);
757 	if (reply("restore interrupted, continue") == FAIL)
758 		done(1);
759 }
760