First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfile\sf_debug.cpp
21 #include <F32plugin.h>
22 #include "sf_file_cache.h"
25 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
28 // ONLY INCLUDED IN DEBUG BUILDS
31 void PrintHeapSize(const TDesC& aMessage)
33 // Display the total memory available
38 TInt heapSize = User::Allocator().Available(biggest);
39 RDebug::Print(_L("%S size=0x%x largest cell=0x%x"),&aMessage,heapSize,biggest);
42 static void SetAllocFailure(const RMessage2* aMessage)
44 // Set alloc failure after allocCount allocations
48 UserHeapAllocFailCount=aMessage->Int1();
49 KernHeapAllocFailCount=UserHeapAllocFailCount;
50 if (UserHeapAllocFailCount>=0)
52 __UHEAP_FAILNEXT(UserHeapAllocFailCount);
53 __KHEAP_FAILNEXT(KernHeapAllocFailCount);
62 TInt FsDebugFunction(CFsRequest* aRequest)
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
72 const RMessage2* message=&(aRequest->Message());
73 switch (message->Int0())
75 case EFsSetAllocFailure:
76 SetAllocFailure(message);
78 case EFsSetErrorCondition:
79 ErrorCondition=message->Int1();
80 ErrorCount=message->Int2();
82 case EFsSetDebugRegister:
83 DebugReg=message->Int1();
87 TUint notifyType=(aRequest->Message().Int2())&KDebugNotifyMask;
90 CDebugChangeInfo* info=new CDebugChangeInfo;
93 const RMessage2& m=aRequest->Message();
94 info->Initialise(notifyType,(TRequestStatus*)m.Ptr3(),m,aRequest->Session());
95 r=FsNotify::AddDebug(info);
99 aRequest->SetCompleted(EFalse);
111 TBool SimulateError(const RMessage2* aMessage)
113 // Return an error message if ErrorCount<=0
116 TInt function = aMessage->Function() & KIpcFunctionMask;
118 if (ErrorCondition!=KErrNone &&
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 &&
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
143 TPtrC GetFunctionName(TInt aFunction)
145 // Print number of alloc fails to complete a given function
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");
295 return _L("Error unknown function");
300 void PrintStartUpReason(TMachineStartupType aReason)
302 // Print the reason the machine is booting up
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;
317 nameBuf=_L("Error unknown startup type");
319 __PRINT1(_L("Machine startup - %S"),&nameBuf);
322 LOCAL_C void AllocPrint(TInt aFunction)
324 // Print number of alloc fails to complete a given function
327 if (UserHeapAllocFailCount || KernHeapAllocFailCount)
329 TPtrC funcName=GetFunctionName(aFunction);
331 __PRINTALLOC(_L("Function %S UserAllocs %d KernAllocs %d"),&funcName,UserHeapAllocFailCount,KernHeapAllocFailCount);
336 void SimulateAllocFailure(TInt aFunctionReturnValue,TInt aFunction)
338 // Simulate alloc failure
343 if (UserHeapAllocFailCount>=0 && (aFunctionReturnValue==KErrDiskFull || aFunctionReturnValue==KErrNoMemory))
345 if (KernHeapAllocFailCount<20)
347 __KHEAP_FAILNEXT(++KernHeapAllocFailCount);
348 __UHEAP_FAILNEXT(UserHeapAllocFailCount);
352 KernHeapAllocFailCount=0;
353 __UHEAP_FAILNEXT(++UserHeapAllocFailCount);
354 __KHEAP_FAILNEXT(KernHeapAllocFailCount);
356 if (UserHeapAllocFailCount<100)
359 if (UserHeapAllocFailCount>=0)
361 AllocPrint(aFunction);
362 UserHeapAllocFailCount=0;
363 KernHeapAllocFailCount=0;
364 __UHEAP_FAILNEXT(UserHeapAllocFailCount);
365 __KHEAP_FAILNEXT(KernHeapAllocFailCount);
370 TInt FsDebugFunction(CFsRequest* /*aRequest*/)
372 // Not in the release build
375 return KErrNotSupported;
379 TInt TFsDebugFunc::DoRequestL(CFsRequest* aRequest)
381 // Not in the release build
384 return FsDebugFunction(aRequest);
387 TInt TFsDebugFunc::Initialise(CFsRequest* /*aRequest*/)
389 // Not in the release build
395 TInt TFsControlIo::DoRequestL(CFsRequest* aRequest)
397 // General purpose test interface - .FSY specific.
398 // Not in the release build
401 TInt command=aRequest->Message().Int1();
402 TAny* param1=(TAny*)aRequest->Message().Ptr2();
403 TAny* param2=(TAny*)aRequest->Message().Ptr3();
406 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
408 { //These are non-drive commands
409 case KControlIoGetCorruptLogRecord:
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);
417 r=aRequest->Write(2,logBuf,0);
420 case KControlIoGetNumberOfCorruptLogRecords:
422 TPtrC8 ptrHits((TUint8*)&gNumberOfCorruptHits,sizeof(gNumberOfCorruptHits));
423 TInt r=aRequest->Write(2,ptrHits,0);
427 case KControlIoGetCorruptListFile:
429 // Get name of file that contains the filenames nominated as "corrupt"
430 TBuf8<KMaxFileName> fileName8;
431 if(gCorruptFileNamesListFile)
433 fileName8.Copy(*gCorruptFileNamesListFile);
437 fileName8.SetLength(0);
439 TInt r=aRequest->Write(2,fileName8,0);
442 case KControlIoCorruptLogRecordReset:
444 TCorruptLogRec::DestroyList();
445 TCorruptNameRec::ResetListConsumed();
448 case KControlIoCacheCount:
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);
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)));
461 TInt r=aRequest->Write(2,pkgBuf);
464 case KControlIoGetLocalDriveNumber:
466 return DriveNumberToLocalDriveNumber(aRequest->Drive()->DriveNumber());
468 case KControlIoCancelDeferredDismount:
470 // Cancel and clear deferred dismount information
471 aRequest->Drive()->ClearDeferredDismount();
474 case KControlIoFileCacheStats:
476 CCacheManager* manager = CCacheManagerFactory::CacheManager();
478 return KErrNotSupported;
480 TFileCacheStats& stats = manager->Stats();
482 TPckgBuf<TFileCacheStats> pkgBuf(stats);
483 TInt r=aRequest->Write(2,pkgBuf);
486 case KControlIoFileCacheConfig:
488 TInt driveNumber = aRequest->Drive()->DriveNumber();
490 TFileCacheSettings::TFileCacheConfig* driveConfig = NULL;
491 TInt r = TFileCacheSettings::GetFileCacheConfig(driveNumber, driveConfig);
492 if (( r != KErrNone) || (driveConfig == NULL))
493 return KErrNotSupported;
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;
505 TPckgBuf<TFileCacheConfig> pkgBuf(config);
506 r=aRequest->Write(2,pkgBuf);
509 case KControlIoFileCacheFlagsWrite:
511 TInt drive = aRequest->Message().Int0();
513 TPckgBuf<TFileCacheFlags> driveFlagsPkg;
514 TFileCacheFlags& driveFlags = driveFlagsPkg();
516 TInt r = aRequest->Read(2, driveFlagsPkg);
520 __CACHE_PRINT2(_L("CACHE: TFileCacheFlags %x on drive %d"), driveFlags, drive);
521 TFileCacheSettings::SetFlags(drive, driveFlags);
525 case KControlIoFlushClosedFiles:
527 TClosedFileUtils::Remove();
530 case KControlIoSimulateLockFailureMode:
532 TPckgBuf<TBool> enabledPkg;
533 TInt r = aRequest->Read(2, enabledPkg);
537 CCacheManager* manager = CCacheManagerFactory::CacheManager();
539 return KErrNotSupported;
540 manager->SimulateLockFailureMode(enabledPkg());
543 case KControlIoSimulateFileCacheWriteFailure:
545 CCacheManager* manager = CCacheManagerFactory::CacheManager();
547 return KErrNotSupported;
548 manager->SimulateWriteFailure();
551 case KControlIoFileCacheDump:
553 CCacheManager* manager = CCacheManagerFactory::CacheManager();
555 return KErrNotSupported;
556 manager->DumpCache();
559 case KControlIoAllocateMaxSegments:
561 TPckgBuf<TBool> enabledPkg;
562 TInt r = aRequest->Read(2, enabledPkg);
566 CCacheManager* manager = CCacheManagerFactory::CacheManager();
568 return KErrNotSupported;
569 manager->AllocateMaxSegments(enabledPkg());
572 case KControlIoDisableFatUtilityFunctions:
574 EnableFatUtilityFunctions = EFalse;
577 case KControlIoEnableFatUtilityFunctions:
579 EnableFatUtilityFunctions = ETrue;
585 return(aRequest->Drive()->ControlIO(aRequest->Message(),command,param1,param2));
588 TInt TFsControlIo::Initialise(CFsRequest* aRequest)
590 // General purpose test interface - .FSY specific.
591 // Not in the release build
594 TInt driveNumber=aRequest->Message().Int0();
595 if(driveNumber<0||driveNumber>=KMaxDrives)
596 return(KErrArgument);
597 ValidateDriveDoSubst(driveNumber,aRequest);