pass2.c revision 134589
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1980, 1986, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 4. Neither the name of the University nor the names of its contributors 141558Srgrimes * may be used to endorse or promote products derived from this software 151558Srgrimes * without specific prior written permission. 161558Srgrimes * 171558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271558Srgrimes * SUCH DAMAGE. 281558Srgrimes */ 291558Srgrimes 30102411Scharnier#if 0 311558Srgrimes#ifndef lint 3223675Speterstatic const char sccsid[] = "@(#)pass2.c 8.9 (Berkeley) 4/28/95"; 33102411Scharnier#endif /* not lint */ 3441477Sjulian#endif 35102411Scharnier#include <sys/cdefs.h> 36102411Scharnier__FBSDID("$FreeBSD: head/sbin/fsck_ffs/pass2.c 134589 2004-09-01 05:48:06Z scottl $"); 37102411Scharnier 381558Srgrimes#include <sys/param.h> 3923675Speter 401558Srgrimes#include <ufs/ufs/dinode.h> 411558Srgrimes#include <ufs/ufs/dir.h> 4274556Smckusick#include <ufs/ffs/fs.h> 4323799Sbde 4423675Speter#include <err.h> 45101037Smux#include <stdint.h> 461558Srgrimes#include <string.h> 4723675Speter 481558Srgrimes#include "fsck.h" 491558Srgrimes 501558Srgrimes#define MINDIRSIZE (sizeof (struct dirtemplate)) 511558Srgrimes 5292839Simpstatic int blksort(const void *, const void *); 5392839Simpstatic int pass2check(struct inodesc *); 541558Srgrimes 557585Sbdevoid 5692839Simppass2(void) 571558Srgrimes{ 5898542Smckusick union dinode *dp; 5992806Sobrien struct inoinfo **inpp, *inp; 601558Srgrimes struct inoinfo **inpend; 611558Srgrimes struct inodesc curino; 6298542Smckusick union dinode dino; 6398542Smckusick int i; 641558Srgrimes char pathbuf[MAXPATHLEN + 1]; 651558Srgrimes 6641474Sjulian switch (inoinfo(ROOTINO)->ino_state) { 671558Srgrimes 681558Srgrimes case USTATE: 691558Srgrimes pfatal("ROOT INODE UNALLOCATED"); 7034266Sjulian if (reply("ALLOCATE") == 0) { 7134266Sjulian ckfini(0); 7223675Speter exit(EEXIT); 7334266Sjulian } 741558Srgrimes if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) 7523675Speter errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); 761558Srgrimes break; 771558Srgrimes 781558Srgrimes case DCLEAR: 791558Srgrimes pfatal("DUPS/BAD IN ROOT INODE"); 801558Srgrimes if (reply("REALLOCATE")) { 811558Srgrimes freeino(ROOTINO); 821558Srgrimes if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) 8323675Speter errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); 841558Srgrimes break; 851558Srgrimes } 8634266Sjulian if (reply("CONTINUE") == 0) { 8734266Sjulian ckfini(0); 8823675Speter exit(EEXIT); 8934266Sjulian } 901558Srgrimes break; 911558Srgrimes 921558Srgrimes case FSTATE: 931558Srgrimes case FCLEAR: 941558Srgrimes pfatal("ROOT INODE NOT DIRECTORY"); 951558Srgrimes if (reply("REALLOCATE")) { 961558Srgrimes freeino(ROOTINO); 971558Srgrimes if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) 9823675Speter errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); 991558Srgrimes break; 1001558Srgrimes } 10134266Sjulian if (reply("FIX") == 0) { 10234266Sjulian ckfini(0); 10323675Speter exit(EEXIT); 10434266Sjulian } 1051558Srgrimes dp = ginode(ROOTINO); 106134589Sscottl DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT); 107134589Sscottl DIP_SET(dp, di_mode, DIP(dp, di_mode) | IFDIR); 1081558Srgrimes inodirty(); 1091558Srgrimes break; 1101558Srgrimes 1111558Srgrimes case DSTATE: 1121558Srgrimes break; 1131558Srgrimes 1141558Srgrimes default: 11541474Sjulian errx(EEXIT, "BAD STATE %d FOR ROOT INODE", 11641474Sjulian inoinfo(ROOTINO)->ino_state); 1171558Srgrimes } 11841474Sjulian inoinfo(ROOTINO)->ino_state = DFOUND; 11996483Sphk inoinfo(WINO)->ino_state = FSTATE; 12096483Sphk inoinfo(WINO)->ino_type = DT_WHT; 1211558Srgrimes /* 1221558Srgrimes * Sort the directory list into disk block order. 1231558Srgrimes */ 1241558Srgrimes qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); 1251558Srgrimes /* 1261558Srgrimes * Check the integrity of each directory. 1271558Srgrimes */ 12823675Speter memset(&curino, 0, sizeof(struct inodesc)); 1291558Srgrimes curino.id_type = DATA; 1301558Srgrimes curino.id_func = pass2check; 1311558Srgrimes inpend = &inpsort[inplast]; 1321558Srgrimes for (inpp = inpsort; inpp < inpend; inpp++) { 13370050Siedowse if (got_siginfo) { 134101037Smux printf("%s: phase 2: dir %td of %d (%d%%)\n", cdevname, 13586514Siedowse inpp - inpsort, (int)inplast, 13686514Siedowse (int)((inpp - inpsort) * 100 / inplast)); 13770050Siedowse got_siginfo = 0; 13870050Siedowse } 139126345Sscottl if (got_sigalarm) { 140126345Sscottl setproctitle("%s p2 %d%%", cdevname, 141126345Sscottl (int)((inpp - inpsort) * 100 / inplast)); 142126345Sscottl got_sigalarm = 0; 143126345Sscottl } 1441558Srgrimes inp = *inpp; 1451558Srgrimes if (inp->i_isize == 0) 1461558Srgrimes continue; 1471558Srgrimes if (inp->i_isize < MINDIRSIZE) { 1481558Srgrimes direrror(inp->i_number, "DIRECTORY TOO SHORT"); 1491558Srgrimes inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); 1501558Srgrimes if (reply("FIX") == 1) { 1511558Srgrimes dp = ginode(inp->i_number); 152134589Sscottl DIP_SET(dp, di_size, inp->i_isize); 1531558Srgrimes inodirty(); 1541558Srgrimes } 1551558Srgrimes } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { 1561558Srgrimes getpathname(pathbuf, inp->i_number, inp->i_number); 15734266Sjulian if (usedsoftdep) 158101037Smux pfatal("%s %s: LENGTH %jd NOT MULTIPLE OF %d", 159101037Smux "DIRECTORY", pathbuf, 160101037Smux (intmax_t)inp->i_isize, DIRBLKSIZ); 16134266Sjulian else 162101037Smux pwarn("%s %s: LENGTH %jd NOT MULTIPLE OF %d", 163101037Smux "DIRECTORY", pathbuf, 164101037Smux (intmax_t)inp->i_isize, DIRBLKSIZ); 1651558Srgrimes if (preen) 1661558Srgrimes printf(" (ADJUSTED)\n"); 1671558Srgrimes inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); 1681558Srgrimes if (preen || reply("ADJUST") == 1) { 1691558Srgrimes dp = ginode(inp->i_number); 170134589Sscottl DIP_SET(dp, di_size, 171134589Sscottl roundup(inp->i_isize, DIRBLKSIZ)); 1721558Srgrimes inodirty(); 1731558Srgrimes } 1741558Srgrimes } 17598542Smckusick dp = &dino; 17698542Smckusick memset(dp, 0, sizeof(struct ufs2_dinode)); 177134589Sscottl DIP_SET(dp, di_mode, IFDIR); 178134589Sscottl DIP_SET(dp, di_size, inp->i_isize); 17998542Smckusick for (i = 0; 18098542Smckusick i < (inp->i_numblks<NDADDR ? inp->i_numblks : NDADDR); 18198542Smckusick i++) 182134589Sscottl DIP_SET(dp, di_db[i], inp->i_blks[i]); 18398542Smckusick if (inp->i_numblks > NDADDR) 18498542Smckusick for (i = 0; i < NIADDR; i++) 185134589Sscottl DIP_SET(dp, di_ib[i], inp->i_blks[NDADDR + i]); 1861558Srgrimes curino.id_number = inp->i_number; 1871558Srgrimes curino.id_parent = inp->i_parent; 1881558Srgrimes (void)ckinode(dp, &curino); 1891558Srgrimes } 1901558Srgrimes /* 1911558Srgrimes * Now that the parents of all directories have been found, 1921558Srgrimes * make another pass to verify the value of `..' 1931558Srgrimes */ 1941558Srgrimes for (inpp = inpsort; inpp < inpend; inpp++) { 1951558Srgrimes inp = *inpp; 1961558Srgrimes if (inp->i_parent == 0 || inp->i_isize == 0) 1971558Srgrimes continue; 19841474Sjulian if (inoinfo(inp->i_parent)->ino_state == DFOUND && 19941474Sjulian inoinfo(inp->i_number)->ino_state == DSTATE) 20041474Sjulian inoinfo(inp->i_number)->ino_state = DFOUND; 2011558Srgrimes if (inp->i_dotdot == inp->i_parent || 2021558Srgrimes inp->i_dotdot == (ino_t)-1) 2031558Srgrimes continue; 2041558Srgrimes if (inp->i_dotdot == 0) { 2051558Srgrimes inp->i_dotdot = inp->i_parent; 2061558Srgrimes fileerror(inp->i_parent, inp->i_number, "MISSING '..'"); 2071558Srgrimes if (reply("FIX") == 0) 2081558Srgrimes continue; 2091558Srgrimes (void)makeentry(inp->i_number, inp->i_parent, ".."); 21041474Sjulian inoinfo(inp->i_parent)->ino_linkcnt--; 2111558Srgrimes continue; 2121558Srgrimes } 2131558Srgrimes fileerror(inp->i_parent, inp->i_number, 2141558Srgrimes "BAD INODE NUMBER FOR '..'"); 2151558Srgrimes if (reply("FIX") == 0) 2161558Srgrimes continue; 21741474Sjulian inoinfo(inp->i_dotdot)->ino_linkcnt++; 21841474Sjulian inoinfo(inp->i_parent)->ino_linkcnt--; 2191558Srgrimes inp->i_dotdot = inp->i_parent; 2201558Srgrimes (void)changeino(inp->i_number, "..", inp->i_parent); 2211558Srgrimes } 2221558Srgrimes /* 2231558Srgrimes * Mark all the directories that can be found from the root. 2241558Srgrimes */ 2251558Srgrimes propagate(); 2261558Srgrimes} 2271558Srgrimes 22823675Speterstatic int 22992839Simppass2check(struct inodesc *idesc) 2301558Srgrimes{ 23192806Sobrien struct direct *dirp = idesc->id_dirp; 23292806Sobrien struct inoinfo *inp; 2331558Srgrimes int n, entrysize, ret = 0; 23498542Smckusick union dinode *dp; 235100935Sphk const char *errmsg; 2361558Srgrimes struct direct proto; 2371558Srgrimes char namebuf[MAXPATHLEN + 1]; 2381558Srgrimes char pathbuf[MAXPATHLEN + 1]; 2391558Srgrimes 2401558Srgrimes /* 2411558Srgrimes * check for "." 2421558Srgrimes */ 2431558Srgrimes if (idesc->id_entryno != 0) 2441558Srgrimes goto chk1; 2451558Srgrimes if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) { 2461558Srgrimes if (dirp->d_ino != idesc->id_number) { 2471558Srgrimes direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'"); 2481558Srgrimes dirp->d_ino = idesc->id_number; 2491558Srgrimes if (reply("FIX") == 1) 2501558Srgrimes ret |= ALTERED; 2511558Srgrimes } 25296483Sphk if (dirp->d_type != DT_DIR) { 2531558Srgrimes direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'"); 2541558Srgrimes dirp->d_type = DT_DIR; 2551558Srgrimes if (reply("FIX") == 1) 2561558Srgrimes ret |= ALTERED; 2571558Srgrimes } 2581558Srgrimes goto chk1; 2591558Srgrimes } 2601558Srgrimes direrror(idesc->id_number, "MISSING '.'"); 2611558Srgrimes proto.d_ino = idesc->id_number; 26296483Sphk proto.d_type = DT_DIR; 2631558Srgrimes proto.d_namlen = 1; 2641558Srgrimes (void)strcpy(proto.d_name, "."); 2651558Srgrimes entrysize = DIRSIZ(0, &proto); 2661558Srgrimes if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) { 2671558Srgrimes pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n", 2681558Srgrimes dirp->d_name); 2691558Srgrimes } else if (dirp->d_reclen < entrysize) { 2701558Srgrimes pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n"); 2711558Srgrimes } else if (dirp->d_reclen < 2 * entrysize) { 2721558Srgrimes proto.d_reclen = dirp->d_reclen; 27323675Speter memmove(dirp, &proto, (size_t)entrysize); 2741558Srgrimes if (reply("FIX") == 1) 2751558Srgrimes ret |= ALTERED; 2761558Srgrimes } else { 2771558Srgrimes n = dirp->d_reclen - entrysize; 2781558Srgrimes proto.d_reclen = entrysize; 27923675Speter memmove(dirp, &proto, (size_t)entrysize); 2801558Srgrimes idesc->id_entryno++; 28141474Sjulian inoinfo(dirp->d_ino)->ino_linkcnt--; 2821558Srgrimes dirp = (struct direct *)((char *)(dirp) + entrysize); 28323675Speter memset(dirp, 0, (size_t)n); 2841558Srgrimes dirp->d_reclen = n; 2851558Srgrimes if (reply("FIX") == 1) 2861558Srgrimes ret |= ALTERED; 2871558Srgrimes } 2881558Srgrimeschk1: 2891558Srgrimes if (idesc->id_entryno > 1) 2901558Srgrimes goto chk2; 2911558Srgrimes inp = getinoinfo(idesc->id_number); 2921558Srgrimes proto.d_ino = inp->i_parent; 29396483Sphk proto.d_type = DT_DIR; 2941558Srgrimes proto.d_namlen = 2; 2951558Srgrimes (void)strcpy(proto.d_name, ".."); 2961558Srgrimes entrysize = DIRSIZ(0, &proto); 2971558Srgrimes if (idesc->id_entryno == 0) { 2981558Srgrimes n = DIRSIZ(0, dirp); 2991558Srgrimes if (dirp->d_reclen < n + entrysize) 3001558Srgrimes goto chk2; 3011558Srgrimes proto.d_reclen = dirp->d_reclen - n; 3021558Srgrimes dirp->d_reclen = n; 3031558Srgrimes idesc->id_entryno++; 30441474Sjulian inoinfo(dirp->d_ino)->ino_linkcnt--; 3051558Srgrimes dirp = (struct direct *)((char *)(dirp) + n); 30623675Speter memset(dirp, 0, (size_t)proto.d_reclen); 3071558Srgrimes dirp->d_reclen = proto.d_reclen; 3081558Srgrimes } 3091558Srgrimes if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) { 3101558Srgrimes inp->i_dotdot = dirp->d_ino; 31196483Sphk if (dirp->d_type != DT_DIR) { 3121558Srgrimes direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'"); 3131558Srgrimes dirp->d_type = DT_DIR; 3141558Srgrimes if (reply("FIX") == 1) 3151558Srgrimes ret |= ALTERED; 3161558Srgrimes } 3171558Srgrimes goto chk2; 3181558Srgrimes } 3191558Srgrimes if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) { 3201558Srgrimes fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); 3211558Srgrimes pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n", 3221558Srgrimes dirp->d_name); 3231558Srgrimes inp->i_dotdot = (ino_t)-1; 3241558Srgrimes } else if (dirp->d_reclen < entrysize) { 3251558Srgrimes fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); 3261558Srgrimes pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n"); 3271558Srgrimes inp->i_dotdot = (ino_t)-1; 3281558Srgrimes } else if (inp->i_parent != 0) { 3291558Srgrimes /* 3301558Srgrimes * We know the parent, so fix now. 3311558Srgrimes */ 3321558Srgrimes inp->i_dotdot = inp->i_parent; 3331558Srgrimes fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); 3341558Srgrimes proto.d_reclen = dirp->d_reclen; 33523675Speter memmove(dirp, &proto, (size_t)entrysize); 3361558Srgrimes if (reply("FIX") == 1) 3371558Srgrimes ret |= ALTERED; 3381558Srgrimes } 3391558Srgrimes idesc->id_entryno++; 3401558Srgrimes if (dirp->d_ino != 0) 34141474Sjulian inoinfo(dirp->d_ino)->ino_linkcnt--; 3421558Srgrimes return (ret|KEEPON); 3431558Srgrimeschk2: 3441558Srgrimes if (dirp->d_ino == 0) 3451558Srgrimes return (ret|KEEPON); 3461558Srgrimes if (dirp->d_namlen <= 2 && 3471558Srgrimes dirp->d_name[0] == '.' && 3481558Srgrimes idesc->id_entryno >= 2) { 3491558Srgrimes if (dirp->d_namlen == 1) { 3501558Srgrimes direrror(idesc->id_number, "EXTRA '.' ENTRY"); 3511558Srgrimes dirp->d_ino = 0; 3521558Srgrimes if (reply("FIX") == 1) 3531558Srgrimes ret |= ALTERED; 3541558Srgrimes return (KEEPON | ret); 3551558Srgrimes } 3561558Srgrimes if (dirp->d_name[1] == '.') { 3571558Srgrimes direrror(idesc->id_number, "EXTRA '..' ENTRY"); 3581558Srgrimes dirp->d_ino = 0; 3591558Srgrimes if (reply("FIX") == 1) 3601558Srgrimes ret |= ALTERED; 3611558Srgrimes return (KEEPON | ret); 3621558Srgrimes } 3631558Srgrimes } 3641558Srgrimes idesc->id_entryno++; 3651558Srgrimes n = 0; 3661558Srgrimes if (dirp->d_ino > maxino) { 3671558Srgrimes fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); 3681558Srgrimes n = reply("REMOVE"); 36996483Sphk } else if (((dirp->d_ino == WINO && dirp->d_type != DT_WHT) || 37023675Speter (dirp->d_ino != WINO && dirp->d_type == DT_WHT))) { 37123675Speter fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY"); 37223675Speter dirp->d_ino = WINO; 37323675Speter dirp->d_type = DT_WHT; 37423675Speter if (reply("FIX") == 1) 37523675Speter ret |= ALTERED; 3761558Srgrimes } else { 3771558Srgrimesagain: 37841474Sjulian switch (inoinfo(dirp->d_ino)->ino_state) { 3791558Srgrimes case USTATE: 3801558Srgrimes if (idesc->id_entryno <= 2) 3811558Srgrimes break; 3821558Srgrimes fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED"); 3831558Srgrimes n = reply("REMOVE"); 3841558Srgrimes break; 3851558Srgrimes 3861558Srgrimes case DCLEAR: 3871558Srgrimes case FCLEAR: 3881558Srgrimes if (idesc->id_entryno <= 2) 3891558Srgrimes break; 39041474Sjulian if (inoinfo(dirp->d_ino)->ino_state == FCLEAR) 3911558Srgrimes errmsg = "DUP/BAD"; 39234266Sjulian else if (!preen && !usedsoftdep) 3931558Srgrimes errmsg = "ZERO LENGTH DIRECTORY"; 3941558Srgrimes else { 3951558Srgrimes n = 1; 3961558Srgrimes break; 3971558Srgrimes } 3981558Srgrimes fileerror(idesc->id_number, dirp->d_ino, errmsg); 3991558Srgrimes if ((n = reply("REMOVE")) == 1) 4001558Srgrimes break; 4011558Srgrimes dp = ginode(dirp->d_ino); 40241474Sjulian inoinfo(dirp->d_ino)->ino_state = 40398542Smckusick (DIP(dp, di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE; 40498542Smckusick inoinfo(dirp->d_ino)->ino_linkcnt = DIP(dp, di_nlink); 4051558Srgrimes goto again; 4061558Srgrimes 4071558Srgrimes case DSTATE: 40841474Sjulian if (inoinfo(idesc->id_number)->ino_state == DFOUND) 40941474Sjulian inoinfo(dirp->d_ino)->ino_state = DFOUND; 410102411Scharnier /* FALLTHROUGH */ 4111558Srgrimes 4121558Srgrimes case DFOUND: 4131558Srgrimes inp = getinoinfo(dirp->d_ino); 4141558Srgrimes if (inp->i_parent != 0 && idesc->id_entryno > 2) { 4151558Srgrimes getpathname(pathbuf, idesc->id_number, 4161558Srgrimes idesc->id_number); 4171558Srgrimes getpathname(namebuf, dirp->d_ino, dirp->d_ino); 41886512Siedowse pwarn("%s%s%s %s %s\n", pathbuf, 41986512Siedowse (strcmp(pathbuf, "/") == 0 ? "" : "/"), 42086512Siedowse dirp->d_name, 4211558Srgrimes "IS AN EXTRANEOUS HARD LINK TO DIRECTORY", 4221558Srgrimes namebuf); 42374556Smckusick if (cursnapshot != 0) 42474556Smckusick break; 42534266Sjulian if (preen) { 42634266Sjulian printf(" (REMOVED)\n"); 42741474Sjulian n = 1; 42841474Sjulian break; 42934266Sjulian } 43041474Sjulian if ((n = reply("REMOVE")) == 1) 4311558Srgrimes break; 4321558Srgrimes } 4331558Srgrimes if (idesc->id_entryno > 2) 4341558Srgrimes inp->i_parent = idesc->id_number; 435102411Scharnier /* FALLTHROUGH */ 4361558Srgrimes 4371558Srgrimes case FSTATE: 43896483Sphk if (dirp->d_type != inoinfo(dirp->d_ino)->ino_type) { 4391558Srgrimes fileerror(idesc->id_number, dirp->d_ino, 4401558Srgrimes "BAD TYPE VALUE"); 44141474Sjulian dirp->d_type = inoinfo(dirp->d_ino)->ino_type; 4421558Srgrimes if (reply("FIX") == 1) 4431558Srgrimes ret |= ALTERED; 4441558Srgrimes } 44541474Sjulian inoinfo(dirp->d_ino)->ino_linkcnt--; 4461558Srgrimes break; 4471558Srgrimes 4481558Srgrimes default: 44923675Speter errx(EEXIT, "BAD STATE %d FOR INODE I=%d", 45041474Sjulian inoinfo(dirp->d_ino)->ino_state, dirp->d_ino); 4511558Srgrimes } 4521558Srgrimes } 4531558Srgrimes if (n == 0) 4541558Srgrimes return (ret|KEEPON); 4551558Srgrimes dirp->d_ino = 0; 4561558Srgrimes return (ret|KEEPON|ALTERED); 4571558Srgrimes} 4581558Srgrimes 4591558Srgrimes/* 4601558Srgrimes * Routine to sort disk blocks. 4611558Srgrimes */ 46223675Speterstatic int 46392839Simpblksort(const void *arg1, const void *arg2) 4641558Srgrimes{ 4651558Srgrimes 466100935Sphk return ((*(struct inoinfo * const *)arg1)->i_blks[0] - 467100935Sphk (*(struct inoinfo * const *)arg2)->i_blks[0]); 4681558Srgrimes} 469