| 0 |      1 | // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
|  |      2 | // All rights reserved.
 | 
|  |      3 | // This component and the accompanying materials are made available
 | 
|  |      4 | // under the terms of the License "Eclipse Public License v1.0"
 | 
|  |      5 | // which accompanies this distribution, and is available
 | 
|  |      6 | // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
|  |      7 | //
 | 
|  |      8 | // Initial Contributors:
 | 
|  |      9 | // Nokia Corporation - initial contribution.
 | 
|  |     10 | //
 | 
|  |     11 | // Contributors:
 | 
|  |     12 | //
 | 
|  |     13 | // Description:
 | 
|  |     14 | // f32\sfile\sf_debug.cpp
 | 
|  |     15 | // 
 | 
|  |     16 | //
 | 
|  |     17 | 
 | 
|  |     18 | #include "sf_std.h"
 | 
|  |     19 | #include <f32dbg.h>
 | 
|  |     20 | #include "f32image.h"
 | 
|  |     21 | #include <F32plugin.h>
 | 
|  |     22 | #include "sf_file_cache.h"
 | 
|  |     23 | 
 | 
|  |     24 | 
 | 
|  |     25 | #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
 | 
|  |     26 | 
 | 
|  |     27 | //
 | 
|  |     28 | // ONLY INCLUDED IN DEBUG BUILDS
 | 
|  |     29 | //
 | 
|  |     30 | 
 | 
|  |     31 | void PrintHeapSize(const TDesC& aMessage)
 | 
|  |     32 | //
 | 
|  |     33 | // Display the total memory available
 | 
|  |     34 | //
 | 
|  |     35 | 	{
 | 
|  |     36 | 
 | 
|  |     37 | 	TInt biggest;
 | 
|  |     38 | 	TInt heapSize = User::Allocator().Available(biggest);
 | 
|  |     39 | 	RDebug::Print(_L("%S size=0x%x largest cell=0x%x"),&aMessage,heapSize,biggest);
 | 
|  |     40 | 	}
 | 
|  |     41 | 
 | 
|  |     42 | static void SetAllocFailure(const RMessage2* aMessage)
 | 
|  |     43 | //
 | 
|  |     44 | // Set alloc failure after allocCount allocations
 | 
|  |     45 | //
 | 
|  |     46 | 	{
 | 
|  |     47 | 
 | 
|  |     48 | 	UserHeapAllocFailCount=aMessage->Int1();
 | 
|  |     49 | 	KernHeapAllocFailCount=UserHeapAllocFailCount;
 | 
|  |     50 | 	if (UserHeapAllocFailCount>=0)
 | 
|  |     51 | 		{
 | 
|  |     52 | 		__UHEAP_FAILNEXT(UserHeapAllocFailCount);
 | 
|  |     53 | 		__KHEAP_FAILNEXT(KernHeapAllocFailCount);
 | 
|  |     54 | 		}
 | 
|  |     55 | 	else
 | 
|  |     56 | 		{
 | 
|  |     57 | 		__UHEAP_RESET;
 | 
|  |     58 | 		__KHEAP_RESET;
 | 
|  |     59 | 		}	
 | 
|  |     60 | 	}
 | 
|  |     61 | 
 | 
|  |     62 | TInt FsDebugFunction(CFsRequest* aRequest)
 | 
|  |     63 | //
 | 
|  |     64 | // SetAllocFailure - Set alloc failure after allocCount allocations
 | 
|  |     65 | // SetErrorCondition - Set simulated error failure
 | 
|  |     66 | // SetDebugRegister - Trigger tracing output
 | 
|  |     67 | // DebugNotify - Request notification of a file server event - .FSY specific
 | 
|  |     68 | //
 | 
|  |     69 | 	{
 | 
|  |     70 | 
 | 
|  |     71 | 	TInt r=KErrNone;
 | 
|  |     72 | 	const RMessage2* message=&(aRequest->Message());
 | 
|  |     73 | 	switch (message->Int0())
 | 
|  |     74 | 		{
 | 
|  |     75 | 	case EFsSetAllocFailure: 
 | 
|  |     76 | 		SetAllocFailure(message); 
 | 
|  |     77 | 		break;
 | 
|  |     78 | 	case EFsSetErrorCondition:
 | 
|  |     79 | 		ErrorCondition=message->Int1();
 | 
|  |     80 | 		ErrorCount=message->Int2();
 | 
|  |     81 | 		break;
 | 
|  |     82 | 	case EFsSetDebugRegister:
 | 
|  |     83 | 		DebugReg=message->Int1();
 | 
|  |     84 | 		break;
 | 
|  |     85 | 	case EFsDebugNotify:
 | 
|  |     86 | 		{
 | 
|  |     87 | 		TUint notifyType=(aRequest->Message().Int2())&KDebugNotifyMask;
 | 
|  |     88 | 		if (notifyType)
 | 
|  |     89 | 			{
 | 
|  |     90 | 			CDebugChangeInfo* info=new CDebugChangeInfo;
 | 
|  |     91 | 			if(!info)
 | 
|  |     92 | 				return(KErrNoMemory);
 | 
|  |     93 | 			const RMessage2& m=aRequest->Message();
 | 
|  |     94 | 			info->Initialise(notifyType,(TRequestStatus*)m.Ptr3(),m,aRequest->Session());
 | 
|  |     95 | 			r=FsNotify::AddDebug(info);
 | 
|  |     96 | 			if(r!=KErrNone)
 | 
|  |     97 | 				delete(info);
 | 
|  |     98 | 			else
 | 
|  |     99 | 				aRequest->SetCompleted(EFalse);
 | 
|  |    100 | 			}
 | 
|  |    101 | 		else
 | 
|  |    102 | 			r=KErrArgument;
 | 
|  |    103 | 		break;
 | 
|  |    104 | 		}
 | 
|  |    105 | 	default:
 | 
|  |    106 | 		break;
 | 
|  |    107 | 		};
 | 
|  |    108 | 	return(r);
 | 
|  |    109 | 	}
 | 
