Ticket #8434: 0001-Modify-intel-partition-mapper-to-fail-if-it-detects-.patch

File 0001-Modify-intel-partition-mapper-to-fail-if-it-detects-.patch, 3.4 KB (added by zymoticb, 12 years ago)

Updated with bonefish's suggestions

  • src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp

    From 2135aa863d52abe4b634780d0698afe02bf3367c Mon Sep 17 00:00:00 2001
    From: Tyler Dixon <t.dixon@mail.utoronto.ca>
    Date: Tue, 1 May 2012 13:03:41 -0400
    Subject: [PATCH] Modify intel partition mapper to fail if it detects a GPT
     disk
    
    ---
     .../intel/PartitionMapParser.cpp                   |   49 ++++++++++++++------
     .../intel/PartitionMapParser.h                     |    1 +
     2 files changed, 35 insertions(+), 15 deletions(-)
    
    diff --git a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp
    index e94b020..fe39014 100644
    a b using std::nothrow;  
    3838// Maximal number of logical partitions per extended partition we allow.
    3939static const int32 kMaxLogicalPartitionCount = 128;
    4040
     41// Constants used to verify if a disk uses a GPT
     42static const int32 kGPTSignatureSize = 8;
     43static const char kGPTSignature[8] = { 'E', 'F', 'I', ' ', 'P', 'A', 'R', 'T' };
    4144
    4245// constructor
    4346PartitionMapParser::PartitionMapParser(int deviceFD, off_t sessionOffset,
    PartitionMapParser::_ReadPartitionTable(off_t offset, partition_table* table)  
    295298    if (table == NULL)
    296299        table = fPartitionTable;
    297300
    298     status_t error = B_OK;
    299 
    300     // read
    301     if (read_pos(fDeviceFD, fSessionOffset + offset, table, toRead) != toRead) {
    302 #ifndef _BOOT_MODE
    303         error = errno;
    304         if (error == B_OK)
    305             error = B_IO_ERROR;
    306 #else
    307         error = B_IO_ERROR;
    308 #endif
    309         TRACE(("intel: _ReadPartitionTable(): reading the partition table "
    310             "failed: %lx\n", error));
    311     }
    312     return error;
     301    // Read the partition table from the device into the table structure
     302    ssize_t bytesRead = read_pos(fDeviceFD,
     303                                 fSessionOffset + offset,
     304                                 table,
     305                                 toRead);
     306    if (bytesRead != (ssize_t) (toRead)){
     307        TRACE(("intel: _ReadPartitionTable(): reading the partition table "
     308            "failed: %lx\n", errno));
     309        return bytesRead < 0 ? errno : B_IO_ERROR;
     310    }
     311
     312    // check for GPT signature "EFI PART"
     313    // located in the 8bytes following the mbr
     314    toRead = kGPTSignatureSize;
     315    char gptSignature[8];
     316    bytesRead = read_pos(fDeviceFD,
     317                         fSessionOffset + offset + sizeof(partition_table),
     318                         &gptSignature,
     319                         toRead);
     320    if(bytesRead != (ssize_t) (toRead)){
     321        TRACE(("intel: _ReadPartitionTable(): checking for GPT signature "
     322                "failed: %lx\n", errno));
     323        return bytesRead < 0 ? errno : B_IO_ERROR;
     324    }
     325    if( memcmp(gptSignature, kGPTSignature, kGPTSignatureSize) == 0){
     326        TRACE(("intel: _ReadPartitionTable(): Disk is formatted as GPT. "
     327                    "GPT disks are currently unsupported\n"));
     328        return B_BAD_DATA;
     329    }
     330
     331    return B_OK;
    313332}
    314333
  • src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h

    diff --git a/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h b/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h
    index 7034bac..bc3cecc 100644
    a b private:  
    5454            PartitionMap*       fMap;
    5555};
    5656
     57
    5758#endif  // PARTITION_MAP_PARSER_H