analyzetool/dynamicmemoryhook/src/atdriveinfo.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     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:  Definitions for the class TATDriveInfo.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <f32file.h>
       
    22 #include <driveinfo.h>
       
    23 #include "atdriveinfo.h"
       
    24 #include "atlog.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // TATDriveInfo::TATDriveInfo
       
    28 // C++ default constructor.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 TATDriveInfo::TATDriveInfo()
       
    32     {
       
    33     LOGSTR1( "TATD TATDriveInfo::TATDriveInfo()" );
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // TATDriveInfo::CreatePath()
       
    38 // -----------------------------------------------------------------------------
       
    39 //    
       
    40 TInt TATDriveInfo::CreatePath( TDes& aPath, 
       
    41     const TDesC& aFileName, const TDesC& aFilePath, RFs& aFs )
       
    42     {
       
    43     LOGSTR1( "TATD TInt TATDriveInfo::CreatePath()" );
       
    44     TInt err( KErrNotFound );
       
    45     
       
    46     // first try to create user defined directory
       
    47     if( aFilePath.Length()>0 )
       
    48     	{
       
    49 		err = aFs.MkDir( aFilePath );
       
    50 		LOGSTR2( "STSE > defined path aFs.MkDir err = %i", err );
       
    51 		
       
    52 		if ( !err || err == KErrAlreadyExists )
       
    53 			{
       
    54 			//directory was succesfully created or exists
       
    55 			aPath.Copy( aFilePath );
       
    56 			if ( aFileName.Length() != 0 && 
       
    57 				 ( ( aPath.MaxLength() - aPath.Length() ) > aFileName.Length() ) )
       
    58 				{
       
    59 				aPath.Append( aFileName );
       
    60 				}
       
    61 			return err;
       
    62 			}
       
    63 		else if( err == KErrBadName )
       
    64 			{
       
    65 			// TODO bad path, log error
       
    66 			// log default name in the end of function
       
    67 			}
       
    68     	}
       
    69 	
       
    70 
       
    71 
       
    72 	//error when trying to create user defined directory, lets use default paths
       
    73     
       
    74     // Drive letter    
       
    75     TChar driveLetter;
       
    76     // Drive number
       
    77     TInt dNumber( EDriveZ );     
       
    78     TBool found( EFalse );
       
    79     // Drive type
       
    80     TUint driveType( KDriveAttRemovable );    
       
    81     
       
    82     
       
    83     while ( !found )
       
    84         {
       
    85         // Get drive letter
       
    86         if ( GetDrive( driveLetter, dNumber, aFs, driveType ) == KErrNotFound )
       
    87         	{
       
    88         	if ( driveType == KDriveAttInternal )
       
    89         		{
       
    90                 return KErrNotFound;
       
    91         		}       	
       
    92             driveType = KDriveAttInternal;
       
    93         	dNumber = EDriveZ;
       
    94         	}       
       
    95         else
       
    96         	{
       
    97 			// Create path
       
    98 			aPath.Delete( 0, aPath.MaxLength() );
       
    99 			aPath.Append( driveLetter );
       
   100 		  
       
   101 		            
       
   102 		#ifdef __WINS__
       
   103             // For emulator the data file is stored to different location
       
   104             aPath.Append( KATDataFilePath );       
       
   105 		#else
       
   106 		    TDriveInfo driveInfo;
       
   107 		    aFs.Drive( driveInfo, dNumber );      
       
   108             // The drive is removable( memory card ) so we can log inside of root folder
       
   109             if ( driveInfo.iDriveAtt & KDriveAttRemovable )
       
   110                 {
       
   111                 aPath.Append( KATDataFilePath );       
       
   112                 }
       
   113             // The drive is internal user can only access data folder so log into that
       
   114             else
       
   115                 {
       
   116                 aPath.Append( KATDataFilePath2 );       
       
   117                 }
       
   118 		#endif
       
   119 						
       
   120 			// Make a directory for logging data file
       
   121 			err = aFs.MkDir( aPath );
       
   122 			LOGSTR2( "STSE > aFs.MkDir err = %i", err );
       
   123 			
       
   124 			if ( !err || err == KErrAlreadyExists )
       
   125 				{                
       
   126                 if ( aFileName.Length() != 0 && 
       
   127                      ( ( aPath.MaxLength() - aPath.Length() ) > aFileName.Length() ) )
       
   128                     {
       
   129                     aPath.Append( aFileName );
       
   130                     }
       
   131 				found = ETrue;
       
   132 				}
       
   133         	}
       
   134         }        
       
   135     return err;        
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // TATDriveInfo::GetDrive()
       
   140 // -----------------------------------------------------------------------------
       
   141 //    
       
   142 TInt TATDriveInfo::GetDrive( TChar& aDrive, TInt& aDriveNumber, RFs& aFs, 
       
   143 	const TUint aDriveType )
       
   144     {
       
   145     LOGSTR1( "TATD TInt TATDriveInfo::GetDrive()" );
       
   146        
       
   147     // Contains drive information.
       
   148     TDriveInfo driveInfo; 
       
   149     
       
   150     for ( TInt i = aDriveNumber; i >= (TInt)EDriveA; i-- )
       
   151         {
       
   152         // Gets information about a drive and the medium mounted on it.
       
   153         // If error occured then skip to next drive.
       
   154         if ( aFs.Drive( driveInfo, i ) != KErrNone )
       
   155             continue;
       
   156                 
       
   157         // Test whether drive is available. If not, skip to next drive.
       
   158         if ( driveInfo.iDriveAtt & KDriveAbsent || i == (TInt)EDriveD ||
       
   159              driveInfo.iDriveAtt & KDriveAttRom || 
       
   160              driveInfo.iMediaAtt & KMediaAttWriteProtected ||
       
   161              driveInfo.iDriveAtt & KDriveFileSysROFS )
       
   162             continue;
       
   163         
       
   164         // Maps a drive number to the corresponding character.
       
   165         if ( aFs.DriveToChar( i, aDrive ) != KErrNone )
       
   166             continue;                
       
   167         
       
   168         if ( driveInfo.iDriveAtt & aDriveType &&
       
   169              driveInfo.iType != EMediaNotPresent &&
       
   170              driveInfo.iType != EMediaCdRom )
       
   171             {
       
   172             TUint status( 0 );
       
   173             
       
   174             switch ( aDriveType )
       
   175                 {
       
   176                 case KDriveAttRemovable:
       
   177                     {
       
   178                     // Get the drive status of the default removable mass storage.                    
       
   179                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   180                         {
       
   181                         // To indicate that the drive is physically removable.
       
   182                         if ( status & DriveInfo::EDriveRemovable &&
       
   183                              !( status & DriveInfo::EDriveCorrupt ) )
       
   184                             {
       
   185                             aDriveNumber = --i;
       
   186                             return KErrNone;
       
   187                             }
       
   188                         }
       
   189                     }
       
   190                     break;
       
   191                 case KDriveAttInternal:
       
   192                     {
       
   193                     // Get the drive status of the default removable mass storage.
       
   194                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   195                         {
       
   196                         // To indicate that the drive is internal and 
       
   197                         // cannot be physically removed.
       
   198                         if ( status & DriveInfo::EDriveInternal &&
       
   199                              !( status & DriveInfo::EDriveExternallyMountable ) )
       
   200                             {
       
   201                             aDriveNumber = --i;
       
   202                             return KErrNone;
       
   203                             }
       
   204                         }
       
   205                     }
       
   206                     break;
       
   207                     
       
   208                 default:
       
   209                     break;
       
   210                 }
       
   211             }
       
   212         }
       
   213     return KErrNotFound;
       
   214     }
       
   215  
       
   216 // End of File