From nobody@FreeBSD.org  Fri Jul 15 23:02:44 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E7C0916A41C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jul 2005 23:02:44 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id AA73843D45
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jul 2005 23:02:44 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j6FN2ibn059635
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jul 2005 23:02:44 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j6FN2iGr059633;
	Fri, 15 Jul 2005 23:02:44 GMT
	(envelope-from nobody)
Message-Id: <200507152302.j6FN2iGr059633@www.freebsd.org>
Date: Fri, 15 Jul 2005 23:02:44 GMT
From: Francis Gendreau <tech@makwa.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: partition table corruption using wdc/wd driver
X-Send-Pr-Version: www-2.3

>Number:         83529
>Category:       kern
>Synopsis:       partition table corruption using wdc/wd driver
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 15 23:10:00 GMT 2005
>Closed-Date:    Wed Nov 23 14:31:28 GMT 2005
>Last-Modified:  Wed Nov 23 14:31:28 GMT 2005
>Originator:     Francis Gendreau
>Release:        FreeBSD 4.11 STABLE
>Organization:
Makwa
>Environment:
FreeBSD  4.11-STABLE FreeBSD 4.11-STABLE #0: Fri Jul 15 17:56:42 EDT 2005     root@:/usr/obj/usr/src/sys/registette  i386
>Description:
I am building a system with two slice on a single drive, since a single slice does not provides me enough partitions for my filesystem design. In order to optimise the operating system, I've compiled the wdc and wd driver, from which I access my partition.

Using the 'ad' driver, I was able to access every partition created of every slices of every drives. The problem here reside in the two commented partitions of the wd0s2 slice.

N.B. I uses the STABLE release onyl because the Robert Watson's ACL patch is included with it. I do ignore if the 4.11-RELEASE also have the problem.

=====================================================================

# cat /etc/fstab
# See the fstab(5) manual page for important information on automatic 
# mounts of network filesystems before modifying this file.
#
# Device      Mountpoint      FStype  Options         Dump    Pass#
/dev/wd1s1b   none            swap    sw              0       0
/dev/wd0s1b   none            swap    sw              0       0
/dev/wd0s1a   /               ufs     rw              1       1
/dev/wd0s2f   /data           ufs     rw              2       2
/dev/wd0s2h   /data/db        ufs     rw              2       2
/dev/wd0s2g   /data/dev       ufs     rw              2       2
#/dev/wd0s2a  /data/profiles  ufs     rw              2       2
/dev/wd1s1f   /data/shares    ufs     rw              2       2
/dev/wd0s1g   /root           ufs     rw              2       2
/dev/wd0s1f   /tmp            ufs     rw              2       2
/dev/wd0s1e   /usr            ufs     rw              2       2
#/dev/wd0s2b  /usr/home       ufs     rw              2       2
/dev/wd0s2e   /usr/local      ufs     rw              2       2
/dev/wd0s1h   /var            ufs     rw              2       2
/dev/wd1s1e   /var/log        ufs     rw              2       2
/dev/wd0s1d   /var/tmp        ufs     rw              2       2
/dev/acd0c    /cdrom          cd9660  ro,noauto       0       0
proc          /proc           procfs  rw              0       0

=====================================================================

