os/kernelhwsrv/kerneltest/e32test/lffs/tf_fsscan.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// this isn't actually a test of the media driver.It scans all loaded media
sl@0
    15
// drivers a filesystems and prints information about them
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32std_private.h>
sl@0
    21
#include <e32svr.h>
sl@0
    22
#include <e32test.h>
sl@0
    23
#include <f32file.h>
sl@0
    24
sl@0
    25
sl@0
    26
sl@0
    27
LOCAL_C void ScanPhysicalDeviceDrivers()
sl@0
    28
	/**
sl@0
    29
	 * Displays list of loaded PDDs
sl@0
    30
	 */
sl@0
    31
	{
sl@0
    32
	RDebug::Print( _L("Scanning loaded media drivers...") );
sl@0
    33
sl@0
    34
	_LIT( KSearchName, "Media.*" );
sl@0
    35
	TFindPhysicalDevice findHb;
sl@0
    36
	findHb.Find(KSearchName);
sl@0
    37
	TFullName name;
sl@0
    38
	while (findHb.Next(name)==KErrNone)
sl@0
    39
		{
sl@0
    40
		_LIT( KFormatStr, "    %S" );
sl@0
    41
		RDebug::Print( KFormatStr, &name );
sl@0
    42
		}
sl@0
    43
sl@0
    44
	RDebug::Print( _L("\r\n") );
sl@0
    45
	}
sl@0
    46
sl@0
    47
sl@0
    48
LOCAL_C void ShowDriveCaps( const TLocalDriveCaps& aCaps )
sl@0
    49
	{
sl@0
    50
	RDebug::Print( _L("    size=%ld"), aCaps.iSize );
sl@0
    51
	RDebug::Print( _L("    media type=%d"), aCaps.iType );
sl@0
    52
	RDebug::Print( _L("    connection bus=%d"), aCaps.iConnectionBusType );
sl@0
    53
	RDebug::Print( _L("    drive attributes=0x%x"), aCaps.iDriveAtt );
sl@0
    54
	RDebug::Print( _L("    media attributes=0x%x"), aCaps.iMediaAtt );
sl@0
    55
    RDebug::Print( _L("    base address=0x%x"), aCaps.iBaseAddress );
sl@0
    56
sl@0
    57
	_LIT( KFsysUnknown, "Unknown" );
sl@0
    58
	_LIT( KFsysRom, "ROM" );
sl@0
    59
	_LIT( KFsysFat, "FAT" );
sl@0
    60
	_LIT( KFsysLffs, "LFFS" );
sl@0
    61
	const TDesC* fsType;
sl@0
    62
	switch( aCaps.iFileSystemId )
sl@0
    63
		{
sl@0
    64
		case KDriveFileSysFAT:
sl@0
    65
			fsType = &KFsysFat;
sl@0
    66
			break;
sl@0
    67
		case KDriveFileSysROM:
sl@0
    68
			fsType = &KFsysRom;
sl@0
    69
			break;
sl@0
    70
		case KDriveFileSysLFFS:
sl@0
    71
			fsType = &KFsysLffs;
sl@0
    72
			break;
sl@0
    73
		default:
sl@0
    74
			fsType = &KFsysUnknown;
sl@0
    75
			break;
sl@0
    76
		}
sl@0
    77
sl@0
    78
	RDebug::Print( _L("    filesystem id=%S (%d)\r\n"), fsType, aCaps.iFileSystemId );
sl@0
    79
	}
sl@0
    80
sl@0
    81
LOCAL_C void ShowVariantDriveInfo()
sl@0
    82
	/**
sl@0
    83
	 * Display drive mapping info from variant/ASSP layers
sl@0
    84
	 */
sl@0
    85
	{
sl@0
    86
	RDebug::Print( _L("Variant drive info...") );
sl@0
    87
sl@0
    88
sl@0
    89
	// Drive info
sl@0
    90
	TDriveInfoV1Buf driveInfo;
sl@0
    91
	TInt r=UserHal::DriveInfo(driveInfo);
sl@0
    92
	if( KErrNone == r )
sl@0
    93
		{
sl@0
    94
		RDebug::Print( _L("Total supported drives = %d"), driveInfo().iTotalSupportedDrives );
sl@0
    95
		}
sl@0
    96
	else
sl@0
    97
		{
sl@0
    98
		RDebug::Print( _L("!! Failed to get drive info (e=%d)"), r );
sl@0
    99
		}
sl@0
   100
sl@0
   101
	// Attempt to open local drives
sl@0
   102
	for( TInt i = 0; i < KMaxLocalDrives; i++ )
sl@0
   103
		{
sl@0
   104
		TBusLocalDrive drive;
sl@0
   105
		TBool changedFlag = EFalse;
sl@0
   106
		TInt r = drive.Connect( i, changedFlag );
sl@0
   107
		if( KErrNone == r )
sl@0
   108
			{
sl@0
   109
			RDebug::Print( _L("LocDrive %d: connected"), i );
sl@0
   110
			TLocalDriveCapsV2Buf caps;
sl@0
   111
			TInt rv = drive.Caps( caps );
sl@0
   112
			if( KErrNone == rv )
sl@0
   113
				{
sl@0
   114
				ShowDriveCaps( caps() );
sl@0
   115
				}
sl@0
   116
			else
sl@0
   117
				{
sl@0
   118
				RDebug::Print( _L("    failed to get caps(%d)"), rv );
sl@0
   119
				}
sl@0
   120
			}
sl@0
   121
		else
sl@0
   122
			{
sl@0
   123
			RDebug::Print( _L("LocDrive %d: not available(%d)"), r );
sl@0
   124
			}
sl@0
   125
		drive.Disconnect();
sl@0
   126
		}
sl@0
   127
sl@0
   128
	RDebug::Print( _L("\r\n") );
sl@0
   129
	}
