From 8f0931174a3e973773dfea895712cefa5e49e4fb Mon Sep 17 00:00:00 2001 From: Xin LI Date: Tue, 26 Feb 2008 03:03:17 +0000 Subject: [PATCH] Be more careful when checking superblock. We have already checked whether fs_bsize is larger than MINBSIZE, which is larger than the value that is used to compared with fs_bsize, the sizeof fs, so the check followed, will be always true. By inspecting the code and some old commit log, I believe that the check must be that *fs_sbsize* is larger than sizeof fs. We round up the size to nearest dev_bsize, as the smallest accepted fs_sbsize, personally, I think this can be even changed to equal, because this number is mostly an invariant in file systems. With this check, fsck_ffs(8) will be more picky and has better chance rejecting bad first superblock rather than referring to bad value it supplied, thus gives better chance for it to check the filesystem carefully. --- sbin/fsck_ffs/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index bdf88b4b0dfd..f6b37a31cdec 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -349,7 +349,7 @@ readsb(int listerr) sblock.fs_sblockloc == sblock_try[i])) && sblock.fs_ncg >= 1 && sblock.fs_bsize >= MINBSIZE && - sblock.fs_bsize >= sizeof(struct fs)) + sblock.fs_sbsize >= roundup(sizeof(struct fs), dev_bsize)) break; } if (sblock_try[i] == -1) {