memana/analyzetoolclient/storageserver/server/src/atdriveinfo.cpp
changeset 0 f0f2b8682603
equal deleted inserted replaced
-1:000000000000 0:f0f2b8682603
       
     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 			aPath.Append( KATDataFilePath );       
       
    73 						
       
    74 			// Make a directory for AToolStorageServer's logging data file
       
    75 			err = aFs.MkDir( aPath );
       
    76 			LOGSTR2( "STSE > aFs.MkDir err = %i", err );
       
    77 			
       
    78 			if ( !err || err == KErrAlreadyExists )
       
    79 				{                
       
    80                 if ( aFileName.Length() != 0 && 
       
    81                      ( ( aPath.MaxLength() - aPath.Length() ) > aFileName.Length() ) )
       
    82                     {
       
    83                     aPath.Append( aFileName );
       
    84                     }
       
    85 				found = ETrue;
       
    86 				}
       
    87         	}
       
    88         }        
       
    89     return err;        
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // TATDriveInfo::GetDrive()
       
    94 // -----------------------------------------------------------------------------
       
    95 //    
       
    96 TInt TATDriveInfo::GetDrive( TChar& aDrive, TInt& aDriveNumber, RFs& aFs, 
       
    97 	const TUint aDriveType )
       
    98     {
       
    99     LOGSTR1( "TATD TInt TATDriveInfo::GetDrive()" );
       
   100        
       
   101     // Contains drive information.
       
   102     TDriveInfo driveInfo; 
       
   103     
       
   104     for ( TInt i = aDriveNumber; i >= (TInt)EDriveA; i-- )
       
   105         {
       
   106         // Gets information about a drive and the medium mounted on it.
       
   107         // If error occured then skip to next drive.
       
   108         if ( aFs.Drive( driveInfo, i ) != KErrNone )
       
   109             continue;
       
   110                 
       
   111         // Test whether drive is available. If not, skip to next drive.
       
   112         if ( driveInfo.iDriveAtt & KDriveAbsent || i == (TInt)EDriveD ||
       
   113              driveInfo.iDriveAtt & KDriveAttRom || 
       
   114              driveInfo.iMediaAtt & KMediaAttWriteProtected ||
       
   115              driveInfo.iDriveAtt & KDriveFileSysROFS )
       
   116             continue;
       
   117         
       
   118         // Maps a drive number to the corresponding character.
       
   119         if ( aFs.DriveToChar( i, aDrive ) != KErrNone )
       
   120             continue;                
       
   121         
       
   122         if ( driveInfo.iDriveAtt & aDriveType &&
       
   123              driveInfo.iType != EMediaNotPresent &&
       
   124              driveInfo.iType != EMediaCdRom )
       
   125             {
       
   126             TUint status( 0 );
       
   127             
       
   128             switch ( aDriveType )
       
   129                 {
       
   130                 case KDriveAttRemovable:
       
   131                     {
       
   132                     // Get the drive status of the default removable mass storage.                    
       
   133                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   134                         {
       
   135                         // To indicate that the drive is physically removable.
       
   136                         if ( status & DriveInfo::EDriveRemovable &&
       
   137                              !( status & DriveInfo::EDriveCorrupt ) )
       
   138                             {
       
   139                             aDriveNumber = --i;
       
   140                             return KErrNone;
       
   141                             }
       
   142                         }
       
   143                     }
       
   144                     break;
       
   145                 case KDriveAttInternal:
       
   146                     {
       
   147                     // Get the drive status of the default removable mass storage.
       
   148                     if ( DriveInfo::GetDriveStatus( aFs, i, status ) == KErrNone )
       
   149                         {
       
   150                         // To indicate that the drive is internal and 
       
   151                         // cannot be physically removed.
       
   152                         if ( status & DriveInfo::EDriveInternal &&
       
   153                              !( status & DriveInfo::EDriveExternallyMountable ) )
       
   154                             {
       
   155                             aDriveNumber = --i;
       
   156                             return KErrNone;
       
   157                             }
       
   158                         }
       
   159                     }
       
   160                     break;
       
   161                     
       
   162                 default:
       
   163                     break;
       
   164                 }
       
   165             }
       
   166         }
       
   167     return KErrNotFound;
       
   168     }
       
   169  
       
   170 // End of File