|  |    110 | 
 | 
|  |    111 | TBool SimulateError(const RMessage2* aMessage)
 | 
|  |    112 | //
 | 
|  |    113 | // Return an error message if ErrorCount<=0
 | 
|  |    114 | //
 | 
|  |    115 | 	{
 | 
|  |    116 | 	TInt function = aMessage->Function() & KIpcFunctionMask;
 | 
|  |    117 | 	
 | 
|  |    118 | 	if (ErrorCondition!=KErrNone && 
 | 
|  |    119 | 		(
 | 
|  |    120 | 		function!=EFsDebugFunction || aMessage->Int0()!=EFsSetErrorCondition) &&
 | 
|  |    121 | 		function!=EFsNotifyChangeCancel &&
 | 
|  |    122 | 		function!=EFsNotifyChangeCancelEx &&
 | 
|  |    123 | 		function!=EFsNotifyDiskSpaceCancel &&
 | 
|  |    124 | 		function!=EFsFormatSubClose && 
 | 
|  |    125 | 		function!=EFsDirSubClose  && 
 | 
|  |    126 | 		function!=EFsFileSubClose && 
 | 
|  |    127 | 		function!=EFsRawSubClose &&
 | 
|  |    128 | 		function!=EFsUnclamp &&
 | 
|  |    129 | 
 | 
|  |    130 |         //-- this operation must not fail. It can only fail if the client's thread has died.
 | 
|  |    131 |         //-- in this case whole session will be cleaned up.
 | 
|  |    132 | 		function!=EFsFileAdopt 
 | 
|  |    133 |         )
 | 
|  |    134 | 		{
 | 
|  |    135 | 		if (ErrorCount<=0)
 | 
|  |    136 | 			return(ETrue);
 | 
|  |    137 | 		ErrorCount--;
 | 
|  |    138 | 		}
 | 
|  |    139 | 	return(EFalse);
 | 
|  |    140 | 	}
 | 
|  |    141 | 
 | 
|  |    142 | 
 | 
|  |    143 | TPtrC GetFunctionName(TInt aFunction)
 | 
|  |    144 | //
 | 
|  |    145 | // Print number of alloc fails to complete a given function
 | 
|  |    146 | //
 | 
