userlibandfileserver/fileserver/shostmassstorage/msproxy/hostusbmsproxy.cpp
changeset 119 6e99f362aa46
parent 33 0173bcd7697c
child 124 5802e2ce68ed
equal deleted inserted replaced
90:947f0dc9f7a8 119:6e99f362aa46
     1 /*
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 * All rights reserved.
     3 // This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 //
     7 //
    18 // hostusbmsproxy.cpp
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
    19 //
    10 //
    20 // This file system extension provides a way to access a drive on the MS system in "raw format".
    11 // Contributors:
    21 // It can be used to test large files / drives
    12 //
       
    13 // Description:
       
    14 // This file system extension provides a way to access a drive on the MS system
       
    15 // in "raw format". It can be used to test large files / drives
    22 //
    16 //
    23 
    17 
    24 /** @file
    18 /** @file
    25 @internalTechnology
    19 @internalTechnology
    26 */
    20 */
    44 	}
    38 	}
    45 
    39 
    46 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo)
    40 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo)
    47 	{
    41 	{
    48 	__MSFNSLOG
    42 	__MSFNSLOG
    49     const TInt KPartitionInfoSize = TMsDataMemMap::KSectorSize;
    43     RBuf8 partitionInfo;
    50 	TBuf8<KPartitionInfoSize> partitionInfo;
    44     TInt r;
    51 	TInt r;
    45     TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength));
    52 
    46     if (r != KErrNone)
    53 	r = iUsbHostMsLun.Read(0 , KPartitionInfoSize, (TDes8 &) partitionInfo);
    47         {
       
    48         return r;
       
    49         }
       
    50 
       
    51 	r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo);
    54 	if (r != KErrNone)
    52 	if (r != KErrNone)
    55         {
    53         {
    56 		__PXYPRINT1(_L("!! Reading medium failed with %d !!"), r);
    54 		__PXYPRINT1(_L("!! Reading medium failed with %d !!"), r);
       
    55         partitionInfo.Close();
    57 		return r;
    56 		return r;
    58         }
    57         }
    59 	TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr();
    58 	TUint8 *iIntBuf = (TUint8 *) partitionInfo.Ptr();
    60 
    59 
    61 	// Read of the first sector successful so check for a Master Boot Record
    60 	// Read of the first sector successful so check for a Master Boot Record
   108                 }
   107                 }
   109 
   108 
   110             TMBRPartitionEntry& partitionEntry = pe[partitionIndex];
   109             TMBRPartitionEntry& partitionEntry = pe[partitionIndex];
   111 
   110 
   112 			iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector,
   111 			iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector,
   113                                        partitionEntry.iNumSectors);
   112                                        partitionEntry.iNumSectors,
       
   113                                        aCapsInfo.iBlockLength);
   114 			__PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"),
   114 			__PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"),
   115 						partitionCount, partitionIndex);
   115 						partitionCount, partitionIndex);
   116 			__PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"),
   116 			__PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"),                         
   117 						partitionEntry.iFirstSector,
   117 						partitionEntry.iFirstSector,
   118 						partitionEntry.iNumSectors);
   118 						partitionEntry.iNumSectors,
       
   119                         aCapsInfo.iBlockLength);
   119 			}
   120 			}
   120 		else
   121 		else
   121 			{
   122 			{
   122             __PXYPRINT(_L("No partition found"));
   123             __PXYPRINT(_L("No partition found"));
   123 			iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks);
   124 			iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength);
   124 			__PXYPRINT2(_L("iFirstSector = x%x iNumSectors = x%x"),
   125 			__PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"),
   125 						0, aCapsInfo.iNumberOfBlocks);
   126 						0, 
       
   127                         aCapsInfo.iNumberOfBlocks,
       
   128                         aCapsInfo.iBlockLength);
   126 			}
   129 			}
   127 		}
   130 		}
       
   131 
       
   132     partitionInfo.Close();
   128 	return KErrNone;
   133 	return KErrNone;
   129 	}
   134 	}
   130 
   135 
   131 /**
   136 /**
   132 Initialise the proxy drive.
   137 Initialise the proxy drive.
   484 
   489 
   485     __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone);
   490     __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone);
   486 	return KErrNone;
   491 	return KErrNone;
   487 	}
   492 	}
   488 
   493 
       
   494 
   489 /**
   495 /**
   490 Write to the proxy drive and pass flags to driver
   496 Write to the proxy drive and pass flags to driver
   491 
   497 
   492 @param aPos    The address from where the write begins.
   498 @param aPos    The address from where the write begins.
   493 @param aLength The length of the write.
   499 @param aLength The length of the write.
   518 	__MSFNSLOG
   524 	__MSFNSLOG
   519     __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"),
   525     __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"),
   520                  aPos, aPos/KBlockSize, aSrc.Length());
   526                  aPos, aPos/KBlockSize, aSrc.Length());
   521 	return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc);
   527 	return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc);
   522 	}
   528 	}
       
   529 
   523 
   530 
   524 /**
   531 /**
   525 Get the proxy drive's capabilities information.
   532 Get the proxy drive's capabilities information.
   526 
   533 
   527 @param anInfo A descriptor of the connected drives capabilities.
   534 @param anInfo A descriptor of the connected drives capabilities.
   560 
   567 
   561         if (capsInfo.iWriteProtect)
   568         if (capsInfo.iWriteProtect)
   562             {
   569             {
   563             c.iMediaAtt |= KMediaAttWriteProtected;
   570             c.iMediaAtt |= KMediaAttWriteProtected;
   564             }
   571             }
       
   572             
       
   573         static const TInt K512ByteSectorSize = 0x200; // 512
       
   574         if(K512ByteSectorSize != capsInfo.iBlockLength)
       
   575         	{
       
   576 	        c.iMediaAtt &= ~KMediaAttFormattable;
       
   577         	}
   565         __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"),
   578         __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"),
   566                     capsInfo.iNumberOfBlocks, capsInfo.iBlockLength,
   579                     capsInfo.iNumberOfBlocks, capsInfo.iBlockLength,
   567 		            caps().iSize, caps().iMediaAtt);
   580 		            caps().iSize, caps().iMediaAtt);
   568 		}
   581 		}
   569 	else
   582 	else if (KErrNotReady)
   570         {
   583         {
   571         __HOSTPRINT(_L("<<< HOST Caps Media Not Present"));
   584         __HOSTPRINT(_L("<<< HOST Caps Media Not Present"));
   572 		c.iType = EMediaNotPresent;
   585 		c.iType = EMediaNotPresent;		
   573 		if(r != KErrNotReady)
   586 		r = KErrNone;
   574 			r = KErrUnknown;
   587         }
       
   588     else
       
   589         {
       
   590         __HOSTPRINT(_L("<<< HOST Caps Unknown Error"));
       
   591         c.iType = EMediaUnknown;
       
   592 		r = KErrUnknown;
   575         }
   593         }
   576 	anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength()));
   594 	anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength()));
   577 	return r;
   595 	return r;
   578 	}
   596 	}
   579 
       
   580 
   597 
   581 
   598 
   582 /**
   599 /**
   583 Format the proxy drive. The drive is assumed to be a single partition. The
   600 Format the proxy drive. The drive is assumed to be a single partition. The
   584 partition size is equivalent to the size of the media.
   601 partition size is equivalent to the size of the media.
   628 */
   645 */
   629 TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo)
   646 TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo)
   630 	{
   647 	{
   631 	__MSFNSLOG
   648 	__MSFNSLOG
   632 
   649 
   633     const TInt KDefaultMaxBytesPerFormat = 0x100 * TMsDataMemMap::KSectorSize;  // 128K
   650     const TInt KDefaultMaxBytesPerFormat = 0x100 * iMsDataMemMap.BlockLength();  // 128K
   634 
   651 
   635     if (aInfo.i512ByteSectorsFormatted < 0)
   652     if (aInfo.i512ByteSectorsFormatted < 0)
   636         return KErrArgument;
   653         return KErrArgument;
   637 
   654 
   638     if (!aInfo.iFormatIsCurrent)
   655     if (!aInfo.iFormatIsCurrent)
   647 			return r;
   664 			return r;
   648 
   665 
   649         iMsDataMemMap.InitDataArea(caps().iSize);
   666         iMsDataMemMap.InitDataArea(caps().iSize);
   650         }
   667         }
   651 
   668 
   652     TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << TMsDataMemMap::KFormatSectorShift;
   669     TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift();
   653     TInt length = aInfo.iMaxBytesPerFormat;
   670     TInt length = aInfo.iMaxBytesPerFormat;
   654     TInt r = Erase(pos, length);
   671     TInt r = Erase(pos, length);
   655 
   672 
   656     if (r == KErrNone)
   673     if (r == KErrNone)
   657         {
   674         {
   658         length += TMsDataMemMap::KSectorSize - 1;
   675         length += iMsDataMemMap.BlockLength() - 1;
   659         length >>= TMsDataMemMap::KFormatSectorShift;
   676         length >>= iMsDataMemMap.FormatSectorShift();
   660         aInfo.i512ByteSectorsFormatted += length;
   677         aInfo.i512ByteSectorsFormatted += length;
   661         }
   678         }
   662 
   679 
   663     return r;
   680     return r;
   664     }
   681     }