sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: // sl@0: // hostusbmsproxy.cpp sl@0: // sl@0: // This file system extension provides a way to access a drive on the MS system in "raw format". sl@0: // It can be used to test large files / drives sl@0: // sl@0: sl@0: /** @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: sl@0: #include "hostusbmsproxy.h" sl@0: #include "debug.h" sl@0: sl@0: sl@0: CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice) sl@0: : CExtProxyDrive(aMount,aDevice) sl@0: { sl@0: __MSFNSLOG sl@0: } sl@0: sl@0: CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive() sl@0: { sl@0: __MSFNSLOG sl@0: iUsbHostMsLun.UnInitialise(); sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) sl@0: { sl@0: __MSFNSLOG sl@0: const TInt KPartitionInfoSize = TMsDataMemMap::KSectorSize; sl@0: TBuf8 partitionInfo; sl@0: TInt r; sl@0: sl@0: r = iUsbHostMsLun.Read(0 , KPartitionInfoSize, (TDes8 &) partitionInfo); sl@0: if (r != KErrNone) sl@0: { sl@0: __PXYPRINT1(_L("!! Reading medium failed with %d !!"), r); sl@0: return r; sl@0: } sl@0: TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr(); sl@0: sl@0: // Read of the first sector successful so check for a Master Boot Record sl@0: if (*(TUint16*)(&iIntBuf[KMBRSignatureOffset])!= KMBRSignature) sl@0: { sl@0: __PXYPRINT(_L("MBR not present")); sl@0: iMsDataMemMap.Reset(); sl@0: } sl@0: else sl@0: { sl@0: // Move the partition entries to a 4 byte boundary sl@0: memcpy(&iIntBuf[0],&iIntBuf[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2)); sl@0: // Search for a x86 default boot partition - let this be the first sl@0: TMBRPartitionEntry* pe = (TMBRPartitionEntry*)(&iIntBuf[0]); sl@0: sl@0: TInt firstValidPartitionCount = -1; sl@0: TInt defaultPartitionNumber = -1; sl@0: TInt partitionCount = 0; sl@0: for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++) sl@0: { sl@0: if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition()) sl@0: { sl@0: __PXYPRINT(_L("Found a Valid Partition")); sl@0: partitionCount++; sl@0: sl@0: if (firstValidPartitionCount < 0) sl@0: firstValidPartitionCount = i; sl@0: sl@0: if (pe->iX86BootIndicator == KBootIndicatorBootable) sl@0: { sl@0: defaultPartitionNumber = i; sl@0: break; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: __PXYPRINT(_L("!! Invalid Partition !!")); sl@0: } sl@0: } sl@0: sl@0: // Check the validity of the partition address boundaries sl@0: if (partitionCount > 0) sl@0: { sl@0: __PXYPRINT1(_L("Using Partition %d"), partitionCount); sl@0: pe = (TMBRPartitionEntry*)(&iIntBuf[0]); sl@0: TInt partitionIndex = firstValidPartitionCount; sl@0: if (defaultPartitionNumber > 0) sl@0: { sl@0: partitionIndex = defaultPartitionNumber; sl@0: } sl@0: sl@0: TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; sl@0: sl@0: iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, sl@0: partitionEntry.iNumSectors); sl@0: __PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"), sl@0: partitionCount, partitionIndex); sl@0: __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"), sl@0: partitionEntry.iFirstSector, sl@0: partitionEntry.iNumSectors); sl@0: } sl@0: else sl@0: { sl@0: __PXYPRINT(_L("No partition found")); sl@0: iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks); sl@0: __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"), sl@0: 0, aCapsInfo.iNumberOfBlocks); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Initialise the proxy drive. sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Initialise() sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::Initialise()")); sl@0: sl@0: if(Mount()) sl@0: { sl@0: // as we can't currently handle remounting devices that have sl@0: // been removed by unplugging the USB cable, disable critical notifiers sl@0: // as there's no point in asking the user to re-insert the disk. sl@0: Mount()->SetNotifyOff(); sl@0: } sl@0: sl@0: // Check for media presence sl@0: TCapsInfo capsInfo; sl@0: TInt err = iUsbHostMsLun.Caps(capsInfo); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: err = InitialiseOffset(capsInfo); sl@0: } sl@0: sl@0: __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::Initialise() err = %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::SetInfo()")); sl@0: TMassStorageUnitInfo iUnitInfo; sl@0: TPckg infoPckg(iUnitInfo); sl@0: TRAPD(err, msg.ReadL(2, infoPckg)); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: __PXYPRINT1(_L("Cant read from the RMessage %d"), err); sl@0: __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID); sl@0: if(err != KErrNone) sl@0: { sl@0: __PXYPRINT1(_L("Initialising logical unit failed %d"), err); sl@0: __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::Dismounted() sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: sl@0: TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: #define GetIndex(msg, aAddress, aIndex) \ sl@0: aIndex = msg.Ptr0() == aAddress ? 0 : \ sl@0: msg.Ptr1() == aAddress ? 1 : \ sl@0: msg.Ptr1() == aAddress ? 2 : \ sl@0: msg.Ptr1() == aAddress ? 3 : -1; sl@0: sl@0: /** sl@0: Read from the proxy drive. sl@0: sl@0: @param aPos The address from where the read begins. sl@0: @param aLength The length of the read. sl@0: @param aTrg A descriptor of the memory buffer from which to read. sl@0: @param aThreadHandle The handle-number representing the drive thread. sl@0: @param aOffset Offset into aTrg to read the data from. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, sl@0: const TAny* aTrg, TInt aThreadHandle, TInt aOffset) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT4(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x 0x%x"), sl@0: aPos, aPos/KBlockSize, aLength, aOffset); sl@0: sl@0: TBool localMessage = (aThreadHandle == KLocalMessageHandle); sl@0: sl@0: // sl@0: // Set file position to where we want to read... sl@0: // sl@0: if(!localMessage) sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: localMessage = (msg.Handle() == KLocalMessageHandle); sl@0: } sl@0: sl@0: TInt index = 0; sl@0: if (!localMessage) sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: GetIndex(msg, aTrg, index); sl@0: sl@0: if (index < 0) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrArgument); sl@0: return KErrArgument; sl@0: } sl@0: } sl@0: sl@0: /* Calculate the end position */ sl@0: TInt64 end = aPos + static_cast(aLength); sl@0: sl@0: /* check whether there is enough source data to write to the destination descriptor */ sl@0: TInt64 truncate; sl@0: if(localMessage) sl@0: { sl@0: truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset); sl@0: __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aTrg)->MaxLength()); sl@0: } sl@0: else sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: truncate = aLength - (msg.GetDesMaxLength(index) - aOffset); sl@0: __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesMaxLength(index)); sl@0: } sl@0: sl@0: __PXYPRINT1(_L("Offset: %08x"), aOffset); sl@0: __PXYPRINT1(_L("Truncate: 0x%lx"), truncate); sl@0: sl@0: if (truncate > 0) sl@0: { sl@0: end -= truncate; sl@0: } sl@0: sl@0: iBuf.SetMax(); sl@0: TInt r; sl@0: TInt64 mediaPos; sl@0: while (aPos < end) sl@0: { sl@0: TInt len = end - aPos; sl@0: mediaPos = aPos; sl@0: r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); sl@0: return r; sl@0: } sl@0: sl@0: if (localMessage) sl@0: { sl@0: TPtr8* pTrgPtr = (TPtr8*)aTrg; sl@0: TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset); sl@0: r = iUsbHostMsLun.Read(mediaPos, len, trgDes); sl@0: if (r != KErrNone) sl@0: return r; sl@0: pTrgPtr->SetLength(aOffset + trgDes.Length()); sl@0: } sl@0: else sl@0: { sl@0: if (len > iBuf.MaxLength()) sl@0: len = iBuf.MaxLength(); sl@0: sl@0: r = iUsbHostMsLun.Read(mediaPos, len, iBuf); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); sl@0: return r; sl@0: } sl@0: sl@0: iBuf.SetLength(len); sl@0: sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: r = msg.Write(index, iBuf, aOffset); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: aPos += len; sl@0: aOffset += len; sl@0: } sl@0: sl@0: __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrNone); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Read from the proxy drive, and pass flags to driver. sl@0: sl@0: @param aPos The address from where the read begins. sl@0: @param aLength The length of the read. sl@0: @param aTrg A descriptor of the memory buffer from which to read. sl@0: @param aThreadHandle The handle-number representing the drive thread. sl@0: @param aOffset Offset into aTrg to read the data from. sl@0: @param aFlags Flags to be passed into the driver. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, sl@0: const TAny* aTrg, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) sl@0: { sl@0: __MSFNSLOG sl@0: return Read(aPos, aLength, aTrg, aThreadHandle, aOffset); sl@0: } sl@0: sl@0: /** sl@0: Read from the proxy drive. sl@0: sl@0: @param aPos The address from where the read begins. sl@0: @param aLength The length of the read. sl@0: @param aTrg A descriptor of the memory buffer from which to read. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, TDes8& aTrg) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT3(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x"), sl@0: aPos, aPos/KBlockSize, aLength); sl@0: return iUsbHostMsLun.Read(iMsDataMemMap.GetDataPos(aPos), aLength, aTrg); sl@0: } sl@0: sl@0: /** sl@0: Write to the proxy drive. sl@0: sl@0: @param aPos The address from where the write begins. sl@0: @param aLength The length of the write. sl@0: @param aSrc A descriptor of the memory buffer from which to write. sl@0: @param aThreadHandle The handle-number representing the drive thread. sl@0: @param aOffset Offset into aSrc to write the data to. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, sl@0: const TAny* aSrc, TInt aThreadHandle, TInt aOffset) sl@0: { sl@0: // sl@0: // Set file position to where we want to write... sl@0: // sl@0: __MSFNSLOG sl@0: __HOSTPRINT4(_L("\n>>> HOST Write Pos=0x%lx LBA=0%lx 0x%x 0x%x"), sl@0: aPos, aPos/KBlockSize, aLength, aOffset); sl@0: sl@0: TBool localMessage = (aThreadHandle == KLocalMessageHandle); sl@0: sl@0: if(!localMessage) sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: localMessage = (msg.Handle() == KLocalMessageHandle); sl@0: } sl@0: sl@0: TInt index = 0; sl@0: if(!localMessage) sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: GetIndex(msg, aSrc, index); sl@0: sl@0: if (index < 0) sl@0: return KErrArgument; sl@0: } sl@0: sl@0: /* Calculate the end position */ sl@0: TInt64 end = aPos + static_cast(aLength); sl@0: /* check whether there is enough source data to read */ sl@0: TInt64 truncate; sl@0: if (localMessage) sl@0: { sl@0: truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset); sl@0: __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aSrc)->Length()); sl@0: } sl@0: else sl@0: { sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: truncate = aLength - (msg.GetDesLength(index) - aOffset); sl@0: __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesLength(index)); sl@0: } sl@0: sl@0: __PXYPRINT1(_L("Offset: %08x"), aOffset); sl@0: __PXYPRINT1(_L("Truncate: 0x%lx"), truncate); sl@0: sl@0: /* if truncate is > 0 we are short of source data as claimed by the aLength. Hence adjust the 'end' */ sl@0: if (truncate > 0) sl@0: { sl@0: end -= truncate; sl@0: } sl@0: sl@0: iBuf.SetMax(); sl@0: sl@0: TInt r; sl@0: TInt64 mediaPos; sl@0: while (aPos < end) sl@0: { sl@0: TInt len = end - aPos; sl@0: mediaPos = aPos; sl@0: r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); sl@0: return r; sl@0: } sl@0: sl@0: if (localMessage) sl@0: { sl@0: r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset)); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); sl@0: return r; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (len > iBuf.Length()) sl@0: len = iBuf.Length(); sl@0: sl@0: RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); sl@0: r = msg.Read(index, iBuf, aOffset); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); sl@0: return r; sl@0: } sl@0: sl@0: r = iUsbHostMsLun.Write(mediaPos, len, iBuf); sl@0: if (r != KErrNone) sl@0: { sl@0: __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: aPos += len; sl@0: aOffset += len; sl@0: } sl@0: sl@0: __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Write to the proxy drive and pass flags to driver sl@0: sl@0: @param aPos The address from where the write begins. sl@0: @param aLength The length of the write. sl@0: @param aSrc A descriptor of the memory buffer from which to write. sl@0: @param aThreadHandle The handle-number representing the drive thread. sl@0: @param aOffset Offset into aSrc to write the data to. sl@0: @param aFlags Flags to be passed into the driver. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, sl@0: const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) sl@0: { sl@0: __MSFNSLOG sl@0: return Write(aPos, aLength, aSrc, aThreadHandle, aOffset); sl@0: } sl@0: sl@0: /** sl@0: Write to the proxy drive. sl@0: sl@0: @param aPos The address from where the write begins. sl@0: @param aSrc A descriptor of the memory buffer from which to write. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"), sl@0: aPos, aPos/KBlockSize, aSrc.Length()); sl@0: return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc); sl@0: } sl@0: sl@0: /** sl@0: Get the proxy drive's capabilities information. sl@0: sl@0: @param anInfo A descriptor of the connected drives capabilities. sl@0: sl@0: @return system wide error code sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT(_L("\n>>> HOST Caps")); sl@0: TLocalDriveCapsV6Buf caps; sl@0: caps.FillZ(); sl@0: sl@0: TLocalDriveCapsV6& c = caps(); sl@0: sl@0: c.iType = EMediaHardDisk; sl@0: c.iConnectionBusType = EConnectionBusUsb; sl@0: c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; sl@0: c.iMediaAtt = KMediaAttFormattable; sl@0: c.iFileSystemId = KDriveFileSysFAT; sl@0: sl@0: TCapsInfo capsInfo; sl@0: TInt r = iUsbHostMsLun.Caps(capsInfo); sl@0: if (KErrNone == r) sl@0: { sl@0: c.iBlockSize = capsInfo.iBlockLength; sl@0: TUint64 size = iMsDataMemMap.DataSize(); sl@0: if (size == 0) sl@0: { sl@0: // No valid partitions so specify the size of the disk sl@0: size = static_cast(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; sl@0: } sl@0: c.iSize = size; sl@0: sl@0: c.iEraseBlockSize = 0; sl@0: sl@0: if (capsInfo.iWriteProtect) sl@0: { sl@0: c.iMediaAtt |= KMediaAttWriteProtected; sl@0: } sl@0: __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), sl@0: capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, sl@0: caps().iSize, caps().iMediaAtt); sl@0: } sl@0: else sl@0: { sl@0: __HOSTPRINT(_L("<<< HOST Caps Media Not Present")); sl@0: c.iType = EMediaNotPresent; sl@0: if(r != KErrNotReady) sl@0: r = KErrUnknown; sl@0: } sl@0: anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Format the proxy drive. The drive is assumed to be a single partition. The sl@0: partition size is equivalent to the size of the media. sl@0: sl@0: @param aPos The position of the data which is being formatted. sl@0: @param aLength [IN] The length of the data which is being formatted. [OUT] The sl@0: length of data formatted, truncated when end of drive is reached. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Erase(TInt64 aPos, TInt& aLength) sl@0: { sl@0: __MSFNSLOG sl@0: __HOSTPRINT3(_L("\n HOST Erase Pos=0x%lx LBA=0x%lx 0x%x"), sl@0: aPos, aPos/KBlockSize, aLength); sl@0: TInt err = iMsDataMemMap.TranslateDataPos(aPos, aLength); sl@0: sl@0: if (err) sl@0: return err; sl@0: sl@0: err = iUsbHostMsLun.Erase(aPos, aLength); sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Format the proxy drive. sl@0: sl@0: @param aPos The position of the data which is being formatted. sl@0: @param aLength The length of the data which is being formatted. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Format(TInt64 aPos, TInt aLength) sl@0: { sl@0: __MSFNSLOG sl@0: return Erase(aPos, aLength); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Format the connected drive. sl@0: sl@0: @param anInfo Device specific format information. sl@0: sl@0: @return system wide error code. sl@0: */ sl@0: TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo) sl@0: { sl@0: __MSFNSLOG sl@0: sl@0: const TInt KDefaultMaxBytesPerFormat = 0x100 * TMsDataMemMap::KSectorSize; // 128K sl@0: sl@0: if (aInfo.i512ByteSectorsFormatted < 0) sl@0: return KErrArgument; sl@0: sl@0: if (!aInfo.iFormatIsCurrent) sl@0: { sl@0: aInfo.iFormatIsCurrent = ETrue; sl@0: aInfo.i512ByteSectorsFormatted = 0; sl@0: aInfo.iMaxBytesPerFormat = KDefaultMaxBytesPerFormat; sl@0: sl@0: TLocalDriveCapsV6Buf caps; sl@0: TInt r = Caps(caps); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: iMsDataMemMap.InitDataArea(caps().iSize); sl@0: } sl@0: sl@0: TInt64 pos = static_cast(aInfo.i512ByteSectorsFormatted) << TMsDataMemMap::KFormatSectorShift; sl@0: TInt length = aInfo.iMaxBytesPerFormat; sl@0: TInt r = Erase(pos, length); sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: length += TMsDataMemMap::KSectorSize - 1; sl@0: length >>= TMsDataMemMap::KFormatSectorShift; sl@0: aInfo.i512ByteSectorsFormatted += length; sl@0: } sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: TInt CUsbHostMsProxyDrive::NotifyChange(TDes8 &aChanged,TRequestStatus* aStatus) sl@0: { sl@0: __MSFNSLOG sl@0: iUsbHostMsLun.NotifyChange(aChanged, *aStatus); sl@0: sl@0: if(*aStatus != KRequestPending) sl@0: return KErrUnknown; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CUsbHostMsProxyDrive::NotifyChangeCancel() sl@0: { sl@0: __MSFNSLOG sl@0: iUsbHostMsLun.NotifyChangeCancel(); sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::SetMountInfo(const TDesC8* /*aMountInfo*/,TInt /*aMountInfoThreadHandle=KCurrentThreadHandle*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::ForceRemount(TUint aFlags) sl@0: { sl@0: __MSFNSLOG sl@0: iUsbHostMsLun.ForceRemount(aFlags); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::Unlock(TMediaPassword& /*aPassword*/, TBool /*aStorePassword*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::Lock(TMediaPassword& /*aOldPassword*/, TMediaPassword& /*aNewPassword*/, TBool /*aStorePassword*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::Clear(TMediaPassword& /*aPassword*/) sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::ErasePassword() sl@0: { sl@0: __MSFNSLOG sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt CUsbHostMsProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput) sl@0: { sl@0: switch(aInterfaceId) sl@0: { sl@0: case ELocalBufferSupport: sl@0: return KErrNone; sl@0: case EFinalised: sl@0: { sl@0: TBool isFinalised = (TBool)aInput; sl@0: if(isFinalised) sl@0: { sl@0: iUsbHostMsLun.SuspendLun(); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: default: sl@0: return KErrNotSupported; sl@0: } sl@0: }