|  |    147 | 	{
 | 
|  |    148 | 
 | 
|  |    149 | 	switch (aFunction)
 | 
|  |    150 | 		{
 | 
|  |    151 | 	case EFsDebugFunction: return _L("EFsDebugFunction");
 | 
|  |    152 | 	case EFsAddFileSystem: return _L("EFsAddFileSystem");
 | 
|  |    153 | 	case EFsRemoveFileSystem: return _L("EFsRemoveFileSystem");
 | 
|  |    154 | 	case EFsMountFileSystem: return _L("EFsMountFileSystem");
 | 
|  |    155 | 	case EFsNotifyChange: return _L("EFsNotifyChange");
 | 
|  |    156 | 	case EFsNotifyChangeCancel: return _L("EFsNotifyChangeCancel");
 | 
|  |    157 | 	case EFsDriveList: return _L("EFsDriveList");
 | 
|  |    158 | 	case EFsDrive: return _L("EFsDrive");
 | 
|  |    159 | 	case EFsVolume: return _L("EFsVolume");
 | 
|  |    160 | 	case EFsSetVolume: return _L("EFsSetVolume");
 | 
|  |    161 | 	case EFsSubst: return _L("EFsSubst");
 | 
|  |    162 | 	case EFsSetSubst: return _L("EFsSetSubst");
 | 
|  |    163 | 	case EFsRealName: return _L("EFsRealName");
 | 
|  |    164 | 	case EFsDefaultPath: return _L("EFsDefaultPath");
 | 
|  |    165 | 	case EFsSetDefaultPath: return _L("EFsSetDefaultPath");
 | 
|  |    166 | 	case EFsSessionPath: return _L("EFsSessionPath");
 | 
|  |    167 | 	case EFsSetSessionPath: return _L("EFsSetSessionPath");
 | 
|  |    168 | 	case EFsMkDir: return _L("EFsMkDir");
 | 
|  |    169 | 	case EFsRmDir: return _L("EFsRmDir");
 | 
|  |    170 | 	case EFsParse: return _L("EFsParse");
 | 
|  |    171 | 	case EFsDelete: return _L("EFsDelete");
 | 
|  |    172 | 	case EFsRename: return _L("EFsRename");
 | 
|  |    173 | 	case EFsReplace: return _L("EFsReplace");
 | 
|  |    174 | 	case EFsEntry: return _L("EFsEntry");
 | 
|  |    175 | 	case EFsSetEntry: return _L("EFsSetEntry");
 | 
|  |    176 | 	case EFsGetDriveName: return _L("EFsGetDriveName");
 | 
|  |    177 | 	case EFsSetDriveName: return _L("EFsSetDriveName");
 | 
|  |    178 | 	case EFsFormatSubClose: return _L("EFsFormatSubClose");
 | 
|  |    179 | 	case EFsDirSubClose: return _L("EFsDirSubClose");
 | 
|  |    180 | 	case EFsFileSubClose: return _L("EFsFileSubClose");
 | 
|  |    181 | 	case EFsRawSubClose: return _L("EFsRawSubClose");
 | 
|  |    182 | 	case EFsFileOpen: return _L("EFsFileOpen");
 | 
|  |    183 | 	case EFsFileCreate: return _L("EFsFileCreate");
 | 
|  |    184 | 	case EFsFileReplace: return _L("EFsFileReplace");
 | 
|  |    185 | 	case EFsFileTemp: return _L("EFsFileTemp");
 | 
|  |    186 | 	case EFsFileRead: return _L("EFsFileRead");
 | 
|  |    187 | 	case EFsFileWrite: return _L("EFsFileWrite");
 | 
|  |    188 | 	case EFsFileLock: return _L("EFsFileLock");
 | 
|  |    189 | 	case EFsFileUnLock: return _L("EFsFileUnLock");
 | 
|  |    190 | 	case EFsFileSeek: return _L("EFsFileSeek");
 | 
|  |    191 | 	case EFsFileFlush: return _L("EFsFileFlush");
 | 
|  |    192 | 	case EFsFileSize: return _L("EFsFileSize");
 | 
|  |    193 | 	case EFsFileSetSize: return _L("EFsFileSetSize");
 | 
|  |    194 | 	case EFsFileAtt: return _L("EFsFileAtt");
 | 
|  |    195 | 	case EFsFileSetAtt: return _L("EFsFileSetAtt");
 | 
|  |    196 | 	case EFsFileModified: return _L("EFsFileModified");
 | 
|  |    197 | 	case EFsFileSetModified: return _L("EFsFileSetModified");
 | 
|  |    198 | 	case EFsFileSet: return _L("EFsFileSet");
 | 
|  |    199 | 	case EFsFileChangeMode: return _L("EFsFileChangeMode");
 | 
|  |    200 | 	case EFsFileRename: return _L("EFsFileRename");
 | 
|  |    201 | 	case EFsDirOpen: return _L("EFsDirOpen");
 | 
|  |    202 | 	case EFsDirReadOne: return _L("EFsDirReadOne");
 | 
|  |    203 | 	case EFsDirReadPacked: return _L("EFsDirReadPacked");
 | 
|  |    204 | 	case EFsFormatOpen: return _L("EFsFormatOpen");
 | 
|  |    205 | 	case EFsFormatNext: return _L("EFsFormatNext");
 | 
|  |    206 | 	case EFsRawDiskOpen: return _L("EFsRawDiskOpen");
 | 
|  |    207 | 	case EFsRawDiskRead: return _L("EFsRawDiskRead");
 | 
|  |    208 | 	case EFsRawDiskWrite: return _L("EFsRawDiskWrite");
 | 
|  |    209 | 	case EFsResourceCountMarkStart: return _L("EFsResourceCountMarkStart");
 | 
|  |    210 | 	case EFsResourceCountMarkEnd: return _L("EFsResourceCountMarkEnd");
 | 
|  |    211 | 	case EFsResourceCount: return _L("EFsResourceCount");
 | 
|  |    212 | 	case EFsCheckDisk: return _L("EFsCheckDisk");
 | 
|  |    213 | 	case EFsGetShortName: return _L("EFsGetShortName");
 | 
|  |    214 | 	case EFsGetLongName: return _L("EFsGetLongName");
 | 
|  |    215 | 	case EFsIsFileOpen: return _L("EFsIsFileOpen");
 | 
|  |    216 | 	case EFsListOpenFiles: return _L("EFsListOpenFiles");
 | 
|  |    217 | 	case EFsSetNotifyUser: return _L("EFsSetNotifyUser");
 | 
|  |    218 | 	case EFsIsFileInRom: return _L("EFsIsFileInRom");
 | 
|  |    219 | 	case EFsGetNotifyUser: return _L("EFsGetNotifyUser");
 | 
|  |    220 | 	case EFsIsValidName: return _L("EFsIsValidName");
 | 
|  |    221 | 	case EFsReadFileSection: return _L("EFsReadFileSection");
 | 
|  |    222 | 	case EFsNotifyChangeEx: return _L("EFsNotifyChangeEx");
 | 
|  |    223 | 	case EFsNotifyChangeCancelEx: return _L("EFsNotifyChangeCancelEx");
 | 
|  |    224 | 	case EFsDismountFileSystem: return _L("EFsDismountFileSystem");
 | 
|  |    225 | 	case EFsFileSystemName: return _L("EFsFileSystemName");
 | 
|  |    226 | 	case EFsScanDrive: return _L("EFsScanDrive");
 | 
|  |    227 | 	case EFsControlIo: return _L("EFsControlIo");
 | 
|  |    228 | 	case EFsLockDrive: return _L("EFsLockDrive");
 | 
|  |    229 | 	case EFsUnlockDrive: return _L("EFsUnlockDrive");
 | 
|  |    230 | 	case EFsClearPassword: return _L("EFsClearPassword");
 | 
|  |    231 | 	case EFsNotifyDiskSpace: return _L("EFsNotifyDiskSpace");
 | 
|  |    232 | 	case EFsNotifyDiskSpaceCancel: return _L("EFsNotifyDiskSpaceCancel");
 | 
|  |    233 | 	case EFsMountFileSystemScan: return _L("EFsMountFileSystemScan");
 | 
|  |    234 | 	case EFsSessionToPrivate: return _L("EFsSessionToPrivate");
 | 
|  |    235 | 	case EFsPrivatePath: return _L("EFsPrivatePath");
 | 
|  |    236 | 	case EFsCreatePrivatePath: return _L("EFsCreatePrivatePath");
 | 
|  |    237 | 	case EFsFileDrive: return _L("EFsFileDrive");
 | 
|  |    238 | 	case EFsRemountDrive: return _L("EFsRemountDrive");
 | 
|  |    239 | 	case EFsAddExtension: return _L("EFsAddExtension");
 | 
|  |    240 | 	case EFsMountExtension: return _L("EFsMountExtension");
 | 
|  |    241 | 	case EFsDismountExtension: return _L("EFsDismountExtension");
 | 
|  |    242 | 	case EFsRemoveExtension: return _L("EFsRemoveExtension");
 | 
|  |    243 | 	case EFsExtensionName: return _L("EFsExtensionName");
 | 
|  |    244 | 	case EFsStartupInitComplete: return _L("EFsStartupInitComplete");
 | 
|  |    245 | 	case EFsSetLocalDriveMapping: return _L("EFsSetLocalDriveMapping");
 | 
|  |    246 | 	case EFsFileDuplicate: return _L("EFsFileDuplicate");
 | 
|  |    247 | 	case EFsFileAdopt: return _L("EFsFileAdopt");
 | 
|  |    248 | 	case EFsFinaliseDrive: return _L("EFsFinaliseDrive");
 | 
|  |    249 | 	case EFsSwapFileSystem: return _L("EFsSwapFileSystem");
 | 
|  |    250 | 	case EFsErasePassword: return _L("EFsErasePassword");
 | 
|  |    251 | 	case EFsReserveDriveSpace: return _L("EFsReserveDriveSpace");
 | 
|  |    252 | 	case EFsGetReserveAccess: return _L("EFsGetReserveAccess");
 | 
|  |    253 | 	case EFsReleaseReserveAccess: return _L("EFsReleaseReserveAccess");
 | 
|  |    254 | 	case EFsFileName: return _L("EFsFileName");
 | 
|  |    255 |     case EFsGetMediaSerialNumber: return _L("EFsGetMediaSerialNumber");
 | 
|  |    256 | 	case EFsFileFullName: return _L("EFsFileFullName");
 | 
|  |    257 | 	case EFsAddPlugin: return _L("EFsAddPlugin");
 | 
|  |    258 | 	case EFsRemovePlugin: return _L("EFsRemovePlugin");
 | 
|  |    259 | 	case EFsMountPlugin: return _L("EFsMountPlugin");
 | 
|  |    260 | 	case EFsDismountPlugin: return _L("EFsDismountPlugin");
 | 
|  |    261 | 	case EFsPluginName: return _L("EFsPluginName");
 | 
|  |    262 | 	case EFsPluginOpen: return _L("EFsPluginOpen");
 | 
|  |    263 | 	case EFsPluginSubClose: return _L("EFsPluginSubClose");
 | 
|  |    264 | 	case EFsPluginDoRequest: return _L("EFsPluginDoRequest");
 | 
|  |    265 | 	case EFsPluginDoControl: return _L("EFsPluginDoControl");
 | 
|  |    266 | 	case EFsPluginDoCancel: return _L("EFsPluginDoCancel");
 | 
|  |    267 | 	case EFsNotifyDismount: return _L("EFsNotifyDismount");
 | 
|  |    268 | 	case EFsNotifyDismountCancel: return _L("EFsNotifyDismountCancel");
 | 
|  |    269 | 	case EFsAllowDismount: return _L("EFsAllowDismount");
 | 
|  |    270 | 	case EFsSetStartupConfiguration: return _L("EFsSetStartupConfiguration");
 | 
|  |    271 | 	case EFsFileReadCancel: return _L("EFsFileReadCancel");
 | 
|  |    272 | 	case EFsAddCompositeMount: return _L("EFsAddCompositeMount");
 | 
|  |    273 | 	case EFsSetSessionFlags: return _L("EFsSetSessionFlags");
 | 
|  |    274 | 	case EFsSetSystemDrive: return _L("EFsSetSystemDrive");
 | 
|  |    275 | 	case EFsBlockMap: return _L("EFsBlockMap");
 | 
|  |    276 | 	case EFsUnclamp: return _L("EFsUnclamp");
 | 
|  |    277 | 	case EFsFileClamp: return _L("EFsFileClamp");
 | 
|  |    278 | 	case EFsQueryVolumeInfoExt: return _L("EFsQueryVolumeInfoExt");
 | 
|  |    279 | 	case EFsInitialisePropertiesFile: return _L("EFsInitialisePropertiesFile");
 | 
|  |    280 | 	case EFsFileWriteDirty: return _L("EFsFileWriteDirty");
 | 
|  |    281 | 	case EFsSynchroniseDriveThread: return _L("EFsSynchroniseDriveThread");
 | 
|  |    282 | 	case EFsAddProxyDrive: return _L("EFsAddProxyDrive");
 | 
|  |    283 | 	case EFsRemoveProxyDrive: return _L("EFsRemoveProxyDrive");
 | 
|  |    284 | 	case EFsMountProxyDrive: return _L("EFsMountProxyDrive");
 | 
|  |    285 | 	case EFsDismountProxyDrive:  return _L("EFsDismountProxyDrive");
 | 
|  |    286 | 	case EFsNotificationAdd : return _L("EFsNotificationAdd"); 
 | 
|  |    287 | 	case EFsNotificationBuffer : return _L("EFsNotificationBuffer");
 | 
|  |    288 | 	case EFsNotificationCancel : return _L("EFsNotificationCancel");
 | 
|  |    289 | 	case EFsNotificationOpen : return _L("EFsNotificationOpen");
 | 
|  |    290 | 	case EFsNotificationRemove : return _L("EFsNotificationRemove");
 | 
|  |    291 | 	case EFsNotificationRequest : return _L("EFsNotificationRequest");
 | 
|  |    292 | 	case EFsNotificationSubClose : return _L("EFsNotificationSubClose");
 | 
|  |    293 | 	case EFsLoadCodePage: return _L("EFsLoadCodePage");
 | 
|  |    294 | 	default:
 | 
|  |    295 | 		return _L("Error unknown function");
 | 
|  |    296 | 		}
 | 
|  |    297 | 	}
 | 
