Re: bin/51619

From: Lukas Ertl <l.ertl_at_univie.ac.at>
Date: Fri, 9 May 2003 14:11:44 +0200 (CEST)
On Thu, 8 May 2003, Kirk McKusick wrote:

> 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).

Allright, how about this one? I'm not quite sure if I got it right, but a
quick test with fsck_ffs -b showed that the old superblocks were wiped
out. I also moved that code to an earlier position, so that I do it before
anything of the new stuff is written.

---8<---
Index: mkfs.c
===================================================================
RCS file: /u/cvs/cvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.75
diff -u -r1.75 mkfs.c
--- mkfs.c	3 May 2003 18:41:58 -0000	1.75
+++ mkfs.c	9 May 2003 12:11:02 -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_ -425,6 +431,24 _at__at_
 	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.
---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 Fri May 09 2003 - 03:12:05 UTC

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