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