|  |    298 | 
 | 
|  |    299 | 
 | 
|  |    300 | void PrintStartUpReason(TMachineStartupType aReason)
 | 
|  |    301 | //
 | 
|  |    302 | // Print the reason the machine is booting up
 | 
|  |    303 | //
 | 
|  |    304 | 	{
 | 
|  |    305 | 
 | 
|  |    306 | 	TBuf<64> nameBuf;
 | 
|  |    307 | 	switch (aReason)
 | 
|  |    308 | 		{
 | 
|  |    309 | 	case EStartupCold: nameBuf=_L("EStartupCold"); break;
 | 
|  |    310 | 	case EStartupColdReset: nameBuf=_L("EStartupColdReset"); break;
 | 
|  |    311 | 	case EStartupNewOs: nameBuf=_L("EStartupNewOs"); break;
 | 
|  |    312 | 	case EStartupPowerFail: nameBuf=_L("StartupPowerFail"); break;
 | 
|  |    313 | 	case EStartupWarmReset: nameBuf=_L("EStartupWarmReset"); break;
 | 
|  |    314 | 	case EStartupKernelFault: nameBuf=_L("EStartupKernelFault"); break;
 | 
|  |    315 | 	case EStartupSafeReset: nameBuf=_L("EStartupSafeReset"); break;
 | 
|  |    316 | 	default:
 | 
|  |    317 | 		nameBuf=_L("Error unknown startup type");
 | 
|  |    318 | 		}
 | 
|  |    319 | 	__PRINT1(_L("Machine startup - %S"),&nameBuf);
 | 
|  |    320 | 	};
 | 
