Exemplo n.º 1
0
void QDriveWatcherEngine::CompareDriveLists(const TDriveList &aDriveList)
{
    if (!(aDriveList.Length() > KMaxDrives - 1) || !(m_previousDriveList.Length() > KMaxDrives - 1))
        return;

    for (int i = 0; i < KMaxDrives; i++) {
        if (aDriveList[i] == KDriveAbsent && m_previousDriveList[i] == KDriveAbsent)
            continue;

        if (aDriveList[i] > KDriveAbsent && m_previousDriveList[i] > KDriveAbsent)
            continue;

        if (aDriveList[i] == KDriveAbsent && m_previousDriveList[i] > KDriveAbsent) {
            TChar volumeChar;
            QString volume;
            if (iFs.DriveToChar(i, volumeChar) == KErrNone)
                volume = QChar(volumeChar).toLatin1();

            m_watcher->emitDriveRemoved(volume);
        } else if (aDriveList[i] > KDriveAbsent && m_previousDriveList[i] == KDriveAbsent) {
            TChar volumeChar;
            QString volume;
            if (iFs.DriveToChar(i, volumeChar) == KErrNone)
                volume = QChar(volumeChar).toLatin1();

            m_watcher->emitDriveAdded(volume);
        }
    }
    m_previousDriveList.Copy(aDriveList);
}
// ---------------------------------------------------------------------------
// CSisxSifPluginUiHandler::AddMemorySelectionL()
// ---------------------------------------------------------------------------
//
void CSisxSifPluginUiHandler::AddMemorySelectionL()
    {
    TInt64 adjustedSize = iMaxInstalledSize + KFreeSpaceTreshold;

    TDriveList driveList;
    TInt driveCount = 0;
    TInt err = DriveInfo::GetUserVisibleDrives( iFs, driveList, driveCount );
    User::LeaveIfError( err );

    iSelectableDrives.Reset();
    TInt driveListLength = driveList.Length();
    for( TInt driveNumber = 0; driveNumber < driveListLength; driveNumber++ )
        {
        if( driveList[ driveNumber ] )
            {
            TUint driveStatus = 0;
            err = DriveInfo::GetDriveStatus( iFs, driveNumber, driveStatus );
            if( !err && !( driveStatus & DriveInfo::EDriveRemote ) )
                {
                TVolumeInfo volumeInfo;
                err = iFs.Volume( volumeInfo, driveNumber );
                if( !err && volumeInfo.iFree > adjustedSize )
                    {
                    iSelectableDrives.Append( driveNumber );
                    }
                }
            }
        }

    iSifUi->SetMemorySelectionL( iSelectableDrives );
    }
Exemplo n.º 3
0
void CMMCStorageStatus::CompareDriveLists(const TDriveList &aDriveList)
{
    if (!(aDriveList.Length() > KMaxDrives - 1) || !(m_previousDriveList.Length() > KMaxDrives - 1))
        return;

    for (int i = 0; i < KMaxDrives; i++) {

        if (aDriveList[i] == KDriveAbsent && m_previousDriveList[i] == KDriveAbsent) {
            continue;
        } else if (aDriveList[i] > KDriveAbsent && m_previousDriveList[i] > KDriveAbsent) {
            continue;
        } else if (aDriveList[i] == KDriveAbsent && m_previousDriveList[i] > KDriveAbsent) {
            TChar volumeChar;
            QString volume;
            bool driveInserted = false;
            if (iFs.DriveToChar(i, volumeChar) == KErrNone)
                volume = QChar(volumeChar).toAscii();

            foreach (MStorageStatusObserver *observer, m_observers)
                observer->storageStatusChanged(driveInserted, volume);
            break;
        } else if (aDriveList[i] > KDriveAbsent && m_previousDriveList[i] == KDriveAbsent) {
            TChar volumeChar;
            QString volume;
            bool driveInserted = true;
            if (iFs.DriveToChar(i, volumeChar) == KErrNone)
                volume = QChar(volumeChar).toAscii();

            foreach (MStorageStatusObserver *observer, m_observers)
                observer->storageStatusChanged(driveInserted, volume);
            break;
        }
    }
    m_previousDriveList.Copy(aDriveList);
}
Exemplo n.º 4
0
// Manual test - requires user to move a card between two physical slots
extern TInt E32Main()
	{
	test.Start(_L("T_MULTISLOT Test"));
	test(fs.Connect()==KErrNone);
	
	// Get the list of removable drive driver-letters
	TDriveList driveList;
	test(fs.DriveList(driveList,KDriveAttRemovable)==KErrNone);
	
	
	TInt length=driveList.Length();
	TBool pass = EFalse;
	
	// i is drive letter (as int)
	// for every removable media logical drive
	for(TInt i=0; i<length; i++)
		{
		if(driveList[i] == 0)
			{
			continue;
			}

		TChar driveChar = i+'A';
		test.Next(_L("Testing Logical Drive"));
		

		TInt FirstlocDrvNum = KErrNotFound;
		TInt SecondlocDrvNum = KErrNotFound;
		TInt driveNum = -1;
		driveNum = i+'A';
		test.Printf(_L("Logical Drive : %d"), driveNum);
		
		// Get local drive number by gettin ghr Serial number fo the card (RFs call), then 
		// enumerating the TBusLocalDrives and finding one that matches.
		test(FindMmcLocalDriveNumber(driveChar,FirstlocDrvNum,driveNum)==KErrNone);
		// Got first local drive number, now move card into second slot.
		test.Printf(_L("<Move MMC Card to second slot, then press any key>"));
		test.Getch();
		// Get second local drive number for same logical drive (should be different local drive number).
		test(FindMmcLocalDriveNumber(driveChar,SecondlocDrvNum,driveNum)==KErrNone);
		if(FirstlocDrvNum!=SecondlocDrvNum)
			{
			pass=ETrue;
			break;
			}
		// else perhaps this wasn't a multislot drive
		}
	test(pass);
	test.End();
	test.Close();
	
	fs.Close();
	return KErrNone;
	}
