Changeset View
Changeset View
Standalone View
Standalone View
sbin/fsck_ffs/pass2.c
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | pass2(void) | ||||
union dinode *dp; | union dinode *dp; | ||||
struct inoinfo **inpp, *inp; | struct inoinfo **inpp, *inp; | ||||
struct inoinfo **inpend; | struct inoinfo **inpend; | ||||
struct inodesc curino; | struct inodesc curino; | ||||
union dinode dino; | union dinode dino; | ||||
int i; | int i; | ||||
char pathbuf[MAXPATHLEN + 1]; | char pathbuf[MAXPATHLEN + 1]; | ||||
switch (inoinfo(ROOTINO)->ino_state) { | switch (inoinfo(UFS_ROOTINO)->ino_state) { | ||||
case USTATE: | case USTATE: | ||||
pfatal("ROOT INODE UNALLOCATED"); | pfatal("ROOT INODE UNALLOCATED"); | ||||
if (reply("ALLOCATE") == 0) { | if (reply("ALLOCATE") == 0) { | ||||
ckfini(0); | ckfini(0); | ||||
exit(EEXIT); | exit(EEXIT); | ||||
} | } | ||||
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) | if (allocdir(UFS_ROOTINO, UFS_ROOTINO, 0755) != UFS_ROOTINO) | ||||
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | ||||
break; | break; | ||||
case DCLEAR: | case DCLEAR: | ||||
pfatal("DUPS/BAD IN ROOT INODE"); | pfatal("DUPS/BAD IN ROOT INODE"); | ||||
if (reply("REALLOCATE")) { | if (reply("REALLOCATE")) { | ||||
freeino(ROOTINO); | freeino(UFS_ROOTINO); | ||||
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) | if (allocdir(UFS_ROOTINO, UFS_ROOTINO, 0755) != | ||||
UFS_ROOTINO) | |||||
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | ||||
break; | break; | ||||
} | } | ||||
if (reply("CONTINUE") == 0) { | if (reply("CONTINUE") == 0) { | ||||
ckfini(0); | ckfini(0); | ||||
exit(EEXIT); | exit(EEXIT); | ||||
} | } | ||||
break; | break; | ||||
case FSTATE: | case FSTATE: | ||||
case FCLEAR: | case FCLEAR: | ||||
case FZLINK: | case FZLINK: | ||||
pfatal("ROOT INODE NOT DIRECTORY"); | pfatal("ROOT INODE NOT DIRECTORY"); | ||||
if (reply("REALLOCATE")) { | if (reply("REALLOCATE")) { | ||||
freeino(ROOTINO); | freeino(UFS_ROOTINO); | ||||
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) | if (allocdir(UFS_ROOTINO, UFS_ROOTINO, 0755) != | ||||
UFS_ROOTINO) | |||||
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | errx(EEXIT, "CANNOT ALLOCATE ROOT INODE"); | ||||
break; | break; | ||||
} | } | ||||
if (reply("FIX") == 0) { | if (reply("FIX") == 0) { | ||||
ckfini(0); | ckfini(0); | ||||
exit(EEXIT); | exit(EEXIT); | ||||
} | } | ||||
dp = ginode(ROOTINO); | dp = ginode(UFS_ROOTINO); | ||||
DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT); | DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT); | ||||
DIP_SET(dp, di_mode, DIP(dp, di_mode) | IFDIR); | DIP_SET(dp, di_mode, DIP(dp, di_mode) | IFDIR); | ||||
inodirty(); | inodirty(); | ||||
break; | break; | ||||
case DSTATE: | case DSTATE: | ||||
case DZLINK: | case DZLINK: | ||||
break; | break; | ||||
default: | default: | ||||
errx(EEXIT, "BAD STATE %d FOR ROOT INODE", | errx(EEXIT, "BAD STATE %d FOR ROOT INODE", | ||||
inoinfo(ROOTINO)->ino_state); | inoinfo(UFS_ROOTINO)->ino_state); | ||||
} | } | ||||
inoinfo(ROOTINO)->ino_state = DFOUND; | inoinfo(UFS_ROOTINO)->ino_state = DFOUND; | ||||
inoinfo(WINO)->ino_state = FSTATE; | inoinfo(UFS_WINO)->ino_state = FSTATE; | ||||
inoinfo(WINO)->ino_type = DT_WHT; | inoinfo(UFS_WINO)->ino_type = DT_WHT; | ||||
/* | /* | ||||
* Sort the directory list into disk block order. | * Sort the directory list into disk block order. | ||||
*/ | */ | ||||
qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); | qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); | ||||
/* | /* | ||||
* Check the integrity of each directory. | * Check the integrity of each directory. | ||||
*/ | */ | ||||
memset(&curino, 0, sizeof(struct inodesc)); | memset(&curino, 0, sizeof(struct inodesc)); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (inp->i_isize < MINDIRSIZE) { | ||||
roundup(inp->i_isize, DIRBLKSIZ)); | roundup(inp->i_isize, DIRBLKSIZ)); | ||||
inodirty(); | inodirty(); | ||||
} | } | ||||
} | } | ||||
dp = &dino; | dp = &dino; | ||||
memset(dp, 0, sizeof(struct ufs2_dinode)); | memset(dp, 0, sizeof(struct ufs2_dinode)); | ||||
DIP_SET(dp, di_mode, IFDIR); | DIP_SET(dp, di_mode, IFDIR); | ||||
DIP_SET(dp, di_size, inp->i_isize); | DIP_SET(dp, di_size, inp->i_isize); | ||||
for (i = 0; i < MIN(inp->i_numblks, NDADDR); i++) | for (i = 0; i < MIN(inp->i_numblks, UFS_NDADDR); i++) | ||||
DIP_SET(dp, di_db[i], inp->i_blks[i]); | DIP_SET(dp, di_db[i], inp->i_blks[i]); | ||||
if (inp->i_numblks > NDADDR) | if (inp->i_numblks > UFS_NDADDR) | ||||
for (i = 0; i < NIADDR; i++) | for (i = 0; i < UFS_NIADDR; i++) | ||||
DIP_SET(dp, di_ib[i], inp->i_blks[NDADDR + i]); | DIP_SET(dp, di_ib[i], | ||||
inp->i_blks[UFS_NDADDR + i]); | |||||
curino.id_number = inp->i_number; | curino.id_number = inp->i_number; | ||||
curino.id_parent = inp->i_parent; | curino.id_parent = inp->i_parent; | ||||
(void)ckinode(dp, &curino); | (void)ckinode(dp, &curino); | ||||
} | } | ||||
/* | /* | ||||
* Now that the parents of all directories have been found, | * Now that the parents of all directories have been found, | ||||
* make another pass to verify the value of `..' | * make another pass to verify the value of `..' | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | if (dirp->d_name[1] == '.') { | ||||
return (KEEPON | ret); | return (KEEPON | ret); | ||||
} | } | ||||
} | } | ||||
idesc->id_entryno++; | idesc->id_entryno++; | ||||
n = 0; | n = 0; | ||||
if (dirp->d_ino > maxino) { | if (dirp->d_ino > maxino) { | ||||
fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); | fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); | ||||
n = reply("REMOVE"); | n = reply("REMOVE"); | ||||
} else if (((dirp->d_ino == WINO && dirp->d_type != DT_WHT) || | } else if (((dirp->d_ino == UFS_WINO && dirp->d_type != DT_WHT) || | ||||
(dirp->d_ino != WINO && dirp->d_type == DT_WHT))) { | (dirp->d_ino != UFS_WINO && dirp->d_type == DT_WHT))) { | ||||
fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY"); | fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY"); | ||||
dirp->d_ino = WINO; | dirp->d_ino = UFS_WINO; | ||||
dirp->d_type = DT_WHT; | dirp->d_type = DT_WHT; | ||||
if (reply("FIX") == 1) | if (reply("FIX") == 1) | ||||
ret |= ALTERED; | ret |= ALTERED; | ||||
} else { | } else { | ||||
again: | again: | ||||
switch (inoinfo(dirp->d_ino)->ino_state) { | switch (inoinfo(dirp->d_ino)->ino_state) { | ||||
case USTATE: | case USTATE: | ||||
if (idesc->id_entryno <= 2) | if (idesc->id_entryno <= 2) | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |