bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #19389] "partnew" Command Writes Unexpected/Errant CHS Values


From: Steve Burtchin
Subject: [bug #19389] "partnew" Command Writes Unexpected/Errant CHS Values
Date: Fri, 23 Mar 2007 05:46:11 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)

URL:
  <http://savannah.gnu.org/bugs/?19389>

                 Summary: "partnew" Command Writes Unexpected/Errant CHS
Values
                 Project: GNU GRUB
            Submitted by: sburtchin
            Submitted on: Friday 03/23/2007 at 05:46
                Category: Disk &amp; Partition
                Severity: Major
                Priority: 5 - Normal
              Item Group: Software Error
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: Steve Burtchin
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 0.97
         Reproducibility: Every Time
         Planned Release: 

    _______________________________________________________

Details:

*Firstly:* All problems described in this bug report have been solved and
thoroughly tested by me on my Compaq Deskpro EN.  For reference see "partnew"
Command Writes Wrong Ending Cylinder in MPT
<http://www.nabble.com/%22partnew%22-Command-Writes-Wrong-Ending-Cylinder-in-MPT-tf2599372.html>.
 I also want to thank *adrian15* for his help to get me started debugging
GRUB.

*Secondly:* Though seemingly related on the surface, I actually found two
entirely unrelated bugs in the "partnew" code.  Both have been solved by
changes to only the code within the "partnew" function.

= The Bugs =

0 The first problem has to do with the calculation of cylinder values for
large disks, *and* for partitions near the end of any size disk.  If a
partition begins or ends on the last or next-to-last cylinder, or past
cylinder 1021 on a large disk, "partnew" incorrectly calculates the cylinder
value to be the largest allowed value for the disk minus two.

For example, on my small disk with CHS 833/240/63:


partnew (hd1,1) 0x05 2071440 10508400


writes C/H/S 137/0/1 thru 830/239/63 (ending cylinder should be 831)

Another example, on my large disk with CHS 10587/240/63:


partnew (hd0,2) 0x0C 116575200 36136800


writes C/H/S 1021/0/1 thru 1021/239/63 (beginning and ending cylinder should
both be 1023)

This is actually a manifestation of another problem external to the "partnew"
function (I was not able to find it).  This is evident when I ask for
"geometry" from the GRUB command line:


>geometry (hd0) 
drive 0x80: C/H/S 1022/240/63, sectors=160086528, LBA 
Partition 0 -- fat - 0xb 
. 
. 

>geometry (hd1) 
drive 0x81: C/H/S 831/240/63, sectors=12594960, LBA 
Partition 0 -- fat - 0xb 
. 
. 


0 The second problem is that "partnew" does not properly handle parameters
equal to zero.  This situation arises when I want to create an 'Undefined'
partition to thoroughly hide it from aggressive operating system installers
(such as the NT os's which recognize filesystems regardless of what
filesystem type is assigned).

For example:


partnew (hd0,3) 0x00 0 0


writes C/H/S 0/0/1 thru 1021/164/4 (I expected C/H/S 0/0/0 thru 0/0/0)

= The Patches =

The complete patches to both problems can be found in the attached
"builtins.c" file.  This has been thoroughly validated by me on my Compaq
Deskpro EN.

0 The fix to the first problem is actually a 'dirty fix' in the sense that it
only covers up a more basic problem (see above).  This patch is a modification
to code suggested by *adrian15*:

Replace:

      /* beg old code
      if (cylinder >= buf_geom.cylinders)
        cylinder = buf_geom.cylinders - 1;
      end old code */
      
      /* begin third part of sburtchin partnew patch (replace lines) */
      bufgeomcylinders = buf_geom.cylinders;
      bufgeomcylinders += 2;
      if (cylinder >= bufgeomcylinders)
        cylinder = bufgeomcylinders - 1;
      /* end third part of sburtchin partnew patch */


0 The patch to correct the second problem is also only a minor change to the
code within the "partnew" function:


      /* begin second part of sburtchin partnew patch (add lines) */
      if (lba <= 0) 
      { 
        *cl = 0; 
        *ch = 0; 
        *dh = 0; 
      } 
      else 
      { 
      /* end second part of sburtchin partnew patch */

      sector = lba % buf_geom.sectors + 1;
      head = (lba / buf_geom.sectors) % buf_geom.heads;
      cylinder = lba / (buf_geom.sectors * buf_geom.heads);

      bufgeomcylinders = buf_geom.cylinders;
      bufgeomcylinders += 2;
      if (cylinder >= bufgeomcylinders)
        cylinder = bufgeomcylinders - 1;

      *cl = sector | ((cylinder & 0x300) >> 2);
      *ch = cylinder & 0xFF;
      *dh = head;

      /* begin fourth part of sburtchin partnew patch (add lines) */
      } 
      /* end fourth part of sburtchin partnew patch */


= What Next? =

I will do whatever I can to help get these changes into the GRUB Legacy code.
 Can someone help me get started writing *ChangeLog*?  Is there a template or
standard format I have to follow?

What about CVS - is that standard with all Linux distros, or do I need to
install it?  I have Debian Sarge, but there were problems reading the
installation CD's, so I may install SuSE for further GRUB development.

What other files do I need to attach to this bug report?



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Friday 03/23/2007 at 05:46  Name: builtins.c  Size: 122kB   By:
sburtchin
Modified &quot;builtins.c&quot; containing patches to &quot;partnew&quot;
function (also contains &quot;eptedit&quot; function patch)
<http://savannah.gnu.org/bugs/download.php?file_id=12238>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?19389>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]