Skip to content

Commit

Permalink
Bug fixes for fsck_ffs(8).
Browse files Browse the repository at this point in the history
Increment a reference count when returning a zero'ed out buffer
after a failed read.

Zero out a structure before using it.

Only dirty a buffer that has been modified.

Submitted by: Chuck Silvers
Sponsored by: Netflix
MFC after:    1 week
  • Loading branch information
Kirk McKusick authored and Kirk McKusick committed Apr 18, 2023
1 parent 7636973 commit 1874653
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion sbin/fsck_ffs/fsutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ getdatablk(ufs2_daddr_t blkno, long size, int type)
* Skip check for inodes because chkrange() considers
* metadata areas invalid to write data.
*/
if (type != BT_INODES && chkrange(blkno, size / sblock.fs_fsize))
if (type != BT_INODES && chkrange(blkno, size / sblock.fs_fsize)) {
failedbuf.b_refcnt++;
return (&failedbuf);
}
bhdp = &bufhashhd[HASH(blkno)];
LIST_FOREACH(bp, bhdp, b_hash)
if (bp->b_bno == fsbtodb(&sblock, blkno)) {
Expand Down
10 changes: 6 additions & 4 deletions sbin/fsck_ffs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ snapremove(ino_t inum)
bzero(&snaplist[i - 1], sizeof(struct inode));
snapcnt--;
}
memset(&idesc, 0, sizeof(struct inodesc));
idesc.id_type = SNAP;
idesc.id_func = snapclean;
idesc.id_number = inum;
Expand All @@ -767,14 +768,15 @@ snapclean(struct inodesc *idesc)
if (blkno == 0)
return (KEEPON);

bp = idesc->id_bp;
dp = idesc->id_dp;
if (blkno == BLK_NOCOPY || blkno == BLK_SNAP) {
if (idesc->id_lbn < UFS_NDADDR)
if (idesc->id_lbn < UFS_NDADDR) {
DIP_SET(dp, di_db[idesc->id_lbn], 0);
else
} else {
bp = idesc->id_bp;
IBLK_SET(bp, bp->b_index, 0);
dirty(bp);
dirty(bp);
}
}
return (KEEPON);
}
Expand Down

0 comments on commit 1874653

Please sign in to comment.