|  |    321 | 
 | 
|  |    322 | LOCAL_C void AllocPrint(TInt aFunction)
 | 
|  |    323 | //
 | 
|  |    324 | // Print number of alloc fails to complete a given function
 | 
|  |    325 | //
 | 
|  |    326 | 	{
 | 
|  |    327 | 	if (UserHeapAllocFailCount || KernHeapAllocFailCount)
 | 
|  |    328 | 		{	
 | 
|  |    329 | 		TPtrC funcName=GetFunctionName(aFunction);
 | 
|  |    330 | 			{
 | 
|  |    331 | 			__PRINTALLOC(_L("Function %S UserAllocs %d KernAllocs %d"),&funcName,UserHeapAllocFailCount,KernHeapAllocFailCount);
 | 
|  |    332 | 			}
 | 
|  |    333 | 		}
 | 
|  |    334 | 	}
 | 
|  |    335 | 
 | 
|  |    336 | void SimulateAllocFailure(TInt aFunctionReturnValue,TInt aFunction)
 | 
|  |    337 | //
 | 
|  |    338 | // Simulate alloc failure
 | 
|  |    339 | //
 | 
|  |    340 | 	{
 | 
|  |    341 | 
 | 
|  |    342 | 	
 | 
|  |    343 | 	if (UserHeapAllocFailCount>=0 && (aFunctionReturnValue==KErrDiskFull || aFunctionReturnValue==KErrNoMemory))
 | 
|  |    344 | 		{
 | 
|  |    345 | 		if (KernHeapAllocFailCount<20)
 | 
|  |    346 | 			{
 | 
|  |    347 | 			__KHEAP_FAILNEXT(++KernHeapAllocFailCount);
 | 
|  |    348 | 			__UHEAP_FAILNEXT(UserHeapAllocFailCount);
 | 
|  |    349 | 			}
 | 
|  |    350 | 		else
 | 
|  |    351 | 			{
 | 
|  |    352 | 			KernHeapAllocFailCount=0;
 | 
|  |    353 | 			__UHEAP_FAILNEXT(++UserHeapAllocFailCount);
 | 
|  |    354 | 			__KHEAP_FAILNEXT(KernHeapAllocFailCount);
 | 
|  |    355 | 			}
 | 
|  |    356 | 		if (UserHeapAllocFailCount<100)
 | 
|  |    357 | 			return;
 | 
|  |    358 | 		}
 | 
|  |    359 | 	if (UserHeapAllocFailCount>=0)
 | 
|  |    360 | 		{
 | 
|  |    361 | 		AllocPrint(aFunction);
 | 
|  |    362 | 		UserHeapAllocFailCount=0;
 | 
|  |    363 | 		KernHeapAllocFailCount=0;
 | 
|  |    364 | 		__UHEAP_FAILNEXT(UserHeapAllocFailCount);
 | 
|  |    365 | 		__KHEAP_FAILNEXT(KernHeapAllocFailCount);
 | 
|  |    366 | 		}
 | 
|  |    367 | 	}
 | 