sl@0
   130
sl@0
   131
sl@0
   132
sl@0
   133
LOCAL_C void ShowVolumeInfo( const TVolumeInfo& aInfo )
sl@0
   134
	{
sl@0
   135
	
sl@0
   136
	RDebug::Print( _L("    media type=%d"), aInfo.iDrive.iType );
sl@0
   137
	RDebug::Print( _L("    drive attributes=0x%x"), aInfo.iDrive.iDriveAtt );
sl@0
   138
	RDebug::Print( _L("    media attributes=0x%x"), aInfo.iDrive.iMediaAtt );
sl@0
   139
	RDebug::Print( _L("    connection bus=%d"), aInfo.iDrive.iConnectionBusType );
sl@0
   140
sl@0
   141
	RDebug::Print( _L("    UID=0x%x"), aInfo.iUniqueID );
sl@0
   142
	RDebug::Print( _L("    size=0x%lx"), aInfo.iSize );
sl@0
   143
	RDebug::Print( _L("    free=0x%lx"), aInfo.iFree );
sl@0
   144
	RDebug::Print( _L("    name=%S"), &aInfo.iName );
sl@0
   145
	}
sl@0
   146
sl@0
   147
sl@0
   148
LOCAL_C void ShowDriveMountInfo()
sl@0
   149
	/**
sl@0
   150
	 * Show mounted filesystems
sl@0
   151
	 */
sl@0
   152
	{
sl@0
   153
	RDebug::Print( _L("Scanning drives") );
sl@0
   154
sl@0
   155
	RFs fs;
sl@0
   156
	TInt rv = fs.Connect();
sl@0
   157
	if( KErrNone != rv )
sl@0
   158
		{
sl@0
   159
		RDebug::Print( _L("!! Failed to connect to F32(%d)"), rv );
sl@0
   160
		return;
sl@0
   161
		}
sl@0
   162
sl@0
   163
	for( TInt i = EDriveA; i <= EDriveZ; i++ )
sl@0
   164
		{
sl@0
   165
		RDebug::Print( _L("Drive %c:"), i+'A' );
sl@0
   166
sl@0
   167
		TFullName name;
sl@0
   168
		rv = fs.FileSystemName(name, i);
sl@0
   169
		if( KErrNone != rv && KErrNotFound != rv)
sl@0
   170
			{
sl@0
   171
			RDebug::Print( _L("    !! failed to read filesystem name(%d)"), rv );
sl@0
   172
			}
sl@0
   173
		else 
sl@0
   174
			{
sl@0
   175
			if (name.Length() != 0)
sl@0
   176
				{
sl@0
   177
				RDebug::Print( _L("    FS=%S"), &name );
sl@0
   178
    			}
sl@0
   179
			else
sl@0
   180
				{
sl@0
   181
				RDebug::Print( _L("    no filesystem") );
sl@0
   182
				}
sl@0
   183
sl@0
   184
			TVolumeInfo volInfo;
sl@0
   185
			rv = fs.Volume( volInfo, i );
sl@0
   186
			if( KErrNone == rv )
sl@0
   187
				{
sl@0
   188
				ShowVolumeInfo( volInfo );
sl@0
   189
				}
sl@0
   190
			else
sl@0
   191
				{
sl@0
   192
				RDebug::Print( _L("    !! failed to get volume info(%d)"), rv );
sl@0
   193
				}
sl@0
   194
			RDebug::Print( _L("\r\n") );
sl@0
   195
			}
sl@0
   196
sl@0
   197
sl@0
   198
		}
sl@0
   199
sl@0
   200
	fs.Close();
sl@0
   201
	}
sl@0
   202
sl@0
   203
sl@0
   204
sl@0
   205
void E32Main()
sl@0
   206
	{
sl@0
   207
	RDebug::Print( _L("TF_FSSCAN") );
sl@0
   208
	
sl@0
   209
	ScanPhysicalDeviceDrivers();
sl@0
   210
	ShowVariantDriveInfo();
sl@0
   211
	ShowDriveMountInfo();
sl@0
   212
sl@0
   213
	RDebug::Print( _L("TF_FSSCAN done") );
sl@0
   214
	}
sl@0
   215