[parted-devel] [PATCH] More correct handling of the HeaderSize field in GPT labels
Jim Meyering
jim at meyering.net
Mon Jul 9 21:21:59 UTC 2007
"Matthew S. Harris" <mharris312 at gmail.com> wrote:
> On 7/9/07, Jim Meyering <jim at meyering.net> wrote:
>> Jim Meyering <jim at meyering.net> wrote:
>> ...
>> > For example, can you give me a sequence of commands to create a
>> > small image for which parted-before-your-patch fails, yet with your
>> > patch it works?
>> >
>> > E.g.,
>> >
>> > dev=loop-file
>> > dd if=/dev/zero of=$dev bs=1 count=50K 2> /dev/null
>> > ./parted -s $dev mklabel gpt
>> > # change HeaderSize and checksum
>> > # do something with the label, e.g., ./parted -s $dev p
>>
>> Alternatively, just create a ZFS partition on OpenSolaris,
>> tell me the commands you used (for reference), send me the first
>> few KB of the image, and I'll do the rest.
>
> The form of the "# change HeaderSize and checksum" commands would be
>
> # In both the primary and backup GPT tables, change HeaderSize to 512
> # and set the checksum appropriately.
> echo -ne '\0\02\0\0\0200\072\0253\0203' | dd of=$dev bs=1 conv=notrunc seek=524
> echo -ne '\0\02\0\0\0164\0155\062\0176' | dd of=$dev bs=1 conv=notrunc
> seek=50700
>
> (where the first four bytes written are the header size and the second
> four bytes are the CRC) but yesterday I had trouble getting checksum
> values to work: I added print statements to print the computed
> checksum, but the value seemed to change after I modified the checksum
> in the image, which shouldn't happen.
Hmm... it worked for me: it's easy (with a debugger) to come
up with the proper checksum _for a given partition table_.
The trouble is that the data being checksummed
is slightly different for each new partition table.
The part that changes is the 16-byte DiskGUID field.
It's supposed to be globally unique after all.
So in order to create the test I want, we'll have to
come up with a way to choose a constant UUID, or perhaps
to mimic the checksum algorithm in the test harness.
I think I can rig up something (enabled only via
something like ./configure --enable-testing, which
would also make it impossible to install) to use
an all-0's UUID.
But that's ugly, too.
I'm tempted to add a bit-field to PedDevice.
There's certainly room, between all of these one-bit
fields that take up 32:
int read_only;
int external_mode;
int dirty;
int boot_dirty;
but this is an external ABI...
Well, perhaps it's not worth it after all.
If someone comes up with a nice way to test this,
please let me know. Otherwise, I'll go ahead and
apply the patch without a test.
More information about the parted-devel
mailing list