Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Apr 2003 13:35:10 +0200 (CEST)
From:      Lukas Ertl <l.ertl@univie.ac.at>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/51619: [PATCH] newfs: wipe UFS1 superblock before writing UFS2 superblock
Message-ID:  <200304301135.h3UBZAoP001532@leelou.in.tern>
Resent-Message-ID: <200304301140.h3UBeEaE084627@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         51619
>Category:       bin
>Synopsis:       [PATCH] newfs: wipe UFS1 superblock before writing UFS2 superblock
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 30 04:40:14 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Lukas Ertl
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Vienna University Computer Center
>Environment:
System: FreeBSD leelou 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Thu Apr 24 16:53:52 CEST 2003 le@leelou:/usr/obj/usr/src/sys/LEELOU i386


	
>Description:

If you have a UFS1 filesystem and create a new UFS2 filesystem over that
one, the old superblock still exists since UFS2 places the superblock
to a different location.

This can cause problems if you try to use this UFS2 filesystem in
FreeBSD 4.x, which has no support of UFS2, but sees the old UFS1
superblock.

See also http://lists.freebsd.org/pipermail/freebsd-current/2003-April/001649.html

>How-To-Repeat:

In 4.x:

   newfs /dev/bla        # create UFS1


In 5-current, but with the same disk:

   newfs /dev/bla        # create UFS2 - but UFS1 superblock is still in place


Back in 4.x:

   mount /dev/bla /mnt   # succeeds, although it is UFS2...

>Fix:

	

--- mkfs.c.diff begins here ---
Index: sbin/newfs/mkfs.c
===================================================================
RCS file: /u/cvs/cvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.74
diff -u -r1.74 mkfs.c
--- sbin/newfs/mkfs.c	22 Feb 2003 23:26:11 -0000	1.74
+++ sbin/newfs/mkfs.c	30 Apr 2003 11:23:49 -0000
@@ -113,6 +113,7 @@
 	quad_t sizepb;
 	int width;
 	char tmpbuf[100];	/* XXX this will break in about 2,500 years */
+	char dummy[SBLOCKSIZE];
 
 	/*
 	 * Our blocks == sector size, and the version of UFS we are using is
@@ -479,8 +480,13 @@
 		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) {
+		if (Oflag != 1) {
+			memset(dummy, '\0', SBLOCKSIZE);
+			bwrite(&disk, SBLOCK_UFS1 / disk.d_bsize, dummy, 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 ?
--- mkfs.c.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304301135.h3UBZAoP001532>