void CReferencePolicyPlugin::AvailableDriveListL()
    {
    OstTraceFunctionEntry0( REF_CREFERENCEPOLICYPLUGIN_AVAILABLEDRIVELISTL_ENTRY );
    
    TBuf8<KPermittedDrvRangeBufLen> permittedRange;
    TDriveList forbiddenList;

    PrepareAvailableDriveList();

    User::LeaveIfError(iRepository->Get(KPermittedRangeUid, permittedRange));
    User::LeaveIfError(iRepository->Get(KForbiddenListUid, forbiddenList));

    for (TInt index = 'A'; index <= 'Z'; index++ )
        {
        if ((index >= permittedRange[0]) && (index <= permittedRange[1]))
            {
            if (KErrNotFound == forbiddenList.Locate(TChar(index)))
                {
                // Permitted
                iAvailableDrvList[index - 'A'] = 0x01;
                }
            }
        }
    OstTraceFunctionExit0( REF_CREFERENCEPOLICYPLUGIN_AVAILABLEDRIVELISTL_EXIT );
    }
void CReferencePolicyPlugin::RetrieveDriveLetterL(TText& aDriveName,
        const TPolicyRequestData& aData)
    {
    OstTraceFunctionEntry0( REF_CREFERENCEPOLICYPLUGIN_RETRIEVEDRIVELETTERL_TTEXT_TPOLICYREQUESTDATA_ENTRY );
    
    TDriveList availableNames;
    FilterFsForbiddenDriveListL(availableNames);

    if (!availableNames.Length())
        {
        // Not any drive letter available
        User::Leave(KErrNotFound);
        }

    // According to REQ8922, When a particular Logical Unit is mounted 
    // for the first time, RefPP shall always try to allocate an 
    // available and unused drive letter to it. Only if such a drive letter
    // can not be found, RefPP shall use the first one in available name
    // list;
    
    // Initialize aDriveName by the first available drive letter
    aDriveName = availableNames[0];
    // Find first such drive letter from available letter list. If it can
    // be found, it will be used.
    FindFirstNotUsedDriveLetter(availableNames, aDriveName);    
    // Search history record
    TInt historyIndex = SearchHistoryByLogicUnit(aData);
    if (KErrNotFound != historyIndex)
        {
        // Find a match one in history
        const TPolicyMountRecord& history = *iHistory[historyIndex];
        TInt location = availableNames.Locate(TChar(history.iDriveName));
        if (KErrNotFound != location)
            {
            // And it is available now. RefPP allocate it to the 
            // LU currently mounted.
            aDriveName = history.iDriveName;
            }
        }
    OstTraceFunctionExit0( REF_CREFERENCEPOLICYPLUGIN_RETRIEVEDRIVELETTERL_TTEXT_TPOLICYREQUESTDATA_EXIT );
    }
void CReferencePolicyPlugin::FindFirstNotUsedDriveLetter(
        const TDriveList& aAvailableNames,
        TText& aDriveName)
    {
    OstTraceFunctionEntry0( REF_CREFERENCEPOLICYPLUGIN_FINDFIRSTNOTUSEDDRIVELETTER_ENTRY );
    
    TDriveList usedLetter;
    TUint index = 0;
    for (index = 0; index < iHistory.Count(); index++)
        {
        const TPolicyMountRecord& record = *iHistory[index];
        usedLetter.Append(TChar(record.iDriveName));
        }
    for (index = 0; index < aAvailableNames.Length(); index++)
        {
        if (usedLetter.Locate(aAvailableNames[index]) == KErrNotFound)
            {
            aDriveName = aAvailableNames[index];
            OstTraceFunctionExit0( REF_CREFERENCEPOLICYPLUGIN_FINDFIRSTNOTUSEDDRIVELETTER_EXIT );
            return; // A unused drive letter found out
            }
        }
    OstTraceFunctionExit0( REF_CREFERENCEPOLICYPLUGIN_FINDFIRSTNOTUSEDDRIVELETTER_EXIT_DUP1 );
    }