userlibandfileserver/fileserver/shostmassstorage/msproxy/tmbr.cpp
author hgs
Tue, 02 Nov 2010 15:29:23 +0000
changeset 300 1d28c8722707
permissions -rw-r--r--
201043_09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
300
1d28c8722707 201043_09
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1d28c8722707 201043_09
hgs
parents:
diff changeset
     2
// All rights reserved.
1d28c8722707 201043_09
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
1d28c8722707 201043_09
hgs
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
1d28c8722707 201043_09
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
1d28c8722707 201043_09
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1d28c8722707 201043_09
hgs
parents:
diff changeset
     7
//
1d28c8722707 201043_09
hgs
parents:
diff changeset
     8
// Initial Contributors:
1d28c8722707 201043_09
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
1d28c8722707 201043_09
hgs
parents:
diff changeset
    10
//
1d28c8722707 201043_09
hgs
parents:
diff changeset
    11
// Contributors:
1d28c8722707 201043_09
hgs
parents:
diff changeset
    12
//
1d28c8722707 201043_09
hgs
parents:
diff changeset
    13
// Description:
1d28c8722707 201043_09
hgs
parents:
diff changeset
    14
//
1d28c8722707 201043_09
hgs
parents:
diff changeset
    15
//
1d28c8722707 201043_09
hgs
parents:
diff changeset
    16
1d28c8722707 201043_09
hgs
parents:
diff changeset
    17
/** @file
1d28c8722707 201043_09
hgs
parents:
diff changeset
    18
@internalTechnology
1d28c8722707 201043_09
hgs
parents:
diff changeset
    19
*/
1d28c8722707 201043_09
hgs
parents:
diff changeset
    20
1d28c8722707 201043_09
hgs
parents:
diff changeset
    21
#include <e32cmn.h>
1d28c8722707 201043_09
hgs
parents:
diff changeset
    22
#include <e32des8.h>
1d28c8722707 201043_09
hgs
parents:
diff changeset
    23
#include <partitions.h>
1d28c8722707 201043_09
hgs
parents:
diff changeset
    24
1d28c8722707 201043_09
hgs
parents:
diff changeset
    25
#include "mscutils.h"
1d28c8722707 201043_09
hgs
parents:
diff changeset
    26
#include "tmbr.h"
1d28c8722707 201043_09
hgs
parents:
diff changeset
    27
1d28c8722707 201043_09
hgs
parents:
diff changeset
    28
#include "OstTraceDefinitions.h"
1d28c8722707 201043_09
hgs
parents:
diff changeset
    29
#ifdef OST_TRACE_COMPILER_IN_USE
1d28c8722707 201043_09
hgs
parents:
diff changeset
    30
#include "tmbrTraces.h"
1d28c8722707 201043_09
hgs
parents:
diff changeset
    31
#endif
1d28c8722707 201043_09
hgs
parents:
diff changeset
    32
1d28c8722707 201043_09
hgs
parents:
diff changeset
    33
1d28c8722707 201043_09
hgs
parents:
diff changeset
    34
TInt TMbr::GetPartition(TDes8& aMbrData, TMBRPartitionEntry& aPartitionEntry)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    35
    {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    36
    TUint8* buffer = const_cast<TUint8*>(aMbrData.Ptr());
1d28c8722707 201043_09
hgs
parents:
diff changeset
    37
1d28c8722707 201043_09
hgs
parents:
diff changeset
    38
    // check first sector for a Master Boot Record
1d28c8722707 201043_09
hgs
parents:
diff changeset
    39
    if (LittleEndian::Get16(&buffer[KMBRSignatureOffset]) != KMBRSignature)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    40
        {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    41
        OstTrace0(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_11,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    42
                  "MBR not present");
1d28c8722707 201043_09
hgs
parents:
diff changeset
    43
        return KErrNotFound;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    44
        }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    45
1d28c8722707 201043_09
hgs
parents:
diff changeset
    46
    memcpy(&buffer[0],&buffer[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2));
1d28c8722707 201043_09
hgs
parents:
diff changeset
    47
    TMBRPartitionEntry* pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    48
1d28c8722707 201043_09
hgs
parents:
diff changeset
    49
    TInt firstValidPartitionCount = -1;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    50
    TInt defaultPartitionNumber = -1;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    51
    TInt partitionCount = 0;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    52
    for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    53
        {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    54
        if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition() || pe->IsValidExFATPartition())
1d28c8722707 201043_09
hgs
parents:
diff changeset
    55
            {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    56
            OstTrace1(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_12,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    57
                      "Partition %d is recognized", i);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    58
            partitionCount++;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    59
1d28c8722707 201043_09
hgs
parents:
diff changeset
    60
            if (firstValidPartitionCount < 0)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    61
                firstValidPartitionCount = i;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    62
1d28c8722707 201043_09
hgs
parents:
diff changeset
    63
            if (pe->iX86BootIndicator == KBootIndicatorBootable)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    64
                {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    65
                OstTrace1(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_13,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    66
                          "Partition %d is bootable", i);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    67
                defaultPartitionNumber = i;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    68
                break;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    69
                }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    70
            }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    71
        else
1d28c8722707 201043_09
hgs
parents:
diff changeset
    72
            {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    73
            OstTrace1(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_14,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    74
                      "Partition %d is invalid", i);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    75
            }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    76
        }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    77
1d28c8722707 201043_09
hgs
parents:
diff changeset
    78
    if (partitionCount > 0)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    79
        {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    80
        pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    81
        TInt partitionIndex = firstValidPartitionCount;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    82
        if (defaultPartitionNumber > 0)
1d28c8722707 201043_09
hgs
parents:
diff changeset
    83
            {
1d28c8722707 201043_09
hgs
parents:
diff changeset
    84
            partitionIndex = defaultPartitionNumber;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    85
            }
1d28c8722707 201043_09
hgs
parents:
diff changeset
    86
1d28c8722707 201043_09
hgs
parents:
diff changeset
    87
        OstTrace1(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_15,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    88
                  "Using Partition %d", partitionIndex);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    89
1d28c8722707 201043_09
hgs
parents:
diff changeset
    90
        TMBRPartitionEntry& partitionEntry = pe[partitionIndex];
1d28c8722707 201043_09
hgs
parents:
diff changeset
    91
        aPartitionEntry = partitionEntry;
1d28c8722707 201043_09
hgs
parents:
diff changeset
    92
1d28c8722707 201043_09
hgs
parents:
diff changeset
    93
        OstTraceExt2(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_16,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    94
                     "partitioncount = %d defaultpartition = %d",
1d28c8722707 201043_09
hgs
parents:
diff changeset
    95
                     partitionCount, partitionIndex);
1d28c8722707 201043_09
hgs
parents:
diff changeset
    96
        OstTraceExt2(TRACE_SHOSTMASSSTORAGE_MBR, TMBR_17,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    97
                     "iFirstSector = x%x iNumSectors = x%x",
1d28c8722707 201043_09
hgs
parents:
diff changeset
    98
                     partitionEntry.iFirstSector,
1d28c8722707 201043_09
hgs
parents:
diff changeset
    99
                     partitionEntry.iNumSectors);
1d28c8722707 201043_09
hgs
parents:
diff changeset
   100
        }
1d28c8722707 201043_09
hgs
parents:
diff changeset
   101
1d28c8722707 201043_09
hgs
parents:
diff changeset
   102
    return partitionCount;
1d28c8722707 201043_09
hgs
parents:
diff changeset
   103
    }
1d28c8722707 201043_09
hgs
parents:
diff changeset
   104