Remove advertising header from all userland binaries.
[dragonfly.git] / sbin / restore / restore.c
1 /*
2  * Copyright (c) 1983, 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  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)restore.c        8.3 (Berkeley) 9/13/94
30  * $FreeBSD: src/sbin/restore/restore.c,v 1.7.2.1 2002/03/01 21:32:28 iedowse Exp $
31  * $DragonFly: src/sbin/restore/restore.c,v 1.9 2008/06/05 18:06:31 swildner Exp $
32  */
33
34 #include <sys/types.h>
35
36 #include <vfs/ufs/dinode.h>
37
38 #include <stdio.h>
39 #include <string.h>
40
41 #include "restore.h"
42 #include "extern.h"
43
44 static char *keyval(int);
45
46 /*
47  * This implements the 't' option.
48  * List entries on the tape.
49  */
50 long
51 listfile(char *name, ufs1_ino_t ino, int type)
52 {
53         long descend = hflag ? GOOD : FAIL;
54
55         if (TSTINO(ino, dumpmap) == 0)
56                 return (descend);
57         vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
58         fprintf(stdout, "%10d\t%s\n", ino, name);
59         return (descend);
60 }
61
62 /*
63  * This implements the 'x' option.
64  * Request that new entries be extracted.
65  */
66 long
67 addfile(char *name, ufs1_ino_t ino, int type)
68 {
69         struct entry *ep;
70         long descend = hflag ? GOOD : FAIL;
71         char buf[100];
72
73         if (TSTINO(ino, dumpmap) == 0) {
74                 dprintf(stdout, "%s: not on the tape\n", name);
75                 return (descend);
76         }
77         if (ino == WINO && command == 'i' && !vflag)
78                 return (descend);
79         if (!mflag) {
80                 sprintf(buf, "./%u", ino);
81                 name = buf;
82                 if (type == NODE) {
83                         genliteraldir(name, ino);
84                         return (descend);
85                 }
86         }
87         ep = lookupino(ino);
88         if (ep != NULL) {
89                 if (strcmp(name, myname(ep)) == 0) {
90                         ep->e_flags |= NEW;
91                         return (descend);
92                 }
93                 type |= LINK;
94         }
95         ep = addentry(name, ino, type);
96         if (type == NODE)
97                 newnode(ep);
98         ep->e_flags |= NEW;
99         return (descend);
100 }
101
102 /*
103  * This is used by the 'i' option to undo previous requests made by addfile.
104  * Delete entries from the request queue.
105  */
106 /* ARGSUSED */
107 long
108 deletefile(char *name, ufs1_ino_t ino, int type)
109 {
110         long descend = hflag ? GOOD : FAIL;
111         struct entry *ep;
112
113         if (TSTINO(ino, dumpmap) == 0)
114                 return (descend);
115         ep = lookupname(name);
116         if (ep != NULL) {
117                 ep->e_flags &= ~NEW;
118                 ep->e_flags |= REMOVED;
119                 if (ep->e_type != NODE)
120                         freeentry(ep);
121         }
122         return (descend);
123 }
124
125 /*
126  * The following four routines implement the incremental
127  * restore algorithm. The first removes old entries, the second
128  * does renames and calculates the extraction list, the third
129  * cleans up link names missed by the first two, and the final
130  * one deletes old directories.
131  *
132  * Directories cannot be immediately deleted, as they may have
133  * other files in them which need to be moved out first. As
134  * directories to be deleted are found, they are put on the
135  * following deletion list. After all deletions and renames
136  * are done, this list is actually deleted.
137  */
138 static struct entry *removelist;
139
140 /*
141  *      Remove invalid whiteouts from the old tree.
142  *      Remove unneeded leaves from the old tree.
143  *      Remove directories from the lookup chains.
144  */
145 void
146 removeoldleaves(void)
147 {
148         struct entry *ep, *nextep;
149         ufs1_ino_t i, mydirino;
150
151         vprintf(stdout, "Mark entries to be removed.\n");
152         if ((ep = lookupino(WINO))) {
153                 vprintf(stdout, "Delete whiteouts\n");
154                 for ( ; ep != NULL; ep = nextep) {
155                         nextep = ep->e_links;
156                         mydirino = ep->e_parent->e_ino;
157                         /*
158                          * We remove all whiteouts that are in directories
159                          * that have been removed or that have been dumped.
160                          */
161                         if (TSTINO(mydirino, usedinomap) &&
162                             !TSTINO(mydirino, dumpmap))
163                                 continue;
164                         delwhiteout(ep);
165                         freeentry(ep);
166                 }
167         }
168         for (i = ROOTINO + 1; i < maxino; i++) {
169                 ep = lookupino(i);
170                 if (ep == NULL)
171                         continue;
172                 if (TSTINO(i, usedinomap))
173                         continue;
174                 for ( ; ep != NULL; ep = ep->e_links) {
175                         dprintf(stdout, "%s: REMOVE\n", myname(ep));
176                         if (ep->e_type == LEAF) {
177                                 removeleaf(ep);
178                                 freeentry(ep);
179                         } else {
180                                 mktempname(ep);
181                                 deleteino(ep->e_ino);
182                                 ep->e_next = removelist;
183                                 removelist = ep;
184                         }
185                 }
186         }
187 }
188
189 /*
190  *      For each directory entry on the incremental tape, determine which
191  *      category it falls into as follows:
192  *      KEEP - entries that are to be left alone.
193  *      NEW - new entries to be added.
194  *      EXTRACT - files that must be updated with new contents.
195  *      LINK - new links to be added.
196  *      Renames are done at the same time.
197  */
198 long
199 nodeupdates(char *name, ufs1_ino_t ino, int type)
200 {
201         struct entry *ep, *np, *ip;
202         long descend = GOOD;
203         int lookuptype = 0;
204         int key = 0;
205                 /* key values */
206 #               define ONTAPE   0x1     /* inode is on the tape */
207 #               define INOFND   0x2     /* inode already exists */
208 #               define NAMEFND  0x4     /* name already exists */
209 #               define MODECHG  0x8     /* mode of inode changed */
210
211         /*
212          * This routine is called once for each element in the
213          * directory hierarchy, with a full path name.
214          * The "type" value is incorrectly specified as LEAF for
215          * directories that are not on the dump tape.
216          *
217          * Check to see if the file is on the tape.
218          */
219         if (TSTINO(ino, dumpmap))
220                 key |= ONTAPE;
221         /*
222          * Check to see if the name exists, and if the name is a link.
223          */
224         np = lookupname(name);
225         if (np != NULL) {
226                 key |= NAMEFND;
227                 ip = lookupino(np->e_ino);
228                 if (ip == NULL)
229                         panic("corrupted symbol table\n");
230                 if (ip != np)
231                         lookuptype = LINK;
232         }
233         /*
234          * Check to see if the inode exists, and if one of its links
235          * corresponds to the name (if one was found).
236          */
237         ip = lookupino(ino);
238         if (ip != NULL) {
239                 key |= INOFND;
240                 for (ep = ip->e_links; ep != NULL; ep = ep->e_links) {
241                         if (ep == np) {
242                                 ip = ep;
243                                 break;
244                         }
245                 }
246         }
247         /*
248          * If both a name and an inode are found, but they do not
249          * correspond to the same file, then both the inode that has
250          * been found and the inode corresponding to the name that
251          * has been found need to be renamed. The current pathname
252          * is the new name for the inode that has been found. Since
253          * all files to be deleted have already been removed, the
254          * named file is either a now unneeded link, or it must live
255          * under a new name in this dump level. If it is a link, it
256          * can be removed. If it is not a link, it is given a
257          * temporary name in anticipation that it will be renamed
258          * when it is later found by inode number.
259          */
260         if (((key & (INOFND|NAMEFND)) == (INOFND|NAMEFND)) && ip != np) {
261                 if (lookuptype == LINK) {
262                         removeleaf(np);
263                         freeentry(np);
264                 } else {
265                         dprintf(stdout, "name/inode conflict, mktempname %s\n",
266                                 myname(np));
267                         mktempname(np);
268                 }
269                 np = NULL;
270                 key &= ~NAMEFND;
271         }
272         if ((key & ONTAPE) &&
273           (((key & INOFND) && ip->e_type != type) ||
274            ((key & NAMEFND) && np->e_type != type)))
275                 key |= MODECHG;
276
277         /*
278          * Decide on the disposition of the file based on its flags.
279          * Note that we have already handled the case in which
280          * a name and inode are found that correspond to different files.
281          * Thus if both NAMEFND and INOFND are set then ip == np.
282          */
283         switch (key) {
284
285         /*
286          * A previously existing file has been found.
287          * Mark it as KEEP so that other links to the inode can be
288          * detected, and so that it will not be reclaimed by the search
289          * for unreferenced names.
290          */
291         case INOFND|NAMEFND:
292                 ip->e_flags |= KEEP;
293                 dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
294                         flagvalues(ip));
295                 break;
296
297         /*
298          * A file on the tape has a name which is the same as a name
299          * corresponding to a different file in the previous dump.
300          * Since all files to be deleted have already been removed,
301          * this file is either a now unneeded link, or it must live
302          * under a new name in this dump level. If it is a link, it
303          * can simply be removed. If it is not a link, it is given a
304          * temporary name in anticipation that it will be renamed
305          * when it is later found by inode number (see INOFND case
306          * below). The entry is then treated as a new file.
307          */
308         case ONTAPE|NAMEFND:
309         case ONTAPE|NAMEFND|MODECHG:
310                 if (lookuptype == LINK) {
311                         removeleaf(np);
312                         freeentry(np);
313                 } else {
314                         mktempname(np);
315                 }
316                 /* fall through */
317
318         /*
319          * A previously non-existent file.
320          * Add it to the file system, and request its extraction.
321          * If it is a directory, create it immediately.
322          * (Since the name is unused there can be no conflict)
323          */
324         case ONTAPE:
325                 ep = addentry(name, ino, type);
326                 if (type == NODE)
327                         newnode(ep);
328                 ep->e_flags |= NEW|KEEP;
329                 dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
330                         flagvalues(ep));
331                 break;
332
333         /*
334          * A file with the same inode number, but a different
335          * name has been found. If the other name has not already
336          * been found (indicated by the KEEP flag, see above) then
337          * this must be a new name for the file, and it is renamed.
338          * If the other name has been found then this must be a
339          * link to the file. Hard links to directories are not
340          * permitted, and are either deleted or converted to
341          * symbolic links. Finally, if the file is on the tape,
342          * a request is made to extract it.
343          */
344         case ONTAPE|INOFND:
345                 if (type == LEAF && (ip->e_flags & KEEP) == 0)
346                         ip->e_flags |= EXTRACT;
347                 /* fall through */
348         case INOFND:
349                 if ((ip->e_flags & KEEP) == 0) {
350                         renameit(myname(ip), name);
351                         moveentry(ip, name);
352                         ip->e_flags |= KEEP;
353                         dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
354                                 flagvalues(ip));
355                         break;
356                 }
357                 if (ip->e_type == NODE) {
358                         descend = FAIL;
359                         fprintf(stderr,
360                                 "deleted hard link %s to directory %s\n",
361                                 name, myname(ip));
362                         break;
363                 }
364                 ep = addentry(name, ino, type|LINK);
365                 ep->e_flags |= NEW;
366                 dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
367                         flagvalues(ep));
368                 break;
369
370         /*
371          * A previously known file which is to be updated. If it is a link,
372          * then all names referring to the previous file must be removed
373          * so that the subset of them that remain can be recreated.
374          */
375         case ONTAPE|INOFND|NAMEFND:
376                 if (lookuptype == LINK) {
377                         removeleaf(np);
378                         freeentry(np);
379                         ep = addentry(name, ino, type|LINK);
380                         if (type == NODE)
381                                 newnode(ep);
382                         ep->e_flags |= NEW|KEEP;
383                         dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
384                                 flagvalues(ep));
385                         break;
386                 }
387                 if (type == LEAF && lookuptype != LINK)
388                         np->e_flags |= EXTRACT;
389                 np->e_flags |= KEEP;
390                 dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
391                         flagvalues(np));
392                 break;
393
394         /*
395          * An inode is being reused in a completely different way.
396          * Normally an extract can simply do an "unlink" followed
397          * by a "creat". Here we must do effectively the same
398          * thing. The complications arise because we cannot really
399          * delete a directory since it may still contain files
400          * that we need to rename, so we delete it from the symbol
401          * table, and put it on the list to be deleted eventually.
402          * Conversely if a directory is to be created, it must be
403          * done immediately, rather than waiting until the
404          * extraction phase.
405          */
406         case ONTAPE|INOFND|MODECHG:
407         case ONTAPE|INOFND|NAMEFND|MODECHG:
408                 if (ip->e_flags & KEEP) {
409                         badentry(ip, "cannot KEEP and change modes");
410                         break;
411                 }
412                 if (ip->e_type == LEAF) {
413                         /* changing from leaf to node */
414                         for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) {
415                                 if (ip->e_type != LEAF)
416                                         badentry(ip, "NODE and LEAF links to same inode");
417                                 removeleaf(ip);
418                                 freeentry(ip);
419                         }
420                         ip = addentry(name, ino, type);
421                         newnode(ip);
422                 } else {
423                         /* changing from node to leaf */
424                         if ((ip->e_flags & TMPNAME) == 0)
425                                 mktempname(ip);
426                         deleteino(ip->e_ino);
427                         ip->e_next = removelist;
428                         removelist = ip;
429                         ip = addentry(name, ino, type);
430                 }
431                 ip->e_flags |= NEW|KEEP;
432                 dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
433                         flagvalues(ip));
434                 break;
435
436         /*
437          * A hard link to a directory that has been removed.
438          * Ignore it.
439          */
440         case NAMEFND:
441                 dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
442                         name);
443                 descend = FAIL;
444                 break;
445
446         /*
447          * If we find a directory entry for a file that is not on
448          * the tape, then we must have found a file that was created
449          * while the dump was in progress. Since we have no contents
450          * for it, we discard the name knowing that it will be on the
451          * next incremental tape.
452          */
453         case 0:
454                 fprintf(stderr, "%s: (inode %d) not found on tape\n",
455                         name, ino);
456                 break;
457
458         /*
459          * If any of these arise, something is grievously wrong with
460          * the current state of the symbol table.
461          */
462         case INOFND|NAMEFND|MODECHG:
463         case NAMEFND|MODECHG:
464         case INOFND|MODECHG:
465                 fprintf(stderr, "[%s] %s: inconsistent state\n", keyval(key),
466                         name);
467                 break;
468
469         /*
470          * These states "cannot" arise for any state of the symbol table.
471          */
472         case ONTAPE|MODECHG:
473         case MODECHG:
474         default:
475                 panic("[%s] %s: impossible state\n", keyval(key), name);
476                 break;
477         }
478         return (descend);
479 }
480
481 /*
482  * Calculate the active flags in a key.
483  */
484 static char *
485 keyval(int key)
486 {
487         static char keybuf[32];
488
489         strcpy(keybuf, "|NIL");
490         keybuf[0] = '\0';
491         if (key & ONTAPE)
492                 strcat(keybuf, "|ONTAPE");
493         if (key & INOFND)
494                 strcat(keybuf, "|INOFND");
495         if (key & NAMEFND)
496                 strcat(keybuf, "|NAMEFND");
497         if (key & MODECHG)
498                 strcat(keybuf, "|MODECHG");
499         return (&keybuf[1]);
500 }
501
502 /*
503  * Find unreferenced link names.
504  */
505 void
506 findunreflinks(void)
507 {
508         struct entry *ep, *np;
509         ufs1_ino_t i;
510
511         vprintf(stdout, "Find unreferenced names.\n");
512         for (i = ROOTINO; i < maxino; i++) {
513                 ep = lookupino(i);
514                 if (ep == NULL || ep->e_type == LEAF || TSTINO(i, dumpmap) == 0)
515                         continue;
516                 for (np = ep->e_entries; np != NULL; np = np->e_sibling) {
517                         if (np->e_flags == 0) {
518                                 dprintf(stdout,
519                                     "%s: remove unreferenced name\n",
520                                     myname(np));
521                                 removeleaf(np);
522                                 freeentry(np);
523                         }
524                 }
525         }
526         /*
527          * Any leaves remaining in removed directories is unreferenced.
528          */
529         for (ep = removelist; ep != NULL; ep = ep->e_next) {
530                 for (np = ep->e_entries; np != NULL; np = np->e_sibling) {
531                         if (np->e_type == LEAF) {
532                                 if (np->e_flags != 0)
533                                         badentry(np, "unreferenced with flags");
534                                 dprintf(stdout,
535                                     "%s: remove unreferenced name\n",
536                                     myname(np));
537                                 removeleaf(np);
538                                 freeentry(np);
539                         }
540                 }
541         }
542 }
543
544 /*
545  * Remove old nodes (directories).
546  * Note that this routine runs in O(N*D) where:
547  *      N is the number of directory entries to be removed.
548  *      D is the maximum depth of the tree.
549  * If N == D this can be quite slow. If the list were
550  * topologically sorted, the deletion could be done in
551  * time O(N).
552  */
553 void
554 removeoldnodes(void)
555 {
556         struct entry *ep, **prev;
557         long change;
558
559         vprintf(stdout, "Remove old nodes (directories).\n");
560         do      {
561                 change = 0;
562                 prev = &removelist;
563                 for (ep = removelist; ep != NULL; ep = *prev) {
564                         if (ep->e_entries != NULL) {
565                                 prev = &ep->e_next;
566                                 continue;
567                         }
568                         *prev = ep->e_next;
569                         removenode(ep);
570                         freeentry(ep);
571                         change++;
572                 }
573         } while (change);
574         for (ep = removelist; ep != NULL; ep = ep->e_next)
575                 badentry(ep, "cannot remove, non-empty");
576 }
577
578 /*
579  * This is the routine used to extract files for the 'r' command.
580  * Extract new leaves.
581  */
582 void
583 createleaves(char *symtabfile)
584 {
585         struct entry *ep;
586         ufs1_ino_t first;
587         long curvol;
588
589         if (command == 'R') {
590                 vprintf(stdout, "Continue extraction of new leaves\n");
591         } else {
592                 vprintf(stdout, "Extract new leaves.\n");
593                 dumpsymtable(symtabfile, volno);
594         }
595         first = lowerbnd(ROOTINO);
596         curvol = volno;
597         while (curfile.ino < maxino) {
598                 first = lowerbnd(first);
599                 /*
600                  * If the next available file is not the one which we
601                  * expect then we have missed one or more files. Since
602                  * we do not request files that were not on the tape,
603                  * the lost files must have been due to a tape read error,
604                  * or a file that was removed while the dump was in progress.
605                  */
606                 while (first < curfile.ino) {
607                         ep = lookupino(first);
608                         if (ep == NULL)
609                                 panic("%d: bad first\n", first);
610                         fprintf(stderr, "%s: not found on tape\n", myname(ep));
611                         ep->e_flags &= ~(NEW|EXTRACT);
612                         first = lowerbnd(first);
613                 }
614                 /*
615                  * If we find files on the tape that have no corresponding
616                  * directory entries, then we must have found a file that
617                  * was created while the dump was in progress. Since we have
618                  * no name for it, we discard it knowing that it will be
619                  * on the next incremental tape.
620                  */
621                 if (first != curfile.ino) {
622                         fprintf(stderr, "expected next file %d, got %d\n",
623                                 first, curfile.ino);
624                         skipfile();
625                         goto next;
626                 }
627                 ep = lookupino(curfile.ino);
628                 if (ep == NULL)
629                         panic("unknown file on tape\n");
630                 if ((ep->e_flags & (NEW|EXTRACT)) == 0)
631                         badentry(ep, "unexpected file on tape");
632                 /*
633                  * If the file is to be extracted, then the old file must
634                  * be removed since its type may change from one leaf type
635                  * to another (e.g. "file" to "character special").
636                  */
637                 if ((ep->e_flags & EXTRACT) != 0) {
638                         removeleaf(ep);
639                         ep->e_flags &= ~REMOVED;
640                 }
641                 extractfile(myname(ep));
642                 ep->e_flags &= ~(NEW|EXTRACT);
643                 /*
644                  * We checkpoint the restore after every tape reel, so
645                  * as to simplify the amount of work required by the
646                  * 'R' command.
647                  */
648         next:
649                 if (curvol != volno) {
650                         dumpsymtable(symtabfile, volno);
651                         skipmaps();
652                         curvol = volno;
653                 }
654         }
655 }
656
657 /*
658  * This is the routine used to extract files for the 'x' and 'i' commands.
659  * Efficiently extract a subset of the files on a tape.
660  */
661 void
662 createfiles(void)
663 {
664         ufs1_ino_t first, next, last;
665         struct entry *ep;
666         long curvol;
667
668         vprintf(stdout, "Extract requested files\n");
669         curfile.action = SKIP;
670         getvol((long)1);
671         skipmaps();
672         skipdirs();
673         first = lowerbnd(ROOTINO);
674         last = upperbnd(maxino - 1);
675         for (;;) {
676                 curvol = volno;
677                 first = lowerbnd(first);
678                 last = upperbnd(last);
679                 /*
680                  * Check to see if any files remain to be extracted
681                  */
682                 if (first > last)
683                         return;
684                 /*
685                  * Reject any volumes with inodes greater than the last
686                  * one needed, so that we can quickly skip backwards to
687                  * a volume containing useful inodes. We can't do this
688                  * if there are no further volumes available (curfile.ino
689                  * >= maxino) or if we are already at the first tape.
690                  */
691                 if (curfile.ino > last && curfile.ino < maxino && volno > 1) {
692                         curfile.action = SKIP;
693                         getvol((long)0);
694                         skipmaps();
695                         skipdirs();
696                         continue;
697                 }
698                 /*
699                  * Decide on the next inode needed.
700                  * Skip across the inodes until it is found
701                  * or a volume change is encountered
702                  */
703                 if (curfile.ino < maxino) {
704                         next = lowerbnd(curfile.ino);
705                         while (next > curfile.ino && volno == curvol)
706                                 skipfile();
707                         if (volno != curvol) {
708                                 skipmaps();
709                                 skipdirs();
710                                 continue;
711                         }
712                 } else {
713                         /*
714                          * No further volumes or inodes available. Set
715                          * `next' to the first inode, so that a warning
716                          * is emitted below for each missing file.
717                          */
718                         next = first;
719                 }
720                 /*
721                  * If the current inode is greater than the one we were
722                  * looking for then we missed the one we were looking for.
723                  * Since we only attempt to extract files listed in the
724                  * dump map, the lost files must have been due to a tape
725                  * read error, or a file that was removed while the dump
726                  * was in progress. Thus we report all requested files
727                  * between the one we were looking for, and the one we
728                  * found as missing, and delete their request flags.
729                  */
730                 while (next < curfile.ino) {
731                         ep = lookupino(next);
732                         if (ep == NULL)
733                                 panic("corrupted symbol table\n");
734                         fprintf(stderr, "%s: not found on tape\n", myname(ep));
735                         ep->e_flags &= ~NEW;
736                         next = lowerbnd(next);
737                 }
738                 /*
739                  * The current inode is the one that we are looking for,
740                  * so extract it per its requested name.
741                  */
742                 if (next == curfile.ino && next <= last) {
743                         ep = lookupino(next);
744                         if (ep == NULL)
745                                 panic("corrupted symbol table\n");
746                         extractfile(myname(ep));
747                         ep->e_flags &= ~NEW;
748                         if (volno != curvol)
749                                 skipmaps();
750                 }
751         }
752 }
753
754 /*
755  * Add links.
756  */
757 void
758 createlinks(void)
759 {
760         struct entry *np, *ep;
761         ufs1_ino_t i;
762         char name[BUFSIZ];
763
764         if ((ep = lookupino(WINO))) {
765                 vprintf(stdout, "Add whiteouts\n");
766                 for ( ; ep != NULL; ep = ep->e_links) {
767                         if ((ep->e_flags & NEW) == 0)
768                                 continue;
769                         addwhiteout(myname(ep));
770                         ep->e_flags &= ~NEW;
771                 }
772         }
773         vprintf(stdout, "Add links\n");
774         for (i = ROOTINO; i < maxino; i++) {
775                 ep = lookupino(i);
776                 if (ep == NULL)
777                         continue;
778                 for (np = ep->e_links; np != NULL; np = np->e_links) {
779                         if ((np->e_flags & NEW) == 0)
780                                 continue;
781                         strcpy(name, myname(ep));
782                         if (ep->e_type == NODE) {
783                                 linkit(name, myname(np), SYMLINK);
784                         } else {
785                                 linkit(name, myname(np), HARDLINK);
786                         }
787                         np->e_flags &= ~NEW;
788                 }
789         }
790 }
791
792 /*
793  * Check the symbol table.
794  * We do this to insure that all the requested work was done, and
795  * that no temporary names remain.
796  */
797 void
798 checkrestore(void)
799 {
800         struct entry *ep;
801         ufs1_ino_t i;
802
803         vprintf(stdout, "Check the symbol table.\n");
804         for (i = WINO; i < maxino; i++) {
805                 for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
806                         ep->e_flags &= ~KEEP;
807                         if (ep->e_type == NODE)
808                                 ep->e_flags &= ~(NEW|EXISTED);
809                         if (ep->e_flags != 0)
810                                 badentry(ep, "incomplete operations");
811                 }
812         }
813 }
814
815 /*
816  * Compare with the directory structure on the tape
817  * A paranoid check that things are as they should be.
818  */
819 long
820 verifyfile(char *name, ufs1_ino_t ino, int type)
821 {
822         struct entry *np, *ep;
823         long descend = GOOD;
824
825         ep = lookupname(name);
826         if (ep == NULL) {
827                 fprintf(stderr, "Warning: missing name %s\n", name);
828                 return (FAIL);
829         }
830         np = lookupino(ino);
831         if (np != ep)
832                 descend = FAIL;
833         for ( ; np != NULL; np = np->e_links)
834                 if (np == ep)
835                         break;
836         if (np == NULL)
837                 panic("missing inumber %d\n", ino);
838         if (ep->e_type == LEAF && type != LEAF)
839                 badentry(ep, "type should be LEAF");
840         return (descend);
841 }