diff options
author | Doug Barton <dougb@FreeBSD.org> | 2003-05-22 18:38:54 +0000 |
---|---|---|
committer | Doug Barton <dougb@FreeBSD.org> | 2003-05-22 18:38:54 +0000 |
commit | a32bb1b53a1341fd3d4dc5e9c097269ba45a0efe (patch) | |
tree | ee6ebf23e61a2664e3b5f722931833971d20d782 /sbin/newfs/mkfs.c | |
parent | cdc95e1bb810a36cd59c3ec47c721f817246253e (diff) | |
download | src-a32bb1b53a1341fd3d4dc5e9c097269ba45a0efe.tar.gz src-a32bb1b53a1341fd3d4dc5e9c097269ba45a0efe.zip |
When newfs'ing a partition with UFS2 that had previously been newfs'ed
with UFS1, the UFS1 superblocks were not deleted. This allowed any
RELENG_4 (or other non-UFS2-aware) fsck to think it knew how to "fix"
the file system, resulting in severe data scrambling.
This patch is a more advanced version than the one originally submitted.
Lukas improved it based on feedback from Kirk, and testing by me. It
blanks all UFS1 superblocks (if any) during a UFS2 newfs, thereby causing
fsck's that are not UFS2 aware to generate the "SEARCH FOR ALTERNATE
SUPER-BLOCK FAILED" message, and exit without damaging the fs.
PR: bin/51619
Submitted by: Lukas Ertl <l.ertl@univie.ac.at>
Reviewed by: kirk
Approved by: re (scottl)
Notes
Notes:
svn path=/head/; revision=115235
Diffstat (limited to 'sbin/newfs/mkfs.c')
-rw-r--r-- | sbin/newfs/mkfs.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 58e736db5eaf..ea576efd2676 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -113,6 +113,12 @@ mkfs(struct partition *pp, char *fsys) quad_t sizepb; int width; char tmpbuf[100]; /* XXX this will break in about 2,500 years */ + union { + struct fs fdummy; + char cdummy[SBLOCKSIZE]; + } dummy; +#define fsdummy dummy.fdummy +#define chdummy dummy.cdummy /* * Our blocks == sector size, and the version of UFS we are using is @@ -425,6 +431,24 @@ mkfs(struct partition *pp, char *fsys) if (sblock.fs_flags & FS_DOSOFTDEP) printf("\twith soft updates\n"); # undef B2MBFACTOR + + /* + * Wipe out old UFS1 superblock(s) if necessary. + */ + if (!Nflag && Oflag != 1) { + i = bread(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE); + if (i == -1) + err(1, "can't read old UFS1 superblock: %s", disk.d_error); + + if (fsdummy.fs_magic == FS_UFS1_MAGIC) { + fsdummy.fs_magic = 0; + bwrite(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE); + for (i = 0; i < fsdummy.fs_ncg; i++) + bwrite(&disk, fsbtodb(&fsdummy, cgsblock(&fsdummy, i)), + chdummy, SBLOCKSIZE); + } + } + /* * Now build the cylinders group blocks and * then print out indices of cylinder groups. |