// ---------------------------------------------------------------------------
// CAppMngr2SisxRuntime::GetAdditionalDirsToScanL()
// ---------------------------------------------------------------------------
//
void CAppMngr2SisxRuntime::GetAdditionalDirsToScanL( RFs& aFsSession,
        RPointerArray<HBufC>& aDirs )
    {
    // Return KAppMngr2DaemonPrivateFolder directories that may contain
    // untrusted applications. Untrusted application is partially installed
    // and user needs to install it's SISX from KAppMngr2DaemonPrivateFolder
    // to complete it's installation. For example, when memory card is inserted
    // in mobile phone, installer processes applications installed in the memory
    // card. If some memory card application requires user-granted capabilities,
    // installer creates SISX in KAppMngr2DaemonPrivateFolder. The SISX must be
    // installed to grant the capabilities to the application.
    TDriveList driveList;
    TInt driveCount = 0;
    User::LeaveIfError( DriveInfo::GetUserVisibleDrives( aFsSession, driveList, driveCount ) );
    
    TInt driveListLength = driveList.Length();
    for( TInt driveNumber = 0; driveNumber < driveListLength; driveNumber++ )
        {
        if( driveList[ driveNumber ] )
            {
            // Internal and remote drives are not listed. Internal drives cannot
            // be removed/replaced, so there are no untrusted applications either.
            // Remote drives cannot be used to install applications at all.
            TUint driveStatus = 0;
            TInt err = DriveInfo::GetDriveStatus( aFsSession, driveNumber, driveStatus );
            if( err == KErrNone && !( driveStatus & DriveInfo::EDriveRemote ) &&
                    !( driveStatus & DriveInfo::EDriveInternal ) )
                {
                TChar driveLetter;
                if( RFs::DriveToChar( driveNumber, driveLetter ) == KErrNone )
                    {
                    const TInt dirLength = KDriveSpec().Length() +
                            KAppMngr2DaemonPrivateFolder().Length(); 
                    HBufC* dir = HBufC::NewLC( dirLength );
                    TPtr dirPtr = dir->Des();
                    dirPtr.Format( KDriveSpec, static_cast<TUint>( driveLetter ) );
                    dirPtr.Append( KAppMngr2DaemonPrivateFolder );
                    aDirs.AppendL( dir );
                    FLOG( "CAppMngr2SisxRuntime::GetAdditionalDirsToScanL: adding %S", dir );
                    CleanupStack::Pop( dir );
                    }
                }
            }
        }
    }
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 );
    }
