Skip to contentSkip to conversation

Support GPT (GUID Partition Table)

RFC PATCH In review Takahashi Tomohiro 3 participants 4 messages Apr 11, 2007 – Apr 13, 2007

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Support GPT (GUID Partition Table)

Hi,

I made a patch for GPT support.

As you see, this patch uses ad-hoc approach.
If you give me an advice, it would be appreciated

Thanks,
Tomohiro Takahashi.

tools/pygrub/src/pygrub Tue Apr 10 20:30:05 2007 +0900 renamed from tools/pygrub/src/pygrub Mon Apr 09 13:40:25 2007 -0600 +7 -0
diff -r 1bde28f762a6 -r 8e08fd1ffa24 tools/pygrub/src/pygrub
@@ -58,6 +60,13 @@ def get_active_partition(file):
        # active partition has 0x80 as the first byte
        if struct.unpack("<c", buf[poff:poff+1]) == ('\x80',):
            return buf[poff:poff+16]
+
+        # type=0xee: GUID partition table
+        # XXX assume the first partition is active
+        if struct.unpack("<c", buf[poff+4:poff+5]) == ('\xee',):
+            os.lseek(fd, 0x400, 0)
+            buf = os.read(fd, 512)
+            return buf[24:40] # XXX buf[32:40]
 
    # if there's not a partition marked as active, fall back to
    # the first partition
#1 lore raw
Quoted 1 line · Takahashi Tomohiro

I made a patch for GPT support.

I don't see anything wrong with it, although won't it always be the first legacy partition that is marked with type 0xee?

-- Keir

#2 lore raw

Hi Keir,

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Wed, 11 Apr 2007 15:27:53 +0100
[email protected](Keir Fraser) said:

Quoted 1 line · Takahashi Tomohiro

I made a patch for GPT support.

I don't see anything wrong with it, although won't it always be the first legacy partition that is marked with type 0xee?

No, but this patch supports the second (or third, ...) legacy partition marked with 0xee.
# I have no idea whether it is necessary well...

This patch has different problems. get_active_partition() returns a entry of a legacy partition. Since the structure of GPT partition entries differs from the structure of legacy partition entries, this patch has the following problem:

- pygrub cannot access a domain more than 2^32 * SECTOR_SIZE because get_fs_offset() treats the offset as a 32-bit integer. In GPT, the offset must be treated as 64-bit integer.

- This patch returns a part of a GUID unique to the partition as legacy partition types. pygrub may misunderstand partition types.

I plan to fix this problem.

Best Regards,

Signature · 1 line
  KUWAMURA Shin'ya
#3 lore raw

Hi Keir,

Quoted 7 lines · On <[email protected]> "KUWAMURA Shin'ya" wrote:

- pygrub cannot access a domain more than 2^32 * SECTOR_SIZE because get_fs_offset() treats the offset as a 32-bit integer. In GPT, the offset must be treated as 64-bit integer.

- This patch returns a part of a GUID unique to the partition as legacy partition types. pygrub may misunderstand partition types.

I fixed these problems.

Best Regards,

Signature · 1 line
  KUWAMURA Shin'ya

# HG changeset patch
# User KUWAMURA Shin'ya <[email protected]> # Date 1176447935 -32400
# Node ID 998f640f53bda5a18d7452192b8b3f140609862a # Parent a839e331f06f7b19ca601b277de9fcbedbeb4a77 fix GPT support.
- 64 bit support for starting of a GPT partition.
- detect partition types precisely.

tools/pygrub/src/pygrub +11 -7
diff -r a839e331f06f -r 998f640f53bd tools/pygrub/src/pygrub
@@ -61,13 +61,6 @@ def get_active_partition(file):
         if struct.unpack("<c", buf[poff:poff+1]) == ('\x80',):
             return buf[poff:poff+16]
 
-        # type=0xee: GUID partition table
-        # XXX assume the first partition is active
-        if struct.unpack("<c", buf[poff+4:poff+5]) == ('\xee',):
-            os.lseek(fd, 0x400, 0)
-            buf = os.read(fd, 512)
-            return buf[24:40] # XXX buf[32:40]
-
     # if there's not a partition marked as active, fall back to
     # the first partition
     return buf[446:446+16]
@@ -97,8 +90,16 @@ def get_solaris_slice(file, offset):
 
     raise RuntimeError, "No root slice found"      
 
+def get_fs_offset_gpt(file):
+    fd = os.open(file, os.O_RDONLY)
+    # assume the first partition is an EFI system partition.
+    os.lseek(fd, SECTOR_SIZE * 2, 0)
+    buf = os.read(fd, 512)
+    return struct.unpack("<Q", buf[32:40])[0] * SECTOR_SIZE
+
 FDISK_PART_SOLARIS=0xbf
 FDISK_PART_SOLARIS_OLD=0x82
+FDISK_PART_GPT=0xee
 
 def get_fs_offset(file):
     if not is_disk_image(file):
@@ -115,6 +116,9 @@ def get_fs_offset(file):
     if type == FDISK_PART_SOLARIS or type == FDISK_PART_SOLARIS_OLD:
         offset += get_solaris_slice(file, offset)
 
+    if type == FDISK_PART_GPT:
+        offset = get_fs_offset_gpt(file)
+    
     return offset
 
 class GrubLineEditor(curses.textpad.Textbox):

_______________________________________________
Xen-ia64-devel mailing list
[email protected]
http://lists.xensource.com/xen-ia64-devel