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