Subject: bin/17910: Recent-FreeBSD-current-mounted filesystems are incompatible with NetBSD fsck
To: None <gnats-bugs@gnats.netbsd.org>
From: None <netbsd-misuser-200202@dcf77-zeit.netscum.dyndns.dk>
List: netbsd-bugs
Date: 08/11/2002 08:07:44
>Number:         17910
>Category:       bin
>Synopsis:       Recent-FreeBSD-current-mounted filesystems are incompatible with NetBSD fsck
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 11 08:08:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Barry Bouwsma
>Release:        netbsd-current (built 06.Jun)
>Organization:
Organisation? Feh.  Company? Even more feh.
>Environment:
urk, sorry, I can't boot NetBSD at the moment (multi-OS)...  i386
>Description:
FreeBSD-current has introduced changes to the superblock in the last
few months, that are incompatible with old FreeBSD-stable, and also
NetBSD.  `fsck' in particular barfs.
The logic of the change to FreeBSD-current's `fsck' program is that
it no longer compares all fields in the superblock (making equal those
fields that are possibly different), but it only compares those fields
that are definitely the same between primary and alternate superblock.
The change was merged into FreeBSD-stable, but at last look, was not
in NetBSD, making NetBSD have difficulty with filesystems that have
been mounted by a recent FreeBSD-current.
>How-To-Repeat:
Mount a filesystem under FreeBSD-current (recent) rw, then boot into
NetBSD.  `fsck' at boot should complain about the alternate superblock
disagreeing with the values in the primary superblock.  The usual way
to get around this is by invoking fsck_ffs with an alternate superblock
as `-b 32' or what have you.
>Fix:
Apply the logic in the patch in the FreeBSD MFC 1.30 to fsck's
setup.c.  This may very well need review for the different architectures
out there; I've only tried it with i386, NetBSD-current.
I've tried to duplicate the FreeBSD diff, fudging it as needed to
match NetBSD.  Here's the patch I applied to NEtBSD-current to get it
to work for me; apologies if it gets mangled since I'm using the web
interface to submit this pr.

less /NetBSD/usr/local/source-hacks/sbin/fsck_ffs/setup.c-patch

--- setup.c-ORIG        Wed Dec 19 11:05:20 2001
+++ setup.c     Tue Aug  6 13:35:04 2002
@@ -573,56 +573,32 @@
 {
        /*
-        * Copy fields which we don't care if they're different in the
-        * alternate superblocks, as they're either likely to be
-        * different because they're per-cylinder-group specific, or
-        * because they're transient details which are only maintained
-        * in the primary superblock.
+        * Compare all fields that should not differ in alternate superblock.
         */
-       asb->fs_firstfield = sb->fs_firstfield;
-       asb->fs_unused_1 = sb->fs_unused_1;
-       asb->fs_time = sb->fs_time;
-       asb->fs_cstotal = sb->fs_cstotal;
-       asb->fs_cgrotor = sb->fs_cgrotor;
-       asb->fs_fmod = sb->fs_fmod;
-       asb->fs_clean = sb->fs_clean;
-       asb->fs_ronly = sb->fs_ronly;
-       asb->fs_flags = sb->fs_flags;
-       asb->fs_maxcontig = sb->fs_maxcontig;
-       asb->fs_minfree = sb->fs_minfree;
-       asb->fs_optim = sb->fs_optim;
-       asb->fs_rotdelay = sb->fs_rotdelay;
-       asb->fs_maxbpg = sb->fs_maxbpg;
-       memmove(asb->fs_ocsp, sb->fs_ocsp, sizeof sb->fs_ocsp);
-       asb->fs_contigdirs = sb->fs_contigdirs;
-       asb->fs_csp = sb->fs_csp;
-       asb->fs_maxcluster = sb->fs_maxcluster;
-       memmove(asb->fs_fsmnt, sb->fs_fsmnt, sizeof sb->fs_fsmnt);
-       memmove(asb->fs_snapinum,
-               sb->fs_snapinum, sizeof sb->fs_snapinum);
-       asb->fs_avgfilesize = sb->fs_avgfilesize;
-       asb->fs_avgfpdir = sb->fs_avgfpdir;
-       asb->fs_pendingblocks = sb->fs_pendingblocks;
-       asb->fs_pendinginodes = sb->fs_pendinginodes;
-       memmove(asb->fs_sparecon,
-               sb->fs_sparecon, sizeof sb->fs_sparecon);
-       /*
-        * The following should not have to be copied, but need to be.
-        */
-       asb->fs_fsbtodb = sb->fs_fsbtodb;
-       asb->fs_interleave = sb->fs_interleave;
-       asb->fs_npsect = sb->fs_npsect;
-       asb->fs_nrpos = sb->fs_nrpos;
-       asb->fs_qbmask = sb->fs_qbmask;
-       asb->fs_qfmask = sb->fs_qfmask;
-       asb->fs_state = sb->fs_state;
-       asb->fs_maxfilesize = sb->fs_maxfilesize;
-
-       /*
-        * Compare the superblocks, effectively checking every other
-        * field to see if they differ.
-        */
-       return (memcmp(sb, asb, (int)sb->fs_sbsize));
+       return (asb->fs_sblkno != sb->fs_sblkno ||
+           asb->fs_cblkno != sb->fs_cblkno ||
+           asb->fs_iblkno != sb->fs_iblkno ||
+           asb->fs_dblkno != sb->fs_dblkno ||
+           asb->fs_cgoffset != sb->fs_cgoffset ||
+           asb->fs_cgmask != sb->fs_cgmask ||
+           asb->fs_ncg != sb->fs_ncg ||
+           asb->fs_bsize != sb->fs_bsize ||
+           asb->fs_fsize != sb->fs_fsize ||
+           asb->fs_frag != sb->fs_frag ||
+           asb->fs_bmask != sb->fs_bmask ||
+           asb->fs_fmask != sb->fs_fmask ||
+           asb->fs_bshift != sb->fs_bshift ||
+           asb->fs_fshift != sb->fs_fshift ||
+           asb->fs_fragshift != sb->fs_fragshift ||
+           asb->fs_fsbtodb != sb->fs_fsbtodb ||
+           asb->fs_sbsize != sb->fs_sbsize ||
+           asb->fs_nindir != sb->fs_nindir ||
+           asb->fs_inopb != sb->fs_inopb ||
+           asb->fs_cssize != sb->fs_cssize ||
+           asb->fs_cpg != sb->fs_cpg ||
+           asb->fs_ipg != sb->fs_ipg ||
+           asb->fs_fpg != sb->fs_fpg ||
+           asb->fs_magic != sb->fs_magic);
 }
 static void


Please review that I didn't make any typos or leave anything out.
I think I gave info in the posting to current-users mailing list to
find the original FreeBSD patch from which I derived the above.
Also, my patch is ugly-as-sin (if it works) so please modify as
needed to fit into the way NetBSD does things.  Thanks.
>Release-Note:
>Audit-Trail:
>Unformatted: