Re: bin/51619

From: Kirk McKusick <mckusick_at_beastie.mckusick.com>
Date: Thu, 08 May 2003 13:47:13 -0700
Your proposed patch would work much better. There is a small
possibility that it would stomp a boot block that just happened
to have the filesystem magic number at that location, but the
chances of that seem pretty remote. It does not address the
alternate superblock issue. The first UFS1 alternate is 32
sectors (16K) in from the beginning of the disk. That alternate
also remains untouched by UFS2. So, someone manually running 
fsck will be given the opportunity to look for alternate
superblocks and will find that one and *still* end up messing
up the filesystem. Indeed to be completely safe, you would 
need to look up every alternate superblock and zero out its
magic number (see the last for-loop in mkfs() for details
on how this is done).

	Kirk McKusick

=-=-=-=-=-=

Date: Thu, 8 May 2003 12:45:20 +0200 (CEST)
From: Lukas Ertl <l.ertl_at_univie.ac.at>
To: Kirk McKusick <mckusick_at_mckusick.com>
cc: freebsd-current_at_freebsd.org, DougB_at_freebsd.org
Subject: Re: bin/51619
X-ASK-Info: Whitelist match

On Wed, 7 May 2003, Kirk McKusick wrote:

> At one time I had the suggested change that you made in bin/51619
> in the FreeBSD-5.0 newfs program. The problem with that change is
> that the bootstrap on some architectures now exceeds 8K which means
> that instead of zeroing an old superblock you destroy the boot code.
> So, I removed the zeroing of the old UFS1 superblock area. A possible
> alternative would be to check for a UFS1 magic number at the old
> location (and also at the 16K first backup location) and zero out
> just those fields if they are found. While it is possible that a
> bootstrap might just have that number at that offset, it is highly
> unlikely.

Hi Kirk,

thanks for clarifying this. Would this patch here be better suited?

---8<---
Index: sbin/newfs/mkfs.c
===================================================================
RCS file: /u/cvs/cvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.75
diff -u -r1.75 mkfs.c
--- sbin/newfs/mkfs.c	3 May 2003 18:41:58 -0000	1.75
+++ sbin/newfs/mkfs.c	8 May 2003 10:42:15 -0000
_at__at_ -113,6 +113,12 _at__at_
 	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
_at__at_ -479,8 +485,22 _at__at_
 		sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
 		sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
 	}
-	if (!Nflag)
+	if (!Nflag) {
+		/*
+		 * Wipe out old UFS1 superblock if necessary.
+		 */
+		if (Oflag != 1) {
+			i = bread(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
+			if (i == -1)
+				err(1, "can't bread: %s", disk.d_error);
+
+			if (fsdummy.fs_magic == FS_UFS1_MAGIC) {
+				fsdummy.fs_magic = 0;
+				bwrite(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
+			}
+		}
 		sbwrite(&disk, 0);
+	}
 	for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
 		wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
 			sblock.fs_cssize - i < sblock.fs_bsize ?
---8<---

regards,
le

-- 
Lukas Ertl                             eMail: l.ertl_at_univie.ac.at
UNIX-Systemadministrator               Tel.:  (+43 1) 4277-14073
Zentraler Informatikdienst (ZID)       Fax.:  (+43 1) 4277-9140
der Universität Wien                   http://mailbox.univie.ac.at/~le/
Received on Thu May 08 2003 - 11:47:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:07 UTC