Skip to contentSkip to conversation

PC partitions and big disks

PATCH Robert Millan 2 participants 5 messages Nov 5, 2007 – Nov 10, 2007

lore
Share & tools
lore
#0 lore raw

This should make the error much clearer when partition exceeds 2 TiB on a PC partition map (currently, all user gets is a "out of partition" error which is hard to figure out if you're unaware of the 2 TiB limit).

Comments?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

* include/grub/types.h (ULONG_MAX32): New macro. (ULONG_MAX64): Likewise.
(ULONG_MAX): Use ULONG_MAX32 / ULONG_MAX64 to define it.

* util/misc.c (grub_util_warn): New function.

* util/biosdisk.c (grub_util_biosdisk_get_grub_dev): Issue a warning when disk->total_sectors' exceeds ULONG_MAX32 on pc' partmap.

include/grub/types.h +5 -2
diff -ur grub2/include/grub/types.h grub2.bigdisk/include/grub/types.h
@@ -92,10 +92,13 @@
 typedef grub_int32_t	grub_ssize_t;
 #endif
 
+#define ULONG_MAX32	4294967295UL
+#define ULONG_MAX64	18446744073709551615UL
+
 #if GRUB_CPU_SIZEOF_VOID_P == 8
-# define ULONG_MAX 18446744073709551615UL
+# define ULONG_MAX ULONG_MAX64
 #else
-# define ULONG_MAX 4294967295UL
+# define ULONG_MAX ULONG_MAX32
 #endif
 
 /* The type for representing a file offset.  */
util/biosdisk.c +3 -0
diff -ur grub2/util/biosdisk.c grub2.bigdisk/util/biosdisk.c
@@ -738,6 +738,9 @@
 	  
 	if (pcdata)
 	  {
+	    if (disk->total_sectors > ULONG_MAX32)
+	      grub_util_warn ("Size of disk exceeds maximum permitted by partition map");
+
 	    if (pcdata->bsd_part < 0)
 	      grub_util_info ("DOS partition %d starts from %lu",
 			      pcdata->dos_part, partition->start);
util/misc.c +13 -0
diff -ur grub2/util/misc.c grub2.bigdisk/util/misc.c
@@ -58,6 +58,19 @@
 }
 
 void
+grub_util_warn (const char *fmt, ...)
+{
+  va_list ap;
+      
+  fprintf (stderr, "%s: warning: ", progname);
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  fputc ('\n', stderr);
+  fflush (stderr);
+}
+
+void
 grub_util_error (const char *fmt, ...)
 {
   va_list ap;
#1 lore raw
Quoted 4 lines · Robert Millan

void

util/misc.c +2 -0
+grub_util_warn (const char *fmt, ...)
+{

util/misc.c line 72

Quoted 10 lines
util/misc.c +10 -0
+  va_list ap;
+      
+  fprintf (stderr, "%s: warning: ", progname);
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  fputc ('\n', stderr);
+  fflush (stderr);
+}
+

Ah, this addition is because I needed a way to print a warning unconditionaly, which we don't currently have (_error does that but aborts, _info only prints in verbose mode).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#2 lore raw
In reply to Robert Millan
Quoted 5 lines · Robert Millan

This should make the error much clearer when partition exceeds 2 TiB on a PC partition map (currently, all user gets is a "out of partition" error which is hard to figure out if you're unaware of the 2 TiB limit).

Comments?

See below :-)

Quoted 11 lines
Signature · 10 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)


	* include/grub/types.h (ULONG_MAX32): New macro.
	(ULONG_MAX64): Likewise.
	(ULONG_MAX): Use ULONG_MAX32 / ULONG_MAX64 to define it.

Please call use a GRUB_* prefix.

Quoted 4 lines

* util/misc.c (grub_util_warn): New function.

* util/biosdisk.c (grub_util_biosdisk_get_grub_dev): Issue a warning when disk->total_sectors' exceeds ULONG_MAX32 on pc' partmap.

Why a warning and not an error? Or perhaps another part of GRUB should return an error?

--
Marco

#3 lore raw
Quoted 24 lines · Marco Gerards
Quoted 5 lines · Robert Millan

This should make the error much clearer when partition exceeds 2 TiB on a PC partition map (currently, all user gets is a "out of partition" error which is hard to figure out if you're unaware of the 2 TiB limit).

Comments?

See below :-)

Quoted 11 lines
Signature · 10 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)


	* include/grub/types.h (ULONG_MAX32): New macro.
	(ULONG_MAX64): Likewise.
	(ULONG_MAX): Use ULONG_MAX32 / ULONG_MAX64 to define it.

Please call use a GRUB_* prefix.

Quoted 7 lines
Quoted 4 lines

* util/misc.c (grub_util_warn): New function.

* util/biosdisk.c (grub_util_biosdisk_get_grub_dev): Issue a warning when disk->total_sectors' exceeds ULONG_MAX32 on pc' partmap.

Why a warning and not an error? Or perhaps another part of GRUB should return an error?

Uhm. The person who reported this later told me that the partmap was in fact not pc' but gpt'. The problem this patch intended to address may still apply, but without reproducing it first, I'd prefer not to run the risk of "fixing" something that wasn't broken.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#4 lore raw
Quoted 30 lines · Robert Millan
Quoted 29 lines · Marco Gerards
Quoted 5 lines · Robert Millan

This should make the error much clearer when partition exceeds 2 TiB on a PC partition map (currently, all user gets is a "out of partition" error which is hard to figure out if you're unaware of the 2 TiB limit).

Comments?

See below :-)

Quoted 11 lines
Signature · 10 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)


	* include/grub/types.h (ULONG_MAX32): New macro.
	(ULONG_MAX64): Likewise.
	(ULONG_MAX): Use ULONG_MAX32 / ULONG_MAX64 to define it.

Please call use a GRUB_* prefix.

Quoted 4 lines

* util/misc.c (grub_util_warn): New function.

* util/biosdisk.c (grub_util_biosdisk_get_grub_dev): Issue a warning when disk->total_sectors' exceeds ULONG_MAX32 on pc' partmap.

Quoted 7 lines
Quoted 2 lines

Why a warning and not an error? Or perhaps another part of GRUB should return an error?

Uhm. The person who reported this later told me that the partmap was in fact not pc' but gpt'. The problem this patch intended to address may still apply, but without reproducing it first, I'd prefer not to run the risk of "fixing" something that wasn't broken.

Ok, fine for me. Please don't forget to add the GRUB_ prefix before committing :-)

--
Marco