From nobody@FreeBSD.org  Fri Jul  9 15:40:49 2010
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 3BF9D106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Jul 2010 15:40:49 +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 123D38FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Jul 2010 15:40:49 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o69FelKq080965
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 Jul 2010 15:40:47 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o69FelM9080964;
	Fri, 9 Jul 2010 15:40:47 GMT
	(envelope-from nobody)
Message-Id: <201007091540.o69FelM9080964@www.freebsd.org>
Date: Fri, 9 Jul 2010 15:40:47 GMT
From: Daniel Feenberg <feenberg@nber.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fdisk prompts with negative partition size
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         148471
>Category:       bin
>Synopsis:       fdisk(8) prompts with negative partition size [regression]
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 09 15:50:02 UTC 2010
>Closed-Date:    
>Last-Modified:  Mon Jul 12 19:50:02 UTC 2010
>Originator:     Daniel Feenberg
>Release:        8.0-Release p2
>Organization:
National Bureau of Economic Research
>Environment:
FreeBSD bulk4 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Jan  5 16:02:27 UTC 2010     root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
With one of the new 2TB Samsung SATA drives with a 3ware controller (in
single drive mode), fdisk reacts in a bizarre manner.

Although it seems to extract the proper drive characteristics:

> parameters extracted from in-core disklabel are:
> cylinders=243151 heads=255 sectors/track=63 (16065 blks/cyl)

When I modify parition 1 and accept all defaults, it suggests a negative
value for size:

> Do you want to change it? [n] y
> 
> The static data for the slice 1 has been reinitialized to:
> sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
>     start 63, size 3906220752 (1907334 Meg), flag 80 (active)
>         beg: cyl 0/ head 1/ sector 1;
>         end: cyl 462/ head 254/ sector 63
> Supply a decimal value for "sysid (165=FreeBSD)" [165]
> Supply a decimal value for "start" [63]
> Supply a decimal value for "size" [-388746544]
> Explicitly specify beg/end address ? [n]
> sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
>     start 63, size 3906220752 (1907334 Meg), flag 80 (active)
>         beg: cyl 0/ head 1/ sector 1;
>         end: cyl 462/ head 254/ sector 63
> Are we happy with this entry? [n] y

Notice that the suggested value for size is -388746544 and the suggested end
cylinder is 462 - both of which are implausible and inconsistent.

Here is the info from dmesg about the drive:

 a2 at twa0 bus 0 target 2 lun 0
 da2: <AMCC 9500S-8    DISK 2.06> Fixed Direct Access SCSI-3 device
>How-To-Repeat:
Obtain 2TB Samsung drive (and possibly 3Ware controller) and run 

  fdisk -i /dev/...

accepting all defaults as one defines a new partion.

Note that this problem did not arise with 300GB drives on the same controller
and an earlier version of FreeBSD.
>Fix:
Beyond my knowledge, but I can guess the problem comes from 32 bit integers,
and perhaps upgrading to 64 bit FreeBSD would solve the problem for me.
However, the bizarre behavior is a bug - if fdisk can't deal with the disk
or controller it could say so explicitly.

>Release-Note:
>Audit-Trail:

From: Tom Couch <tom.couch.storage@gmail.com>
To: bug-followup@FreeBSD.org, feenberg@nber.org
Cc:  
Subject: Re: bin/148471: fdisk(8) prompts with negative partition size 
	[regression]
Date: Mon, 12 Jul 2010 11:53:20 -0700

 --000e0ce0cda62f4846048b3544d4
 Content-Type: text/plain; charset=ISO-8859-1
 
 What is the drive model and serial number?
 
 The 3ware 9500S controller will not support > 2TB drives.
 
 Tom Couch
 
 --000e0ce0cda62f4846048b3544d4
 Content-Type: text/html; charset=ISO-8859-1
 
 <div>What is the drive model and serial number?</div><div><br></div><div>The 3ware 9500S controller will not support &gt; 2TB drives.</div><div><br></div><div>Tom Couch</div>
 
 --000e0ce0cda62f4846048b3544d4--

From: Daniel Feenberg <feenberg@nber.org>
To: Tom Couch <tom.couch.storage@gmail.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/148471: fdisk(8) prompts with negative partition size 
 [regression]
Date: Mon, 12 Jul 2010 15:37:50 -0400 (EDT)

 On Mon, 12 Jul 2010, Tom Couch wrote:
 
 > What is the drive model and serial number?
 
 They are  Samsung HD203WI. Here is the output of diskinfo:
 
    diskinfo -ctv /dev/da0
    /dev/da0
          512             # sectorsize
          1999988850688   # mediasize in bytes (1.8T)
          3906228224      # mediasize in sectors
          243151          # Cylinders according to firmware.
          255             # Heads according to firmware.
          63              # Sectors according to firmware.
          WZ402752F36918001E9B    # Disk ident.
 
 >
 > The 3ware 9500S controller will not support > 2TB drives.
 >
 
 OK, but this drive is south of 2TB.
 
 I subsequently newfs'ed the bare drive, and am testing the result now. It 
 appears to me that the filesystem is corrupted in some way, but I don't 
 have sufficient information yet to file another bug report. So far the 
 problems appear only after writing over 1 TB to the drive, which takes 
 many hours. (The problem seems to be that the filesize measured by wc does 
 not correspond to the filesize reported by ls or the space used by 
 reported by df).
 
 In any case, even if the 9500S-8 is providing bad data, it would seem 
 prudent for fdisk to do some range checking before suggesting a default 
 action that is physically impossible.
 
 Thank you
 Daniel Feenberg
 feenberg@nber.org
 
 > Tom Couch
 >
>Unformatted:
