aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2022-07-21 05:45:18 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2022-07-21 05:52:10 +0000
commitf030f1102c62d3de498cf2b5f0ce8d3582182923 (patch)
treecc6fa6f7325fd3938c195a36a7c56d1754106cc9 /sbin
parent7c332e97bbd3a90152c3c37d4fb259c2648f1298 (diff)
downloadsrc-f030f1102c62d3de498cf2b5f0ce8d3582182923.tar.gz
src-f030f1102c62d3de498cf2b5f0ce8d3582182923.zip
Delete UFS2 backup superblock recovery info when building a UFS1 filesystem.
Only the UFS2 filesystem has support for storing information needed to find alternate superblocks. If that information is inadvertently left in place when building a UFS1 filesystem, fsck_ffs may stumble across it and attempt to use it to recover the UFS1 filesystem which can only end poorly.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs/mkfs.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index a6c4ee60c2d5..48091d7882d0 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -636,23 +636,26 @@ restart:
* Read the last sector of the boot block, replace the last
* 20 bytes with the recovery information, then write it back.
* The recovery information only works for UFS2 filesystems.
+ * For UFS1, zero out the area to ensure that an old UFS2
+ * recovery block is not accidentally found.
*/
- if (sblock.fs_magic == FS_UFS2_MAGIC) {
- if ((fsrbuf = malloc(realsectorsize)) == NULL || bread(&disk,
- part_ofs + (SBLOCK_UFS2 - realsectorsize) / disk.d_bsize,
- fsrbuf, realsectorsize) == -1)
- err(1, "can't read recovery area: %s", disk.d_error);
- fsr =
- (struct fsrecovery *)&fsrbuf[realsectorsize - sizeof *fsr];
+ if ((fsrbuf = malloc(realsectorsize)) == NULL || bread(&disk,
+ part_ofs + (SBLOCK_UFS2 - realsectorsize) / disk.d_bsize,
+ fsrbuf, realsectorsize) == -1)
+ err(1, "can't read recovery area: %s", disk.d_error);
+ fsr = (struct fsrecovery *)&fsrbuf[realsectorsize - sizeof *fsr];
+ if (sblock.fs_magic != FS_UFS2_MAGIC) {
+ memset(fsr, 0, sizeof *fsr);
+ } else {
fsr->fsr_magic = sblock.fs_magic;
fsr->fsr_fpg = sblock.fs_fpg;
fsr->fsr_fsbtodb = sblock.fs_fsbtodb;
fsr->fsr_sblkno = sblock.fs_sblkno;
fsr->fsr_ncg = sblock.fs_ncg;
- wtfs((SBLOCK_UFS2 - realsectorsize) / disk.d_bsize,
- realsectorsize, fsrbuf);
- free(fsrbuf);
}
+ wtfs((SBLOCK_UFS2 - realsectorsize) / disk.d_bsize,
+ realsectorsize, fsrbuf);
+ free(fsrbuf);
/*
* Update information about this partition in pack
* label, to that it may be updated on disk.