From nobody@FreeBSD.org  Sun Jan 13 22:02:09 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A4C7D16A468
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Jan 2008 22:02:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 895BF13C468
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Jan 2008 22:02:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0DM0ueb015215
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 13 Jan 2008 22:00:56 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m0DM0uAh015214;
	Sun, 13 Jan 2008 22:00:56 GMT
	(envelope-from nobody)
Message-Id: <200801132200.m0DM0uAh015214@www.freebsd.org>
Date: Sun, 13 Jan 2008 22:00:56 GMT
From: Dieter <freebsd@sopwith.solgatos.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fsck_ffs -b 32 doesn't repair primary superblock
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         119638
>Category:       kern
>Synopsis:       [ffs] fsck_ffs -b 32 doesn't repair primary superblock
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 13 22:10:01 UTC 2008
>Closed-Date:    Mon May 18 03:08:58 UTC 2009
>Last-Modified:  Mon May 18 03:08:58 UTC 2009
>Originator:     Dieter
>Release:        6.2
>Organization:
>Environment:
6.2-RELEASE amd64
>Description:
fsck_ffs -b 32 doesn't repair primary superblock

# fsck_ffs -b 32  /dev/da0s1
Alternate super block location: 32
** /dev/da0s1
** Last Mounted on
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
451 files, 994 used, 95917 free (21 frags, 11987 blocks, 0.0% fragmentation)

# mount /dev/da0s1 /mnt
mount: /dev/da0s1: Operation not permitted

console says: WARNING: R/W mount of /mnt denied.  Filesystem is not clean - run fsck


# fsck_ffs   /dev/da0s1
** /dev/da0s1
BAD SUPER BLOCK: VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE
ioctl (GCINFO): Inappropriate ioctl for device
fsck_ffs: /dev/da0s1: can't read disk label
# fsck   /dev/da0s1
** /dev/da0s1
BAD SUPER BLOCK: VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE
ioctl (GCINFO): Inappropriate ioctl for device
fsck_ufs: /dev/da0s1: can't read disk label

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Yoshihiro Ota <ota@j.email.ne.jp>
To: bug-followup@FreeBSD.org
Cc: freebsd@sopwith.solgatos.com
Subject: Re: kern/119638: [ffs] fsck_ffs -b 32 doesn't repair primary
 superblock
Date: Tue, 11 Mar 2008 01:21:53 -0400

 Was your filesystem on /dev/da0s1 "UFS version 1?"
 
 See "man fsck_ffs":
 
      -b      Use the block specified immediately after the flag as the super
              block for the file system.  An alternate super block is usually
              located at block 32 for UFS1, and block 160 for UFS2.
 
 If you had UFS2, which is the default since 5.1-RELEASE for almost 4 years,
 you should have used 160, instead.
 
 Hiro
State-Changed-From-To: open->feedback 
State-Changed-By: vwe 
State-Changed-When: Tue Mar 11 16:28:17 UTC 2008 
State-Changed-Why:  

Note that submitter has been asked for feedback. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119638 

From: Dieter <freebsd@sopwith.solgatos.com>
To: Yoshihiro Ota <ota@j.email.ne.jp>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/119638: [ffs] fsck_ffs -b 32 doesn't repair primary superblock 
Date: Tue, 11 Mar 2008 14:31:49 +0100

 > Was your filesystem on /dev/da0s1 "UFS version 1?"
 > 
 > See "man fsck_ffs":
 > 
 >      -b      Use the block specified immediately after the flag as the super
 >              block for the file system.  An alternate super block is usually
 >              located at block 32 for UFS1, and block 160 for UFS2.
 > 
 > If you had UFS2, which is the default since 5.1-RELEASE for almost 4 years,
 > you should have used 160, instead.
 
 AAAUUGHH!!!
 
 For decades, FFS always used 32 as the first backup superblock, and
 now some rocket scientist has broken it.  Now we have some random
 block.  :-(   160?  I'm getting block 256 as the first alternate.
 
 Despite this, fsck was perfectly happy using whatever bits happened to be at
 block 32 and mangled the filesystem accordingly.  Except it didn't repair
 the primary superblock for some reason.
 
 Fsck accepting block 32 when it isn't really the superblock is a whole
 other (more difficult) problem.  If block 32 is a data block, there is
 nothing stopping it from looking like a superblock.  Have to think about
 that one.
 
 This PR is about fsck not repairing the primary superblock.  Why didn't
 fsck repair the primary superblock once it had mangled everything else
 into compliance?

From: Yoshihiro Ota <ota@j.email.ne.jp>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119638: [ffs] fsck_ffs -b 32 doesn't repair primary
 superblock
Date: Sat, 19 Apr 2008 04:59:53 -0400

 When you provide a super block with -b option, fsck_ffs does far less sanity check compare to normal mode.  Indeed, it checks only the UFS magic numbers.  Then, it assumes that the supplied super block is correct and try to adjust based on the block given.
 
 You provided a wrong block which coincidentally fulfilled this simple sanity check.  fsck_ffs corrected based on the information given.  However, as you provided wrong data, it could only result corrupting the file system information.
 
 This is not a bug but an operational mistake.
 
 Hiro
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Mon May 18 03:07:43 UTC 2009 
State-Changed-Why:  
A later response concluded that fsck was working as designed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119638 
>Unformatted:
