mtpfws/mtpfw/src/cmtpstoragemgr.cpp
changeset 49 c20dd21d1eb4
parent 29 3ae5cb0b4c02
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    18 #include <mtp/mtpdatatypeconstants.h>
    18 #include <mtp/mtpdatatypeconstants.h>
    19 #include <mtp/mtpprotocolconstants.h>
    19 #include <mtp/mtpprotocolconstants.h>
    20 
    20 
    21 #include "cmtpdataprovidercontroller.h"
    21 #include "cmtpdataprovidercontroller.h"
    22 #include "cmtpstoragemgr.h"
    22 #include "cmtpstoragemgr.h"
       
    23 #include "mtpdebug.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "cmtpstoragemgrTraces.h"
       
    27 #endif
       
    28 
    23 
    29 
    24 // Class constants.
    30 // Class constants.
    25 __FLOG_STMT(_LIT8(KComponent,"StorageMgr");)
       
    26 
    31 
    27 // StorageID bit manipulation patterns.
    32 // StorageID bit manipulation patterns.
    28 static const TUint32    KLogicalIdMask(0x0000FFFF);
    33 static const TUint32    KLogicalIdMask(0x0000FFFF);
    29 static const TUint32    KPhysicalIdMask(0xFFFF0000);
    34 static const TUint32    KPhysicalIdMask(0xFFFF0000);
    30 
    35 
    52 /**
    57 /**
    53 Destructor.
    58 Destructor.
    54 */
    59 */
    55 EXPORT_C CMTPStorageMgr::~CMTPStorageMgr()
    60 EXPORT_C CMTPStorageMgr::~CMTPStorageMgr()
    56     {
    61     {
    57     __FLOG(_L8("~CMTPStorageMgr - Entry"));
    62     OstTraceFunctionEntry0( CMTPSTORAGEMGR_CMTPSTORAGEMGR_DES_ENTRY );
    58     iPhysicalStorageNumbers.Reset();
    63     iPhysicalStorageNumbers.Reset();
    59     iStorages.ResetAndDestroy();
    64     iStorages.ResetAndDestroy();
    60     iSingletons.Close();
    65     iSingletons.Close();
    61     __FLOG(_L8("~CMTPStorageMgr - Exit"));
    66     OstTraceFunctionExit0( CMTPSTORAGEMGR_CMTPSTORAGEMGR_DES_EXIT );
    62     __FLOG_CLOSE;
       
    63     }
    67     }
    64 
    68 
    65 /**
    69 /**
    66 Extracts the storage number of the logical storage ID encoded in the specified
    70 Extracts the storage number of the logical storage ID encoded in the specified
    67 StorageID.
    71 StorageID.
    68 @param aStorageId The storage ID.
    72 @param aStorageId The storage ID.
    69 @return The storage number.
    73 @return The storage number.
    70 */
    74 */
    71 EXPORT_C TUint CMTPStorageMgr::LogicalStorageNumber(TUint32 aStorageId) 
    75 EXPORT_C TUint CMTPStorageMgr::LogicalStorageNumber(TUint32 aStorageId) 
    72     {
    76     {
       
    77     OstTraceFunctionEntry0( CMTPSTORAGEMGR_LOGICALSTORAGENUMBER_ENTRY );
       
    78     OstTraceFunctionExit0( CMTPSTORAGEMGR_LOGICALSTORAGENUMBER_EXIT );
    73     return (aStorageId & KLogicalNumberMask);
    79     return (aStorageId & KLogicalNumberMask);
    74     }
    80     }
    75 
    81 
    76 /**
    82 /**
    77 Extracts the ID of the data provider responsible for the logical storage ID 
    83 Extracts the ID of the data provider responsible for the logical storage ID 
    79 @param aStorageId The storage ID.
    85 @param aStorageId The storage ID.
    80 @return The data provider owner ID.
    86 @return The data provider owner ID.
    81 */    
    87 */    
    82 EXPORT_C TUint CMTPStorageMgr::LogicalStorageOwner(TUint32 aStorageId) 
    88 EXPORT_C TUint CMTPStorageMgr::LogicalStorageOwner(TUint32 aStorageId) 
    83     {
    89     {
       
    90     OstTraceFunctionEntry0( CMTPSTORAGEMGR_LOGICALSTORAGEOWNER_ENTRY );
    84     return ((aStorageId & KLogicalIdMask) >> KLogicalOwnerShift);
    91     return ((aStorageId & KLogicalIdMask) >> KLogicalOwnerShift);
    85     }
    92     }
    86 
    93 
    87 /**
    94 /**
    88 Extracts the storage number of the physical storage ID encoded in the specified
    95 Extracts the storage number of the physical storage ID encoded in the specified
    90 @param aStorageId The storage ID.
    97 @param aStorageId The storage ID.
    91 @return The storage number.
    98 @return The storage number.
    92 */
    99 */
    93 EXPORT_C TUint CMTPStorageMgr::PhysicalStorageNumber(TUint32 aStorageId) 
   100 EXPORT_C TUint CMTPStorageMgr::PhysicalStorageNumber(TUint32 aStorageId) 
    94     {
   101     {
       
   102     OstTraceFunctionEntry0( CMTPSTORAGEMGR_PHYSICALSTORAGENUMBER_ENTRY );
    95     return ((aStorageId & KPhysicalIdMask) >> KPhysicalNumberShift);
   103     return ((aStorageId & KPhysicalIdMask) >> KPhysicalNumberShift);
    96     }
   104     }
    97     
   105     
    98 /**
   106 /**
    99 Extracts the ID of the data provider responsible for the physical storage ID 
   107 Extracts the ID of the data provider responsible for the physical storage ID 
   101 @param aStorageId The storage ID.
   109 @param aStorageId The storage ID.
   102 @return The data provider owner ID.
   110 @return The data provider owner ID.
   103 */
   111 */
   104 EXPORT_C TUint CMTPStorageMgr::PhysicalStorageOwner(TUint32 aStorageId) 
   112 EXPORT_C TUint CMTPStorageMgr::PhysicalStorageOwner(TUint32 aStorageId) 
   105     {
   113     {
       
   114     OstTraceFunctionEntry0( CMTPSTORAGEMGR_PHYSICALSTORAGEOWNER_ENTRY );
   106     return ((aStorageId & KPhysicalIdMask) >> KPhysicalOwnerShift);
   115     return ((aStorageId & KPhysicalIdMask) >> KPhysicalOwnerShift);
   107     }
   116     }
   108 
   117 
   109 /**
   118 /**
   110 Sets the default MTP StorageID. This should be set once at start up and not 
   119 Sets the default MTP StorageID. This should be set once at start up and not 
   113 @panic USER 0, in debug builds only, if the default StorageID is set more than
   122 @panic USER 0, in debug builds only, if the default StorageID is set more than
   114 once.
   123 once.
   115 */    
   124 */    
   116 EXPORT_C void CMTPStorageMgr::SetDefaultStorageId(TUint32 aStorageId)
   125 EXPORT_C void CMTPStorageMgr::SetDefaultStorageId(TUint32 aStorageId)
   117     {
   126     {
   118     __FLOG(_L8("SetDefaultStorageId - Entry"));
   127     OstTraceFunctionEntry0( CMTPSTORAGEMGR_SETDEFAULTSTORAGEID_ENTRY );
   119     iDefaultStorageId = aStorageId;
   128     iDefaultStorageId = aStorageId;
   120     __FLOG_VA((_L8("Default StorageId = 0x%08X"), aStorageId));
   129     OstTrace1(TRACE_NORMAL, CMTPSTORAGEMGR_SETDEFAULTSTORAGEID, 
   121     __FLOG(_L8("SetDefaultStorageId - Exit"));
   130             "Default StorageId = 0x%08X", aStorageId);
       
   131     OstTraceFunctionExit0( CMTPSTORAGEMGR_SETDEFAULTSTORAGEID_EXIT );
   122     }
   132     }
   123 
   133 
   124 /**
   134 /**
   125 Creates a mapping between the specified Symbian OS drive number and MTP 
   135 Creates a mapping between the specified Symbian OS drive number and MTP 
   126 StorageID.
   136 StorageID.
   128 @param aStorageId The MTP StorageID.
   138 @param aStorageId The MTP StorageID.
   129 @leave One of the sysem wide error codes, if a processing failure occurs.
   139 @leave One of the sysem wide error codes, if a processing failure occurs.
   130 */
   140 */
   131 EXPORT_C void CMTPStorageMgr::SetDriveMappingL(TDriveNumber aDriveNumber, TUint32 aStorageId)
   141 EXPORT_C void CMTPStorageMgr::SetDriveMappingL(TDriveNumber aDriveNumber, TUint32 aStorageId)
   132     {
   142     {
   133     __FLOG(_L8("DefineDriveNumberMapping - Entry"));
   143     OstTraceFunctionEntry0( CMTPSTORAGEMGR_SETDRIVEMAPPINGL_ENTRY );
   134     iMapDriveToStorage[aDriveNumber] = aStorageId;
   144     iMapDriveToStorage[aDriveNumber] = aStorageId;
   135     __FLOG_VA((_L8("Drive number %d = StorageID 0x%08X"), aDriveNumber, aStorageId));
   145     OstTraceExt2(TRACE_NORMAL, CMTPSTORAGEMGR_SETDRIVEMAPPINGL, 
   136     __FLOG(_L8("DefineDriveNumberMapping - Exit"));
   146             "Drive number %d = StorageID 0x%08X", (int)aDriveNumber, (int)aStorageId);
       
   147     OstTraceFunctionExit0( CMTPSTORAGEMGR_SETDRIVEMAPPINGL_EXIT );
   137     }
   148     }
   138 
   149 
   139 /**
   150 /**
   140 Sets the framework storages owner identifier. This should be set once at start 
   151 Sets the framework storages owner identifier. This should be set once at start 
   141 up and not subsequently changed.
   152 up and not subsequently changed.
   143 @panic USER 0, in debug builds only, if the framework storages owner identifier
   154 @panic USER 0, in debug builds only, if the framework storages owner identifier
   144 is set more than once.
   155 is set more than once.
   145 */    
   156 */    
   146 EXPORT_C void CMTPStorageMgr::SetFrameworkId(TUint aDataProviderId)
   157 EXPORT_C void CMTPStorageMgr::SetFrameworkId(TUint aDataProviderId)
   147     {
   158     {
   148     __FLOG(_L8("SetFrameworkStoragesOwner - Entry"));
   159     OstTraceFunctionEntry0( CMTPSTORAGEMGR_SETFRAMEWORKID_ENTRY );
   149     __ASSERT_DEBUG((iFrameworkId == KErrNotFound), User::Invariant());
   160     __ASSERT_DEBUG((iFrameworkId == KErrNotFound), User::Invariant());
   150     iFrameworkId = aDataProviderId;
   161     iFrameworkId = aDataProviderId;
   151     __FLOG_VA((_L8("System storages owner DP Id = %d"), aDataProviderId));
   162     OstTrace1(TRACE_NORMAL, CMTPSTORAGEMGR_SETFRAMEWORKID, 
   152     __FLOG(_L8("SetFrameworkStoragesOwner - Exit"));
   163                 "System storages owner DP Id = %d", aDataProviderId);    
       
   164     OstTraceFunctionExit0( CMTPSTORAGEMGR_SETFRAMEWORKID_EXIT );
   153     }    
   165     }    
   154     
   166     
   155 EXPORT_C TUint32 CMTPStorageMgr::AllocateLogicalStorageIdL(TUint aDataProviderId, TDriveNumber aDriveNumber, const CMTPStorageMetaData& aStorage)
   167 EXPORT_C TUint32 CMTPStorageMgr::AllocateLogicalStorageIdL(TUint aDataProviderId, TDriveNumber aDriveNumber, const CMTPStorageMetaData& aStorage)
   156     {
   168     {
   157     __FLOG(_L8("AllocateLogicalStorageIdL - Entry"));
   169     OstTraceFunctionEntry0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL_TDRIVERNUMBER_ENTRY );
   158     TUint id(AllocateLogicalStorageIdL(aDataProviderId, PhysicalStorageId(aDriveNumber), aStorage));
   170     TUint id(AllocateLogicalStorageIdL(aDataProviderId, PhysicalStorageId(aDriveNumber), aStorage));
   159     __FLOG(_L8("AllocateLogicalStorageIdL - Exit"));
   171     OstTraceFunctionExit0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL_EXIT );
   160     return id;
   172     return id;
   161     }
   173     }
   162 
   174 
   163 EXPORT_C TUint32 CMTPStorageMgr::AllocateLogicalStorageIdL(TUint aDataProviderId, TUint32 aPhysicalStorageId, const CMTPStorageMetaData& aStorage)
   175 EXPORT_C TUint32 CMTPStorageMgr::AllocateLogicalStorageIdL(TUint aDataProviderId, TUint32 aPhysicalStorageId, const CMTPStorageMetaData& aStorage)
   164     {
   176     {
   165     __FLOG(_L8("AllocateLogicalStorageIdL - Entry"));
   177     OstTraceFunctionEntry0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL_TUINT32_ENTRY );
   166     //if support uninstall DP, comment the below assert.
   178     //if support uninstall DP, comment the below assert.
   167     //__ASSERT_DEBUG((aDataProviderId < iSingletons.DpController().Count()), User::Invariant());
   179     //__ASSERT_DEBUG((aDataProviderId < iSingletons.DpController().Count()), User::Invariant());
   168     
   180     
   169     // Resolve the physical storage.
   181     // Resolve the physical storage.
   170     CMTPStorageMetaData& physical(StorageMetaDataL(aPhysicalStorageId));
   182     CMTPStorageMetaData& physical(StorageMetaDataL(aPhysicalStorageId));
   171     // Validate the SUID and storage type.
   183     // Validate the SUID and storage type.
   172     if (iStorages.Find(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), StorageKeyMatchSuid) != KErrNotFound)
   184     if (iStorages.Find(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), StorageKeyMatchSuid) != KErrNotFound)
   173         {
   185         {
   174         // SUID is not unique.
   186         // SUID is not unique.
       
   187         OstTrace0( TRACE_ERROR, CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, "SUID is not unique" );
   175         User::Leave(KErrAlreadyExists);
   188         User::Leave(KErrAlreadyExists);
   176         }
   189         }
   177     else if (aStorage.Uint(CMTPStorageMetaData::EStorageSystemType) != physical.Uint(CMTPStorageMetaData::EStorageSystemType))
   190     else if (aStorage.Uint(CMTPStorageMetaData::EStorageSystemType) != physical.Uint(CMTPStorageMetaData::EStorageSystemType))
   178         {
   191         {
   179         // Physical/logical storage type mis-match.
   192         // Physical/logical storage type mis-match.
       
   193         OstTrace0( TRACE_ERROR, DUP2_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, "Physical/logical storage type mis-match" );   
   180         User::Leave(KErrArgument);
   194         User::Leave(KErrArgument);
   181         }
   195         }
   182     else if (aStorage.Uint(CMTPStorageMetaData::EStorageSystemType) == CMTPStorageMetaData::ESystemTypeDefaultFileSystem)
   196     else if (aStorage.Uint(CMTPStorageMetaData::EStorageSystemType) == CMTPStorageMetaData::ESystemTypeDefaultFileSystem)
   183         {   
   197         {   
   184         // Validate that the SUID path exists.
   198         // Validate that the SUID path exists.
   185         if (!BaflUtils::PathExists(iSingletons.Fs(), aStorage.DesC(CMTPStorageMetaData::EStorageSuid)))
   199         if (!BaflUtils::PathExists(iSingletons.Fs(), aStorage.DesC(CMTPStorageMetaData::EStorageSuid)))
   186             {
   200             {
       
   201             OstTrace0( TRACE_ERROR, DUP3_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, "the SUID path doesn't exist" );
   187             User::Leave(KErrPathNotFound);
   202             User::Leave(KErrPathNotFound);
   188             }
   203             }
   189      
   204      
   190         // Validate that the SUID path corresponds to the physical storage drive.
   205         // Validate that the SUID path corresponds to the physical storage drive.
   191         TInt storageDrive(DriveNumber(aPhysicalStorageId));
   206         TInt storageDrive(DriveNumber(aPhysicalStorageId));
   192         TParse p;
   207         TParse p;
   193         User::LeaveIfError(p.Set(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), NULL, NULL));
   208         LEAVEIFERROR(p.Set(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), NULL, NULL),
       
   209                 OstTrace0( TRACE_ERROR, DUP4_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, "storage can't be parsed!"));       
   194         TInt suidDrive(0);
   210         TInt suidDrive(0);
   195         User::LeaveIfError(iSingletons.Fs().CharToDrive(TChar(p.Drive()[0]), suidDrive));
   211         LEAVEIFERROR(iSingletons.Fs().CharToDrive(TChar(p.Drive()[0]), suidDrive),
       
   212                 OstTrace0( TRACE_ERROR, DUP5_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, "CharToDrive failed!" ));
       
   213                 
   196         if (suidDrive != storageDrive)
   214         if (suidDrive != storageDrive)
   197             {
   215             {
   198             // SUID path/physical storage drive mis-match.
   216             // SUID path/physical storage drive mis-match.
       
   217             OstTraceExt2( TRACE_ERROR, DUP6_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, 
       
   218                     "SUID path %d /physical storage drive %d  mis-match", suidDrive, storageDrive);     
   199             User::Leave(KErrArgument);
   219             User::Leave(KErrArgument);
   200             }
   220             }
   201         }
   221         }
   202     
   222     
   203     // Allocate a logical StorageId.
   223     // Allocate a logical StorageId.
   204     TInt32 id(AllocateLogicalStorageId(aDataProviderId, aPhysicalStorageId));
   224     TInt32 id(AllocateLogicalStorageId(aDataProviderId, aPhysicalStorageId));
   205     User::LeaveIfError(id);
   225     LEAVEIFERROR(id,
   206     
   226             OstTraceExt2( TRACE_ERROR, DUP7_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL, 
       
   227                     "allocate logical storageId for Dp %d, Physical StorageId %d failed!", aDataProviderId, aPhysicalStorageId));
       
   228 
   207     // Create the logical storage meta-data.
   229     // Create the logical storage meta-data.
   208     CMTPStorageMetaData* logical(CMTPStorageMetaData::NewLC(aStorage));
   230     CMTPStorageMetaData* logical(CMTPStorageMetaData::NewLC(aStorage));
   209     logical->SetUint(CMTPStorageMetaData::EStorageId, id);
   231     logical->SetUint(CMTPStorageMetaData::EStorageId, id);
   210     
   232     
   211     // Store the logical storage meta-data.
   233     // Store the logical storage meta-data.
   218     physical.GetUintArrayL(CMTPStorageMetaData::EStorageLogicalIds, logicals);
   240     physical.GetUintArrayL(CMTPStorageMetaData::EStorageLogicalIds, logicals);
   219     logicals.InsertInOrderL(id);
   241     logicals.InsertInOrderL(id);
   220     physical.SetUintArrayL(CMTPStorageMetaData::EStorageLogicalIds, logicals);
   242     physical.SetUintArrayL(CMTPStorageMetaData::EStorageLogicalIds, logicals);
   221     CleanupStack::PopAndDestroy(&logicals);
   243     CleanupStack::PopAndDestroy(&logicals);
   222     
   244     
   223 #ifdef __FLOG_ACTIVE
   245 #ifdef OST_TRACE_COMPILER_IN_USE
   224     HBufC8* buf(HBufC8::NewLC(aStorage.DesC(CMTPStorageMetaData::EStorageSuid).Length()));
   246     HBufC8* buf(HBufC8::NewLC(aStorage.DesC(CMTPStorageMetaData::EStorageSuid).Length()));
   225     buf->Des().Copy(aStorage.DesC(CMTPStorageMetaData::EStorageSuid));
   247     buf->Des().Copy(aStorage.DesC(CMTPStorageMetaData::EStorageSuid));
   226     __FLOG_VA((_L8("Allocated logical StorageID 0x%08X for storage SUID %S"), id, buf));
   248     OstTraceExt2(TRACE_NORMAL, DUP8_CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL_TUINT32,
       
   249             "Allocated logical StorageID 0x%08X for storage SUID %s", (TUint)id, *buf);
   227     CleanupStack::PopAndDestroy(buf);
   250     CleanupStack::PopAndDestroy(buf);
   228 #endif // __FLOG_ACTIVE    
   251 #endif // OST_TRACE_COMPILER_IN_USE    
   229     __FLOG(_L8("AllocateLogicalStorageIdL - Exit"));
   252     OstTraceFunctionExit0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEIDL_TUINT32_EXIT );
   230     return id;
   253     return id;
   231     }
   254     }
   232 
   255 
   233 EXPORT_C TUint32 CMTPStorageMgr::AllocatePhysicalStorageIdL(TUint aDataProviderId, const CMTPStorageMetaData& aStorage)
   256 EXPORT_C TUint32 CMTPStorageMgr::AllocatePhysicalStorageIdL(TUint aDataProviderId, const CMTPStorageMetaData& aStorage)
   234     {
   257     {
   235     __FLOG(_L8("AllocatePhysicalStorageIdL - Entry"));
   258     OstTraceFunctionEntry0( CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEIDL_ENTRY );
   236     
   259     
   237     // Validate the SUID.
   260     // Validate the SUID.
   238     if (iStorages.Find(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), StorageKeyMatchSuid) != KErrNotFound)
   261     if (iStorages.Find(aStorage.DesC(CMTPStorageMetaData::EStorageSuid), StorageKeyMatchSuid) != KErrNotFound)
   239         {
   262         {
   240         // SUID is not unique.
   263         // SUID is not unique.
       
   264         OstTrace0( TRACE_ERROR, DUP1_CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEIDL, "SUID is not unique" );
   241         User::Leave(KErrAlreadyExists);
   265         User::Leave(KErrAlreadyExists);
   242         }
   266         }
   243     
   267     
   244     // Allocate a physical StorageId.
   268     // Allocate a physical StorageId.
   245     TInt32 id(AllocatePhysicalStorageId(aDataProviderId));
   269     TInt32 id(AllocatePhysicalStorageId(aDataProviderId));
   246     User::LeaveIfError(id);
   270     LEAVEIFERROR(id,
       
   271             OstTrace1( TRACE_ERROR, DUP2_CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEIDL, "Allocate Physical StorageId for Dp %d failed", aDataProviderId));
       
   272             
   247     
   273     
   248     // Create the physical storage meta-data.
   274     // Create the physical storage meta-data.
   249     CMTPStorageMetaData* physical(CMTPStorageMetaData::NewLC(aStorage));
   275     CMTPStorageMetaData* physical(CMTPStorageMetaData::NewLC(aStorage));
   250     const RArray<TUint> noStorages;
   276     const RArray<TUint> noStorages;
   251     physical->SetUint(CMTPStorageMetaData::EStorageId, id);
   277     physical->SetUint(CMTPStorageMetaData::EStorageId, id);
   253     
   279     
   254     // Store the physical storage meta-data.
   280     // Store the physical storage meta-data.
   255     iStorages.InsertInOrderL(physical, StorageOrder);
   281     iStorages.InsertInOrderL(physical, StorageOrder);
   256     CleanupStack::Pop(physical);
   282     CleanupStack::Pop(physical);
   257     
   283     
   258     __FLOG_VA((_L8("Allocated physical StorageID 0x%08X"), id));
   284     OstTrace1(TRACE_NORMAL, CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEIDL,
   259     __FLOG(_L8("AllocatePhysicalStorageIdL - Exit"));
   285             "Allocated physical StorageID 0x%08X", id);
       
   286     OstTraceFunctionExit0( CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEIDL_EXIT );
   260     return id;
   287     return id;
   261     }
   288     }
   262 
   289 
   263 EXPORT_C TInt CMTPStorageMgr::DeallocateLogicalStorageId(TUint aDataProviderId, TUint32 aLogicalStorageId)
   290 EXPORT_C TInt CMTPStorageMgr::DeallocateLogicalStorageId(TUint aDataProviderId, TUint32 aLogicalStorageId)
   264     {
   291     {
   265     __FLOG(_L8("DeallocateLogicalStorageId - Entry"));
   292     OstTraceFunctionEntry0( CMTPSTORAGEMGR_DEALLOCATELOGICALSTORAGEID_ENTRY );
   266     TInt ret(KErrArgument);
   293     TInt ret(KErrArgument);
   267     
   294     
   268     // Validate the StorageID.
   295     // Validate the StorageID.
   269     if (LogicalStorageId(aLogicalStorageId))
   296     if (LogicalStorageId(aLogicalStorageId))
   270         {
   297         {
   281                 TRAPD(err, RemoveLogicalStorageL(ret));
   308                 TRAPD(err, RemoveLogicalStorageL(ret));
   282                 ret = err;
   309                 ret = err;
   283                 }
   310                 }
   284             }
   311             }
   285         }
   312         }
   286     __FLOG(_L8("DeallocateLogicalStorageId - Exit"));
   313     OstTraceFunctionExit0( CMTPSTORAGEMGR_DEALLOCATELOGICALSTORAGEID_EXIT );
   287     return ret;
   314     return ret;
   288     }
   315     }
   289 
   316 
   290 EXPORT_C void CMTPStorageMgr::DeallocateLogicalStorageIds(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   317 EXPORT_C void CMTPStorageMgr::DeallocateLogicalStorageIds(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   291     {
   318     {
   292     __FLOG(_L8("DeallocateLogicalStorageIds - Entry"));
   319     OstTraceFunctionEntry0( CMTPSTORAGEMGR_DEALLOCATELOGICALSTORAGEIDS_ENTRY );
   293     TInt ret(iStorages.FindInOrder(aPhysicalStorageId, StorageOrder));
   320     TInt ret(iStorages.FindInOrder(aPhysicalStorageId, StorageOrder));
   294     if (ret != KErrNotFound)
   321     if (ret != KErrNotFound)
   295         {
   322         {
   296         const RArray<TUint>& logicals(iStorages[ret]->UintArray(CMTPStorageMetaData::EStorageLogicalIds));
   323         const RArray<TUint>& logicals(iStorages[ret]->UintArray(CMTPStorageMetaData::EStorageLogicalIds));
   297         TUint count(logicals.Count());
   324         TUint count(logicals.Count());
   303                 DeallocateLogicalStorageId(aDataProviderId, logicals[KIdx]);
   330                 DeallocateLogicalStorageId(aDataProviderId, logicals[KIdx]);
   304                 }
   331                 }
   305             count--;
   332             count--;
   306             }
   333             }
   307         }
   334         }
   308     __FLOG(_L8("DeallocateLogicalStorageIds - Exit"));
   335     OstTraceFunctionExit0( CMTPSTORAGEMGR_DEALLOCATELOGICALSTORAGEIDS_EXIT );
   309     }
   336     }
   310 
   337 
   311 EXPORT_C TInt CMTPStorageMgr::DeallocatePhysicalStorageId(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   338 EXPORT_C TInt CMTPStorageMgr::DeallocatePhysicalStorageId(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   312     {
   339     {
   313     __FLOG(_L8("DeallocatePhysicalStorageId - Entry"));
   340     OstTraceFunctionEntry0( CMTPSTORAGEMGR_DEALLOCATEPHYSICALSTORAGEID_ENTRY );
   314     TInt ret(KErrArgument);
   341     TInt ret(KErrArgument);
   315     
   342     
   316     // Validate the StorageID.
   343     // Validate the StorageID.
   317     if (!LogicalStorageId(aPhysicalStorageId))
   344     if (!LogicalStorageId(aPhysicalStorageId))
   318         {
   345         {
   339                 delete iStorages[ret];
   366                 delete iStorages[ret];
   340                 iStorages.Remove(ret);
   367                 iStorages.Remove(ret);
   341                 }
   368                 }
   342             }
   369             }
   343         }
   370         }
   344     __FLOG(_L8("DeallocatePhysicalStorageId - Exit"));
   371     OstTraceFunctionExit0( CMTPSTORAGEMGR_DEALLOCATEPHYSICALSTORAGEID_EXIT );
   345     return ret;
   372     return ret;
   346     }
   373     }
   347 
   374 
   348 EXPORT_C TUint32 CMTPStorageMgr::DefaultStorageId() const
   375 EXPORT_C TUint32 CMTPStorageMgr::DefaultStorageId() const
   349     {
   376     {
   350     __FLOG(_L8("DefaultStorageId - Entry"));
   377     OstTraceFunctionEntry0( CMTPSTORAGEMGR_DEFAULTSTORAGEID_ENTRY );
   351     __FLOG(_L8("DefaultStorageId - Exit"));
   378     OstTraceFunctionExit0( CMTPSTORAGEMGR_DEFAULTSTORAGEID_EXIT );
   352     return iDefaultStorageId;
   379     return iDefaultStorageId;
   353     }
   380     }
   354 
   381 
   355 EXPORT_C TInt CMTPStorageMgr::DriveNumber(TUint32 aStorageId) const
   382 EXPORT_C TInt CMTPStorageMgr::DriveNumber(TUint32 aStorageId) const
   356     {
   383     {
   357     __FLOG(_L8("DriveNumber - Entry"));
   384     OstTraceFunctionEntry0( CMTPSTORAGEMGR_DRIVENUMBER_ENTRY );
   358     TInt drive(KErrNotFound);
   385     TInt drive(KErrNotFound);
   359     if (PhysicalStorageOwner(aStorageId) == iFrameworkId)
   386     if (PhysicalStorageOwner(aStorageId) == iFrameworkId)
   360         {
   387         {
   361         const TUint32 KPhysicalId(PhysicalStorageId(aStorageId));
   388         const TUint32 KPhysicalId(PhysicalStorageId(aStorageId));
   362         const TUint KCount(iMapDriveToStorage.Count());
   389         const TUint KCount(iMapDriveToStorage.Count());
   366                 {
   393                 {
   367                 drive = i;
   394                 drive = i;
   368                 }
   395                 }
   369             }
   396             }
   370         }
   397         }
   371     __FLOG(_L8("DriveNumber - Exit"));
   398     OstTraceFunctionExit0( CMTPSTORAGEMGR_DRIVENUMBER_EXIT );
   372     return drive;
   399     return drive;
   373     }
   400     }
   374 
   401 
   375 EXPORT_C TInt32 CMTPStorageMgr::FrameworkStorageId(TDriveNumber aDriveNumber) const
   402 EXPORT_C TInt32 CMTPStorageMgr::FrameworkStorageId(TDriveNumber aDriveNumber) const
   376     {
   403     {
   377     __FLOG(_L8("FrameworkStorageId - Entry"));
   404     OstTraceFunctionEntry0( CMTPSTORAGEMGR_FRAMEWORKSTORAGEID_ENTRY );
   378     TInt32 ret(KErrNotFound);
   405     TInt32 ret(KErrNotFound);
   379     TInt32 id(iMapDriveToStorage[aDriveNumber]);
   406     TInt32 id(iMapDriveToStorage[aDriveNumber]);
   380     if ((id != KErrNotFound) && (LogicalStorageId(id)))
   407     if ((id != KErrNotFound) && (LogicalStorageId(id)))
   381         {
   408         {
   382         ret = id;
   409         ret = id;
   383         }
   410         }
   384     __FLOG(_L8("FrameworkStorageId - Exit"));
   411     OstTraceFunctionExit0( CMTPSTORAGEMGR_FRAMEWORKSTORAGEID_EXIT );
   385     return ret;
   412     return ret;
   386     }
   413     }
   387 
   414 
   388 EXPORT_C void CMTPStorageMgr::GetAvailableDrivesL(RArray<TDriveNumber>& aDrives) const
   415 EXPORT_C void CMTPStorageMgr::GetAvailableDrivesL(RArray<TDriveNumber>& aDrives) const
   389     {
   416     {
   390     __FLOG(_L8("GetAvailableDrivesL - Entry"));
   417     OstTraceFunctionEntry0( CMTPSTORAGEMGR_GETAVAILABLEDRIVESL_ENTRY );
   391     aDrives.Reset();
   418     aDrives.Reset();
   392     for (TUint i(0); (i < iMapDriveToStorage.Count()); i++)
   419     for (TUint i(0); (i < iMapDriveToStorage.Count()); i++)
   393         {
   420         {
   394         if (iMapDriveToStorage[i] != KErrNotFound)
   421         if (iMapDriveToStorage[i] != KErrNotFound)
   395             {
   422             {
   396             aDrives.AppendL(static_cast<TDriveNumber>(i));
   423             aDrives.AppendL(static_cast<TDriveNumber>(i));
   397             }
   424             }
   398         }
   425         }
   399     __FLOG(_L8("GetAvailableDrivesL - Exit"));
   426     OstTraceFunctionExit0( CMTPSTORAGEMGR_GETAVAILABLEDRIVESL_EXIT );
   400     }
   427     }
   401 
   428 
   402 EXPORT_C void CMTPStorageMgr::GetLogicalStoragesL(const TMTPStorageMgrQueryParams& aParams, RPointerArray<const CMTPStorageMetaData>& aStorages) const
   429 EXPORT_C void CMTPStorageMgr::GetLogicalStoragesL(const TMTPStorageMgrQueryParams& aParams, RPointerArray<const CMTPStorageMetaData>& aStorages) const
   403     {
   430     {
   404     __FLOG(_L8("GetLogicalStoragesL - Entry"));
   431     OstTraceFunctionEntry0( CMTPSTORAGEMGR_GETLOGICALSTORAGESL_ENTRY );
   405     aStorages.Reset();
   432     aStorages.Reset();
   406     const TBool KAllStorages(aParams.StorageSuid() == KNullDesC);
   433     const TBool KAllStorages(aParams.StorageSuid() == KNullDesC);
   407     const TBool KAllStorageSystemTypes(aParams.StorageSystemType() == CMTPStorageMetaData::ESystemTypeUndefined);
   434     const TBool KAllStorageSystemTypes(aParams.StorageSystemType() == CMTPStorageMetaData::ESystemTypeUndefined);
   408     const TUint KCount(iStorages.Count());
   435     const TUint KCount(iStorages.Count());
   409     for (TUint i(0); (i < KCount); i++)
   436     for (TUint i(0); (i < KCount); i++)
   414             (LogicalStorageId(storage.Uint(CMTPStorageMetaData::EStorageId))))
   441             (LogicalStorageId(storage.Uint(CMTPStorageMetaData::EStorageId))))
   415             {
   442             {
   416             aStorages.AppendL(iStorages[i]);
   443             aStorages.AppendL(iStorages[i]);
   417             }
   444             }
   418         }
   445         }
   419     __FLOG(_L8("GetLogicalStoragesL - Exit"));
   446     OstTraceFunctionExit0( CMTPSTORAGEMGR_GETLOGICALSTORAGESL_EXIT );
   420     }
   447     }
   421 
   448 
   422 EXPORT_C void CMTPStorageMgr::GetPhysicalStoragesL(const TMTPStorageMgrQueryParams& aParams, RPointerArray<const CMTPStorageMetaData>& aStorages) const
   449 EXPORT_C void CMTPStorageMgr::GetPhysicalStoragesL(const TMTPStorageMgrQueryParams& aParams, RPointerArray<const CMTPStorageMetaData>& aStorages) const
   423     {
   450     {
   424     __FLOG(_L8("GetPhysicalStoragesL - Entry"));
   451     OstTraceFunctionEntry0( CMTPSTORAGEMGR_GETPHYSICALSTORAGESL_ENTRY );
   425     aStorages.Reset();
   452     aStorages.Reset();
   426     const TBool KAllStorages(aParams.StorageSuid() == KNullDesC);
   453     const TBool KAllStorages(aParams.StorageSuid() == KNullDesC);
   427     const TBool KAllStorageSystemTypes(aParams.StorageSystemType() == CMTPStorageMetaData::ESystemTypeUndefined);
   454     const TBool KAllStorageSystemTypes(aParams.StorageSystemType() == CMTPStorageMetaData::ESystemTypeUndefined);
   428     const TUint KCount(iStorages.Count());
   455     const TUint KCount(iStorages.Count());
   429     for (TUint i(0); (i < KCount); i++)
   456     for (TUint i(0); (i < KCount); i++)
   434             (!LogicalStorageId(storage.Uint(CMTPStorageMetaData::EStorageId))))
   461             (!LogicalStorageId(storage.Uint(CMTPStorageMetaData::EStorageId))))
   435             {
   462             {
   436             aStorages.AppendL(iStorages[i]);
   463             aStorages.AppendL(iStorages[i]);
   437             }
   464             }
   438         }
   465         }
   439     __FLOG(_L8("GetPhysicalStoragesL - Exit"));
   466     OstTraceFunctionExit0( CMTPSTORAGEMGR_GETPHYSICALSTORAGESL_EXIT );
   440     }
   467     }
   441 
   468 
   442 EXPORT_C TUint32 CMTPStorageMgr::LogicalStorageId(TUint32 aStorageId) const
   469 EXPORT_C TUint32 CMTPStorageMgr::LogicalStorageId(TUint32 aStorageId) const
   443     {
   470     {
   444     __FLOG(_L8("LogicalStorageId - Entry"));
   471     OstTraceFunctionEntry0( CMTPSTORAGEMGR_LOGICALSTORAGEID_TUINT32_ENTRY );
   445     __FLOG(_L8("LogicalStorageId - Exit"));
   472     OstTraceFunctionExit0( CMTPSTORAGEMGR_LOGICALSTORAGEID_TUINT32_EXIT );
   446     return (aStorageId & KLogicalIdMask);
   473     return (aStorageId & KLogicalIdMask);
   447     }
   474     }
   448 
   475 
   449 EXPORT_C TInt32 CMTPStorageMgr::LogicalStorageId(const TDesC& aStorageSuid) const
   476 EXPORT_C TInt32 CMTPStorageMgr::LogicalStorageId(const TDesC& aStorageSuid) const
   450     {
   477     {
   451     __FLOG(_L8("LogicalStorageId - Entry"));
   478     OstTraceFunctionEntry0( CMTPSTORAGEMGR_LOGICALSTORAGEID_TDESC_ENTRY );
   452     TInt32 id(KErrNotFound);
   479     TInt32 id(KErrNotFound);
   453     TInt idx(iStorages.Find(aStorageSuid, StorageKeyMatchSuid));
   480     TInt idx(iStorages.Find(aStorageSuid, StorageKeyMatchSuid));
   454     if (idx != KErrNotFound)
   481     if (idx != KErrNotFound)
   455         {
   482         {
   456         id = iStorages[idx]->Uint(CMTPStorageMetaData::EStorageId);
   483         id = iStorages[idx]->Uint(CMTPStorageMetaData::EStorageId);
   457         if (!LogicalStorageId(id))
   484         if (!LogicalStorageId(id))
   458             {
   485             {
   459             id = KErrNotFound;
   486             id = KErrNotFound;
   460             }
   487             }
   461         }
   488         }
   462     __FLOG(_L8("LogicalStorageId - Exit"));
   489     OstTraceFunctionExit0( CMTPSTORAGEMGR_LOGICALSTORAGEID_TDESC_EXIT );
   463     return id;
   490     return id;
   464     }
   491     }
   465 
   492 
   466 EXPORT_C TInt32 CMTPStorageMgr::PhysicalStorageId(TDriveNumber aDriveNumber) const
   493 EXPORT_C TInt32 CMTPStorageMgr::PhysicalStorageId(TDriveNumber aDriveNumber) const
   467     {
   494     {
   468     __FLOG(_L8("PhysicalStorageId - Entry"));
   495     OstTraceFunctionEntry0( CMTPSTORAGEMGR_PHYSICALSTORAGEID_TDRIVENUMBER_ENTRY );
   469     TInt32 storageId(iMapDriveToStorage[aDriveNumber]);
   496     TInt32 storageId(iMapDriveToStorage[aDriveNumber]);
   470     if (storageId != KErrNotFound)
   497     if (storageId != KErrNotFound)
   471         {
   498         {
   472         storageId = PhysicalStorageId(storageId);
   499         storageId = PhysicalStorageId(storageId);
   473         }
   500         }
   474     __FLOG(_L8("PhysicalStorageId - Exit"));
   501     OstTraceFunctionExit0( CMTPSTORAGEMGR_PHYSICALSTORAGEID_TDRIVENUMBER_EXIT );
   475     return storageId;
   502     return storageId;
   476     }
   503     }
   477 
   504 
   478 EXPORT_C TUint32 CMTPStorageMgr::PhysicalStorageId(TUint32 aStorageId) const
   505 EXPORT_C TUint32 CMTPStorageMgr::PhysicalStorageId(TUint32 aStorageId) const
   479     {
   506     {
   480     __FLOG(_L8("PhysicalStorageId - Entry"));
   507     OstTraceFunctionEntry0( CMTPSTORAGEMGR_PHYSICALSTORAGEID_TUINT32_ENTRY );
   481     __FLOG(_L8("PhysicalStorageId - Exit"));
   508     OstTraceFunctionExit0( CMTPSTORAGEMGR_PHYSICALSTORAGEID_TUINT32_EXIT );
   482     return (aStorageId & KPhysicalIdMask);
   509     return (aStorageId & KPhysicalIdMask);
   483     }
   510     }
   484 
   511 
   485 EXPORT_C const CMTPStorageMetaData& CMTPStorageMgr::StorageL(TUint32 aStorageId) const
   512 EXPORT_C const CMTPStorageMetaData& CMTPStorageMgr::StorageL(TUint32 aStorageId) const
   486     {
   513     {
   487     __FLOG(_L8("StorageL - Entry"));
   514     OstTraceFunctionEntry0( CMTPSTORAGEMGR_STORAGEL_ENTRY );
   488     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   515     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   489     User::LeaveIfError(idx);
   516     LEAVEIFERROR(idx,
   490     __FLOG(_L8("StorageL - Exit"));
   517             OstTrace1( TRACE_ERROR, CMTPSTORAGEMGR_STORAGEL, "can't find storage with StorageId %d", idx ));
       
   518     OstTraceFunctionExit0( CMTPSTORAGEMGR_STORAGEL_EXIT );
   491     return *iStorages[idx];
   519     return *iStorages[idx];
   492     }
   520     }
   493 
   521 
   494 EXPORT_C TUint32 CMTPStorageMgr::StorageId(TUint32 aPhysicalStorageId, TUint32 aLogicalStorageId) const
   522 EXPORT_C TUint32 CMTPStorageMgr::StorageId(TUint32 aPhysicalStorageId, TUint32 aLogicalStorageId) const
   495     {
   523     {
   496     __FLOG(_L8("StorageId - Entry"));
   524     OstTraceFunctionEntry0( CMTPSTORAGEMGR_STORAGEID_ENTRY );
   497     __FLOG(_L8("StorageId - Exit"));
   525     OstTraceFunctionExit0( CMTPSTORAGEMGR_STORAGEID_EXIT );
   498     return (aPhysicalStorageId | aLogicalStorageId);
   526     return (aPhysicalStorageId | aLogicalStorageId);
   499     }
   527     }
   500 
   528 
   501 EXPORT_C TBool CMTPStorageMgr::ValidStorageId(TUint32 aStorageId) const
   529 EXPORT_C TBool CMTPStorageMgr::ValidStorageId(TUint32 aStorageId) const
   502     {
   530     {
   503     __FLOG(_L8("ValidStorageId - Entry"));
   531     OstTraceFunctionEntry0( CMTPSTORAGEMGR_VALIDSTORAGEID_ENTRY );
   504     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   532     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   505     if(KErrNotFound == idx)
   533     if(KErrNotFound == idx)
   506     	{
   534     	{
   507     	__FLOG(_L8("ValidStorageId - False Exit"));
   535     	OstTraceFunctionExit0( CMTPSTORAGEMGR_VALIDSTORAGEID_EXIT );
   508     	return EFalse;
   536     	return EFalse;
   509     	}
   537     	}
   510     
   538     
   511     _LIT(KSeperator,"\\");
   539     _LIT(KSeperator,"\\");
   512 	TBool ret = ETrue;
   540 	TBool ret = ETrue;
   528             buf.Append(KSeperator);
   556             buf.Append(KSeperator);
   529             
   557             
   530             ret = BaflUtils::PathExists(iSingletons.Fs(), buf);
   558             ret = BaflUtils::PathExists(iSingletons.Fs(), buf);
   531 			}
   559 			}
   532 		}
   560 		}
   533   
   561     
   534     __FLOG(_L8("ValidStorageId - Exit"));
   562     OstTraceFunctionExit0( DUP1_CMTPSTORAGEMGR_VALIDSTORAGEID_EXIT );
   535     
       
   536     return ret;
   563     return ret;
   537     }
   564     }
   538     
   565     
   539 EXPORT_C CMTPTypeString* CMTPStorageMgr::VolumeIdL(TUint aDataProviderId, TUint32 aStorageId, const TDesC& aVolumeIdSuffix) const
   566 EXPORT_C CMTPTypeString* CMTPStorageMgr::VolumeIdL(TUint aDataProviderId, TUint32 aStorageId, const TDesC& aVolumeIdSuffix) const
   540     {
   567     {
   541     __FLOG(_L8("VolumeIdL - Entry"));
   568     OstTraceFunctionEntry0( CMTPSTORAGEMGR_VOLUMEIDL_ENTRY );
   542 
   569 
   543     // Validate the StorageId.
   570     // Validate the StorageId.
   544     TUint owner(LogicalStorageId(aStorageId) ? LogicalStorageOwner(aStorageId) : PhysicalStorageOwner(aStorageId));
   571     TUint owner(LogicalStorageId(aStorageId) ? LogicalStorageOwner(aStorageId) : PhysicalStorageOwner(aStorageId));
   545     if (!ValidStorageId(aStorageId))
   572     if (!ValidStorageId(aStorageId))
   546         {
   573         {
       
   574         OstTrace1( TRACE_ERROR, CMTPSTORAGEMGR_VOLUMEIDL, "invalid storage id %d", aStorageId);
   547         User::Leave(KErrNotFound);
   575         User::Leave(KErrNotFound);
   548         }
   576         }
   549     else if (aDataProviderId != owner)
   577     else if (aDataProviderId != owner)
   550         {
   578         {
       
   579         OstTrace1( TRACE_ERROR, DUP1_CMTPSTORAGEMGR_VOLUMEIDL, "Dp %d not owner", aDataProviderId);
   551         User::Leave(KErrAccessDenied);
   580         User::Leave(KErrAccessDenied);
   552         }
   581         }
   553     
   582     
   554     // Generate a unique volume ID.
   583     // Generate a unique volume ID.
   555     RBuf16 buffer;
   584     RBuf16 buffer;
   564         buffer.Append(aVolumeIdSuffix.Left(KMTPMaxStringCharactersLength - buffer.Length()));
   593         buffer.Append(aVolumeIdSuffix.Left(KMTPMaxStringCharactersLength - buffer.Length()));
   565         }
   594         }
   566 
   595 
   567     CMTPTypeString* volumeId = CMTPTypeString::NewL(buffer);
   596     CMTPTypeString* volumeId = CMTPTypeString::NewL(buffer);
   568 	CleanupStack::PopAndDestroy(&buffer);  
   597 	CleanupStack::PopAndDestroy(&buffer);  
   569     __FLOG(_L8("VolumeIdL - Exit"));
   598     OstTraceFunctionExit0( CMTPSTORAGEMGR_VOLUMEIDL_EXIT );
   570     return volumeId;
   599     return volumeId;
   571     }   
   600     }   
   572     
   601     
   573 /**
   602 /**
   574 Constructor.
   603 Constructor.
   575 */
   604 */
   576 CMTPStorageMgr::CMTPStorageMgr() :
   605 CMTPStorageMgr::CMTPStorageMgr() :
   577     iFrameworkId(KErrNotFound)
   606     iFrameworkId(KErrNotFound)
   578     {
   607     {
   579 
       
   580     }
   608     }
   581     
   609     
   582 /**
   610 /**
   583 Second phase constructor.
   611 Second phase constructor.
   584 @leave One of the system wide error code, if a processing failure occurs.
   612 @leave One of the system wide error code, if a processing failure occurs.
   585 */
   613 */
   586 void CMTPStorageMgr::ConstructL()
   614 void CMTPStorageMgr::ConstructL()
   587     {
   615     {
   588     __FLOG_OPEN(KMTPSubsystem, KComponent);
   616     OstTraceFunctionEntry0( CMTPSTORAGEMGR_CONSTRUCTL_ENTRY );
   589     __FLOG(_L8("ConstructL - Entry"));
       
   590     iSingletons.OpenL();
   617     iSingletons.OpenL();
   591     for (TUint i(0); (i < KMaxDrives); i++)
   618     for (TUint i(0); (i < KMaxDrives); i++)
   592         {
   619         {
   593         iMapDriveToStorage[i] = KErrNotFound;
   620         iMapDriveToStorage[i] = KErrNotFound;
   594         }
   621         }
   595     __FLOG(_L8("ConstructL - Exit"));
   622     OstTraceFunctionExit0( CMTPSTORAGEMGR_CONSTRUCTL_EXIT );
   596     }
   623     }
   597     
   624     
   598 /**
   625 /**
   599 Allocates a new 32-bit logical StorageId for the storage owner as a partition 
   626 Allocates a new 32-bit logical StorageId for the storage owner as a partition 
   600 of the specified physical MTP StorageID.
   627 of the specified physical MTP StorageID.
   604 @return KErrNotFound, if the specified physical MTP StorageID does not exist
   631 @return KErrNotFound, if the specified physical MTP StorageID does not exist
   605 @return KErrOverflow, if the maximum number of storages would be exceeded.
   632 @return KErrOverflow, if the maximum number of storages would be exceeded.
   606 */
   633 */
   607 TInt32 CMTPStorageMgr::AllocateLogicalStorageId(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   634 TInt32 CMTPStorageMgr::AllocateLogicalStorageId(TUint aDataProviderId, TUint32 aPhysicalStorageId)
   608     {
   635     {
   609     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("AllocateLogicalStorageId - Entry"));
   636     OstTraceFunctionEntry0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEID_ENTRY );
   610     TInt ret(iStorages.FindInOrder(aPhysicalStorageId, StorageOrder));
   637     TInt ret(iStorages.FindInOrder(aPhysicalStorageId, StorageOrder));
   611     if (ret != KErrNotFound)
   638     if (ret != KErrNotFound)
   612         {
   639         {
   613         // Scan for the first available storage number.
   640         // Scan for the first available storage number.
   614         const RArray<TUint>& logicalIds(iStorages[ret]->UintArray(CMTPStorageMetaData::EStorageLogicalIds));
   641         const RArray<TUint>& logicalIds(iStorages[ret]->UintArray(CMTPStorageMetaData::EStorageLogicalIds));
   623         if (num >= KMaxOwnedStorages)
   650         if (num >= KMaxOwnedStorages)
   624             {
   651             {
   625             ret = KErrOverflow;
   652             ret = KErrOverflow;
   626             }
   653             }
   627         }
   654         }
   628     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("AllocateLogicalStorageId - Exit"));
   655     OstTraceFunctionExit0( CMTPSTORAGEMGR_ALLOCATELOGICALSTORAGEID_EXIT );
   629     return ret;
   656     return ret;
   630     }
   657     }
   631     
   658     
   632 /**
   659 /**
   633 Allocates a new 32-bit physical StorageId for the storage owner.
   660 Allocates a new 32-bit physical StorageId for the storage owner.
   636 @return KErrOverflow, if the maximum number of storages would be exceeded.
   663 @return KErrOverflow, if the maximum number of storages would be exceeded.
   637 @return One of the system wide error code, if a processing failure occurs.
   664 @return One of the system wide error code, if a processing failure occurs.
   638 */
   665 */
   639 TInt32 CMTPStorageMgr::AllocatePhysicalStorageId(TUint aDataProviderId)
   666 TInt32 CMTPStorageMgr::AllocatePhysicalStorageId(TUint aDataProviderId)
   640     {
   667     {
   641     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("AllocatePhysicalStorageId - Entry"));
   668     OstTraceFunctionEntry0( CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEID_ENTRY );
   642     TInt32 ret(KErrNone);
   669     TInt32 ret(KErrNone);
   643     while ((iPhysicalStorageNumbers.Count() < (aDataProviderId + 1)) && (ret == KErrNone))
   670     while ((iPhysicalStorageNumbers.Count() < (aDataProviderId + 1)) && (ret == KErrNone))
   644         {
   671         {
   645         ret = iPhysicalStorageNumbers.Append(0);
   672         ret = iPhysicalStorageNumbers.Append(0);
   646         }
   673         }
   654         else
   681         else
   655             {
   682             {
   656             ret = KErrOverflow;
   683             ret = KErrOverflow;
   657             }
   684             }
   658         }
   685         }
   659     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("AllocatePhysicalStorageId - Exit"));
   686     OstTraceFunctionExit0( CMTPSTORAGEMGR_ALLOCATEPHYSICALSTORAGEID_EXIT );
   660     return ret;
   687     return ret;
   661     }
   688     }
   662 	
   689 	
   663 /**
   690 /**
   664 Encodes the specified physical MTP StorageID, data provider identifier, and 
   691 Encodes the specified physical MTP StorageID, data provider identifier, and 
   734 @param aIdx The storages table index.
   761 @param aIdx The storages table index.
   735 @leave One of the system wide error codes, if a processing failure occurs.
   762 @leave One of the system wide error codes, if a processing failure occurs.
   736 */
   763 */
   737 void CMTPStorageMgr::RemoveLogicalStorageL(TUint aIdx)
   764 void CMTPStorageMgr::RemoveLogicalStorageL(TUint aIdx)
   738     {
   765     {
   739     __FLOG(_L8("RemoveLogicalStorageL - Entry"));
   766     OstTraceFunctionEntry0( CMTPSTORAGEMGR_REMOVELOGICALSTORAGEL_ENTRY );
   740     TUint32 id(iStorages[aIdx]->Uint(CMTPStorageMetaData::EStorageId));
   767     TUint32 id(iStorages[aIdx]->Uint(CMTPStorageMetaData::EStorageId));
   741     
   768     
   742     // Disassociate the logical and physical storages.
   769     // Disassociate the logical and physical storages.
   743     CMTPStorageMetaData& physical(StorageMetaDataL(PhysicalStorageId(id)));
   770     CMTPStorageMetaData& physical(StorageMetaDataL(PhysicalStorageId(id)));
   744     RArray<TUint> logicals;
   771     RArray<TUint> logicals;
   749     CleanupStack::PopAndDestroy(&logicals);
   776     CleanupStack::PopAndDestroy(&logicals);
   750     
   777     
   751     // Delete the storage.
   778     // Delete the storage.
   752     delete iStorages[aIdx];
   779     delete iStorages[aIdx];
   753     iStorages.Remove(aIdx);
   780     iStorages.Remove(aIdx);
   754     __FLOG(_L8("RemoveLogicalStorageL - Entry"));
   781     OstTraceFunctionExit0( CMTPSTORAGEMGR_REMOVELOGICALSTORAGEL_EXIT );
   755     }
   782     }
   756     
   783     
   757 /**
   784 /**
   758 Provides a non-const reference to the storage meta-data for the specified 
   785 Provides a non-const reference to the storage meta-data for the specified 
   759 logical MTP StorageID.
   786 logical MTP StorageID.
   761 @leave KErrNotFound if the specified StorageID does not exist.
   788 @leave KErrNotFound if the specified StorageID does not exist.
   762 @leave One of the system wide error codes, if a processing failure occurs.
   789 @leave One of the system wide error codes, if a processing failure occurs.
   763 */
   790 */
   764 CMTPStorageMetaData& CMTPStorageMgr::StorageMetaDataL(TUint32 aStorageId)
   791 CMTPStorageMetaData& CMTPStorageMgr::StorageMetaDataL(TUint32 aStorageId)
   765     {
   792     {
   766     __FLOG(_L8("StorageMetaDataL - Entry"));
   793     OstTraceFunctionEntry0( CMTPSTORAGEMGR_STORAGEMETADATAL_ENTRY );
   767     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   794     TInt idx(iStorages.FindInOrder(aStorageId, StorageOrder));
   768     User::LeaveIfError(idx);
   795     LEAVEIFERROR(idx,
   769     __FLOG(_L8("StorageMetaDataL - Exit"));
   796             OstTrace1( TRACE_ERROR, CMTPSTORAGEMGR_STORAGEMETADATAL, "can't find storage with storageId %d", idx ));
       
   797     OstTraceFunctionExit0( CMTPSTORAGEMGR_STORAGEMETADATAL_EXIT );
   770     return *iStorages[idx];
   798     return *iStorages[idx];
   771     }
   799     }
   772    
   800    
   773 /**
   801 /**
   774 Implements a storage key match identity relation using 
   802 Implements a storage key match identity relation using