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