dir.c (331722) | dir.c (344887) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30#if 0 31#ifndef lint 32static const char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95"; 33#endif /* not lint */ 34#endif 35#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1980, 1986, 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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30#if 0 31#ifndef lint 32static const char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95"; 33#endif /* not lint */ 34#endif 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: stable/11/sbin/fsck_ffs/dir.c 331722 2018-03-29 02:50:57Z eadler $"); | 36__FBSDID("$FreeBSD: stable/11/sbin/fsck_ffs/dir.c 344887 2019-03-07 13:53:59Z kib $"); |
37 38#include <sys/param.h> 39#include <sys/time.h> 40#include <sys/types.h> 41#include <sys/sysctl.h> 42 43#include <ufs/ufs/dinode.h> 44#include <ufs/ufs/dir.h> --- 271 unchanged lines hidden (view full) --- 316 pfatal("LINK COUNT INCREASING"); 317 } 318 if (preen) 319 printf(" (ADJUSTED)\n"); 320 } 321 if (preen || reply("ADJUST") == 1) { 322 if (bkgrdflag == 0) { 323 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) - lcnt); | 37 38#include <sys/param.h> 39#include <sys/time.h> 40#include <sys/types.h> 41#include <sys/sysctl.h> 42 43#include <ufs/ufs/dinode.h> 44#include <ufs/ufs/dir.h> --- 271 unchanged lines hidden (view full) --- 316 pfatal("LINK COUNT INCREASING"); 317 } 318 if (preen) 319 printf(" (ADJUSTED)\n"); 320 } 321 if (preen || reply("ADJUST") == 1) { 322 if (bkgrdflag == 0) { 323 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) - lcnt); |
324 inodirty(); | 324 inodirty(dp); |
325 } else { 326 cmd.value = idesc->id_number; 327 cmd.size = -lcnt; 328 if (debug) 329 printf("adjrefcnt ino %ld amt %lld\n", 330 (long)cmd.value, 331 (long long)cmd.size); 332 if (sysctl(adjrefcnt, MIBSIZE, 0, 0, --- 108 unchanged lines hidden (view full) --- 441 if ((lfdir = allocdir(ROOTINO, (ino_t)0, lfmode)) == 0) { 442 pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); 443 return (0); 444 } 445 if ((changeino(ROOTINO, lfname, lfdir) & ALTERED) == 0) { 446 pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); 447 return (0); 448 } | 325 } else { 326 cmd.value = idesc->id_number; 327 cmd.size = -lcnt; 328 if (debug) 329 printf("adjrefcnt ino %ld amt %lld\n", 330 (long)cmd.value, 331 (long long)cmd.size); 332 if (sysctl(adjrefcnt, MIBSIZE, 0, 0, --- 108 unchanged lines hidden (view full) --- 441 if ((lfdir = allocdir(ROOTINO, (ino_t)0, lfmode)) == 0) { 442 pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); 443 return (0); 444 } 445 if ((changeino(ROOTINO, lfname, lfdir) & ALTERED) == 0) { 446 pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); 447 return (0); 448 } |
449 inodirty(); | 449 inodirty(dp); |
450 idesc.id_type = ADDR; 451 idesc.id_func = pass4check; 452 idesc.id_number = oldlfdir; 453 adjust(&idesc, inoinfo(oldlfdir)->ino_linkcnt + 1); 454 inoinfo(oldlfdir)->ino_linkcnt = 0; 455 dp = ginode(lfdir); 456 } 457 if (inoinfo(lfdir)->ino_state != DFOUND) { --- 8 unchanged lines hidden (view full) --- 466 } 467 inoinfo(orphan)->ino_linkcnt--; 468 if (lostdir) { 469 if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 && 470 parentdir != (ino_t)-1) 471 (void)makeentry(orphan, lfdir, ".."); 472 dp = ginode(lfdir); 473 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) + 1); | 450 idesc.id_type = ADDR; 451 idesc.id_func = pass4check; 452 idesc.id_number = oldlfdir; 453 adjust(&idesc, inoinfo(oldlfdir)->ino_linkcnt + 1); 454 inoinfo(oldlfdir)->ino_linkcnt = 0; 455 dp = ginode(lfdir); 456 } 457 if (inoinfo(lfdir)->ino_state != DFOUND) { --- 8 unchanged lines hidden (view full) --- 466 } 467 inoinfo(orphan)->ino_linkcnt--; 468 if (lostdir) { 469 if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 && 470 parentdir != (ino_t)-1) 471 (void)makeentry(orphan, lfdir, ".."); 472 dp = ginode(lfdir); 473 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) + 1); |
474 inodirty(); | 474 inodirty(dp); |
475 inoinfo(lfdir)->ino_linkcnt++; 476 pwarn("DIR I=%lu CONNECTED. ", (u_long)orphan); 477 if (parentdir != (ino_t)-1) { 478 printf("PARENT WAS I=%lu\n", (u_long)parentdir); 479 /* 480 * The parent directory, because of the ordering 481 * guarantees, has had the link count incremented 482 * for the child, but no entry was made. This --- 44 unchanged lines hidden (view full) --- 527 idesc.id_func = mkentry; 528 idesc.id_number = parent; 529 idesc.id_parent = ino; /* this is the inode to enter */ 530 idesc.id_fix = DONTKNOW; 531 idesc.id_name = strdup(name); 532 dp = ginode(parent); 533 if (DIP(dp, di_size) % DIRBLKSIZ) { 534 DIP_SET(dp, di_size, roundup(DIP(dp, di_size), DIRBLKSIZ)); | 475 inoinfo(lfdir)->ino_linkcnt++; 476 pwarn("DIR I=%lu CONNECTED. ", (u_long)orphan); 477 if (parentdir != (ino_t)-1) { 478 printf("PARENT WAS I=%lu\n", (u_long)parentdir); 479 /* 480 * The parent directory, because of the ordering 481 * guarantees, has had the link count incremented 482 * for the child, but no entry was made. This --- 44 unchanged lines hidden (view full) --- 527 idesc.id_func = mkentry; 528 idesc.id_number = parent; 529 idesc.id_parent = ino; /* this is the inode to enter */ 530 idesc.id_fix = DONTKNOW; 531 idesc.id_name = strdup(name); 532 dp = ginode(parent); 533 if (DIP(dp, di_size) % DIRBLKSIZ) { 534 DIP_SET(dp, di_size, roundup(DIP(dp, di_size), DIRBLKSIZ)); |
535 inodirty(); | 535 inodirty(dp); |
536 } 537 if ((ckinode(dp, &idesc) & ALTERED) != 0) 538 return (1); 539 getpathname(pathbuf, parent, parent); 540 dp = ginode(parent); 541 if (expanddir(dp, pathbuf) == 0) 542 return (0); 543 return (ckinode(dp, &idesc) & ALTERED); --- 39 unchanged lines hidden (view full) --- 583 goto bad; 584 memmove(bp->b_un.b_buf, &emptydir, sizeof emptydir); 585 pwarn("NO SPACE LEFT IN %s", name); 586 if (preen) 587 printf(" (EXPANDED)\n"); 588 else if (reply("EXPAND") == 0) 589 goto bad; 590 dirty(bp); | 536 } 537 if ((ckinode(dp, &idesc) & ALTERED) != 0) 538 return (1); 539 getpathname(pathbuf, parent, parent); 540 dp = ginode(parent); 541 if (expanddir(dp, pathbuf) == 0) 542 return (0); 543 return (ckinode(dp, &idesc) & ALTERED); --- 39 unchanged lines hidden (view full) --- 583 goto bad; 584 memmove(bp->b_un.b_buf, &emptydir, sizeof emptydir); 585 pwarn("NO SPACE LEFT IN %s", name); 586 if (preen) 587 printf(" (EXPANDED)\n"); 588 else if (reply("EXPAND") == 0) 589 goto bad; 590 dirty(bp); |
591 inodirty(); | 591 inodirty(dp); |
592 return (1); 593bad: 594 DIP_SET(dp, di_db[lastbn], DIP(dp, di_db[lastbn + 1])); 595 DIP_SET(dp, di_db[lastbn + 1], 0); 596 DIP_SET(dp, di_size, DIP(dp, di_size) - sblock.fs_bsize); 597 DIP_SET(dp, di_blocks, DIP(dp, di_blocks) - btodb(sblock.fs_bsize)); 598 freeblk(newblk, sblock.fs_frag); 599 return (0); --- 24 unchanged lines hidden (view full) --- 624 } 625 memmove(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate)); 626 for (cp = &bp->b_un.b_buf[DIRBLKSIZ]; 627 cp < &bp->b_un.b_buf[sblock.fs_fsize]; 628 cp += DIRBLKSIZ) 629 memmove(cp, &emptydir, sizeof emptydir); 630 dirty(bp); 631 DIP_SET(dp, di_nlink, 2); | 592 return (1); 593bad: 594 DIP_SET(dp, di_db[lastbn], DIP(dp, di_db[lastbn + 1])); 595 DIP_SET(dp, di_db[lastbn + 1], 0); 596 DIP_SET(dp, di_size, DIP(dp, di_size) - sblock.fs_bsize); 597 DIP_SET(dp, di_blocks, DIP(dp, di_blocks) - btodb(sblock.fs_bsize)); 598 freeblk(newblk, sblock.fs_frag); 599 return (0); --- 24 unchanged lines hidden (view full) --- 624 } 625 memmove(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate)); 626 for (cp = &bp->b_un.b_buf[DIRBLKSIZ]; 627 cp < &bp->b_un.b_buf[sblock.fs_fsize]; 628 cp += DIRBLKSIZ) 629 memmove(cp, &emptydir, sizeof emptydir); 630 dirty(bp); 631 DIP_SET(dp, di_nlink, 2); |
632 inodirty(); | 632 inodirty(dp); |
633 if (ino == ROOTINO) { 634 inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink); 635 cacheino(dp, ino); 636 return(ino); 637 } 638 if (!INO_IS_DVALID(parent)) { 639 freeino(ino); 640 return (0); --- 4 unchanged lines hidden (view full) --- 645 inp->i_dotdot = parent; 646 inoinfo(ino)->ino_state = inoinfo(parent)->ino_state; 647 if (inoinfo(ino)->ino_state == DSTATE) { 648 inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink); 649 inoinfo(parent)->ino_linkcnt++; 650 } 651 dp = ginode(parent); 652 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) + 1); | 633 if (ino == ROOTINO) { 634 inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink); 635 cacheino(dp, ino); 636 return(ino); 637 } 638 if (!INO_IS_DVALID(parent)) { 639 freeino(ino); 640 return (0); --- 4 unchanged lines hidden (view full) --- 645 inp->i_dotdot = parent; 646 inoinfo(ino)->ino_state = inoinfo(parent)->ino_state; 647 if (inoinfo(ino)->ino_state == DSTATE) { 648 inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink); 649 inoinfo(parent)->ino_linkcnt++; 650 } 651 dp = ginode(parent); 652 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) + 1); |
653 inodirty(); | 653 inodirty(dp); |
654 return (ino); 655} 656 657/* 658 * free a directory inode 659 */ 660static void 661freedir(ino_t ino, ino_t parent) 662{ 663 union dinode *dp; 664 665 if (ino != parent) { 666 dp = ginode(parent); 667 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) - 1); | 654 return (ino); 655} 656 657/* 658 * free a directory inode 659 */ 660static void 661freedir(ino_t ino, ino_t parent) 662{ 663 union dinode *dp; 664 665 if (ino != parent) { 666 dp = ginode(parent); 667 DIP_SET(dp, di_nlink, DIP(dp, di_nlink) - 1); |
668 inodirty(); | 668 inodirty(dp); |
669 } 670 freeino(ino); 671} 672 673/* 674 * generate a temporary name for the lost+found directory. 675 */ 676static int --- 33 unchanged lines hidden --- | 669 } 670 freeino(ino); 671} 672 673/* 674 * generate a temporary name for the lost+found directory. 675 */ 676static int --- 33 unchanged lines hidden --- |