38 } |
38 } |
39 |
39 |
40 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) |
40 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) |
41 { |
41 { |
42 __MSFNSLOG |
42 __MSFNSLOG |
43 const TInt KPartitionInfoSize = TMsDataMemMap::KSectorSize; |
43 RBuf8 partitionInfo; |
44 TBuf8<KPartitionInfoSize> partitionInfo; |
44 TInt r; |
45 TInt r; |
45 TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength)); |
46 |
46 if (r != KErrNone) |
47 r = iUsbHostMsLun.Read(0 , KPartitionInfoSize, (TDes8 &) partitionInfo); |
47 { |
|
48 return r; |
|
49 } |
|
50 |
|
51 r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo); |
48 if (r != KErrNone) |
52 if (r != KErrNone) |
49 { |
53 { |
50 __PXYPRINT1(_L("!! Reading medium failed with %d !!"), r); |
54 __PXYPRINT1(_L("!! Reading medium failed with %d !!"), r); |
|
55 partitionInfo.Close(); |
51 return r; |
56 return r; |
52 } |
57 } |
53 TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr(); |
58 TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr(); |
54 |
59 |
55 // Read of the first sector successful so check for a Master Boot Record |
60 // Read of the first sector successful so check for a Master Boot Record |
102 } |
107 } |
103 |
108 |
104 TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; |
109 TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; |
105 |
110 |
106 iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, |
111 iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, |
107 partitionEntry.iNumSectors); |
112 partitionEntry.iNumSectors, |
|
113 aCapsInfo.iBlockLength); |
108 __PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"), |
114 __PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"), |
109 partitionCount, partitionIndex); |
115 partitionCount, partitionIndex); |
110 __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"), |
116 __PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"), |
111 partitionEntry.iFirstSector, |
117 partitionEntry.iFirstSector, |
112 partitionEntry.iNumSectors); |
118 partitionEntry.iNumSectors, |
|
119 aCapsInfo.iBlockLength); |
113 } |
120 } |
114 else |
121 else |
115 { |
122 { |
116 __PXYPRINT(_L("No partition found")); |
123 __PXYPRINT(_L("No partition found")); |
117 iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks); |
124 iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength); |
118 __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"), |
125 __PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"), |
119 0, aCapsInfo.iNumberOfBlocks); |
126 0, |
|
127 aCapsInfo.iNumberOfBlocks, |
|
128 aCapsInfo.iBlockLength); |
120 } |
129 } |
121 } |
130 } |
|
131 |
|
132 partitionInfo.Close(); |
122 return KErrNone; |
133 return KErrNone; |
123 } |
134 } |
124 |
135 |
125 /** |
136 /** |
126 Initialise the proxy drive. |
137 Initialise the proxy drive. |
556 |
567 |
557 if (capsInfo.iWriteProtect) |
568 if (capsInfo.iWriteProtect) |
558 { |
569 { |
559 c.iMediaAtt |= KMediaAttWriteProtected; |
570 c.iMediaAtt |= KMediaAttWriteProtected; |
560 } |
571 } |
|
572 |
|
573 static const TInt K512ByteSectorSize = 0x200; // 512 |
|
574 if(K512ByteSectorSize != capsInfo.iBlockLength) |
|
575 { |
|
576 c.iMediaAtt &= ~KMediaAttFormattable; |
|
577 } |
561 __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), |
578 __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), |
562 capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, |
579 capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, |
563 caps().iSize, caps().iMediaAtt); |
580 caps().iSize, caps().iMediaAtt); |
564 } |
581 } |
565 else if (KErrNotReady) |
582 else if (KErrNotReady) |
646 return r; |
664 return r; |
647 |
665 |
648 iMsDataMemMap.InitDataArea(caps().iSize); |
666 iMsDataMemMap.InitDataArea(caps().iSize); |
649 } |
667 } |
650 |
668 |
651 TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << TMsDataMemMap::KFormatSectorShift; |
669 TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift(); |
652 TInt length = aInfo.iMaxBytesPerFormat; |
670 TInt length = aInfo.iMaxBytesPerFormat; |
653 TInt r = Erase(pos, length); |
671 TInt r = Erase(pos, length); |
654 |
672 |
655 if (r == KErrNone) |
673 if (r == KErrNone) |
656 { |
674 { |
657 length += TMsDataMemMap::KSectorSize - 1; |
675 length += iMsDataMemMap.BlockLength() - 1; |
658 length >>= TMsDataMemMap::KFormatSectorShift; |
676 length >>= iMsDataMemMap.FormatSectorShift(); |
659 aInfo.i512ByteSectorsFormatted += length; |
677 aInfo.i512ByteSectorsFormatted += length; |
660 } |
678 } |
661 |
679 |
662 return r; |
680 return r; |
663 } |
681 } |