Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Aug 2004 00:30:17 +0800
From:      Xin LI <delphij@frontfree.net>
To:        re@FreeBSD.org, freebsd-fs@FreeBSD.org
Subject:   [PATCH] Generalize BAD_MAGIC usage so it will apply to UFS1 too
Message-ID:  <20040816163017.GA2890@frontfree.net>

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

--/WwmFnJnmDyWGHa4
Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf"
Content-Disposition: inline


--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,

Here is a patch which will generalize UFS2's BAD FLAG to UFS1 initialization
as well.

Cheers,
--=20
Xin LI <delphij frontfree net>	http://www.delphij.net/
See complete headers for GPG key and other information.


--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-ufs2
Content-Transfer-Encoding: quoted-printable

Index: src/sbin/fsck_ffs/setup.c
diff -u src/sbin/fsck_ffs/setup.c:1.47 src/sbin/fsck_ffs/setup.c:1.47.1000.1
--- src/sbin/fsck_ffs/setup.c:1.47	Sat Apr 10 03:58:28 2004
+++ src/sbin/fsck_ffs/setup.c	Wed May 12 05:53:32 2004
@@ -306,7 +306,7 @@
 		super =3D bflag;
 		if ((bread(fsreadfd, (char *)&sblock, super, (long)SBLOCKSIZE)))
 			return (0);
-		if (sblock.fs_magic =3D=3D FS_BAD2_MAGIC) {
+		if (sblock.fs_magic =3D=3D FS_BAD_MAGIC) {
 			fprintf(stderr, BAD_MAGIC_MSG);
 			exit(11);
 		}
@@ -322,7 +322,7 @@
 			if ((bread(fsreadfd, (char *)&sblock, super,
 			    (long)SBLOCKSIZE)))
 				return (0);
-			if (sblock.fs_magic =3D=3D FS_BAD2_MAGIC) {
+			if (sblock.fs_magic =3D=3D FS_BAD_MAGIC) {
 				fprintf(stderr, BAD_MAGIC_MSG);
 				exit(11);
 			}
Index: src/sbin/newfs/mkfs.c
diff -u src/sbin/newfs/mkfs.c:1.85 src/sbin/newfs/mkfs.c:1.85.1000.1
--- src/sbin/newfs/mkfs.c:1.85	Sat Apr 10 03:58:33 2004
+++ src/sbin/newfs/mkfs.c	Wed May 12 05:53:36 2004
@@ -236,8 +236,14 @@
 	}
 	sblock.fs_fsbtodb =3D ilog2(sblock.fs_fsize / sectorsize);
 	sblock.fs_size =3D fssize =3D dbtofsb(&sblock, fssize);
+
+	/*
+	 * Before the filesystem is finally initialized, mark it
+	 * as incompletely initialized.
+	 */
+	sblock.fs_magic =3D FS_BAD_MAGIC;
+
 	if (Oflag =3D=3D 1) {
-		sblock.fs_magic =3D FS_UFS1_MAGIC;
 		sblock.fs_sblockloc =3D SBLOCK_UFS1;
 		sblock.fs_nindir =3D sblock.fs_bsize / sizeof(ufs1_daddr_t);
 		sblock.fs_inopb =3D sblock.fs_bsize / sizeof(struct ufs1_dinode);
@@ -257,7 +263,6 @@
 		sblock.fs_old_postblformat =3D 1;
 		sblock.fs_old_nrpos =3D 1;
 	} else {
-		sblock.fs_magic =3D FS_BAD2_MAGIC;
 		sblock.fs_sblockloc =3D SBLOCK_UFS2;
 		sblock.fs_nindir =3D sblock.fs_bsize / sizeof(ufs2_daddr_t);
 		sblock.fs_inopb =3D sblock.fs_bsize / sizeof(struct ufs2_dinode);
@@ -455,8 +460,8 @@
 	}
 	if (Eflag =3D=3D 2)
 		printf("** Leaving BAD MAGIC on Eflag 2\n");
-	else if (Oflag !=3D 1)
-		sblock.fs_magic =3D FS_UFS2_MAGIC;
+	else
+		sblock.fs_magic =3D (Oflag !=3D 1) ? FS_UFS2_MAGIC : FS_UFS1_MAGIC;
=20
 	/*
 	 * Now build the cylinders group blocks and
Index: src/sys/ufs/ffs/fs.h
diff -u src/sys/ufs/ffs/fs.h:1.43 src/sys/ufs/ffs/fs.h:1.42.1000.2
--- src/sys/ufs/ffs/fs.h:1.43	Tue Jun  1 00:53:46 2004
+++ src/sys/ufs/ffs/fs.h	Tue Jun  1 22:52:01 2004
@@ -357,7 +357,7 @@
  */
 #define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast filesystem magic number */
 #define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast filesystem magic number */
-#define	FS_BAD2_MAGIC	0x19960408	/* UFS2 incomplete newfs magic number */
+#define	FS_BAD_MAGIC	0x19960408	/* UFS incomplete newfs magic number */
 #define	FS_OKAY		0x7c269d38	/* superblock checksum */
 #define FS_42INODEFMT	-1		/* 4.2BSD inode format */
 #define FS_44INODEFMT	2		/* 4.4BSD inode format */

--J2SCkAp4GZ/dPZZf--

--/WwmFnJnmDyWGHa4
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (FreeBSD)

iD8DBQFBIOEZOfuToMruuMARAjQXAJwKkqVJEWKeBhI2gEKXJC1mmyhS9gCdFiB+
0qFHkRWg8TgAwTYh7p9CYJY=
=+Q3z
-----END PGP SIGNATURE-----

--/WwmFnJnmDyWGHa4--



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