# fdisk /dev/wd0
******* Working on device /dev/wd0 *******
parameters extracted from in-core disklabel are:
cylinders=4112 heads=255 sectors/track=63 (16065 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4112 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165,(FreeBSD/NetBSD/386BSD)
    start 63, size 12610962 (6157 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 784/ head 254/ sector 63
The data for partition 2 is:
sysid 165,(FreeBSD/NetBSD/386BSD)
    start 12611025, size 67681845 (33047 Meg), flag 0
        beg: cyl 785/ head 0/ sector 1;
        end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>

=====================================================================

# disklabel -r /dev/wd0s1
# /dev/wd0s1:
type: ESDI
disk: ad0s1
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 784
sectors/unit: 12610962
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # milliseconds
track-to-track seek: 0  # milliseconds
drivedata: 0

8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:  2097152        0    4.2BSD     2048 16384    89   # (Cyl.    0 - 130*)
  b:  1048576  2097152      swap                        # (Cyl.  130*- 195*)
  c: 12610962        0    unused        0     0         # (Cyl.    0 - 784*)
  d:  1076626 11534336    4.2BSD     2048 16384    89   # (Cyl.  717*- 784*)
  e:  4194304  3145728    4.2BSD     2048 16384    89   # (Cyl.  195*- 456*)
  f:  1048576  7340032    4.2BSD     2048 16384    89   # (Cyl.  456*- 522*)
  g:  1048576  8388608    4.2BSD     2048 16384    89   # (Cyl.  522*- 587*)
  h:  2097152  9437184    4.2BSD     2048 16384    89   # (Cyl.  587*- 717*)
#

=====================================================================

# /dev/wd0s2:
type: ESDI
disk: ad0s2
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 4213
sectors/unit: 67681845
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # milliseconds
track-to-track seek: 0  # milliseconds
drivedata: 0

8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a: 41943040 31485393    4.2BSD     2048 16384    89   # (Cyl. 1959*- 4570*)
  b:  6864437 73428433    4.2BSD     2048 16384    89   # (Cyl. 4570*- 4997*)
  c: 67681845 12611025    unused        0     0         # (Cyl.  785 - 4997)
  e:  4194304 12611025    4.2BSD     2048 16384    89   # (Cyl.  785 - 1046*)
  f:  2097152 16805329    4.2BSD     2048 16384    89   # (Cyl. 1046*- 1176*)
  g:  4194304 18902481    4.2BSD     2048 16384    89   # (Cyl. 1176*- 1437*)
  h:  8388608 23096785    4.2BSD     2048 16384    89   # (Cyl. 1437*- 1959*)
partition a: partition extends past end of unit
partition b: offset past end of unit
partition b: partition extends past end of unit
partition c: partition extends past end of unit
Warning, partition c doesn't start at 0!
Warning, An incorrect partition c may cause problems for standard system utilities
#

=====================================================================



>How-To-Repeat:
To repeat the problem, simply create a second slice using disklabel while installing the operating system. The problem, after 3 re-installations, always reside in the 2 last created partition of the second slice of the drive. The system repports their parameters are invalid.
>Fix:
      
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: Francis Gendreau <tech@makwa.net>
Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject: Re: kern/83529: partition table corruption using wdc/wd driver
Date: Tue, 9 Aug 2005 08:24:27 +1000 (EST)

 On Fri, 15 Jul 2005, Francis Gendreau wrote:
 
 > I am building a system with two slice on a single drive, since a single slice does not provides me enough partitions for my filesystem design. In order to optimise the operating system, I've compiled the wdc and wd driver, from which I access my partition.
 
 Please use lines shorter than 256 characters.
 
 > Using the 'ad' driver, I was able to access every partition created of every slices of every drives. The problem here reside in the two commented partitions of the wd0s2 slice.
 >
 > N.B. I uses the STABLE release onyl because the Robert Watson's ACL patch is included with it. I do ignore if the 4.11-RELEASE also have the problem.
 
 You shouldn't use the wdc/wd driver, since it is not maintained and the 
 ata/ad driver works well enough for most hardware.
 
 However, the wdc/wd driver still seems to work well enough for disks
 smaller than 137GB (1GB = 10^9 bytes).  On my test system, there were
 similar but not identical problems accessing partitions until I
 configured the wd driver to use the "LBA addressing" flag 0x1000 (see
 wd(4)).  Try using this flag.  It shouldn't be needed, but is needed
 for all disks larger than 33GB due to driver bugs.  Some disks have a
 hard limit of 8GB, and the driver gets the test for this mostly wrong
 and ends up intentionally breaking CHS above 33GB where it might work,
 without intentionally breaking CHS between 8-33GB where it might not
 work (the intentional breakage is just to truncate disks to a limit
 above which the driver fears that they might not work).
 
 On my test system (a not very old one with an nForce2 motherboard and
 a 120GB drive), the problems were that a slice which crossed the 33GB
 boundary became partly inaccessible and a slice beyond the 33GB boundary
 became completely inaccessible.  The problem is show by boot messages:
 
 %%%
 Aug  9 04:55:12 epsplex kernel: wdc0 at port 0x1f0-0x1f7 irq 14 flags 0xa0ffa0ff on isa0
 Aug  9 04:55:12 epsplex kernel: wd0: cannot handle 234441648 total sectors; truncating to 66060288
 ...
 Aug  9 04:55:12 epsplex kernel: wd0s2: slice extends beyond end of disk: truncating from 57512700 to 49979223 sectors
 Aug  9 04:55:12 epsplex kernel: wd0s3: slice starts beyond end of the disk: rejecting it
 %%%
 
 Your second slice lies across the 33GB boundary like my first slice.  Your
 disklabel -r output shows that the kernel didn't fix up the partition
 offsets within the slice.  I can't explain how truncating the partition
 could cause this.
 
 After setting the LBA flag, the old wd driver worked perfectly on my
 relatively new test system.  It even gave the maximum drive transfer
 rate of 47MB/sec despite it having no support for either nForce2 or
 UDMA faster than 33MHz.  It apparently uses generic DMA and the BIOS
 sets this up right for UDMA100.
 
 Bruce

From: Bruce Evans <bde@zeta.org.au>
To: Francis Gendreau <tech@makwa.net>
Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject: Re: kern/83529: partition table corruption using wdc/wd driver
Date: Tue, 9 Aug 2005 09:00:05 +1000 (EST)

 On Tue, 9 Aug 2005, Bruce Evans wrote:
 
 > However, the wdc/wd driver still seems to work well enough for disks
 > smaller than 137GB (1GB = 10^9 bytes).  On my test system, there were
 > similar but not identical problems accessing partitions until I
 > configured the wd driver to use the "LBA addressing" flag 0x1000 (see
 > wd(4)).  Try using this flag.  It shouldn't be needed, but is needed
 > for all disks larger than 33GB due to driver bugs.  Some disks have a
 > hard limit of 8GB, and the driver gets the test for this mostly wrong
 > and ends up intentionally breaking CHS above 33GB where it might work,
 > without intentionally breaking CHS between 8-33GB where it might not
 > work (the intentional breakage is just to truncate disks to a limit
 > above which the driver fears that they might not work).
 
 Oops.  The test is correct.  The 33GB limit is unrelated to hardware
 limits.  It results from (virtual) disk geometries with more than 63
 sectors being impractical because old BIOS interfaces are limited to
 this number and the wd driver doesn't change the CHS translation very
 much.  In CHS mode, the driver uses the number of sectors in the current
 translation mode; this is set by the BIOS, so for not very old disks
 and not very new or very old BIOSes, it is almost always 63 instead of
 the maximum of 255, so the 137GB limit is reduced by a factor of 255/63
 to become 33GB.  The BIOS on my test machine is new enough to support
 255 sectors, but I never use this because of compatibility problems
 (partition tables are still limited to 63 sectors of CHS addressing
 is used to boot).
 
 Bruce
State-Changed-From-To: open->closed 
State-Changed-By: jhb 
State-Changed-When: Wed Nov 23 14:30:50 GMT 2005 
State-Changed-Why:  
Use the ata(4) driver instead of wd(4). 

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