[Top][All Lists]

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

Re: "partnew" Command Writes Wrong Ending Cylinder in MPT

From: sburtchin
Subject: Re: "partnew" Command Writes Wrong Ending Cylinder in MPT
Date: Wed, 22 Nov 2006 23:56:59 -0800 (PST)

BUG Found! - well, more or less depend on your POV.

adrian15 wrote:
> Maybe you may find the error better than me as long as you have more 
> knowledge than me on how this C/H/S stuff should work. 
The problem occurs at this code line:

      if (cylinder >= buf_geom.cylinders) 
        cylinder = buf_geom.cylinders - 1;
All the code you provided me is correct, at least for calculating CHS values
and the bytes that have to be written back to the disk.  I manually ran
several sets of numbers through the code and the correct three bytes for
writing to the disk were calculated each time.  The algorithm here is
different than mine, but calculates the correct values.  This I am
absolutely sure.

The problem is that at this point in the code, "buff_geom.cylinders" is
equal to 2 less than what it should be.  For example, for my large disk,
"buff_geom.cylinders" should be "1024", but in fact it is "1022".  Likewise,
on my small disk with "833" cylinders, "buff_geom.cylinders" should be
"833", but is actually "831" resulting in the erroneous "830" ending
cylinder value in some of the examples I provided.

sburtchin wrote:
> I got some really strange results with partnew when I plugged in values
> that did not begin/end on cylinder boundaries 
I must have mistyped or miscalculated because I have been unable to
reproduce any strange results, or find anything in the code that would allow
such to happen.  Please ignore this statement.

sburtchin wrote:
> there are situations where it is highly desirable to make a partition
> appear not to exist (eg. when installing Microsoft operating systems, and
> in practice too).  (unused partition table entries are supposed to be all
> zeroes)  This is most effectively achieved by zeroing out the entry for it
> in the MPT (as opposed to just changing the filesystem type ["hiding"] to
> make it look like an unrecognized filesystem).  There are tools for doing
> this, but for efficiency it would be very desireable to be able to do this
> from GRUB.  There are two obvious ways to achieve this: 1) partnew could
> test the fourth argument to see if it is equal to zero (ie. a zero length
> partition), and if true then write all zeroes to that entry in the MPT
I would like to propose the following code change to allow blanking of a
partition table entry
with a command like "partnew (hd0,3) 0x00 0 0".  New/Changed code is in

   /* Convert a LBA address to a CHS address in the INT 13 format.  */ 
   auto void lba_to_chs (int lba, int *cl, int *ch, int *dh); 
   void lba_to_chs (int lba, int *cl, int *ch, int *dh) 
       int cylinder, head, sector; 

       if (lba <= 0)
         *cl = 0;
         *ch = 0;
         *dh = 0;
         sector = lba % buf_geom.sectors + 1; 
         head = (lba / buf_geom.sectors) % buf_geom.heads; 
         cylinder = lba / (buf_geom.sectors * buf_geom.heads); 

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

         *cl = sector | ((cylinder & 0x300) >> 2); 
         *ch = cylinder & 0xFF; 
         *dh = head;
View this message in context: 
Sent from the Grub - Bugs mailing list archive at Nabble.com.

reply via email to

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