Skip to contentSkip to conversation

: grub: Partitions can start at zero.

PATCH In review David Miller 2 participants 5 messages Apr 20, 2009 – Apr 30, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : grub: Partitions can start at zero.

With Sun partitions, individual partitions can start at disk address zero. That's right, zero.

This works because UFS and EXT{2,3,4} superblocks are offset far enough into the partition that it won't overwrite the disk label nor the boot block.

I added an, arguably hackish, heuristic to handle this properly. Basically if the OS device name does not end in a digit we'll believe that a zero hdg.start value can be a partition.

If anyone has a better way to handle this, let me know :-)

2009-04-19 David S. Miller <[email protected]>

* util/hostdisk.c (device_is_wholedisk): New function. (grub_util_biosdisk_get_grub_dev): Shortcut when hdg.start is zero only if device_is_wholedisk() returns true.

---
 util/hostdisk.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
util/hostdisk.c +11 -1
index aa41703..b55d7fe 100644
@@ -827,6 +827,16 @@ convert_system_partition_to_system_disk (const char *os_dev)
 }
 
 static int
+device_is_wholedisk (const char *os_dev)
+{
+  int len = strlen (os_dev);
+
+  if (os_dev[len - 1] < '0' || os_dev[len - 1] > '9')
+    return 1;
+  return 0;
+}
+
+static int
 find_system_device (const char *os_dev)
 {
   int i;
@@ -961,7 +971,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
 
     grub_util_info ("%s starts from %lu", os_dev, hdg.start);
     
-    if (hdg.start == 0)
+    if (hdg.start == 0 && device_is_wholedisk (os_dev))
       return name;
 
     grub_util_info ("opening the device %s", name);
Signature · 1 line
1.6.2.3
#1 lore raw
Quoted 8 lines · David Miller

With Sun partitions, individual partitions can start at disk address zero. That's right, zero.

This works because UFS and EXT{2,3,4} superblocks are offset far enough into the partition that it won't overwrite the disk label nor the boot block.

Quoted 6 lines

I added an, arguably hackish, heuristic to handle this properly. Basically if the OS device name does not end in a digit we'll believe that a zero hdg.start value can be a partition.

If anyone has a better way to handle this, let me know :-)

What about the way I proposed in thread on implementing nested partitions?

Quoted 51 lines

2009-04-19 David S. Miller <[email protected]>

* util/hostdisk.c (device_is_wholedisk): New function. (grub_util_biosdisk_get_grub_dev): Shortcut when hdg.start is zero only if device_is_wholedisk() returns true.

---
 util/hostdisk.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
util/hostdisk.c +10 -0
index aa41703..b55d7fe 100644
@@ -827,6 +827,16 @@ convert_system_partition_to_system_disk (const char
 *os_dev)
 }
 
 static int
+device_is_wholedisk (const char *os_dev)
+{
+  int len = strlen (os_dev);
+
+  if (os_dev[len - 1] < '0' || os_dev[len - 1] > '9')
+    return 1;
+  return 0;
+}
+
+static int
 find_system_device (const char *os_dev)
 {

int i;

util/hostdisk.c +1 -2
@@ -961,7 +971,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
 
    grub_util_info ("%s starts from %lu", os_dev, hdg.start);
 
-    if (hdg.start == 0)
+    if (hdg.start == 0 && device_is_wholedisk (os_dev))
      return name;
 
    grub_util_info ("opening the device %s", name);
--

1.6.2.3

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw

From: Vladimir Serbinenko <[email protected]>
Date: Mon, 20 Apr 2009 18:53:35 +0200

Quoted 10 lines · David Miller
Quoted 9 lines

With Sun partitions, individual partitions can start at disk address zero. That's right, zero.

This works because UFS and EXT{2,3,4} superblocks are offset far enough into the partition that it won't overwrite the disk label nor the boot block.

Quoted 7 lines
Quoted 6 lines

I added an, arguably hackish, heuristic to handle this properly. Basically if the OS device name does not end in a digit we'll believe that a zero hdg.start value can be a partition.

If anyone has a better way to handle this, let me know :-)

What about the way I proposed in thread on implementing nested partitions?

Thanks for your feedback, I'll take a look at this.

#3 lore raw
In reply to Vladimir Serbinenko

From: Vladimir Serbinenko <[email protected]>
Date: Mon, 20 Apr 2009 18:53:35 +0200

Quoted 10 lines · David Miller
Quoted 9 lines

With Sun partitions, individual partitions can start at disk address zero. That's right, zero.

This works because UFS and EXT{2,3,4} superblocks are offset far enough into the partition that it won't overwrite the disk label nor the boot block.

Quoted 7 lines
Quoted 6 lines

I added an, arguably hackish, heuristic to handle this properly. Basically if the OS device name does not end in a digit we'll believe that a zero hdg.start value can be a partition.

If anyone has a better way to handle this, let me know :-)

What about the way I proposed in thread on implementing nested partitions?

Yes it seems that it should be able to handle this situation.

I cannot say %100 for sure until I see the code you end up writing, of course :)

#4 lore raw
In reply to Vladimir Serbinenko

From: Vladimir Serbinenko <[email protected]>
Date: Mon, 20 Apr 2009 18:53:35 +0200

Quoted 10 lines · David Miller
Quoted 9 lines

With Sun partitions, individual partitions can start at disk address zero. That's right, zero.

This works because UFS and EXT{2,3,4} superblocks are offset far enough into the partition that it won't overwrite the disk label nor the boot block.

Quoted 7 lines
Quoted 6 lines

I added an, arguably hackish, heuristic to handle this properly. Basically if the OS device name does not end in a digit we'll believe that a zero hdg.start value can be a partition.

If anyone has a better way to handle this, let me know :-)

What about the way I proposed in thread on implementing nested partitions?

After some discussions with Vladimir on IRC, he agreed that my change goes in for now until his nested partition work is ready.

So I have committed this change.

GRUB works on sparc64 right now on the one test system I got working tonight, a sparc64 virtualized Sun LDOM guest system. In fact most systems should work as long as they don't have "," characters in their block device OF path name.

I'm working on that problem now.