|  |    368 | 
 | 
|  |    369 | #else
 | 
|  |    370 | TInt FsDebugFunction(CFsRequest* /*aRequest*/)
 | 
|  |    371 | //
 | 
|  |    372 | // Not in the release build
 | 
|  |    373 | //
 | 
|  |    374 | 	{
 | 
|  |    375 | 	return KErrNotSupported;
 | 
|  |    376 | 	}
 | 
|  |    377 | #endif
 | 
|  |    378 | 
 | 
|  |    379 | TInt TFsDebugFunc::DoRequestL(CFsRequest* aRequest)
 | 
|  |    380 | //
 | 
|  |    381 | // Not in the release build
 | 
|  |    382 | //
 | 
|  |    383 | 	{
 | 
|  |    384 | 	return FsDebugFunction(aRequest);
 | 
|  |    385 | 	}
 | 
|  |    386 | 
 | 
|  |    387 | TInt TFsDebugFunc::Initialise(CFsRequest* /*aRequest*/)
 | 
|  |    388 | //
 | 
|  |    389 | // Not in the release build
 | 
|  |    390 | //
 | 
|  |    391 | 	{
 | 
|  |    392 | 	return KErrNone;
 | 
|  |    393 | 	}
 | 
|  |    394 | 
 | 
|  |    395 | TInt TFsControlIo::DoRequestL(CFsRequest* aRequest)
 | 
|  |    396 | //
 | 
|  |    397 | // General purpose test interface - .FSY specific.
 | 
|  |    398 | // Not in the release build
 | 
|  |    399 | //
 | 
