[haiku-commits] haiku: hrev44963 - src/add-ons/kernel/partitioning_systems/intel

  • From: fredrik.holmqvist@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 5 Dec 2012 22:42:39 +0100 (CET)

hrev44963 adds 1 changeset to branch 'master'
old head: 2574bdfcc753167b4880749a7e1656936fe51fd9
new head: 36b210830fa8ea2b4eb6387630b69812d3e18936
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=36b2108+%5E2574bdf

----------------------------------------------------------------------------

36b2108: Modify intel partition mapper to fail if it detects a GPT disk
  
  Slightly amended patch from Tyler Dixon. This fixes #8434.
  Tested on my new GPT-disk with:
        jam run ":<build>makebootable" --dry-run /dev/sda4
  
  Signed-off-by: Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>

                                  [ Tyler Dixon <t.dixon@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44963
Commit:      36b210830fa8ea2b4eb6387630b69812d3e18936
URL:         http://cgit.haiku-os.org/haiku/commit/?id=36b2108
Author:      Tyler Dixon <t.dixon@xxxxxxxxxxxxxxxx>
Date:        Tue May  1 17:03:41 2012 UTC
Committer:   Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Commit-Date: Wed Dec  5 21:40:22 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/8434

----------------------------------------------------------------------------

1 file changed, 35 insertions(+), 13 deletions(-)
.../intel/PartitionMapParser.cpp                 | 48 ++++++++++++++------

----------------------------------------------------------------------------

diff --git 
a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp 
b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp
index e94b020..c3c6bda 100644
--- a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp
+++ b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp
@@ -33,11 +33,21 @@
 #      define TRACE(x) ;
 #endif
 
+#ifdef _USER_MODE
+#      define ERROR(x) printf x
+#else
+#      define ERROR(x) dprintf x
+#endif
+
 using std::nothrow;
 
 // Maximal number of logical partitions per extended partition we allow.
 static const int32 kMaxLogicalPartitionCount = 128;
 
+// Constants used to verify if a disk uses a GPT
+static const int32 kGPTSignatureSize = 8;
+static const char kGPTSignature[8] = { 'E', 'F', 'I', ' ', 'P', 'A', 'R', 'T' 
};
+
 
 // constructor
 PartitionMapParser::PartitionMapParser(int deviceFD, off_t sessionOffset,
@@ -295,20 +305,32 @@ PartitionMapParser::_ReadPartitionTable(off_t offset, 
partition_table* table)
        if (table == NULL)
                table = fPartitionTable;
 
-       status_t error = B_OK;
+       // Read the partition table from the device into the table structure
+       ssize_t bytesRead = read_pos(fDeviceFD, fSessionOffset + offset,
+               table, toRead);
+       if (bytesRead != (ssize_t)toRead) {
+               TRACE(("intel: _ReadPartitionTable(): reading the partition "
+                       "table failed: %lx\n", errno));
+               return bytesRead < 0 ? errno : B_IO_ERROR;
+       }
 
-       // read
-       if (read_pos(fDeviceFD, fSessionOffset + offset, table, toRead) != 
toRead) {
-#ifndef _BOOT_MODE
-               error = errno;
-               if (error == B_OK)
-                       error = B_IO_ERROR;
-#else
-               error = B_IO_ERROR;
-#endif
-               TRACE(("intel: _ReadPartitionTable(): reading the partition 
table "
-                       "failed: %lx\n", error));
+       // check for GPT signature "EFI PART"
+       // located in the 8bytes following the mbr
+       toRead = kGPTSignatureSize;
+       char gptSignature[8];
+       bytesRead = read_pos(fDeviceFD, fSessionOffset + offset
+               + sizeof(partition_table), &gptSignature, toRead);
+       if (bytesRead != (ssize_t)toRead) {
+               TRACE(("intel: _ReadPartitionTable(): checking for GPT "
+                       "signature failed: %lx\n", errno));
+               return bytesRead < 0 ? errno : B_IO_ERROR;
        }
-       return error;
+       if (memcmp(gptSignature, kGPTSignature, kGPTSignatureSize) == 0) {
+               ERROR(("Error: Disk is GPT-formatted: "
+                       "GPT disks are currently unsupported.\n"));
+               return B_BAD_DATA;
+       }
+
+       return B_OK;
 }
 


Other related posts: