Additional validity checking in newfs(8).

A check in the superblock validity code verifies that the computed
size of the filesystem cylinder groups (CGSIZE macro) does not
exceed the filesystem block size (fs_bsize).

A report was received that a filesystem had been flagged as failing
this check. We were unable to determine how the reported filesystem
could have been created. This commit adds a check at the end of the
newfs(8) command to verify that the the cylinder group size is valid.
If an oversize cylinder group is found newfs(8) prints a diagnostic
output and rebuilds the filesystem to make it compiliant.

MFC after:   1 week
This commit is contained in:
Kirk McKusick
2023-04-29 12:49:50 -07:00
parent a2d1957bbc
commit 62dc21b107
+16
View File
@@ -332,6 +332,7 @@ mkfs(struct partition *pp, char *fsys)
* can put into each cylinder group. If this is too big, we reduce
* the density until it fits.
*/
retry:
maxinum = (((int64_t)(1)) << 32) - INOPB(&sblock);
minfragsperinode = 1 + fssize / maxinum;
if (density == 0) {
@@ -666,6 +667,21 @@ mkfs(struct partition *pp, char *fsys)
pp->p_frag = sblock.fs_frag;
pp->p_cpg = sblock.fs_fpg;
}
/*
* This should NOT happen. If it does complain loudly and
* take evasive action.
*/
if ((int32_t)CGSIZE(&sblock) > sblock.fs_bsize) {
printf("INTERNAL ERROR: ipg %d, fpg %d, contigsumsize %d, ",
sblock.fs_ipg, sblock.fs_fpg, sblock.fs_contigsumsize);
printf("old_cpg %d, size_cg %jd, CGSIZE %jd\n",
sblock.fs_old_cpg, sizeof(struct cg), CGSIZE(&sblock));
printf("Please file a FreeBSD bug report and include this "
"output\n");
maxblkspercg = fragstoblks(&sblock, sblock.fs_fpg) - 1;
density = 0;
goto retry;
}
}
/*