analyzetool/storageserver/server/src/atdriveinfo.cpp
branchRCL_3
changeset 49 7fdc9a71d314
parent 46 e26895079d7c
child 59 8ad140f3dd41
equal deleted inserted replaced
46:e26895079d7c 49:7fdc9a71d314
     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 "atstorageservercommon.h"
       
    25 #include "atlog.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // TATDriveInfo::TATDriveInfo
       
    29 // C++ default constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 TATDriveInfo::TATDriveInfo()
       
    33     {
       
    34     LOGSTR1( "TATD TATDriveInfo::TATDriveInfo()" );
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // TATDriveInfo::CreatePath()
       
    39 // -----------------------------------------------------------------------------
       
    40 //    
       
    41 TInt TATDriveInfo::CreatePath( TDes& aPath, 
       
    42     const TDesC& aFileName, RFs& aFs )
       
    43     {
       
    44     LOGSTR1( "TATD TInt TATDriveInfo::CreatePath()" );
       
    45     
       
    46     // Drive letter    
       
    47     TChar driveLetter;
       
    48     // Drive number
       
    49     TInt dNumber( EDriveZ );     
       
    50     TBool found( EFalse );
       
    51     // Drive type
       
    52     TUint driveType( KDriveAttRemovable );    
       
    53     TInt err( KErrNotFound );
       
    54     
       
    55     while ( !found )
       
    56         {
       
    57         // Get drive letter
       
    58         if ( GetDrive( driveLetter, dNumber, aFs, driveType ) == KErrNotFound )
       
    59         	{
       
    60         	if ( driveType == KDriveAttInternal )
       
    61         		{
       
    62                 return KErrNotFound;
       
    63         		}       	
       
    64             driveType = KDriveAttInternal;
       
    65         	dNumber = EDriveZ;
       
    66         	}       
       
    67         else
       
    68         	{
       
    69 			// Create path
       
    70 			aPath.Delete( 0, aPath.MaxLength() );
       
    71 			aPath.Append( driveLetter );
       
    72 		  
       
    73 		            
       
    74 		#ifdef __WINS__
       
    75             // For emulator the data file is stored to different location
       
    76             aPath.Append( KATDataFilePath );       
       
    77 		#else
       
    78 		    TDriveInfo driveInfo;
       
    79 		    aFs.Drive( driveInfo, dNumber );      
       
    80             // The drive is removable( memory card ) so we can log inside of root folder
       
    81             if ( driveInfo.iDriveAtt & KDriveAttRemovable )
       
    82                 {
       
    83                 aPath.Append( KATDataFilePath );       
       
    84                 }
       
    85             // The drive is internal user can only access data folder so log into that
       
    86             else
       
    87                 {
       
    88                 aPath.Append( KATDataFilePath2 );       
       
    89                 }
       
    90 		#endif
       
    91 						
       
    92 			// Make a directory for AToolStorageServer's logging data file
       
    93 			err = aFs.MkDir( aPath );
       
    94 			LOGSTR2( "STSE > aFs.MkDir err = %i", err );
       
    95 			
       
    96 			if ( !err || err == KErrAlreadyExists )
       
    97 				{                
       
    98                 if ( aFileName.Length() != 0 && 
       
    99                      ( ( aPath.MaxLength() - aPath.Length() ) > aFileName.Length() ) )
       
   100                     {
       
   101                     aPath.Append( aFileName );
       
   102                     }
       
   103 				found = ETrue;
       
   104 				}
       
   105         	}
       
   106         }        
       
   107     return err;        
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // TATDriveInfo::GetDrive()
       
   112 // -----------------------------------------------------------------------------
       
   113 //    
       
   114 TInt TATDriveInfo::GetDrive( TChar& aDrive, TInt& aDriveNumber, RFs& aFs, 
       
   115 	const TUint aDriveType )
       
   116     {
       
   117     LOGSTR1( "TATD TInt TATDriveInfo::GetDrive()" );
       
   118        
       
   119     // Contains drive information.
       
   120     TDriveInfo driveInfo; 
       
   121     
       
   122     for ( TInt i = aDriveNumber; i >= (TInt)EDriveA; i-- )
       
   123         {
       
   124         // Gets information about a drive and the medium mounted on it.
       
   125         // If error occured then skip to next drive.
       
   126         if ( aFs.Drive( driveInfo, i ) != KErrNone )
       
   127             continue;
       
   128                 
       
   129         // Test whether drive is available. If not, skip to next drive.
       
   130         if ( driveInfo.iDriveAtt & KDriveAbsent || i == (TInt)EDriveD ||
       
   131              driveInfo.iDriveAtt & KDriveAttRom || 
       
   132              driveInfo.iMediaAtt & KMediaAttWriteProtected ||
       
   133              driveInfo.iDriveAtt & KDriveFileSysROFS )
       
   134             continue;
       
   135         
       
   136         // Maps a drive number to the corresponding character.
       
   137         if ( aFs.DriveToChar( i, aDrive ) != KErrNone )
       
   138             continue;                
       
   139         
       
   140         if ( driveInfo.iDriveAtt & aDriveType &&
       
   141              driveInfo.iType != EMediaNotPresent &&
       
   142              driveInfo.iType != EMediaCdRom )
       
   143             {
       
   144             TUint status( 0 );
       
   145             
       
   146             switch ( aDriveType )
       
   147                 {
       
   148                 case KDriveAttRemovable:
       
   149                     {
       
   150                     // Get the drive status of the default removable mass storage.                    
       
   151                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   152                         {
       
   153                         // To indicate that the drive is physically removable.
       
   154                         if ( status & DriveInfo::EDriveRemovable &&
       
   155                              !( status & DriveInfo::EDriveCorrupt ) )
       
   156                             {
       
   157                             aDriveNumber = --i;
       
   158                             return KErrNone;
       
   159                             }
       
   160                         }
       
   161                     }
       
   162                     break;
       
   163                 case KDriveAttInternal:
       
   164                     {
       
   165                     // Get the drive status of the default removable mass storage.
       
   166                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   167                         {
       
   168                         // To indicate that the drive is internal and 
       
   169                         // cannot be physically removed.
       
   170                         if ( status & DriveInfo::EDriveInternal &&
       
   171                              !( status & DriveInfo::EDriveExternallyMountable ) )
       
   172                             {
       
   173                             aDriveNumber = --i;
       
   174                             return KErrNone;
       
   175                             }
       
   176                         }
       
   177                     }
       
   178                     break;
       
   179                     
       
   180                 default:
       
   181                     break;
       
   182                 }
       
   183             }
       
   184         }
       
   185     return KErrNotFound;
       
   186     }
       
   187  
       
   188 // End of File