Ticket #8990: 0001-Intel-add-on-partition-size-greater-than-2-TB-gsoc2015.patch

File 0001-Intel-add-on-partition-size-greater-than-2-TB-gsoc2015.patch, 2.2 KB (added by kushalsingh007, 9 years ago)

A patch which limits the maximum size, over which intel partition map can be initialized to 2TB. (Also includes small changes for operator precedence issue)

  • src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp

    From f332e26062bf4ff4b83e0a3cd7a5ad8bdc8253e8 Mon Sep 17 00:00:00 2001
    From: kushalsingh007 <kushal.spiderman.singh@gmail.com>
    Date: Sun, 25 Jan 2015 18:51:44 +0530
    Subject: [PATCH] * Previously intel add-on allowed creation of partition with
     size > 2TB, now it allows partition size and offset to be less than 2TB
     limit. * Fixed minor overflow condition and operator precedence issue with
     Logical NOT. * Fixes #8990
    
    ---
     src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp | 16 ++++++++++------
     1 file changed, 10 insertions(+), 6 deletions(-)
    
    diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp
    index d9c1450..1edaecd 100644
    a b PartitionMapAddOn::CreatePartitionHandle(BMutablePartition* partition,  
    9090bool
    9191PartitionMapAddOn::CanInitialize(const BMutablePartition* partition)
    9292{
     93    const off_t kMBRLimit = (off_t)1 <<41;  //2TB is the limit on the max size.
     94   
    9395    // If it's big enough, but not too big (ie. larger than 2^32 blocks) we can
    94     // initialize it.
     96    // initialize it. Also, the highest offset of a partition should be lesser
     97    // than 2TB.
    9598    return partition->Size() >= 2 * partition->BlockSize()
    96         && partition->Size() / partition->BlockSize() < UINT32_MAX;
     99        && partition->Size() <= kMBRLimit
     100        && partition->Offset() < kMBRLimit;
    97101}
    98102
    99103
    status_t  
    101105PartitionMapAddOn::ValidateInitialize(const BMutablePartition* partition,
    102106    BString* name, const char* parameters)
    103107{
    104     if (!CanInitialize(partition)
    105         || (parameters != NULL && parameters[0] != '\0')) {
     108    if (!(CanInitialize(partition)
     109        || (parameters != NULL && parameters[0] != '\0'))) {
    106110        return B_BAD_VALUE;
    107111    }
    108112
    status_t  
    118122PartitionMapAddOn::Initialize(BMutablePartition* partition, const char* name,
    119123    const char* parameters, BPartitionHandle** _handle)
    120124{
    121     if (!CanInitialize(partition)
     125    if (!(CanInitialize(partition)
    122126        || (name != NULL && name[0] != '\0')
    123         || (parameters != NULL && parameters[0] != '\0')) {
     127        || (parameters != NULL && parameters[0] != '\0'))) {
    124128        return B_BAD_VALUE;
    125129    }
    126130