Ticket #8990: 0001-Intel-Partition-Addon-2TB-limit-fix-gsoc2015.patch

File 0001-Intel-Partition-Addon-2TB-limit-fix-gsoc2015.patch, 2.3 KB (added by kushalsingh007, 9 years ago)

Made comment more descriptive and made conditions more readable. (Changed the commit message)

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

    From 509fc0d252641108f8bfccc5098f05040df58ac2 Mon Sep 17 00:00:00 2001
    From: kushalsingh007 <kushal.spiderman.singh@gmail.com>
    Date: Mon, 26 Jan 2015 08:47:32 +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. * Made some conditions more readable and easier to understand. * Fixes
     #8990
    
    ---
     src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp | 19 ++++++++++++-------
     1 file changed, 12 insertions(+), 7 deletions(-)
    
    diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp
    index d9c1450..e34a03b 100644
    a b PartitionMapAddOn::CreatePartitionHandle(BMutablePartition* partition,  
    9090bool
    9191PartitionMapAddOn::CanInitialize(const BMutablePartition* partition)
    9292{
     93    const off_t kMBRLimit = ((off_t)1 <<32) * 512;
     94        // Limit on size is (max_sector_count)*(sector size)=(2^32)*(512)=2TB.
     95   
    9396    // If it's big enough, but not too big (ie. larger than 2^32 blocks) we can
    94     // initialize it.
     97    // initialize it. Also, the highest offset of a partition should be lesser
     98    // than 2TB.
    9599    return partition->Size() >= 2 * partition->BlockSize()
    96         && partition->Size() / partition->BlockSize() < UINT32_MAX;
     100        && partition->Size() <= kMBRLimit
     101        && partition->Offset() < kMBRLimit;
    97102}
    98103
    99104
    status_t  
    101106PartitionMapAddOn::ValidateInitialize(const BMutablePartition* partition,
    102107    BString* name, const char* parameters)
    103108{
    104     if (!CanInitialize(partition)
    105         || (parameters != NULL && parameters[0] != '\0')) {
     109    if ((!CanInitialize(partition))
     110        || (parameters == NULL) || (parameters[0] == '\0')) {
    106111        return B_BAD_VALUE;
    107112    }
    108113
    status_t  
    118123PartitionMapAddOn::Initialize(BMutablePartition* partition, const char* name,
    119124    const char* parameters, BPartitionHandle** _handle)
    120125{
    121     if (!CanInitialize(partition)
    122         || (name != NULL && name[0] != '\0')
    123         || (parameters != NULL && parameters[0] != '\0')) {
     126    if ((!CanInitialize(partition))
     127        || (name == NULL) || (name[0] == '\0')
     128        || (parameters == NULL) || (parameters[0] == '\0')) {
    124129        return B_BAD_VALUE;
    125130    }
    126131