Yesterday I had to fix a badly broken disk, and found that fsck kept dying:
DIR I=64512 CONNECTED. PARENT WAS I=4032 fsck: cannot find inode 995904 fsdb found the inodes with no problem: fsdb (inum: 64512)> inode 995904 current inode: directory I=995904 MODE=40777 SIZE=512 MTIME=Feb 14 15:27:07 2000 [0 nsec] CTIME=Feb 14 15:27:07 2000 [0 nsec] ATIME=Feb 24 10:31:58 2000 [0 nsec] OWNER=nobody GRP=nobody LINKCNT=4 FLAGS=0 BLKCNT=2 GEN=38a41386 Direct blocks: 8094568 0 0 0 0 0 0 0 0 0 0 0 Indirect blocks: 0 0 0 The problem turns out to be a program logic error in fsck. It stores directory inodes internally in hash lists, using the number of directories to form the hash key: inpp = &inphead[inumber % numdirs]; Elsewhere, however, it increments numdirs when it finds unattached directories. I've made the following fix, which solved the problem in the case in hand. Submitted by: Greg Lehey <grog@lemis.com> Reviewed by: Matthew Dillon <dillon@apollo.backplane.com> Approved by: Kirk McKusick <mckusick@mckusick.com>
This commit is contained in:
parent
20fb384ee0
commit
e50342e665
@ -182,7 +182,7 @@ struct inoinfo {
|
||||
u_int i_numblks; /* size of block array in bytes */
|
||||
ufs_daddr_t i_blks[1]; /* actually longer */
|
||||
} **inphead, **inpsort;
|
||||
long numdirs, listmax, inplast;
|
||||
long numdirs, dirhash, listmax, inplast;
|
||||
long countdirs; /* number of directories we actually found */
|
||||
|
||||
char *cdevname; /* name of device being checked */
|
||||
|
@ -396,7 +396,7 @@ cacheino(dp, inumber)
|
||||
malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t));
|
||||
if (inp == NULL)
|
||||
errx(EEXIT, "cannot increase directory list");
|
||||
inpp = &inphead[inumber % numdirs];
|
||||
inpp = &inphead[inumber % dirhash];
|
||||
inp->i_nexthash = *inpp;
|
||||
*inpp = inp;
|
||||
inp->i_parent = inumber == ROOTINO ? ROOTINO : (ino_t)0;
|
||||
@ -424,7 +424,7 @@ getinoinfo(inumber)
|
||||
{
|
||||
register struct inoinfo *inp;
|
||||
|
||||
for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
|
||||
for (inp = inphead[inumber % dirhash]; inp; inp = inp->i_nexthash) {
|
||||
if (inp->i_number != inumber)
|
||||
continue;
|
||||
return (inp);
|
||||
|
@ -286,6 +286,7 @@ setup(dev)
|
||||
goto badsb;
|
||||
}
|
||||
numdirs = sblock.fs_cstotal.cs_ndir;
|
||||
dirhash = numdirs;
|
||||
if (numdirs == 0) {
|
||||
printf("numdirs is zero, try using an alternate superblock\n");
|
||||
goto badsb;
|
||||
|
@ -182,7 +182,7 @@ struct inoinfo {
|
||||
u_int i_numblks; /* size of block array in bytes */
|
||||
ufs_daddr_t i_blks[1]; /* actually longer */
|
||||
} **inphead, **inpsort;
|
||||
long numdirs, listmax, inplast;
|
||||
long numdirs, dirhash, listmax, inplast;
|
||||
long countdirs; /* number of directories we actually found */
|
||||
|
||||
char *cdevname; /* name of device being checked */
|
||||
|
@ -396,7 +396,7 @@ cacheino(dp, inumber)
|
||||
malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t));
|
||||
if (inp == NULL)
|
||||
errx(EEXIT, "cannot increase directory list");
|
||||
inpp = &inphead[inumber % numdirs];
|
||||
inpp = &inphead[inumber % dirhash];
|
||||
inp->i_nexthash = *inpp;
|
||||
*inpp = inp;
|
||||
inp->i_parent = inumber == ROOTINO ? ROOTINO : (ino_t)0;
|
||||
@ -424,7 +424,7 @@ getinoinfo(inumber)
|
||||
{
|
||||
register struct inoinfo *inp;
|
||||
|
||||
for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
|
||||
for (inp = inphead[inumber % dirhash]; inp; inp = inp->i_nexthash) {
|
||||
if (inp->i_number != inumber)
|
||||
continue;
|
||||
return (inp);
|
||||
|
@ -286,6 +286,7 @@ setup(dev)
|
||||
goto badsb;
|
||||
}
|
||||
numdirs = sblock.fs_cstotal.cs_ndir;
|
||||
dirhash = numdirs;
|
||||
if (numdirs == 0) {
|
||||
printf("numdirs is zero, try using an alternate superblock\n");
|
||||
goto badsb;
|
||||
|
@ -182,7 +182,7 @@ struct inoinfo {
|
||||
u_int i_numblks; /* size of block array in bytes */
|
||||
ufs_daddr_t i_blks[1]; /* actually longer */
|
||||
} **inphead, **inpsort;
|
||||
long numdirs, listmax, inplast;
|
||||
long numdirs, dirhash, listmax, inplast;
|
||||
long countdirs; /* number of directories we actually found */
|
||||
|
||||
char *cdevname; /* name of device being checked */
|
||||
|
@ -396,7 +396,7 @@ cacheino(dp, inumber)
|
||||
malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t));
|
||||
if (inp == NULL)
|
||||
errx(EEXIT, "cannot increase directory list");
|
||||
inpp = &inphead[inumber % numdirs];
|
||||
inpp = &inphead[inumber % dirhash];
|
||||
inp->i_nexthash = *inpp;
|
||||
*inpp = inp;
|
||||
inp->i_parent = inumber == ROOTINO ? ROOTINO : (ino_t)0;
|
||||
@ -424,7 +424,7 @@ getinoinfo(inumber)
|
||||
{
|
||||
register struct inoinfo *inp;
|
||||
|
||||
for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
|
||||
for (inp = inphead[inumber % dirhash]; inp; inp = inp->i_nexthash) {
|
||||
if (inp->i_number != inumber)
|
||||
continue;
|
||||
return (inp);
|
||||
|
@ -286,6 +286,7 @@ setup(dev)
|
||||
goto badsb;
|
||||
}
|
||||
numdirs = sblock.fs_cstotal.cs_ndir;
|
||||
dirhash = numdirs;
|
||||
if (numdirs == 0) {
|
||||
printf("numdirs is zero, try using an alternate superblock\n");
|
||||
goto badsb;
|
||||
|
Loading…
Reference in New Issue
Block a user