bugGNU GRUB - Bugs: bug #19389, "partnew" Command Writes...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

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

Submitted by:  Steve Burtchin <sburtchin>
Submitted on:  Fri 23 Mar 2007 05:46:09 AM UTC  
 
Category:  Disk & Partition Severity:  Major
Priority:  5 - Normal Item Group:  Software Error
Status:  None Privacy:  Public
Assigned to:  None Originator Name:  Steve Burtchin
Open/Closed:  Closed Release:  0.97
Release:  None Reproducibility:  Every Time
Planned Release:  None

Sat 15 Dec 2007 09:46:52 PM UTC, comment #2: 

We've moved to GRUB 2 as a development platform. Please can you check if this bug still applies there, and if it does, reopen it?

Thanks

Robert Millan <robertmh>
Project Administrator
Mon 16 Apr 2007 02:04:37 AM UTC, comment #1: 

Added ChangeLog and attached patches in Unified Diff format for ChangeLog, /stage2/builtins.c and /docs/grub.texi

ChangeLog is repeated here for reference:

2007-04-11  Steve Burtchin  <sburtchin@woh.rr.com>

        * stage2/builtins.c (partnew_func): Added new variable
        "bufgeomcylinders" set equal to "buf_geom.cylinders" plus 2;
        allows for correct calculation of cylinder value when near CHS
        limit or near end of disk (for small disks).
        * stage2/builtins.c (partnew_func): Added test "if (lba <= 0)...
        ...else" and new code to handle input values (relative and total
        sectors) equal to zero; allows resetting a MPT slot to all zeroes.
        * docs/grub.texi (partnew): Added instructions to zero slot in MPT.

Is there anything else I need to do?

NOTE: See bug #19410: Unable to Create Logical Partition with "partnew" Command for diff files containing both patches combined.

(file #12488, file #12489, file #12490)

Steve Burtchin <sburtchin>
Fri 23 Mar 2007 05:46:09 AM UTC, original submission:  

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.  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

  1. 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
.
.

  1. 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.

  1. 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 */

  1. 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?

Steve Burtchin <sburtchin>

 

Attached Files
file #12488:  grub.texi.pn.diff added by sburtchin (748B - text/x-diff - Revised patches are in Unified Diff format)
file #12489:  ChangeLog.pn.diff added by sburtchin (1KiB - text/x-diff - Revised patches are in Unified Diff format)
file #12490:  builtins.c.pn.diff added by sburtchin (2KiB - text/x-diff - Revised patches are in Unified Diff format)
file #12238:  builtins.c added by sburtchin (122KiB - text/plain - Modified "builtins.c" containing patches to "partnew" function (also contains "eptedit" function patch))

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by robertmh (Posted a comment)
  • -email is unavailable- added by sburtchin (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-12-15 robertmh Open/ClosedOpen => Closed
    2007-04-16 sburtchin Attached File- => Added grub.texi.pn.diff, #12488
        Attached File- => Added ChangeLog.pn.diff, #12489
        Attached File- => Added builtins.c.pn.diff, #12490
    2007-03-23 sburtchin Attached File- => Added builtins.c, #12238
        Carbon-Copy- => Added adrian15

    Back to the top


    Powered by Savane 3.6