From owner-freebsd-fs@FreeBSD.ORG Thu Dec 8 14:05:54 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 698E3106566B; Thu, 8 Dec 2011 14:05:54 +0000 (UTC) (envelope-from rmh.aybabtu@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id B5E0A8FC08; Thu, 8 Dec 2011 14:05:53 +0000 (UTC) Received: by wgbdr11 with SMTP id dr11so3438966wgb.31 for ; Thu, 08 Dec 2011 06:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=qrJOUiJRGylHrthn0eoqGR0BtnWhbkl9jc+/8tbIuX4=; b=vSQiGEPy45SaN7qHewiWjNa5Xs/5yGEnBJtxzaH9R7QXOecmZee1NMMtT2n0N2zaEH hptD4UkmZtMY2YU5a2oxoCovH+dimgIGvRd4H4EVH43NXL4+rND4yFVSgFEy09aBz+7F apxIBxyYa10YKjZmvjyRvFdvO1BPc39xsW940= Received: by 10.180.104.2 with SMTP id ga2mr5870328wib.33.1323351790300; Thu, 08 Dec 2011 05:43:10 -0800 (PST) Received: from thorin (52.Red-95-122-67.staticIP.rima-tde.net. [95.122.67.52]) by mx.google.com with ESMTPS id ei9sm1473666wid.0.2011.12.08.05.43.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Dec 2011 05:43:09 -0800 (PST) Sender: Robert Millan Received: from rmh by thorin with local (Exim 4.72) (envelope-from ) id 1RYeFf-0001NJ-5y; Thu, 08 Dec 2011 14:43:07 +0100 Date: Thu, 8 Dec 2011 14:43:07 +0100 From: Robert Millan To: freebsd-fs@freebsd.org, dougb@freebsd.org Message-ID: <20111208134307.GA5266@thorin> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pvezYHf7grwyp3Bc" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Adrian Chadd Subject: [PATCH] Wipe other file systems when creating new UFS X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2011 14:05:54 -0000 --pvezYHf7grwyp3Bc Content-Type: multipart/mixed; boundary="UugvWAfsgieZRqgk" Content-Disposition: inline --UugvWAfsgieZRqgk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, This patch resolves a problem reported to Debian BTS [1] which also affects FreeBSD. The problem is that if you create a ZFS file system in a partition and later decide you'd rather use UFS and overwrite it, remnants of ZFS uberblocks are left at the beginning and end of the partition. This can lead to disaster (data loss) if "zpool import" is attempted, as it would destroy UFS data structures. newfs(8) currently erases remnants of UFS if they exist. I think it should go further and erase first and last 512 kiB of the partition. [1] http://bugs.debian.org/635272 --=20 Robert Millan --UugvWAfsgieZRqgk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="wipe_other_fs.diff" Content-Transfer-Encoding: quoted-printable Index: sbin/newfs/mkfs.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sbin/newfs/mkfs.c (revision 228348) +++ sbin/newfs/mkfs.c (working copy) @@ -113,6 +113,7 @@ mkfs(struct partition *pp, char *fsys) { int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg; + off_t mediasize; long i, j, csfrags; uint cg; time_t utime; @@ -505,24 +506,23 @@ sblock.fs_size * sblock.fs_fsize - sblock.fs_sblockloc); } /* - * Wipe out old UFS1 superblock(s) if necessary. + * Wipe out other file systems. For now we erase first and last 512 kiB + * (this works for at least UFS1 and ZFS). */ - if (!Nflag && Oflag !=3D 1) { - i =3D bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOC= KSIZE); - if (i =3D=3D -1) - err(1, "can't read old UFS1 superblock: %s", disk.d_error); + if (!Eflag && !Nflag) { + mediasize =3D get_block_device_size(disk.d_fd); =20 - if (fsdummy.fs_magic =3D=3D FS_UFS1_MAGIC) { - fsdummy.fs_magic =3D 0; - bwrite(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, - chdummy, SBLOCKSIZE); - for (cg =3D 0; cg < fsdummy.fs_ncg; cg++) { - if (fsbtodb(&fsdummy, cgsblock(&fsdummy, cg)) > fssize) - break; - bwrite(&disk, part_ofs + fsbtodb(&fsdummy, - cgsblock(&fsdummy, cg)), chdummy, SBLOCKSIZE); - } - } + printf("Erasing sectors [%jd...%jd]\n", + sblock.fs_sblockloc / disk.d_bsize, + fsbtodb(&sblock, sblock.fs_size) - 1); + berase(&disk, sblock.fs_sblockloc / disk.d_bsize, + 1024 * disk.d_bsize - sblock.fs_sblockloc); + + printf("Erasing sectors [%jd...%jd]\n", + (mediasize - 1024 * 512) / disk.d_bsize, + (mediasize / disk.d_bsize) - 1); + berase(&disk, (mediasize - 1024 * 512) / disk.d_bsize, + 1024 * 512); } if (!Nflag) do_sbwrite(&disk); --UugvWAfsgieZRqgk-- --pvezYHf7grwyp3Bc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/kFreeBSD) iQIcBAEBCAAGBQJO4L7pAAoJELd1onhloKnOSckP/2naJNqSpTOE84U+Ng/HcgW7 OtrYHlcTGVaeb+dV/MsFPiTW3g+w8A3+r1UsU8E9hrJGjZ27OQfI5dPZa9xgtRow GAWLpmc0Hh5tvEGcCSEPhJX/03DzejzkYEPE9hIorp2ovoviaR+UpROi+RaH3ode 37OorAMp47xDXBHHe5BC2oOooRHCRrZMHaJFtoHXesykK0ehUmYZEYzeWIyKdtnd piZ54+veQvnTBROYrUNlY0DrDH9zuROLF7Pzhh5sx/8YSvrzjnJrqozO0pP2+hbs 1176skKzAGG5HOl5xxSS5Q5zf3y0Zdvi/+N5bdM918jhB2UH6d9UfrOSKNjNQzpH RdJ0ACA/7CW7kdgSa6yYjKlpkLpp3gAIJ8VicLoJF7RYV1MhZK4YDsfx3NcDHF2k pa5qCMAjQwPmO0iQHjA6oRnuy6/KNJj+quI0e+G+XAtq/pOHb+RwChDLJYjq6tw0 nGSGgRKWveOTbN94t2AxrPlh1IRLcO7po/p+T2d4RojqEt8/U8yEO/J2An1gETEx 8Mtyt0BtyDx1d3v/U6Ko8Gp8Qly4WiJ9KaO0fnTN+DTFXgAplJ0oXGxAAjZw0nfY 4BQPCEfejMpGMsNwTARh+w9usDxrdZ0FPK3c1Jf01gsDaMnNHB2cWZaDHCti0iia CEYYqBB3aNWfPx1KobHN =SO4B -----END PGP SIGNATURE----- --pvezYHf7grwyp3Bc--