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. |
525 @return system wide error code |
536 @return system wide error code |
526 */ |
537 */ |
527 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) |
538 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) |
528 { |
539 { |
529 __MSFNSLOG |
540 __MSFNSLOG |
530 __HOSTPRINT(_L("\n>>> HOST Caps")); |
541 __HOSTPRINT(_L(">>> HOST Caps")); |
531 TLocalDriveCapsV6Buf caps; |
542 TLocalDriveCapsV6Buf caps; |
532 caps.FillZ(); |
543 caps.FillZ(); |
533 |
544 |
534 TLocalDriveCapsV6& c = caps(); |
545 TLocalDriveCapsV6& c = caps(); |
535 |
546 |
536 c.iType = EMediaHardDisk; |
|
537 c.iConnectionBusType = EConnectionBusUsb; |
547 c.iConnectionBusType = EConnectionBusUsb; |
538 c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; |
548 c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; |
539 c.iMediaAtt = KMediaAttFormattable; |
549 c.iMediaAtt = KMediaAttFormattable; |
540 c.iFileSystemId = KDriveFileSysFAT; |
550 c.iFileSystemId = KDriveFileSysFAT; |
541 |
551 |
542 TCapsInfo capsInfo; |
552 TCapsInfo capsInfo; |
543 TInt r = iUsbHostMsLun.Caps(capsInfo); |
553 TInt r = iUsbHostMsLun.Caps(capsInfo); |
|
554 |
544 if (KErrNone == r) |
555 if (KErrNone == r) |
545 { |
556 { |
546 c.iBlockSize = capsInfo.iBlockLength; |
557 c.iType = capsInfo.iMediaType; |
547 TUint64 size = iMsDataMemMap.DataSize(); |
558 |
548 if (size == 0) |
559 if (capsInfo.iMediaType == EMediaHardDisk) |
549 { |
560 { |
550 // No valid partitions so specify the size of the disk |
561 c.iBlockSize = capsInfo.iBlockLength; |
551 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; |
562 TUint64 size = iMsDataMemMap.DataSize(); |
|
563 |
|
564 if (size == 0) |
|
565 { |
|
566 // No valid partitions so specify the size of the disk |
|
567 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; |
|
568 } |
|
569 c.iSize = size; |
|
570 |
|
571 c.iEraseBlockSize = 0; |
|
572 |
|
573 if (capsInfo.iWriteProtect) |
|
574 { |
|
575 c.iMediaAtt |= KMediaAttWriteProtected; |
|
576 } |
|
577 |
|
578 static const TInt K512ByteSectorSize = 0x200; // 512 |
|
579 if(K512ByteSectorSize != capsInfo.iBlockLength) |
|
580 { |
|
581 // not formattable if sector size is not 512 |
|
582 c.iMediaAtt &= ~KMediaAttFormattable; |
|
583 } |
|
584 __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), |
|
585 capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, |
|
586 caps().iSize, caps().iMediaAtt); |
552 } |
587 } |
553 c.iSize = size; |
588 else if (capsInfo.iMediaType == EMediaCdRom) |
554 |
|
555 c.iEraseBlockSize = 0; |
|
556 |
|
557 if (capsInfo.iWriteProtect) |
|
558 { |
589 { |
559 c.iMediaAtt |= KMediaAttWriteProtected; |
590 // not formattable |
|
591 c.iMediaAtt &= ~KMediaAttFormattable; |
|
592 __HOSTPRINT(_L(">>> HOST Caps MediaType = EMediaCdRom")); |
560 } |
593 } |
561 __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), |
594 else |
562 capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, |
595 { |
563 caps().iSize, caps().iMediaAtt); |
596 // do nothing |
|
597 } |
564 } |
598 } |
565 else if (KErrNotReady) |
599 else if (KErrNotReady) |
566 { |
600 { |
567 __HOSTPRINT(_L("<<< HOST Caps Media Not Present")); |
601 __HOSTPRINT(_L("<<< HOST Caps Media Not Present")); |
568 c.iType = EMediaNotPresent; |
602 c.iType = EMediaNotPresent; |
569 r = KErrNone; |
603 r = KErrNone; |
570 } |
604 } |
571 else |
605 else |
572 { |
606 { |
573 __HOSTPRINT(_L("<<< HOST Caps Unknown Error")); |
607 __HOSTPRINT(_L("<<< HOST Caps Unknown Error")); |
|
608 c.iType = EMediaUnknown; |
574 r = KErrUnknown; |
609 r = KErrUnknown; |
575 } |
610 } |
576 anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); |
611 anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); |
577 return r; |
612 return r; |
578 } |
613 } |
646 return r; |
681 return r; |
647 |
682 |
648 iMsDataMemMap.InitDataArea(caps().iSize); |
683 iMsDataMemMap.InitDataArea(caps().iSize); |
649 } |
684 } |
650 |
685 |
651 TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << TMsDataMemMap::KFormatSectorShift; |
686 TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift(); |
652 TInt length = aInfo.iMaxBytesPerFormat; |
687 TInt length = aInfo.iMaxBytesPerFormat; |
653 TInt r = Erase(pos, length); |
688 TInt r = Erase(pos, length); |
654 |
689 |
655 if (r == KErrNone) |
690 if (r == KErrNone) |
656 { |
691 { |
657 length += TMsDataMemMap::KSectorSize - 1; |
692 length += iMsDataMemMap.BlockLength() - 1; |
658 length >>= TMsDataMemMap::KFormatSectorShift; |
693 length >>= iMsDataMemMap.FormatSectorShift(); |
659 aInfo.i512ByteSectorsFormatted += length; |
694 aInfo.i512ByteSectorsFormatted += length; |
660 } |
695 } |
661 |
696 |
662 return r; |
697 return r; |
663 } |
698 } |