userlibandfileserver/fileserver/shostmassstorage/msproxy/hostusbmsproxy.cpp
changeset 300 1d28c8722707
parent 245 647ab20fee2e
equal deleted inserted replaced
293:0659d0e1a03c 300:1d28c8722707
    20 */
    20 */
    21 
    21 
    22 #include <f32fsys.h>
    22 #include <f32fsys.h>
    23 
    23 
    24 #include "hostusbmsproxy.h"
    24 #include "hostusbmsproxy.h"
    25 #include "debug.h"
    25 #include "tmbr.h"
       
    26 
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 static const TUint KBlockSize = 0x200;
       
    30 #include "hostusbmsproxyTraces.h"
       
    31 #endif
    26 
    32 
    27 
    33 
    28 CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice)
    34 CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice)
    29 :   CExtProxyDrive(aMount,aDevice)
    35 :   CExtProxyDrive(aMount,aDevice)
    30 	{
    36     {
    31 	__MSFNSLOG
    37     }
    32 	}
       
    33 
    38 
    34 CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive()
    39 CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive()
    35 	{
    40     {
    36 	__MSFNSLOG
    41     iUsbHostMsLun.UnInitialise();
    37 	iUsbHostMsLun.UnInitialise();
    42     }
    38 	}
       
    39 
    43 
    40 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo)
    44 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo)
    41 	{
    45     {
    42 	__MSFNSLOG
       
    43     RBuf8 partitionInfo;
    46     RBuf8 partitionInfo;
    44     TInt r;
    47     TInt r;
    45     TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength));
    48     TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength));
    46     if (r != KErrNone)
    49     if (r != KErrNone)
    47         {
    50         {
    48         return r;
    51         return r;
    49         }
    52         }
    50 
    53 
    51 	r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo);
    54     r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo);
    52 	if (r != KErrNone)
    55     if (r != KErrNone)
    53         {
    56         {
    54 		__PXYPRINT1(_L("!! Reading medium failed with %d !!"), r);
    57         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_10,
    55         partitionInfo.Close();
    58                   "!! Reading medium failed with %d !!", r);
    56 		return r;
    59         }
    57         }
    60     else
    58 	TUint8* buffer = const_cast<TUint8*>(partitionInfo.Ptr());
    61         {
    59 
    62         TMBRPartitionEntry partitionEntry;
    60 	// Read of the first sector successful so check for a Master Boot Record
    63         TInt partitionCount = TMbr::GetPartition(partitionInfo, partitionEntry);
    61 	if (*(reinterpret_cast<TUint16*>(&buffer[KMBRSignatureOffset]))!= KMBRSignature)
    64 
    62 		{
    65         if (partitionCount == 0)
    63 		__PXYPRINT(_L("MBR not present"));
    66             {
    64         iMsDataMemMap.Reset();
    67             OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_11,
    65         }
    68                       "No partition found");
    66 	else
    69             iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength);
    67 		{
    70             OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_12,
    68 		// Move the partition entries to a 4 byte boundary
    71                          "iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x",
    69 		memcpy(&buffer[0],&buffer[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2));
    72                          0,
    70 		// Search for a x86 default boot partition - let this be the first
    73                          aCapsInfo.iNumberOfBlocks,
    71 		TMBRPartitionEntry* pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]);
    74                          aCapsInfo.iBlockLength);
    72 
    75 
    73 		TInt firstValidPartitionCount = -1;
    76             }
    74 		TInt defaultPartitionNumber = -1;
    77         else if (partitionCount > 0)
    75 		TInt partitionCount = 0;
    78             {
    76 		for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++)
    79             iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector,
    77 			{
       
    78 			if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition() || pe->IsValidExFATPartition())
       
    79 				{
       
    80 				__PXYPRINT(_L("Found a Valid Partition"));
       
    81 				partitionCount++;
       
    82 
       
    83 				if (firstValidPartitionCount < 0)
       
    84 					firstValidPartitionCount = i;
       
    85 
       
    86 				if (pe->iX86BootIndicator == KBootIndicatorBootable)
       
    87                     {
       
    88 					defaultPartitionNumber = i;
       
    89 					break;
       
    90                     }
       
    91 				}
       
    92 			else
       
    93 				{
       
    94 				__PXYPRINT(_L("!! Invalid Partition !!"));
       
    95 				}
       
    96 			}
       
    97 
       
    98 		// Check the validity of the partition address boundaries
       
    99 	    if (partitionCount > 0)
       
   100 		    {
       
   101             __PXYPRINT1(_L("Using Partition %d"), partitionCount);
       
   102 			pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]);
       
   103             TInt partitionIndex = firstValidPartitionCount;
       
   104             if (defaultPartitionNumber > 0)
       
   105                 {
       
   106                 partitionIndex = defaultPartitionNumber;
       
   107                 }
       
   108 
       
   109             TMBRPartitionEntry& partitionEntry = pe[partitionIndex];
       
   110 
       
   111 			iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector,
       
   112                                        partitionEntry.iNumSectors,
    80                                        partitionEntry.iNumSectors,
   113                                        aCapsInfo.iBlockLength);
    81                                        aCapsInfo.iBlockLength);
   114 			__PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"),
    82             OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_13,
   115 						partitionCount, partitionIndex);
    83                          "iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x",
   116 			__PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"),                         
    84                          partitionEntry.iFirstSector,
   117 						partitionEntry.iFirstSector,
    85                          partitionEntry.iNumSectors,
   118 						partitionEntry.iNumSectors,
    86                          aCapsInfo.iBlockLength);
   119                         aCapsInfo.iBlockLength);
    87             }
   120 			}
    88         else    // MBR is not valid
   121 		else
    89             {
   122 			{
    90             iMsDataMemMap.Reset();
   123             __PXYPRINT(_L("No partition found"));
    91             OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_14,
   124 			iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength);
    92                       "MBR not present");
   125 			__PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"),
    93             }
   126 						0, 
    94         }
   127                         aCapsInfo.iNumberOfBlocks,
       
   128                         aCapsInfo.iBlockLength);
       
   129 			}
       
   130 		}
       
   131 
       
   132     partitionInfo.Close();
    95     partitionInfo.Close();
   133 	return KErrNone;
    96     return r;
   134 	}
    97     }
       
    98 
   135 
    99 
   136 /**
   100 /**
   137 Initialise the proxy drive.
   101 Initialise the proxy drive.
   138 @return system wide error code.
   102 @return system wide error code.
   139 */
   103 */
   140 TInt CUsbHostMsProxyDrive::Initialise()
   104 TInt CUsbHostMsProxyDrive::Initialise()
   141 	{
   105     {
   142 	__MSFNSLOG
   106     OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_20,
   143     __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::Initialise()"));
   107               ">>> CUsbHostMsProxyDrive::Initialise()");
   144 
   108 
   145 	if(Mount())
   109     if(Mount())
   146 		{
   110         {
   147 		// as we can't currently handle remounting devices that have
   111         // as we can't currently handle remounting devices that have
   148 		// been removed by unplugging the USB cable, disable critical notifiers
   112         // been removed by unplugging the USB cable, disable critical notifiers
   149 		// as there's no point in asking the user to re-insert the disk.
   113         // as there's no point in asking the user to re-insert the disk.
   150 		Mount()->SetNotifyOff();
   114         Mount()->SetNotifyOff();
   151 		}
   115         }
   152 
   116 
   153     // Check for media presence
   117     // Check for media presence
   154 	TCapsInfo capsInfo;
   118     TCapsInfo capsInfo;
   155 	TInt err = iUsbHostMsLun.Caps(capsInfo);
   119     TInt err = iUsbHostMsLun.Caps(capsInfo);
   156 
   120 
   157     if (err == KErrNone && capsInfo.iMediaType == EMediaHardDisk)
   121     if (err == KErrNone && capsInfo.iMediaType == EMediaHardDisk)
   158         {
   122         {
   159         err = InitialiseOffset(capsInfo);
   123         err = InitialiseOffset(capsInfo);
   160         }
   124         }
   161 
   125 
   162     __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::Initialise() err = %d"), err);
   126     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_21,
       
   127               "<<< CUsbHostMsProxyDrive::Initialise() err = %d", err);
   163     return err;
   128     return err;
   164 	}
   129     }
   165 
   130 
   166 TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3)
   131 TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3)
   167     {
   132     {
   168 	__MSFNSLOG
   133     OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_22,
   169     __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::SetInfo()"));
   134               ">>> CUsbHostMsProxyDrive::SetInfo()");
   170 	TMassStorageUnitInfo iUnitInfo;
   135     TMassStorageUnitInfo iUnitInfo;
   171     TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo);
   136     TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo);
   172 	TRAPD(err, msg.ReadL(2, infoPckg));
   137     TRAPD(err, msg.ReadL(2, infoPckg));
   173 
   138 
   174 	if(err != KErrNone)
   139     if(err != KErrNone)
   175 		{
   140         {
   176 		__PXYPRINT1(_L("Cant read from the RMessage %d"), err);
   141         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_23,
   177         __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
   142                   "Cant read from the RMessage %d", err);
   178 		return err;
   143         OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_24,
   179 		}
   144                   "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err);
   180 
   145         return err;
   181 	err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID);
   146         }
   182 	if(err != KErrNone)
   147 
   183 		{
   148     err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID);
   184 		__PXYPRINT1(_L("Initialising logical unit failed %d"), err);
   149     if(err != KErrNone)
   185         __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
   150         {
   186 		return err;
   151         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_25,
   187 		}
   152                   "Initialising logical unit failed %d", err);
   188 
   153         OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_26,
   189     __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err);
   154                   "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err);
   190 	return err;
   155         return err;
       
   156         }
       
   157 
       
   158     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_27,
       
   159               "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err);
       
   160     return err;
   191     }
   161     }
   192 
   162 
   193 TInt CUsbHostMsProxyDrive::Dismounted()
   163 TInt CUsbHostMsProxyDrive::Dismounted()
   194 	{
   164     {
   195 	__MSFNSLOG
   165     return KErrNone;
   196 	return KErrNone;
   166     }
   197 	}
       
   198 
   167 
   199 TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/)
   168 TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/)
   200 	{
   169     {
   201 	__MSFNSLOG
   170     return KErrNotSupported;
   202 	return KErrNotSupported;
   171     }
   203 	}
       
   204 
   172 
   205 
   173 
   206 TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/)
   174 TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/)
   207 	{
   175     {
   208 	__MSFNSLOG
   176     return KErrNotSupported;
   209 	return KErrNotSupported;
   177     }
   210 	}
   178 
   211 
   179 #define GetIndex(msg, aAddress, aIndex)         \
   212 #define GetIndex(msg, aAddress, aIndex)			\
   180     aIndex = msg.Ptr0() == aAddress ? 0 :               \
   213 	aIndex = msg.Ptr0() == aAddress ? 0 :				\
   181                 msg.Ptr1() == aAddress ? 1 :            \
   214 				msg.Ptr1() == aAddress ? 1 :			\
   182                     msg.Ptr1() == aAddress ? 2 :        \
   215 					msg.Ptr1() == aAddress ? 2 :		\
   183                         msg.Ptr1() == aAddress ? 3 : -1;
   216 						msg.Ptr1() == aAddress ? 3 : -1;
       
   217 
   184 
   218 /**
   185 /**
   219 Read from the proxy drive.
   186 Read from the proxy drive.
   220 
   187 
   221 @param aPos    The address from where the read begins.
   188 @param aPos    The address from where the read begins.
   226 
   193 
   227 @return system wide error code.
   194 @return system wide error code.
   228 */
   195 */
   229 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
   196 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
   230                                 const TAny* aTrg, TInt aThreadHandle, TInt aOffset)
   197                                 const TAny* aTrg, TInt aThreadHandle, TInt aOffset)
   231 	{
   198     {
   232 	__MSFNSLOG
   199     OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_300,
   233     __HOSTPRINT4(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x 0x%x"),
   200                  ">>> HOST Read Pos=0x%x %x LBA=0x%x %x",
   234                  aPos, aPos/KBlockSize, aLength, aOffset);
   201                  I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize));
   235 
   202     OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_301,
   236 	TBool localMessage = (aThreadHandle == KLocalMessageHandle);
   203                  ">>> Len 0x%x Offset 0x%x",
   237 
   204                  (TUint)aLength, (TUint)aOffset);
   238 	//
   205 
   239 	// Set file position to where we want to read...
   206     TBool localMessage = (aThreadHandle == KLocalMessageHandle);
   240 	//
   207 
   241 	if(!localMessage)
   208     //
   242 		{
   209     // Set file position to where we want to read...
   243 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   210     //
   244 		localMessage = (msg.Handle() == KLocalMessageHandle);
   211     if(!localMessage)
   245 		}
   212         {
   246 
   213         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   247 	TInt index = 0;
   214         localMessage = (msg.Handle() == KLocalMessageHandle);
   248 	if (!localMessage)
   215         }
   249 		{
   216 
   250 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   217     TInt index = 0;
   251 		GetIndex(msg, aTrg, index);
   218     if (!localMessage)
   252 
   219         {
   253 		if (index < 0)
   220         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   254             {
   221         GetIndex(msg, aTrg, index);
   255             __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrArgument);
   222 
       
   223         if (index < 0)
       
   224             {
       
   225             OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_302,
       
   226                       "<<< HOST Read ret=%d", KErrArgument);
   256             return KErrArgument;
   227             return KErrArgument;
   257             }
   228             }
   258 		}
   229         }
   259 
   230 
   260 	/* Calculate the end position */
   231     /* Calculate the end position */
   261 	TInt64 end = aPos + static_cast<TInt64>(aLength);
   232     TInt64 end = aPos + static_cast<TInt64>(aLength);
   262 
   233 
   263 	/* check whether there is enough source data to write to the destination descriptor */
   234     /* check whether there is enough source data to write to the destination descriptor */
   264 	TInt64 truncate;
   235     TInt64 truncate;
   265 	if(localMessage)
   236     if(localMessage)
   266 		{
   237         {
   267 		truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset);
   238         truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset);
   268 	    __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aTrg)->MaxLength());
   239         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_303,
   269 		}
   240                   "Descriptor length: %08x", ((TPtr8* )aTrg)->MaxLength());
   270 	else
   241         }
   271 		{
   242     else
   272 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   243         {
   273 		truncate = aLength - (msg.GetDesMaxLength(index) - aOffset);
   244         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   274 	    __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesMaxLength(index));
   245         truncate = aLength - (msg.GetDesMaxLength(index) - aOffset);
   275 		}
   246         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_304,
   276 
   247                   "Descriptor length: %08x", msg.GetDesMaxLength(index));
   277 	__PXYPRINT1(_L("Offset: %08x"), aOffset);
   248         }
   278 	__PXYPRINT1(_L("Truncate: 0x%lx"), truncate);
   249 
   279 
   250     OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_305,
   280 	if (truncate > 0)
   251               "Offset: %08x", aOffset);
   281 		{
   252     OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_306,
   282 		end -= truncate;
   253               "Truncate: 0x%lx", truncate);
   283 		}
   254 
   284 
   255     if (truncate > 0)
   285 	iBuf.SetMax();
   256         {
       
   257         end -= truncate;
       
   258         }
       
   259 
       
   260     iBuf.SetMax();
   286     TInt r;
   261     TInt r;
   287     TInt64 mediaPos;
   262     TInt64 mediaPos;
   288 	while (aPos < end)
   263     while (aPos < end)
   289         {
   264         {
   290 		TInt len = end - aPos;
   265         TInt len = end - aPos;
   291         mediaPos = aPos;
   266         mediaPos = aPos;
   292         r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
   267         r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
   293         if (r != KErrNone)
   268         if (r != KErrNone)
   294             {
   269             {
   295             __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
   270             OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_307,
       
   271                       "<<< HOST Read ret=%d", r);
   296             return r;
   272             return r;
   297             }
   273             }
   298 
   274 
   299 		if (localMessage)
   275         if (localMessage)
   300 			{
   276             {
   301 			TPtr8* pTrgPtr = (TPtr8*)aTrg;
   277             TPtr8* pTrgPtr = (TPtr8*)aTrg;
   302 			TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset);
   278             TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset);
   303 			r = iUsbHostMsLun.Read(mediaPos, len, trgDes);
   279             r = iUsbHostMsLun.Read(mediaPos, len, trgDes);
   304 			if (r != KErrNone)
   280             if (r != KErrNone)
   305 				return r;
   281                 return r;
   306 			pTrgPtr->SetLength(aOffset + trgDes.Length());
   282             pTrgPtr->SetLength(aOffset + trgDes.Length());
   307 			}
   283             }
   308 		else
   284         else
   309 			{
   285             {
   310 			if (len > iBuf.MaxLength())
   286             if (len > iBuf.MaxLength())
   311 				len = iBuf.MaxLength();
   287                 len = iBuf.MaxLength();
   312 
   288 
   313             r = iUsbHostMsLun.Read(mediaPos, len, iBuf);
   289             r = iUsbHostMsLun.Read(mediaPos, len, iBuf);
   314 			if (r != KErrNone)
   290             if (r != KErrNone)
   315                 {
   291                 {
   316                 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
   292                 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_308,
       
   293                           "<<< HOST Read ret=%d", r);
   317                 return r;
   294                 return r;
   318                 }
   295                 }
   319 
   296 
   320 			iBuf.SetLength(len);
   297             iBuf.SetLength(len);
   321 
   298 
   322 			RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   299             RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   323 			r = msg.Write(index, iBuf, aOffset);
   300             r = msg.Write(index, iBuf, aOffset);
   324 			if (r != KErrNone)
   301             if (r != KErrNone)
   325                 {
   302                 {
   326                 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r);
   303                 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_309,
       
   304                           "<<< HOST Read ret=%d", r);
   327                 return r;
   305                 return r;
   328                 }
   306                 }
   329 			}
   307             }
   330 
   308 
   331         aPos += len;
   309         aPos += len;
   332         aOffset += len;
   310         aOffset += len;
   333         }
   311         }
   334 
   312 
   335     __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrNone);
   313     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_310,
   336 	return KErrNone;
   314               "<<< HOST Read ret=%d", KErrNone);
   337 	}
   315     return KErrNone;
       
   316     }
   338 
   317 
   339 
   318 
   340 /**
   319 /**
   341 Read from the proxy drive, and pass flags to driver.
   320 Read from the proxy drive, and pass flags to driver.
   342 
   321 
   349 
   328 
   350 @return system wide error code.
   329 @return system wide error code.
   351 */
   330 */
   352 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
   331 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength,
   353                                 const TAny* aTrg, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
   332                                 const TAny* aTrg, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
   354 	{
   333     {
   355 	__MSFNSLOG
   334     return Read(aPos, aLength, aTrg, aThreadHandle, aOffset);
   356 	return Read(aPos, aLength, aTrg, aThreadHandle, aOffset);
   335     }
   357 	}
       
   358 
   336 
   359 /**
   337 /**
   360 Read from the proxy drive.
   338 Read from the proxy drive.
   361 
   339 
   362 @param aPos    The address from where the read begins.
   340 @param aPos    The address from where the read begins.
   364 @param aTrg    A descriptor of the memory buffer from which to read.
   342 @param aTrg    A descriptor of the memory buffer from which to read.
   365 
   343 
   366 @return system wide error code.
   344 @return system wide error code.
   367 */
   345 */
   368 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, TDes8& aTrg)
   346 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, TDes8& aTrg)
   369 	{
   347     {
   370 	__MSFNSLOG
   348     OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_40,
   371     __HOSTPRINT3(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x"),
   349                  ">>> HOST Read Pos=0x%x %x LBA=0x%x %x 0x%x",
   372                  aPos, aPos/KBlockSize, aLength);
   350                  I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aLength);
   373 	return iUsbHostMsLun.Read(iMsDataMemMap.GetDataPos(aPos), aLength, aTrg);
   351     return iUsbHostMsLun.Read(iMsDataMemMap.GetDataPos(aPos), aLength, aTrg);
   374 	}
   352     }
   375 
   353 
   376 /**
   354 /**
   377 Write to the proxy drive.
   355 Write to the proxy drive.
   378 
   356 
   379 @param aPos    The address from where the write begins.
   357 @param aPos    The address from where the write begins.
   384 
   362 
   385 @return system wide error code.
   363 @return system wide error code.
   386 */
   364 */
   387 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
   365 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
   388                                  const TAny* aSrc, TInt aThreadHandle, TInt aOffset)
   366                                  const TAny* aSrc, TInt aThreadHandle, TInt aOffset)
   389 	{
   367     {
   390 	//
   368     //
   391 	// Set file position to where we want to write...
   369     // Set file position to where we want to write...
   392 	//
   370     //
   393 	__MSFNSLOG
   371     OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_50,
   394     __HOSTPRINT4(_L("\n>>> HOST Write Pos=0x%lx LBA=0%lx 0x%x 0x%x"),
   372                  ">>> HOST Write Pos=0x%x %x LBA=0%x %x",
   395                  aPos, aPos/KBlockSize, aLength, aOffset);
   373                  I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize));
   396 
   374     OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_501,
   397 	TBool localMessage = (aThreadHandle == KLocalMessageHandle);
   375                  "Len=0x%x Offset=0x%x",
   398 
   376                  (TUint)aLength, (TUint)aOffset);
   399 	if(!localMessage)
   377 
   400 		{
   378     TBool localMessage = (aThreadHandle == KLocalMessageHandle);
   401 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   379 
   402 		localMessage = (msg.Handle() == KLocalMessageHandle);
   380     if(!localMessage)
   403 		}
   381         {
   404 
   382         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   405 	TInt index = 0;
   383         localMessage = (msg.Handle() == KLocalMessageHandle);
   406 	if(!localMessage)
   384         }
   407 		{
   385 
   408 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   386     TInt index = 0;
   409 		GetIndex(msg, aSrc, index);
   387     if(!localMessage)
   410 
   388         {
   411 		if (index < 0)
   389         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   412 			return KErrArgument;
   390         GetIndex(msg, aSrc, index);
   413 		}
   391 
   414 
   392         if (index < 0)
   415 	/* Calculate the end position */
   393             return KErrArgument;
   416 	TInt64 end =  aPos + static_cast<TInt64>(aLength);
   394         }
   417 	/* check whether there is enough source data to read */
   395 
   418 	TInt64 truncate;
   396     /* Calculate the end position */
   419 	if (localMessage)
   397     TInt64 end =  aPos + static_cast<TInt64>(aLength);
   420 		{
   398     /* check whether there is enough source data to read */
   421 		truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset);
   399     TInt64 truncate;
   422 	    __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aSrc)->Length());
   400     if (localMessage)
   423 		}
   401         {
   424 	else
   402         truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset);
   425 		{
   403         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_51,
   426 		RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   404                   "Descriptor length: %08x", ((TPtr8* )aSrc)->Length());
   427 		truncate = aLength - (msg.GetDesLength(index) - aOffset);
   405         }
   428 	    __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesLength(index));
   406     else
   429 		}
   407         {
   430 
   408         RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   431 	__PXYPRINT1(_L("Offset: %08x"), aOffset);
   409         truncate = aLength - (msg.GetDesLength(index) - aOffset);
   432 	__PXYPRINT1(_L("Truncate: 0x%lx"), truncate);
   410         OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_52,
   433 
   411                   "Descriptor length: %08x", msg.GetDesLength(index));
   434 	/* if truncate is > 0  we are short of source data as claimed by the aLength. Hence adjust the 'end' */
   412         }
   435 	if (truncate > 0)
   413 
   436 		{
   414     OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_53,
   437 		end -= truncate;
   415               "Offset: %08x", aOffset);
   438 		}
   416     OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_54,
   439 
   417               "Truncate: 0x%lx", truncate);
   440 	iBuf.SetMax();
   418 
       
   419     /* if truncate is > 0  we are short of source data as claimed by the aLength. Hence adjust the 'end' */
       
   420     if (truncate > 0)
       
   421         {
       
   422         end -= truncate;
       
   423         }
       
   424 
       
   425     iBuf.SetMax();
   441 
   426 
   442     TInt r;
   427     TInt r;
   443     TInt64 mediaPos;
   428     TInt64 mediaPos;
   444 	while (aPos < end)
   429     while (aPos < end)
   445         {
   430         {
   446 		TInt len = end - aPos;
   431         TInt len = end - aPos;
   447         mediaPos = aPos;
   432         mediaPos = aPos;
   448         r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
   433         r = iMsDataMemMap.CheckBlockInRange(mediaPos, len);
   449         if (r != KErrNone)
   434         if (r != KErrNone)
   450             {
   435             {
   451             __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
   436             OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_55,
       
   437                       "<<< HOST Write ret=%d", r);
   452             return r;
   438             return r;
   453             }
   439             }
   454 
   440 
   455 		if (localMessage)
   441         if (localMessage)
   456 			{
   442             {
   457 			r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset));
   443             r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset));
   458 
   444 
   459 			if (r != KErrNone)
   445             if (r != KErrNone)
   460                 {
   446                 {
   461                 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
   447                 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_56,
       
   448                           "<<< HOST Write ret=%d", r);
   462                 return r;
   449                 return r;
   463                 }
   450                 }
   464 			}
   451             }
   465 		else
   452         else
   466 			{
   453             {
   467 			if (len > iBuf.Length())
   454             if (len > iBuf.Length())
   468 				len = iBuf.Length();
   455                 len = iBuf.Length();
   469 
   456 
   470 			RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   457             RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle);
   471 			r = msg.Read(index, iBuf, aOffset);
   458             r = msg.Read(index, iBuf, aOffset);
   472 			if (r != KErrNone)
   459             if (r != KErrNone)
   473                 {
   460                 {
   474                 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
   461                 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_57,
       
   462                           "<<< HOST Write ret=%d", r);
   475                 return r;
   463                 return r;
   476                 }
   464                 }
   477 
   465 
   478 			r = iUsbHostMsLun.Write(mediaPos, len, iBuf);
   466             r = iUsbHostMsLun.Write(mediaPos, len, iBuf);
   479 			if (r != KErrNone)
   467             if (r != KErrNone)
   480                 {
   468                 {
   481                 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r);
   469                 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_58,
       
   470                           "<<< HOST Write ret=%d", r);
   482                 return r;
   471                 return r;
   483                 }
   472                 }
   484 			}
   473             }
   485 
   474 
   486         aPos += len;
   475         aPos += len;
   487         aOffset += len;
   476         aOffset += len;
   488         }
   477         }
   489 
   478 
   490     __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone);
   479     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_59,
   491 	return KErrNone;
   480               "<<< HOST Write ret=%d", KErrNone);
   492 	}
   481     return KErrNone;
       
   482     }
   493 
   483 
   494 
   484 
   495 /**
   485 /**
   496 Write to the proxy drive and pass flags to driver
   486 Write to the proxy drive and pass flags to driver
   497 
   487 
   504 
   494 
   505 @return system wide error code.
   495 @return system wide error code.
   506 */
   496 */
   507 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
   497 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength,
   508                                  const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
   498                                  const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */)
   509 	{
   499     {
   510 	__MSFNSLOG
   500     return Write(aPos, aLength, aSrc, aThreadHandle, aOffset);
   511 	return Write(aPos, aLength, aSrc, aThreadHandle, aOffset);
   501     }
   512 	}
       
   513 
   502 
   514 /**
   503 /**
   515 Write to the proxy drive.
   504 Write to the proxy drive.
   516 
   505 
   517 @param aPos    The address from where the write begins.
   506 @param aPos    The address from where the write begins.
   518 @param aSrc    A descriptor of the memory buffer from which to write.
   507 @param aSrc    A descriptor of the memory buffer from which to write.
   519 
   508 
   520 @return system wide error code.
   509 @return system wide error code.
   521 */
   510 */
   522 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
   511 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
   523 	{
   512     {
   524 	__MSFNSLOG
   513     OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_60,
   525     __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"),
   514                  ">>> HOST Write Pos=0x%x %x LBA=0x%x %x Len=0x%x",
   526                  aPos, aPos/KBlockSize, aSrc.Length());
   515                  I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aSrc.Length());
   527 	return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc);
   516     return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc);
   528 	}
   517     }
   529 
   518 
   530 
   519 
   531 /**
   520 /**
   532 Get the proxy drive's capabilities information.
   521 Get the proxy drive's capabilities information.
   533 
   522 
   534 @param anInfo A descriptor of the connected drives capabilities.
   523 @param anInfo A descriptor of the connected drives capabilities.
   535 
   524 
   536 @return system wide error code
   525 @return system wide error code
   537 */
   526 */
   538 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo)
   527 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo)
   539 	{
   528     {
   540 	__MSFNSLOG
   529     OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_70,
   541     __HOSTPRINT(_L(">>> HOST Caps"));
   530               ">>> HOST Caps");
   542 	TLocalDriveCapsV6Buf caps;
   531     TLocalDriveCapsV6Buf caps;
   543     caps.FillZ();
   532     caps.FillZ();
   544 
   533 
   545     TLocalDriveCapsV6& c = caps();
   534     TLocalDriveCapsV6& c = caps();
   546 
   535 
   547     c.iConnectionBusType = EConnectionBusUsb;
   536     c.iConnectionBusType = EConnectionBusUsb;
   548 	c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal;
   537     c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal;
   549 	c.iMediaAtt = KMediaAttFormattable;
   538     c.iMediaAtt = KMediaAttFormattable;
   550 	c.iFileSystemId = KDriveFileSysFAT;
   539     c.iFileSystemId = KDriveFileSysFAT;
   551 
   540 
   552 	TCapsInfo capsInfo;
   541     TCapsInfo capsInfo;
   553 	TInt r = iUsbHostMsLun.Caps(capsInfo);
   542     TInt r = iUsbHostMsLun.Caps(capsInfo);
   554 
   543 
   555 	if (KErrNone == r)
   544     if (KErrNone == r)
   556 		{
   545         {
   557         c.iType = capsInfo.iMediaType;
   546         c.iType = capsInfo.iMediaType;
   558 
   547 
   559         if (capsInfo.iMediaType == EMediaHardDisk)
   548         if (capsInfo.iMediaType == EMediaHardDisk)
   560             {
   549             {
   561             c.iBlockSize = capsInfo.iBlockLength;
   550             c.iBlockSize = capsInfo.iBlockLength;
   562             TUint64 size = iMsDataMemMap.DataSize();
   551             TUint64 size = iMsDataMemMap.DataSize();
   563     
   552 
   564             if (size == 0)
   553             if (size == 0)
   565                 {
   554                 {
   566                 // No valid partitions so specify the size of the disk
   555                 // No valid partitions so specify the size of the disk
   567                 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
   556                 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
   568                 }
   557                 }
   569             c.iSize = size;
   558             c.iSize = size;
   570     
   559 
   571             c.iEraseBlockSize = 0;
   560             c.iEraseBlockSize = 0;
   572     
   561 
   573             if (capsInfo.iWriteProtect)
   562             if (capsInfo.iWriteProtect)
   574                 {
   563                 {
   575                 c.iMediaAtt |= KMediaAttWriteProtected;
   564                 c.iMediaAtt |= KMediaAttWriteProtected;
   576                 }
   565                 }
   577                 
   566 
   578             static const TInt K512ByteSectorSize = 0x200; // 512
   567             static const TInt K512ByteSectorSize = 0x200; // 512
   579             if(K512ByteSectorSize != capsInfo.iBlockLength)
   568             if(K512ByteSectorSize != capsInfo.iBlockLength)
   580                 {
   569                 {
   581                 // not formattable if sector size is not 512
   570                 // not formattable if sector size is not 512
   582                 c.iMediaAtt &= ~KMediaAttFormattable;
   571                 c.iMediaAtt &= ~KMediaAttFormattable;
   583                 }
   572                 }
   584             __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"),
   573             OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_710,
   585                         capsInfo.iNumberOfBlocks, capsInfo.iBlockLength,
   574                          "<<< HOST Caps Block[num=0x%x size=0x%x]",
   586                         caps().iSize, caps().iMediaAtt);
   575                          capsInfo.iNumberOfBlocks, capsInfo.iBlockLength);
       
   576             OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_711,
       
   577                          "Media size=0x%x %x", I64HIGH(caps().iSize), I64LOW(caps().iSize));
       
   578             OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_712,
       
   579                       "WP=0x%x", caps().iMediaAtt);
   587             }
   580             }
   588         else if (capsInfo.iMediaType == EMediaCdRom)
   581         else if (capsInfo.iMediaType == EMediaCdRom)
   589             {
   582             {
   590             // not formattable
   583             // not formattable
   591             c.iMediaAtt &= ~KMediaAttFormattable;
   584             c.iMediaAtt &= ~KMediaAttFormattable;
   592             __HOSTPRINT(_L(">>> HOST Caps MediaType = EMediaCdRom"));
   585             OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_72,
       
   586                       ">>> HOST Caps MediaType = EMediaCdRom");
   593             }
   587             }
   594         else
   588         else
   595             {
   589             {
   596             // do nothing
   590             // do nothing
   597             }
   591             }
   598 		}
   592         }
   599 	else if (KErrNotReady == r)
   593     else if (KErrNotReady == r)
   600         {
   594         {
   601         __HOSTPRINT(_L("<<< HOST Caps Media Not Present"));
   595         OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_73,
   602 		c.iType = EMediaNotPresent;		
   596                   "<<< HOST Caps Media Not Present");
   603 		r = KErrNone;
   597         c.iType = EMediaNotPresent;
   604         }
   598         r = KErrNone;
   605 	else if (KErrGeneral == r)
   599         }
   606         {
   600     else if (KErrGeneral == r)
   607         __HOSTPRINT(_L("<<< HOST Caps Unable to communicate with media"));
   601         {
   608 		c.iType = EMediaUnknown;		
   602         OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_74,
       
   603                   "<<< HOST Caps Unable to communicate with media");
       
   604         c.iType = EMediaUnknown;
   609         }
   605         }
   610 
   606 
   611     else
   607     else
   612         {
   608         {
   613         __HOSTPRINT(_L("<<< HOST Caps Unknown Error"));
   609         OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_75,
       
   610                   "<<< HOST Caps Unknown Error");
   614         c.iType = EMediaUnknown;
   611         c.iType = EMediaUnknown;
   615 		r = KErrUnknown;
   612         r = KErrUnknown;
   616         }
   613         }
   617 	anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength()));
   614     anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength()));
   618 	return r;
   615     return r;
   619 	}
   616     }
   620 
   617 
   621 
   618 
   622 /**
   619 /**
   623 Format the proxy drive. The drive is assumed to be a single partition. The
   620 Format the proxy drive. The drive is assumed to be a single partition. The
   624 partition size is equivalent to the size of the media.
   621 partition size is equivalent to the size of the media.
   628 length of data formatted, truncated when end of drive is reached.
   625 length of data formatted, truncated when end of drive is reached.
   629 
   626 
   630 @return system wide error code.
   627 @return system wide error code.
   631 */
   628 */
   632 TInt CUsbHostMsProxyDrive::Erase(TInt64 aPos, TInt& aLength)
   629 TInt CUsbHostMsProxyDrive::Erase(TInt64 aPos, TInt& aLength)
   633 	{
   630     {
   634 	__MSFNSLOG
   631     OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_80,
   635     __HOSTPRINT3(_L("\n HOST Erase Pos=0x%lx LBA=0x%lx 0x%x"),
   632                  "HOST Erase Pos=0x%x %x LBA=0x%x %x 0x%x",
   636                  aPos, aPos/KBlockSize, aLength);
   633                  I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aLength);
   637     TInt err = iMsDataMemMap.TranslateDataPos(aPos, aLength);
   634     TInt err = iMsDataMemMap.TranslateDataPos(aPos, aLength);
   638 
   635 
   639     if (err)
   636     if (err)
   640         return err;
   637         return err;
   641 
   638 
   642     err = iUsbHostMsLun.Erase(aPos, aLength);
   639     err = iUsbHostMsLun.Erase(aPos, aLength);
   643     return err;
   640     return err;
   644 	}
   641     }
   645 
   642 
   646 
   643 
   647 /**
   644 /**
   648 Format the proxy drive.
   645 Format the proxy drive.
   649 
   646 
   651 @param aLength The length of the data which is being formatted.
   648 @param aLength The length of the data which is being formatted.
   652 
   649 
   653 @return system wide error code.
   650 @return system wide error code.
   654 */
   651 */
   655 TInt CUsbHostMsProxyDrive::Format(TInt64 aPos, TInt aLength)
   652 TInt CUsbHostMsProxyDrive::Format(TInt64 aPos, TInt aLength)
   656 	{
   653     {
   657 	__MSFNSLOG
       
   658     return Erase(aPos, aLength);
   654     return Erase(aPos, aLength);
   659 	}
   655     }
   660 
   656 
   661 
   657 
   662 /**
   658 /**
   663 Format the connected drive.
   659 Format the connected drive.
   664 
   660 
   665 @param anInfo Device specific format information.
   661 @param anInfo Device specific format information.
   666 
   662 
   667 @return system wide error code.
   663 @return system wide error code.
   668 */
   664 */
   669 TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo)
   665 TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo)
   670 	{
   666     {
   671 	__MSFNSLOG
       
   672 
       
   673     const TInt KDefaultMaxBytesPerFormat = 0x100 * iMsDataMemMap.BlockLength();  // 128K
   667     const TInt KDefaultMaxBytesPerFormat = 0x100 * iMsDataMemMap.BlockLength();  // 128K
   674 
   668 
   675     if (aInfo.i512ByteSectorsFormatted < 0)
   669     if (aInfo.i512ByteSectorsFormatted < 0)
   676         return KErrArgument;
   670         return KErrArgument;
   677 
   671 
   679         {
   673         {
   680         aInfo.iFormatIsCurrent = ETrue;
   674         aInfo.iFormatIsCurrent = ETrue;
   681         aInfo.i512ByteSectorsFormatted = 0;
   675         aInfo.i512ByteSectorsFormatted = 0;
   682         aInfo.iMaxBytesPerFormat = KDefaultMaxBytesPerFormat;
   676         aInfo.iMaxBytesPerFormat = KDefaultMaxBytesPerFormat;
   683 
   677 
   684 		TLocalDriveCapsV6Buf caps;
   678         TLocalDriveCapsV6Buf caps;
   685 		TInt r = Caps(caps);
   679         TInt r = Caps(caps);
   686 		if (r != KErrNone)
   680         if (r != KErrNone)
   687 			return r;
   681             return r;
   688 
   682 
   689         iMsDataMemMap.InitDataArea(caps().iSize);
   683         iMsDataMemMap.InitDataArea(caps().iSize);
   690         }
   684         }
   691 
   685 
   692     TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift();
   686     TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift();
   703     return r;
   697     return r;
   704     }
   698     }
   705 
   699 
   706 
   700 
   707 TInt CUsbHostMsProxyDrive::NotifyChange(TDes8 &aChanged,TRequestStatus* aStatus)
   701 TInt CUsbHostMsProxyDrive::NotifyChange(TDes8 &aChanged,TRequestStatus* aStatus)
   708 	{
   702     {
   709 	__MSFNSLOG
   703     iUsbHostMsLun.NotifyChange(aChanged, *aStatus);
   710 	iUsbHostMsLun.NotifyChange(aChanged, *aStatus);
   704 
   711 
   705     if(*aStatus != KRequestPending)
   712 	if(*aStatus != KRequestPending)
   706         return KErrUnknown;
   713 		return KErrUnknown;
   707 
   714 
   708     return KErrNone;
   715 	return KErrNone;
   709     }
   716 	}
       
   717 
   710 
   718 void CUsbHostMsProxyDrive::NotifyChangeCancel()
   711 void CUsbHostMsProxyDrive::NotifyChangeCancel()
   719 	{
   712     {
   720 	__MSFNSLOG
   713     iUsbHostMsLun.NotifyChangeCancel();
   721 	iUsbHostMsLun.NotifyChangeCancel();
   714     }
   722 	}
       
   723 
   715 
   724 TInt CUsbHostMsProxyDrive::SetMountInfo(const TDesC8* /*aMountInfo*/,TInt /*aMountInfoThreadHandle=KCurrentThreadHandle*/)
   716 TInt CUsbHostMsProxyDrive::SetMountInfo(const TDesC8* /*aMountInfo*/,TInt /*aMountInfoThreadHandle=KCurrentThreadHandle*/)
   725     {
   717     {
   726 	__MSFNSLOG
       
   727     return KErrNone;
   718     return KErrNone;
   728     }
   719     }
   729 
   720 
   730 TInt CUsbHostMsProxyDrive::ForceRemount(TUint aFlags)
   721 TInt CUsbHostMsProxyDrive::ForceRemount(TUint aFlags)
   731     {
   722     {
   732 	__MSFNSLOG
       
   733     iUsbHostMsLun.ForceRemount(aFlags);
   723     iUsbHostMsLun.ForceRemount(aFlags);
   734     return KErrNone;
   724     return KErrNone;
   735     }
   725     }
   736 
   726 
   737 TInt CUsbHostMsProxyDrive::Unlock(TMediaPassword& /*aPassword*/, TBool /*aStorePassword*/)
   727 TInt CUsbHostMsProxyDrive::Unlock(TMediaPassword& /*aPassword*/, TBool /*aStorePassword*/)
   738     {
   728     {
   739 	__MSFNSLOG
       
   740     return KErrNotSupported;
   729     return KErrNotSupported;
   741     }
   730     }
   742 
   731 
   743 TInt CUsbHostMsProxyDrive::Lock(TMediaPassword& /*aOldPassword*/, TMediaPassword& /*aNewPassword*/, TBool /*aStorePassword*/)
   732 TInt CUsbHostMsProxyDrive::Lock(TMediaPassword& /*aOldPassword*/, TMediaPassword& /*aNewPassword*/, TBool /*aStorePassword*/)
   744     {
   733     {
   745 	__MSFNSLOG
       
   746     return KErrNotSupported;
   734     return KErrNotSupported;
   747     }
   735     }
   748 
   736 
   749 TInt CUsbHostMsProxyDrive::Clear(TMediaPassword& /*aPassword*/)
   737 TInt CUsbHostMsProxyDrive::Clear(TMediaPassword& /*aPassword*/)
   750     {
   738     {
   751 	__MSFNSLOG
       
   752     return KErrNotSupported;
   739     return KErrNotSupported;
   753     }
   740     }
   754 
   741 
   755 TInt CUsbHostMsProxyDrive::ErasePassword()
   742 TInt CUsbHostMsProxyDrive::ErasePassword()
   756     {
   743     {
   757 	__MSFNSLOG
       
   758     return KErrNotSupported;
   744     return KErrNotSupported;
   759     }
   745     }
   760 
   746 
   761 TInt CUsbHostMsProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
   747 TInt CUsbHostMsProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
   762 	{
   748     {
   763 	switch(aInterfaceId)
   749     switch(aInterfaceId)
   764 		{
   750         {
   765 		case ELocalBufferSupport:
   751         case ELocalBufferSupport:
   766 			return KErrNone;
   752             return KErrNone;
   767 		case EFinalised:
   753         case EFinalised:
   768 			{
   754             {
   769 			TBool isFinalised = (TBool)aInput;
   755             TBool isFinalised = (TBool)aInput;
   770 			if(isFinalised)
   756             if(isFinalised)
   771 				{
   757                 {
   772 				iUsbHostMsLun.SuspendLun();
   758                 iUsbHostMsLun.SuspendLun();
   773 				}
   759                 }
   774 			}
   760             }
   775 			return KErrNone;
   761             return KErrNone;
   776 		default:
   762         default:
   777 			return KErrNotSupported;
   763             return KErrNotSupported;
   778 		}
   764         }
   779 	}
   765     }