//------------------------------------------------------------------------
//CHttpDownloadManagerServerEngine::QueryDynDriveListLC
//------------------------------------------------------------------------
HBufC8* CHttpDownloadManagerServerEngine::QueryDynDriveListLC()
    {
    TDriveList driveList;
    TInt driveCount( 0 );
    TInt err;
    TChar driveLetter;
    TBuf8<KMaxDriveListStrLen> driveLettersDyn;

    // Checking validity of drives in Cenrep List
    // drive letters are separated by semicolons
    // Destination is FFS in default
    TInt drive;
    User::LeaveIfError(
        DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive ) );

    for( TInt i = 0; i < iDriveLettersCenRep.Length(); i = i + 2 )
        {
        if( iRfs.CharToDrive( iDriveLettersCenRep[i], drive ) == KErrNone )
            {
            TUint status;
            if ( DriveInfo::GetDriveStatus( iRfs, drive, status ) == KErrNone )
                {
                if ( ( status & ( DriveInfo::EDriveUserVisible | DriveInfo::EDrivePresent ) ) )
                    {
                    CLOG_WRITE_1( "Drive %d is present and visible", drive);
                    }
                }
            }
        }

    if ( iDriveLettersCenRep.Length() > 0 )
        {
        driveLettersDyn.Append( iDriveLettersCenRep );
        if ( driveLettersDyn[driveLettersDyn.Length() - 1] != ';' )
            {
            driveLettersDyn.Append( KDefaultDriveListSep );
            }
        }

    // get the list of drives available in real time
    err = DriveInfo::GetUserVisibleDrives( iRfs, driveList, driveCount );
    if ( err == KErrNone )
        {
        TInt count( driveList.Length() );
        for ( TInt i( 0 ); i < count; ++i )
            {
            if ( driveList[ i ] )
                {
                User::LeaveIfError( iRfs.DriveToChar( i, driveLetter) );
                TInt drivePos = driveLettersDyn.LocateF( driveLetter );
                if ( drivePos == KErrNotFound )
                    {
                    driveLettersDyn.Append( driveLetter ); 
                    driveLettersDyn.Append( KDefaultDriveListSep ); 
                    }
                }
            }

        CLOG_WRITE_1( "Pref. drive list dynamic: [%S]", &driveLettersDyn );
        }
    else
        {
        CLOG_WRITE_1( "GetUserVisibleDrives failed with %d", err );
        }

    HBufC8* driveLetters = HBufC8::NewLC( KMaxDriveListStrLen );
    driveLetters->Des().Copy( driveLettersDyn );
    return driveLetters;
    }
Exemplo n.º 9
0
TBool CPMRfsPlugin::IsMMCFormatFlagEnabledL()
	{
	RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabledL()");
	
	RFs rfs;
	User::LeaveIfError( rfs.Connect() );
	CleanupClosePushL( rfs );	
#ifndef RD_MULTIPLE_DRIVE
	TFileName fullPath;
	fullPath.Append( _L("e") );
	fullPath.Append( MDriveColon );	
	fullPath.Append( KDMUtilServerPrivatePath );
	fullPath.Append( KMMCEraseFlagFileName );
		
	RFile file;
	TInt err = file.Open( rfs, fullPath, EFileRead );
	file.Close();
	
	CleanupStack::PopAndDestroy( &rfs );
	
	if( err == KErrNone )
		{
		RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue");
		return ETrue;
		}
	
	RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err);
	return EFalse;
#else
	TDriveList driveList;
	TInt driveCount;
	TBool fileReplace = EFalse;
	TInt err = KErrNone;
	
	//Get all removeable drive, both physically and logically
	User::LeaveIfError(DriveInfo::GetUserVisibleDrives(
            rfs,  driveList,  driveCount, KDriveAttRemovable ));
    
    TInt max(driveList.Length());
    
    RFileWriteStream file;
    for(TInt i=0; i<max;++i)
    {
    	if (driveList[i])
    	{
    		TUint status;
    		DriveInfo::GetDriveStatus(rfs, i, status);
    		//To make sure the drive is physically removeable not logically removeable	
    		//need to format internal mass memory also. So no need to check the below condition
    		//if (status & DriveInfo::EDriveRemovable)
    		{
    			TChar driveLetter;
    			rfs.DriveToChar(i,driveLetter);
				
				TFileName fullPath;
				fullPath.Append( driveLetter );
				fullPath.Append( MDriveColon );
				fullPath.Append( KDMUtilServerPrivatePath );
				fullPath.Append( KMMCEraseFlagFileName );
				
				RFile flagfile;
				err = flagfile.Open( rfs, fullPath, EFileRead );
				flagfile.Close();

				if( err == KErrNone )
				{
					if (!fileReplace)
					{
						User::LeaveIfError(file.Temp(rfs, _L("C:\\"),iFileName, EFileWrite));	
						file.WriteInt16L(65279);
						CleanupClosePushL(file);  
							
						fileReplace = ETrue;
						RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - File created on private path");
					}
			
					file.WriteL(_L("FORMAT"));
					file.WriteL(_L(" "));
					TBuf<4> DriveLetterBuf;
					DriveLetterBuf.Append(driveLetter);
					file.WriteL(DriveLetterBuf);
					file.WriteL(_L(":"));
					file.WriteL(_L("\r\n"));
					
				}
					
			}
    	}
     }
     
   	if (fileReplace)
   	{
   		file.CommitL();
   		CleanupStack::PopAndDestroy(); // pop file
   	}
		
	CleanupStack::PopAndDestroy( &rfs );	
     if (fileReplace)
     {
     	RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue:");
     	return ETrue;
     }
     else
     {
     	RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err);
     	return EFalse;
     }
    

#endif //RD_MULTIPLE_DRIVE
	}