|  |    400 | 	{
 | 
|  |    401 | 	TInt command=aRequest->Message().Int1();
 | 
|  |    402 | 	TAny* param1=(TAny*)aRequest->Message().Ptr2();
 | 
|  |    403 | 	TAny* param2=(TAny*)aRequest->Message().Ptr3();
 | 
|  |    404 | 
 | 
|  |    405 | 
 | 
|  |    406 | #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
 | 
|  |    407 | 	switch(command)
 | 
|  |    408 | 		{	//These are non-drive commands
 | 
|  |    409 | 		case KControlIoGetCorruptLogRecord:
 | 
|  |    410 | 			{
 | 
|  |    411 | 			// number of the log record to be retrieved (1-based)
 | 
|  |    412 | 			TInt logRecNum=(TInt)param2;
 | 
|  |    413 | 			TFsDebugCorruptLogRecordBuf logBuf;
 | 
|  |    414 | 			TInt r=TCorruptLogRec::GetLogRecord(logBuf,logRecNum);
 | 
|  |    415 | 			if(r!=KErrNone)
 | 
|  |    416 | 				return r;
 | 
|  |    417 | 			r=aRequest->Write(2,logBuf,0);
 | 
|  |    418 | 			return r;
 | 
|  |    419 | 			}
 | 
|  |    420 | 		case KControlIoGetNumberOfCorruptLogRecords:
 | 
|  |    421 | 			{
 | 
|  |    422 | 			TPtrC8 ptrHits((TUint8*)&gNumberOfCorruptHits,sizeof(gNumberOfCorruptHits));
 | 
|  |    423 | 			TInt r=aRequest->Write(2,ptrHits,0);
 | 
|  |    424 | 
 | 
|  |    425 | 			return r;
 | 
|  |    426 | 			}
 | 
|  |    427 | 		case KControlIoGetCorruptListFile:
 | 
|  |    428 | 			{
 | 
|  |    429 | 			// Get name of file that contains the filenames nominated as "corrupt"
 | 
|  |    430 | 			TBuf8<KMaxFileName> fileName8;
 | 
|  |    431 | 			if(gCorruptFileNamesListFile)
 | 
|  |    432 | 				{
 | 
|  |    433 | 				fileName8.Copy(*gCorruptFileNamesListFile);
 | 
|  |    434 | 				}
 | 
|  |    435 | 			else
 | 
|  |    436 | 				{
 | 
|  |    437 | 				fileName8.SetLength(0);
 | 
|  |    438 | 				}
 | 
|  |    439 | 			TInt r=aRequest->Write(2,fileName8,0);
 | 
|  |    440 | 			return r;
 | 
|  |    441 | 			}
 | 
|  |    442 | 		case KControlIoCorruptLogRecordReset:
 | 
|  |    443 | 			{
 | 
|  |    444 | 			TCorruptLogRec::DestroyList();
 | 
|  |    445 | 			TCorruptNameRec::ResetListConsumed();
 | 
|  |    446 | 			return KErrNone;
 | 
|  |    447 | 			}
 | 
|  |    448 | 		case KControlIoCacheCount:
 | 
|  |    449 | 			{
 | 
|  |    450 | 			TIOCacheValues cacheValues;
 | 
|  |    451 | 			cacheValues.iCloseCount= RequestAllocator::CloseCount();
 | 
|  |    452 | 			cacheValues.iFreeCount= RequestAllocator::FreeCount();
 | 
|  |    453 | 			cacheValues.iAllocated=	RequestAllocator::AllocatedCount();
 | 
|  |    454 | 			cacheValues.iTotalCount= RequestAllocator::TotalCount();
 | 
|  |    455 | 			TPckgBuf<TIOCacheValues> pkgBuf(cacheValues);
 | 
|  |    456 | 
 | 
|  |    457 | 			// ensure we only write what the client buffer can hold -
 | 
|  |    458 | 			// this allows TIOCacheValues to increase in size without breaking BC
 | 
|  |    459 | 			pkgBuf.SetLength(Min(pkgBuf.MaxLength(), aRequest->Message().GetDesMaxLengthL(2)));
 | 
|  |    460 | 			
 | 
|  |    461 | 			TInt r=aRequest->Write(2,pkgBuf);
 | 
|  |    462 | 			return r;
 | 
|  |    463 | 			}
 | 
|  |    464 | 		case KControlIoGetLocalDriveNumber:
 | 
|  |    465 | 			{
 | 
|  |    466 | 			return DriveNumberToLocalDriveNumber(aRequest->Drive()->DriveNumber());
 | 
|  |    467 | 			}
 | 
|  |    468 | 		case KControlIoCancelDeferredDismount:
 | 
|  |    469 | 			{
 | 
|  |    470 | 			// Cancel and clear deferred dismount information
 | 
|  |    471 | 			aRequest->Drive()->ClearDeferredDismount();
 | 
|  |    472 | 			return KErrNone;
 | 
|  |    473 | 			}
 | 
|  |    474 | 		case KControlIoFileCacheStats:
 | 
|  |    475 | 			{
 | 
|  |    476 | 			CCacheManager* manager = CCacheManagerFactory::CacheManager();
 | 
|  |    477 | 			if (manager == NULL)
 | 
|  |    478 | 				return KErrNotSupported;
 | 
|  |    479 | 
 | 
|  |    480 | 			TFileCacheStats& stats = manager->Stats();
 | 
|  |    481 | 
 | 
|  |    482 | 			TPckgBuf<TFileCacheStats> pkgBuf(stats);
 | 
|  |    483 | 			TInt r=aRequest->Write(2,pkgBuf);
 | 
|  |    484 | 			return r;
 | 
|  |    485 | 			}
 | 
|  |    486 | 		case KControlIoFileCacheConfig:
 | 
|  |    487 | 			{
 | 
|  |    488 | 			TInt driveNumber = aRequest->Drive()->DriveNumber();
 | 
|  |    489 | 
 | 
|  |    490 | 			TFileCacheSettings::TFileCacheConfig* driveConfig = NULL;
 | 
|  |    491 | 			TInt r = TFileCacheSettings::GetFileCacheConfig(driveNumber, driveConfig);
 | 
|  |    492 | 			if (( r != KErrNone) || (driveConfig == NULL))
 | 
|  |    493 | 				return KErrNotSupported;
 | 
|  |    494 | 
 | 
|  |    495 | 			TFileCacheConfig config;
 | 
|  |    496 | 			config.iDrive = driveConfig->iDrive;
 | 
|  |    497 | 			config.iFlags = driveConfig->iFlags;
 | 
|  |    498 | 			config.iFileCacheReadAsync = driveConfig->iFileCacheReadAsync;
 | 
|  |    499 | 			config.iFairSchedulingLen = driveConfig->iFairSchedulingLen;
 | 
|  |    500 | 			config.iCacheSize = driveConfig->iCacheSize;
 | 
|  |    501 | 			config.iMaxReadAheadLen = driveConfig->iMaxReadAheadLen;
 | 
|  |    502 | 			config.iClosedFileKeepAliveTime = driveConfig->iClosedFileKeepAliveTime;
 | 
|  |    503 | 			config.iDirtyDataFlushTime = driveConfig->iDirtyDataFlushTime;
 | 
|  |    504 | 
 | 
|  |    505 | 			TPckgBuf<TFileCacheConfig> pkgBuf(config);
 | 
|  |    506 | 			r=aRequest->Write(2,pkgBuf);
 | 
|  |    507 | 			return r;
 | 
|  |    508 | 			}
 | 
|  |    509 | 		case KControlIoFileCacheFlagsWrite:
 | 
|  |    510 | 			{
 | 
|  |    511 | 			TInt drive = aRequest->Message().Int0();
 | 
|  |    512 | 
 | 
|  |    513 | 			TPckgBuf<TFileCacheFlags> driveFlagsPkg;
 | 
|  |    514 | 			TFileCacheFlags& driveFlags = driveFlagsPkg();
 | 
|  |    515 | 
 | 
|  |    516 | 			TInt r = aRequest->Read(2, driveFlagsPkg);
 | 
|  |    517 | 			if (r != KErrNone)
 | 
|  |    518 | 				return r;
 | 
|  |    519 | 
 | 
|  |    520 | 			__CACHE_PRINT2(_L("CACHE: TFileCacheFlags %x on drive %d"), driveFlags, drive);
 | 
|  |    521 | 			TFileCacheSettings::SetFlags(drive, driveFlags);
 | 
|  |    522 | 
 | 
|  |    523 | 			return r;
 | 
|  |    524 | 			}
 | 
|  |    525 | 		case KControlIoFlushClosedFiles:
 | 
|  |    526 | 			{
 | 
|  |    527 | 			TClosedFileUtils::Remove();
 | 
|  |    528 | 			return KErrNone;
 | 
|  |    529 | 			}
 | 
|  |    530 | 		case KControlIoSimulateLockFailureMode:
 | 
|  |    531 | 			{
 | 
|  |    532 | 			TPckgBuf<TBool> enabledPkg;
 | 
|  |    533 | 			TInt r = aRequest->Read(2, enabledPkg);
 | 
|  |    534 | 			if (r != KErrNone)
 | 
|  |    535 | 				return r;
 | 
|  |    536 | 
 | 
|  |    537 | 			CCacheManager* manager = CCacheManagerFactory::CacheManager();
 | 
|  |    538 | 			if (manager == NULL)
 | 
|  |    539 | 				return KErrNotSupported;
 | 
|  |    540 | 			manager->SimulateLockFailureMode(enabledPkg());
 | 
|  |    541 | 			return KErrNone;
 | 
|  |    542 | 			}
 | 
|  |    543 | 		case KControlIoSimulateFileCacheWriteFailure:
 | 
|  |    544 | 			{
 | 
|  |    545 | 			CCacheManager* manager = CCacheManagerFactory::CacheManager();
 | 
|  |    546 | 			if (manager == NULL)
 | 
|  |    547 | 				return KErrNotSupported;
 | 
|  |    548 | 			manager->SimulateWriteFailure();
 | 
|  |    549 | 			return KErrNone;
 | 
|  |    550 | 			}
 | 
|  |    551 | 		case KControlIoFileCacheDump:
 | 
|  |    552 | 			{
 | 
|  |    553 | 			CCacheManager* manager = CCacheManagerFactory::CacheManager();
 | 
|  |    554 | 			if (manager == NULL)
 | 
|  |    555 | 				return KErrNotSupported;
 | 
|  |    556 | 			manager->DumpCache();
 | 
|  |    557 | 			return KErrNone;
 | 
|  |    558 | 			}
 | 
|  |    559 | 		case KControlIoAllocateMaxSegments:
 | 
|  |    560 | 			{
 | 
|  |    561 | 			TPckgBuf<TBool> enabledPkg;
 | 
|  |    562 | 			TInt r = aRequest->Read(2, enabledPkg);
 | 
|  |    563 | 			if (r != KErrNone)
 | 
|  |    564 | 				return r;
 | 
|  |    565 | 
 | 
|  |    566 | 			CCacheManager* manager = CCacheManagerFactory::CacheManager();
 | 
|  |    567 | 			if (manager == NULL)
 | 
|  |    568 | 				return KErrNotSupported;
 | 
|  |    569 | 			manager->AllocateMaxSegments(enabledPkg());
 | 
|  |    570 | 			return KErrNone;
 | 
|  |    571 | 			}
 | 
|  |    572 | 		case KControlIoDisableFatUtilityFunctions:
 | 
|  |    573 | 			{
 | 
|  |    574 | 			EnableFatUtilityFunctions = EFalse;
 | 
|  |    575 | 			return KErrNone;
 | 
|  |    576 | 			}
 | 
|  |    577 | 		case KControlIoEnableFatUtilityFunctions:
 | 
|  |    578 | 			{
 | 
|  |    579 | 			EnableFatUtilityFunctions = ETrue;
 | 
|  |    580 | 			return KErrNone;
 | 
|  |    581 | 			}
 | 
|  |    582 | 		}
 | 
|  |    583 | #endif
 | 
|  |    584 | 
 | 
|  |    585 | 	return(aRequest->Drive()->ControlIO(aRequest->Message(),command,param1,param2));
 | 
|  |    586 | 	}
 | 
|  |    587 | 
 | 
|  |    588 | TInt TFsControlIo::Initialise(CFsRequest* aRequest)
 | 
|  |    589 | //
 | 
|  |    590 | // General purpose test interface - .FSY specific.
 | 
|  |    591 | // Not in the release build
 | 
|  |    592 | //
 | 
|  |    593 | 	{
 | 
|  |    594 | 	TInt driveNumber=aRequest->Message().Int0();
 | 
|  |    595 | 	if(driveNumber<0||driveNumber>=KMaxDrives)
 | 
|  |    596 | 		return(KErrArgument);
 | 
|  |    597 | 	ValidateDriveDoSubst(driveNumber,aRequest);
 | 
|  |    598 | 	return KErrNone;
 | 
|  |    599 | 	}
 | 
|  |    600 | 
 |