os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/msproxy/hostusbmsproxy.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/msproxy/hostusbmsproxy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,739 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +//
1.21 +// hostusbmsproxy.cpp
1.22 +//
1.23 +// This file system extension provides a way to access a drive on the MS system in "raw format".
1.24 +// It can be used to test large files / drives
1.25 +//
1.26 +
1.27 +/** @file
1.28 +@internalTechnology
1.29 +*/
1.30 +
1.31 +#include <f32fsys.h>
1.32 +
1.33 +#include "hostusbmsproxy.h"
1.34 +#include "debug.h"
1.35 +
1.36 +
1.37 +CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice)
1.38 +: CExtProxyDrive(aMount,aDevice)
1.39 + {
1.40 + __MSFNSLOG
1.41 + }
1.42 +
1.43 +CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive()
1.44 + {
1.45 + __MSFNSLOG
1.46 + iUsbHostMsLun.UnInitialise();
1.47 + }
1.48 +
1.49 +TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo)
1.50 + {
1.51 + __MSFNSLOG
1.52 + const TInt KPartitionInfoSize = TMsDataMemMap::KSectorSize;
1.53 + TBuf8<KPartitionInfoSize> partitionInfo;
1.54 + TInt r;
1.55 +
1.56 + r = iUsbHostMsLun.Read(0 , KPartitionInfoSize, (TDes8 &) partitionInfo);
1.57 + if (r != KErrNone)
1.58 + {
1.59 + __PXYPRINT1(_L("!! Reading medium failed with %d !!"), r);
1.60 + return r;
1.61 + }
1.62 + TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr();
1.63 +
1.64 + // Read of the first sector successful so check for a Master Boot Record
1.65 + if (*(TUint16*)(&iIntBuf[KMBRSignatureOffset])!= KMBRSignature)
1.66 + {
1.67 + __PXYPRINT(_L("MBR not present"));
1.68 + iMsDataMemMap.Reset();
1.69 + }
1.70 + else
1.71 + {
1.72 + // Move the partition entries to a 4 byte boundary
1.73 + memcpy(&iIntBuf[0],&iIntBuf[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2));
1.74 + // Search for a x86 default boot partition - let this be the first
1.75 + TMBRPartitionEntry* pe = (TMBRPartitionEntry*)(&iIntBuf[0]);
1.76 +
1.77 + TInt firstValidPartitionCount = -1;
1.78 + TInt defaultPartitionNumber = -1;
1.79 + TInt partitionCount = 0;
1.80 + for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++)
1.81 + {
1.82 + if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition())
1.83 + {
1.84 + __PXYPRINT(_L("Found a Valid Partition"));
1.85 + partitionCount++;
1.86 +
1.87 + if (firstValidPartitionCount < 0)
1.88 + firstValidPartitionCount = i;
1.89 +
1.90 + if (pe->iX86BootIndicator == KBootIndicatorBootable)
1.91 + {
1.92 + defaultPartitionNumber = i;
1.93 + break;
1.94 + }
1.95 + }
1.96 + else
1.97 + {
1.98 + __PXYPRINT(_L("!! Invalid Partition !!"));
1.99 + }
1.100 + }
1.101 +
1.102 + // Check the validity of the partition address boundaries
1.103 + if (partitionCount > 0)
1.104 + {
1.105 + __PXYPRINT1(_L("Using Partition %d"), partitionCount);
1.106 + pe = (TMBRPartitionEntry*)(&iIntBuf[0]);
1.107 + TInt partitionIndex = firstValidPartitionCount;
1.108 + if (defaultPartitionNumber > 0)
1.109 + {
1.110 + partitionIndex = defaultPartitionNumber;
1.111 + }
1.112 +
1.113 + TMBRPartitionEntry& partitionEntry = pe[partitionIndex];
1.114 +
1.115 + iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector,
1.116 + partitionEntry.iNumSectors);
1.117 + __PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"),
1.118 + partitionCount, partitionIndex);
1.119 + __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"),
1.120 + partitionEntry.iFirstSector,
1.121 + partitionEntry.iNumSectors);
1.122 + }
1.123 + else
1.124 + {
1.125 + __PXYPRINT(_L("No partition found"));
1.126 + iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks);
1.127 + __PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"),
1.128 + 0, aCapsInfo.iNumberOfBlocks);
1.129 + }
1.130 + }
1.131 + return KErrNone;
1.132 + }
1.133 +
1.134 +/**
1.135 +Initialise the proxy drive.
1.136 +@return system wide error code.
1.137 +*/
1.138 +TInt CUsbHostMsProxyDrive::Initialise()
1.139 + {
1.140 + __MSFNSLOG
1.141 + __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::Initialise()"));
1.142 +
1.143 + if(Mount())
1.144 + {
1.145 + // as we can't currently handle remounting devices that have
1.146 + // been removed by unplugging the USB cable, disable critical notifiers
1.147 + // as there's no point in asking the user to re-insert the disk.
1.148 + Mount()->SetNotifyOff();
1.149 + }
1.150 +
1.151 + // Check for media presence
1.152 + TCapsInfo capsInfo;
1.153 + TInt err = iUsbHostMsLun.Caps(capsInfo);
1.154 +
1.155 + if (err == KErrNone)
1.156 + {
1.157 + err = InitialiseOffset(capsInfo);
1.158 + }
1.159 +
1.160 + __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::Initialise() err = %d"), err);
1.161 + return err;
1.162 + }
1.163 +
1.164 +TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3)
1.165 + {
1.166 + __MSFNSLOG
1.167 + __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::SetInfo()"));
1.168 + TMassStorageUnitInfo iUnitInfo;
1.169 + TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo);
1.170 + TRAPD(err, msg.ReadL(2, infoPckg));
1.171 +
1.172 + if(err != KErrNone)
1.173 + {
1.174 + __PXYPRINT1(_L("Cant read from the RMessage %d"), err);
1.175 + __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
1.176 + return err;
1.177 + }
1.178 +
1.179 + err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID);
1.180 + if(err != KErrNone)
1.181 + {
1.182 + __PXYPRINT1(_L("Initialising logical unit failed %d"), err);
1.183 + __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
1.184 + return err;
1.185 + }
1.186 +
1.187 + __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
1.188 + return err;
1.189 + }
1.190 +
1.191 +TInt CUsbHostMsProxyDrive::Dismounted()
1.192 + {
1.193 + __MSFNSLOG
1.194 + return KErrNone;
1.195 + }
1.196 +
1.197 +TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/)
1.198 + {
1.199 + __MSFNSLOG
1.200 + return KErrNotSupported;
1.201 + }
1.202 +
1.203 +
1.204 +TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/)
1.205 + {
1.206 + __MSFNSLOG
1.207 + return KErrNotSupported;
1.208 + }
1.209 +
1.210 +#define GetIndex(msg, aAddress, aIndex) \
1.211 + aIndex = msg.Ptr0() == aAddress ? 0 : \
1.212 + msg.Ptr1() == aAddress ? 1 : \
1.213 + msg.Ptr1() == aAddress ? 2 : \
1.214 + msg.Ptr1() == aAddress ? 3 : -1;
1.215 +
1.216 +/**
1.217 +Read from the proxy drive.
1.218 +
1.219 +@param aPos The address from where the read begins.
1.220 +@param aLength The length of the read.
1.221 +@param aTrg A descriptor of the memory buffer from which to read.
1.222 +@param aThreadHandle The handle-number representing the drive thread.
1.223 +@param aOffset Offset into aTrg to read the data from.
1.224 +
1.225 +@return system wide error code.
1.226 +*/
1.227 +TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
1.228 + const TAny* aTrg, TInt aThreadHandle, TInt aOffset)
1.229 + {
1.230 + __MSFNSLOG
1.231 + __HOSTPRINT4(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x 0x%x"),
1.232 + aPos, aPos/KBlockSize, aLength, aOffset);
1.233 +
1.234 + TBool localMessage = (aThreadHandle == KLocalMessageHandle);
1.235 +
1.236 + //
1.237 + // Set file position to where we want to read...
1.238 + //
1.239 + if(!localMessage)
1.240 + {
1.241 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.242 + localMessage = (msg.Handle() == KLocalMessageHandle);
1.243 + }
1.244 +
1.245 + TInt index = 0;
1.246 + if (!localMessage)
1.247 + {
1.248 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.249 + GetIndex(msg, aTrg, index);
1.250 +
1.251 + if (index < 0)
1.252 + {
1.253 + __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrArgument);
1.254 + return KErrArgument;
1.255 + }
1.256 + }
1.257 +
1.258 + /* Calculate the end position */
1.259 + TInt64 end = aPos + static_cast<TInt64>(aLength);
1.260 +
1.261 + /* check whether there is enough source data to write to the destination descriptor */
1.262 + TInt64 truncate;
1.263 + if(localMessage)
1.264 + {
1.265 + truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset);
1.266 + __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aTrg)->MaxLength());
1.267 + }
1.268 + else
1.269 + {
1.270 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.271 + truncate = aLength - (msg.GetDesMaxLength(index) - aOffset);
1.272 + __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesMaxLength(index));
1.273 + }
1.274 +
1.275 + __PXYPRINT1(_L("Offset: %08x"), aOffset);
1.276 + __PXYPRINT1(_L("Truncate: 0x%lx"), truncate);
1.277 +
1.278 + if (truncate > 0)
1.279 + {
1.280 + end -= truncate;
1.281 + }
1.282 +
1.283 + iBuf.SetMax();
1.284 + TInt r;
1.285 + TInt64 mediaPos;
1.286 + while (aPos < end)
1.287 + {
1.288 + TInt len = end - aPos;
1.289 + mediaPos = aPos;
1.290 + r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
1.291 + if (r != KErrNone)
1.292 + {
1.293 + __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
1.294 + return r;
1.295 + }
1.296 +
1.297 + if (localMessage)
1.298 + {
1.299 + TPtr8* pTrgPtr = (TPtr8*)aTrg;
1.300 + TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset);
1.301 + r = iUsbHostMsLun.Read(mediaPos, len, trgDes);
1.302 + if (r != KErrNone)
1.303 + return r;
1.304 + pTrgPtr->SetLength(aOffset + trgDes.Length());
1.305 + }
1.306 + else
1.307 + {
1.308 + if (len > iBuf.MaxLength())
1.309 + len = iBuf.MaxLength();
1.310 +
1.311 + r = iUsbHostMsLun.Read(mediaPos, len, iBuf);
1.312 + if (r != KErrNone)
1.313 + {
1.314 + __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
1.315 + return r;
1.316 + }
1.317 +
1.318 + iBuf.SetLength(len);
1.319 +
1.320 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.321 + r = msg.Write(index, iBuf, aOffset);
1.322 + if (r != KErrNone)
1.323 + {
1.324 + __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
1.325 + return r;
1.326 + }
1.327 + }
1.328 +
1.329 + aPos += len;
1.330 + aOffset += len;
1.331 + }
1.332 +
1.333 + __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrNone);
1.334 + return KErrNone;
1.335 + }
1.336 +
1.337 +
1.338 +/**
1.339 +Read from the proxy drive, and pass flags to driver.
1.340 +
1.341 +@param aPos The address from where the read begins.
1.342 +@param aLength The length of the read.
1.343 +@param aTrg A descriptor of the memory buffer from which to read.
1.344 +@param aThreadHandle The handle-number representing the drive thread.
1.345 +@param aOffset Offset into aTrg to read the data from.
1.346 +@param aFlags Flags to be passed into the driver.
1.347 +
1.348 +@return system wide error code.
1.349 +*/
1.350 +TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
1.351 + const TAny* aTrg, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
1.352 + {
1.353 + __MSFNSLOG
1.354 + return Read(aPos, aLength, aTrg, aThreadHandle, aOffset);
1.355 + }
1.356 +
1.357 +/**
1.358 +Read from the proxy drive.
1.359 +
1.360 +@param aPos The address from where the read begins.
1.361 +@param aLength The length of the read.
1.362 +@param aTrg A descriptor of the memory buffer from which to read.
1.363 +
1.364 +@return system wide error code.
1.365 +*/
1.366 +TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, TDes8& aTrg)
1.367 + {
1.368 + __MSFNSLOG
1.369 + __HOSTPRINT3(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x"),
1.370 + aPos, aPos/KBlockSize, aLength);
1.371 + return iUsbHostMsLun.Read(iMsDataMemMap.GetDataPos(aPos), aLength, aTrg);
1.372 + }
1.373 +
1.374 +/**
1.375 +Write to the proxy drive.
1.376 +
1.377 +@param aPos The address from where the write begins.
1.378 +@param aLength The length of the write.
1.379 +@param aSrc A descriptor of the memory buffer from which to write.
1.380 +@param aThreadHandle The handle-number representing the drive thread.
1.381 +@param aOffset Offset into aSrc to write the data to.
1.382 +
1.383 +@return system wide error code.
1.384 +*/
1.385 +TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
1.386 + const TAny* aSrc, TInt aThreadHandle, TInt aOffset)
1.387 + {
1.388 + //
1.389 + // Set file position to where we want to write...
1.390 + //
1.391 + __MSFNSLOG
1.392 + __HOSTPRINT4(_L("\n>>> HOST Write Pos=0x%lx LBA=0%lx 0x%x 0x%x"),
1.393 + aPos, aPos/KBlockSize, aLength, aOffset);
1.394 +
1.395 + TBool localMessage = (aThreadHandle == KLocalMessageHandle);
1.396 +
1.397 + if(!localMessage)
1.398 + {
1.399 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.400 + localMessage = (msg.Handle() == KLocalMessageHandle);
1.401 + }
1.402 +
1.403 + TInt index = 0;
1.404 + if(!localMessage)
1.405 + {
1.406 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.407 + GetIndex(msg, aSrc, index);
1.408 +
1.409 + if (index < 0)
1.410 + return KErrArgument;
1.411 + }
1.412 +
1.413 + /* Calculate the end position */
1.414 + TInt64 end = aPos + static_cast<TInt64>(aLength);
1.415 + /* check whether there is enough source data to read */
1.416 + TInt64 truncate;
1.417 + if (localMessage)
1.418 + {
1.419 + truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset);
1.420 + __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aSrc)->Length());
1.421 + }
1.422 + else
1.423 + {
1.424 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.425 + truncate = aLength - (msg.GetDesLength(index) - aOffset);
1.426 + __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesLength(index));
1.427 + }
1.428 +
1.429 + __PXYPRINT1(_L("Offset: %08x"), aOffset);
1.430 + __PXYPRINT1(_L("Truncate: 0x%lx"), truncate);
1.431 +
1.432 + /* if truncate is > 0 we are short of source data as claimed by the aLength. Hence adjust the 'end' */
1.433 + if (truncate > 0)
1.434 + {
1.435 + end -= truncate;
1.436 + }
1.437 +
1.438 + iBuf.SetMax();
1.439 +
1.440 + TInt r;
1.441 + TInt64 mediaPos;
1.442 + while (aPos < end)
1.443 + {
1.444 + TInt len = end - aPos;
1.445 + mediaPos = aPos;
1.446 + r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
1.447 + if (r != KErrNone)
1.448 + {
1.449 + __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
1.450 + return r;
1.451 + }
1.452 +
1.453 + if (localMessage)
1.454 + {
1.455 + r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset));
1.456 +
1.457 + if (r != KErrNone)
1.458 + {
1.459 + __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
1.460 + return r;
1.461 + }
1.462 + }
1.463 + else
1.464 + {
1.465 + if (len > iBuf.Length())
1.466 + len = iBuf.Length();
1.467 +
1.468 + RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
1.469 + r = msg.Read(index, iBuf, aOffset);
1.470 + if (r != KErrNone)
1.471 + {
1.472 + __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
1.473 + return r;
1.474 + }
1.475 +
1.476 + r = iUsbHostMsLun.Write(mediaPos, len, iBuf);
1.477 + if (r != KErrNone)
1.478 + {
1.479 + __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
1.480 + return r;
1.481 + }
1.482 + }
1.483 +
1.484 + aPos += len;
1.485 + aOffset += len;
1.486 + }
1.487 +
1.488 + __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone);
1.489 + return KErrNone;
1.490 + }
1.491 +
1.492 +/**
1.493 +Write to the proxy drive and pass flags to driver
1.494 +
1.495 +@param aPos The address from where the write begins.
1.496 +@param aLength The length of the write.
1.497 +@param aSrc A descriptor of the memory buffer from which to write.
1.498 +@param aThreadHandle The handle-number representing the drive thread.
1.499 +@param aOffset Offset into aSrc to write the data to.
1.500 +@param aFlags Flags to be passed into the driver.
1.501 +
1.502 +@return system wide error code.
1.503 +*/
1.504 +TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
1.505 + const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
1.506 + {
1.507 + __MSFNSLOG
1.508 + return Write(aPos, aLength, aSrc, aThreadHandle, aOffset);
1.509 + }
1.510 +
1.511 +/**
1.512 +Write to the proxy drive.
1.513 +
1.514 +@param aPos The address from where the write begins.
1.515 +@param aSrc A descriptor of the memory buffer from which to write.
1.516 +
1.517 +@return system wide error code.
1.518 +*/
1.519 +TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
1.520 + {
1.521 + __MSFNSLOG
1.522 + __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"),
1.523 + aPos, aPos/KBlockSize, aSrc.Length());
1.524 + return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc);
1.525 + }
1.526 +
1.527 +/**
1.528 +Get the proxy drive's capabilities information.
1.529 +
1.530 +@param anInfo A descriptor of the connected drives capabilities.
1.531 +
1.532 +@return system wide error code
1.533 +*/
1.534 +TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo)
1.535 + {
1.536 + __MSFNSLOG
1.537 + __HOSTPRINT(_L("\n>>> HOST Caps"));
1.538 + TLocalDriveCapsV6Buf caps;
1.539 + caps.FillZ();
1.540 +
1.541 + TLocalDriveCapsV6& c = caps();
1.542 +
1.543 + c.iType = EMediaHardDisk;
1.544 + c.iConnectionBusType = EConnectionBusUsb;
1.545 + c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal;
1.546 + c.iMediaAtt = KMediaAttFormattable;
1.547 + c.iFileSystemId = KDriveFileSysFAT;
1.548 +
1.549 + TCapsInfo capsInfo;
1.550 + TInt r = iUsbHostMsLun.Caps(capsInfo);
1.551 + if (KErrNone == r)
1.552 + {
1.553 + c.iBlockSize = capsInfo.iBlockLength;
1.554 + TUint64 size = iMsDataMemMap.DataSize();
1.555 + if (size == 0)
1.556 + {
1.557 + // No valid partitions so specify the size of the disk
1.558 + size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
1.559 + }
1.560 + c.iSize = size;
1.561 +
1.562 + c.iEraseBlockSize = 0;
1.563 +
1.564 + if (capsInfo.iWriteProtect)
1.565 + {
1.566 + c.iMediaAtt |= KMediaAttWriteProtected;
1.567 + }
1.568 + __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"),
1.569 + capsInfo.iNumberOfBlocks, capsInfo.iBlockLength,
1.570 + caps().iSize, caps().iMediaAtt);
1.571 + }
1.572 + else
1.573 + {
1.574 + __HOSTPRINT(_L("<<< HOST Caps Media Not Present"));
1.575 + c.iType = EMediaNotPresent;
1.576 + if(r != KErrNotReady)
1.577 + r = KErrUnknown;
1.578 + }
1.579 + anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength()));
1.580 + return r;
1.581 + }
1.582 +
1.583 +
1.584 +
1.585 +/**
1.586 +Format the proxy drive. The drive is assumed to be a single partition. The
1.587 +partition size is equivalent to the size of the media.
1.588 +
1.589 +@param aPos The position of the data which is being formatted.
1.590 +@param aLength [IN] The length of the data which is being formatted. [OUT] The
1.591 +length of data formatted, truncated when end of drive is reached.
1.592 +
1.593 +@return system wide error code.
1.594 +*/
1.595 +TInt CUsbHostMsProxyDrive::Erase(TInt64 aPos, TInt& aLength)
1.596 + {
1.597 + __MSFNSLOG
1.598 + __HOSTPRINT3(_L("\n HOST Erase Pos=0x%lx LBA=0x%lx 0x%x"),
1.599 + aPos, aPos/KBlockSize, aLength);
1.600 + TInt err = iMsDataMemMap.TranslateDataPos(aPos, aLength);
1.601 +
1.602 + if (err)
1.603 + return err;
1.604 +
1.605 + err = iUsbHostMsLun.Erase(aPos, aLength);
1.606 + return err;
1.607 + }
1.608 +
1.609 +
1.610 +/**
1.611 +Format the proxy drive.
1.612 +
1.613 +@param aPos The position of the data which is being formatted.
1.614 +@param aLength The length of the data which is being formatted.
1.615 +
1.616 +@return system wide error code.
1.617 +*/
1.618 +TInt CUsbHostMsProxyDrive::Format(TInt64 aPos, TInt aLength)
1.619 + {
1.620 + __MSFNSLOG
1.621 + return Erase(aPos, aLength);
1.622 + }
1.623 +
1.624 +
1.625 +/**
1.626 +Format the connected drive.
1.627 +
1.628 +@param anInfo Device specific format information.
1.629 +
1.630 +@return system wide error code.
1.631 +*/
1.632 +TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo)
1.633 + {
1.634 + __MSFNSLOG
1.635 +
1.636 + const TInt KDefaultMaxBytesPerFormat = 0x100 * TMsDataMemMap::KSectorSize; // 128K
1.637 +
1.638 + if (aInfo.i512ByteSectorsFormatted < 0)
1.639 + return KErrArgument;
1.640 +
1.641 + if (!aInfo.iFormatIsCurrent)
1.642 + {
1.643 + aInfo.iFormatIsCurrent = ETrue;
1.644 + aInfo.i512ByteSectorsFormatted = 0;
1.645 + aInfo.iMaxBytesPerFormat = KDefaultMaxBytesPerFormat;
1.646 +
1.647 + TLocalDriveCapsV6Buf caps;
1.648 + TInt r = Caps(caps);
1.649 + if (r != KErrNone)
1.650 + return r;
1.651 +
1.652 + iMsDataMemMap.InitDataArea(caps().iSize);
1.653 + }
1.654 +
1.655 + TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << TMsDataMemMap::KFormatSectorShift;
1.656 + TInt length = aInfo.iMaxBytesPerFormat;
1.657 + TInt r = Erase(pos, length);
1.658 +
1.659 + if (r == KErrNone)
1.660 + {
1.661 + length += TMsDataMemMap::KSectorSize - 1;
1.662 + length >>= TMsDataMemMap::KFormatSectorShift;
1.663 + aInfo.i512ByteSectorsFormatted += length;
1.664 + }
1.665 +
1.666 + return r;
1.667 + }
1.668 +
1.669 +
1.670 +TInt CUsbHostMsProxyDrive::NotifyChange(TDes8 &aChanged,TRequestStatus* aStatus)
1.671 + {
1.672 + __MSFNSLOG
1.673 + iUsbHostMsLun.NotifyChange(aChanged, *aStatus);
1.674 +
1.675 + if(*aStatus != KRequestPending)
1.676 + return KErrUnknown;
1.677 +
1.678 + return KErrNone;
1.679 + }
1.680 +
1.681 +void CUsbHostMsProxyDrive::NotifyChangeCancel()
1.682 + {
1.683 + __MSFNSLOG
1.684 + iUsbHostMsLun.NotifyChangeCancel();
1.685 + }
1.686 +
1.687 +TInt CUsbHostMsProxyDrive::SetMountInfo(const TDesC8* /*aMountInfo*/,TInt /*aMountInfoThreadHandle=KCurrentThreadHandle*/)
1.688 + {
1.689 + __MSFNSLOG
1.690 + return KErrNone;
1.691 + }
1.692 +
1.693 +TInt CUsbHostMsProxyDrive::ForceRemount(TUint aFlags)
1.694 + {
1.695 + __MSFNSLOG
1.696 + iUsbHostMsLun.ForceRemount(aFlags);
1.697 + return KErrNone;
1.698 + }
1.699 +
1.700 +TInt CUsbHostMsProxyDrive::Unlock(TMediaPassword& /*aPassword*/, TBool /*aStorePassword*/)
1.701 + {
1.702 + __MSFNSLOG
1.703 + return KErrNotSupported;
1.704 + }
1.705 +
1.706 +TInt CUsbHostMsProxyDrive::Lock(TMediaPassword& /*aOldPassword*/, TMediaPassword& /*aNewPassword*/, TBool /*aStorePassword*/)
1.707 + {
1.708 + __MSFNSLOG
1.709 + return KErrNotSupported;
1.710 + }
1.711 +
1.712 +TInt CUsbHostMsProxyDrive::Clear(TMediaPassword& /*aPassword*/)
1.713 + {
1.714 + __MSFNSLOG
1.715 + return KErrNotSupported;
1.716 + }
1.717 +
1.718 +TInt CUsbHostMsProxyDrive::ErasePassword()
1.719 + {
1.720 + __MSFNSLOG
1.721 + return KErrNotSupported;
1.722 + }
1.723 +
1.724 +TInt CUsbHostMsProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
1.725 + {
1.726 + switch(aInterfaceId)
1.727 + {
1.728 + case ELocalBufferSupport:
1.729 + return KErrNone;
1.730 + case EFinalised:
1.731 + {
1.732 + TBool isFinalised = (TBool)aInput;
1.733 + if(isFinalised)
1.734 + {
1.735 + iUsbHostMsLun.SuspendLun();
1.736 + }
1.737 + }
1.738 + return KErrNone;
1.739 + default:
1.740 + return KErrNotSupported;
1.741 + }
1.742 + }