First public contribution.
1 // Copyright (c) 2002-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 // @file f32test\concur\cfafsdly.cpp
19 #include "cfafsdlyif.h"
20 #include "cfafshmem.h"
22 IMPORT_C TUint32 DebugRegister();
24 const TInt KMajorVersionNumber=1;
25 const TInt KMinorVersionNumber=0;
28 /// Class containing debugging functions.
31 static void Printf(TRefByValue<const TDesC> aFmt, ...)
33 if (DebugRegister() & KDLYTRC)
38 buf.FormatList(aFmt, list);
39 RDebug::Print(_L("%S"), &buf);
42 static void After(TInt usec)
47 timer.After(stat, usec);
48 User::WaitForRequest(stat);
54 TTestFile::TTestFile()
55 /// Initialise a file (clear the size).
60 void TTestFile::Entry(TEntry& aEntry) const
61 /// Set up a standard entry item for the file. Note that it strips off any
62 /// path from the name of the file.
63 /// @param aEntry Item to receive data about the file.
65 TInt i = iName.LocateReverse('\\');
66 if (i == KErrNotFound)
70 aEntry.iName = iName.Mid(i);
71 aEntry.iAtt = KEntryAttNormal;
73 aEntry.iModified = iTime;
81 TTestFile* TTestDir::Create(const TDesC& aName)
82 /// Create a new file, if there is any space left.
83 /// @param aName Name of the file to be created.
84 /// @return Pointer to the file structure if it there is space, NULL if not.
87 for (i = 0; i < KMaxFiles; i++)
89 if (iFile[i].iName.Length() == 0)
91 iFile[i].iName = aName;
99 const TTestFile* TTestDir::Find(const TDesC& aName) const
100 /// Find a file by name.
101 /// @param aName Name of file to find (no wildcards).
102 /// @return Pointer to the file structure if it is found, NULL if not.
105 for (i = 0; i < KMaxFiles; i++)
107 if (aName == iFile[i].iName)
115 TTestFile* TTestDir::Find(const TDesC& aName)
116 /// Find a file by name.
117 /// @param aName Name of file to find (no wildcards).
118 /// @return Pointer to the file structure if it is found, NULL if not.
121 for (i = 0; i < KMaxFiles; i++)
123 if (aName == iFile[i].iName)
131 void TTestDir::Delete(const TDesC& aName)
132 /// Delete a file by name (no wildcards) by setting its name to zero length.
133 /// No error is returned if it doesn't exist.
134 /// @param aName Name of file to delete (no wildcards).
137 for (i = 0; i < KMaxFiles; i++)
139 if (aName == iFile[i].iName)
141 iFile[i].iName.SetLength(0);
147 TTestFile* TTestDir::Entry(TInt aIndex)
148 /// Return a pointer to the specified file by number, or NULL if the index
151 return (aIndex >= 0 && aIndex < KMaxFiles ? &iFile[aIndex] : NULL);
154 CTestFileSystem::CTestFileSystem()
159 __DECLARE_NAME(_S("CTestFileSystem"));
160 TTestDebug::Printf(_L("CTestFileSystem::CTestFileSystem()\n"));
163 CTestFileSystem::~CTestFileSystem()
168 TTestDebug::Printf(_L("CTestFileSystem::~CTestFileSystem()\n"));
171 TInt CTestFileSystem::Install()
173 /// Install the file system
176 TTestDebug::Printf(_L("CTestFileSystem::Install()\n"));
177 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KF32BuildVersionNumber);
178 TPtrC name=_L("DelayFS");
179 return(SetName(&name));
182 CMountCB* CTestFileSystem::NewMountL() const
184 /// Create a new mount control block
187 TTestDebug::Printf(_L("CTestFileSystem::NewMountL()\n"));
188 return (new(ELeave) CTestMountCB);
191 CFileCB* CTestFileSystem::NewFileL() const
193 /// Create a new file
196 TTestDebug::Printf(_L("CTestFileSystem::NewFileL()\n"));
197 return (new(ELeave) CTestFileCB);
200 CDirCB* CTestFileSystem::NewDirL() const
202 /// create a new directory lister
205 TTestDebug::Printf(_L("CTestFileSystem::NewDirL()\n"));
206 return (new(ELeave) CTestDirCB);
209 CFormatCB* CTestFileSystem::NewFormatL() const
211 /// Create a new media formatter
214 TTestDebug::Printf(_L("CTestFileSystem::NewFormatL()\n"));
215 return (new(ELeave) CTestFormatCB);
218 TInt CTestFileSystem::DefaultPath(TDes& aPath) const
220 /// Return the intial default path
223 TTestDebug::Printf(_L("CTestFileSystem::DefaultPath(%S)\n"), aPath.Ptr());
228 void CTestFileSystem::DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const
230 /// Return drive info - iDriveAtt already set
233 TTestDebug::Printf(_L("CTestFileSystem::DriveInfo(%d)\n"), aDriveNumber);
234 anInfo.iMediaAtt = KMediaAttFormattable;
235 anInfo.iType = EMediaHardDisk;
236 // anInfo.iDriveAtt = KDriveAttRemote | KDriveAttRemovable;
237 anInfo.iDriveAtt = KDriveAttRemote;
240 TBusLocalDrive& CTestFileSystem::DriveNumberToLocalDrive(TInt aDriveNumber)
242 /// Return the local drive associated with aDriveNumber
245 TTestDebug::Printf(_L("CTestFileSystem::DriveNumberToLocalDrive()\n"));
246 return(GetLocalDrive(aDriveNumber));
250 Reports whether the specified interface is supported - if it is,
251 the supplied interface object is modified to it
253 @param aInterfaceId The interface of interest
254 @param aInterface The interface object
255 @return KErrNone if the interface is supported, otherwise KErrNotFound
257 @see CFileSystem::GetInterface()
259 TInt CTestFileSystem::GetInterface(TInt aInterfaceId, TAny*& aInterface,TAny* aInput)
263 case CFileSystem::EProxyDriveSupport: // The Filesystem supports proxy drives
267 return(CFileSystem::GetInterface(aInterfaceId, aInterface, aInput));
271 CFileSystem* CTestFileSystem::NewL()
273 /// Create a new filesystem and return the pointer to its structure.
276 CFileSystem* testFSys = new(ELeave) CTestFileSystem;
281 /////////////////////////////////////////////////////////////////////////////
283 static void cvtbuff(TBuf<64>& aOut, const TDesC8& aIn)
284 /// Copy an 8-bit buffer to a generic one.
285 /// @param aOut Generic text buffer.
286 /// @param aIn 8-bit buffer to be copied.
289 TInt n = aIn.Length();
293 for (i = 0; i < n; i++)
294 aOut[i] = TText(aIn[i]);
297 CTestFileCB::CTestFileCB() : CFileCB(), iFile(NULL), iData(NULL)
299 TTestDebug::Printf(_L("CTestFileCB::CTestFileCB()\n"));
302 CTestFileCB::~CTestFileCB()
304 CTestFileCB* file = (CTestFileCB*)this;
306 TTestDebug::Printf(_L("CTestFileCB::~CTestFileCB(%S)\n"), &file->iFile->iName);
308 TTestDebug::Printf(_L("CTestFileCB::~CTestFileCB()\n"));
311 void CTestFileCB::RenameL(const TDesC& aNewName)
312 /// Rename a file (not supported).
314 TTestDebug::Printf(_L("CTestFileCB::RenameL(%S)\n"), aNewName.Ptr());
317 void CTestFileCB::ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage)
318 /// Read from a file. This introduces a fixed delay of 1 second (by default;
319 /// 10mS if KDLYFAST bit is set in the debug register), gets the data from the
320 /// file area and optionally traces it.
323 TInt max = (aPos > iSize ? 0 : iSize - aPos);
324 TInt len = (aLength > max ? max : aLength);
325 // set up return data
326 THMem dataBuffer(aDes, aMessage);
327 dataBuffer.Write(iData+aPos, len, 0);
329 /// now output traces
330 TTestDebug::Printf(_L("CTestFileCB::ReadL(%4d, %4d, %.8X)\n"), aPos, aLength, aDes);
331 TPtr8 pbuf(iData+aPos, len, max);
334 TTestDebug::After(DebugRegister() & KDLYFAST ? 10000 : 1000000);
335 TTestDebug::Printf(_L("CTestFileCB::ReadL(%4d, %4d, %.8X=%.32S) exit\n"), aPos, aLength, aDes, &buf);
338 void CTestFileCB::WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage)
339 /// Write to a file. This introduces a fixed delay of 1 second (by default;
340 /// 10mS if KDLYFAST bit is set in the debug register), puts the data into the
341 /// file area if there is room and optionally traces it.
343 // Set the modified attribute (so Flush() makes its way through)
344 iAtt |= KEntryAttModified;
345 // set up maximum length
346 TInt max = (aPos > KMaxFileLen ? 0 : KMaxFileLen - aPos);
347 TInt len = (aLength > max ? max : aLength);
348 TInt pos = aPos + len;
350 THMem dataBuffer(aDes, aMessage);
351 dataBuffer.Read(iData+aPos, len, 0);
354 iFile->iSize = iSize;
357 TPtr8 pbuf(iData+aPos, len, max);
360 TTestDebug::Printf(_L("CTestFileCB::WriteL(%4d, %4d, %.8X=%.32S)\n"), aPos, aLength, aDes, &buf);
361 TTestDebug::After(DebugRegister() & KDLYFAST ? 10000 : 1000000);
362 TTestDebug::Printf(_L("CTestFileCB::WriteL(%4d, %4d, %.8X) exit\n"), aPos, aLength, aDes);
365 TInt CTestFileCB::Address(TInt& aPos) const
368 TTestDebug::Printf(_L("CTestFileCB::Address(%d)\n"), aPos);
372 void CTestFileCB::SetSizeL(TInt aSize)
375 TTestDebug::Printf(_L("CTestFileCB::SetSizeL(%d)\n"), aSize);
378 void CTestFileCB::SetEntryL(const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask)
381 TTestDebug::Printf(_L("CTestFileCB::SetEntryL(%.8X, %.8X, %.8X)\n"), aTime.Int64(), aSetAttMask, aClearAttMask);
384 void CTestFileCB::FlushDataL()
385 /// Flushes the file (well, actually does nothing other than introduce a fixed delay
386 // of 2.5 seconds (by default; 10mS if KDLYFAST bit is set in the debug register).
388 TTestDebug::Printf(_L("CTestFileCB::FlushDataL()\n"));
389 if(iAtt & KEntryAttModified)
391 iAtt &= ~KEntryAttModified;
392 TTestDebug::After(3500000);
396 void CTestFileCB::FlushAllL()
399 TTestDebug::Printf(_L("CTestFileCB::FlushAllL()\n"));
402 void CTestFileCB::CheckPos(TInt aPos)
405 TTestDebug::Printf(_L("CTestFileCB::CheckPos(%d)\n"), aPos);
408 /////////////////////////////////////////////////////////////////////////////
410 CTestMountCB::CTestMountCB() : CMountCB()
412 TTestDebug::Printf(_L("CTestMountCB::CTestMountCB()\n"));
414 SetVolumeName(HBufC::NewL(0));
417 CTestMountCB::~CTestMountCB()
419 TTestDebug::Printf(_L("CTestMountCB::~CTestMountCB()\n"));
422 void CTestMountCB::MountL(TBool aForceMount)
426 TTestDebug::Printf(_L("CTestMountCB::MountL(forced)\n"));
428 TTestDebug::Printf(_L("CTestMountCB::MountL()\n"));
431 TInt CTestMountCB::ReMount()
434 TTestDebug::Printf(_L("CTestMountCB::ReMount()\n"));
438 void CTestMountCB::Dismounted()
441 TTestDebug::Printf(_L("CTestMountCB::Dismounted()\n"));
444 void CTestMountCB::VolumeL(TVolumeInfo& aVolume) const
445 /// Gets data about the volume -- the name is fixed and the size and free
446 /// space remaining are constant.
448 TTestDebug::Printf(_L("CTestMountCB::VolumeL()\n"));
449 aVolume.iName = _L("DelayTest");
450 aVolume.iSize = KMaxFileLen;
451 aVolume.iFree = KMaxFileLen;
454 void CTestMountCB::SetVolumeL(TDes& aName)
457 TTestDebug::Printf(_L("CTestMountCB::SetVolumeL(%S)\n"), &aName);
460 void CTestMountCB::MkDirL(const TDesC& aName)
462 TTestDebug::Printf(_L("CTestMountCB::MkDirL(%S)\n"), &aName);
463 User::Leave(KErrNotSupported);
466 void CTestMountCB::RmDirL(const TDesC& aName)
469 TTestDebug::Printf(_L("CTestMountCB::RmDirL(%S)\n"), &aName);
472 void CTestMountCB::DeleteL(const TDesC& aName)
474 TTestDebug::Printf(_L("CTestMountCB::DeleteL(%S)\n"), &aName);
478 void CTestMountCB::RenameL(const TDesC& anOldName,const TDesC& anNewName)
481 TTestDebug::Printf(_L("CTestMountCB::RenameL(%S, %S)\n"), &anOldName, &anNewName);
484 void CTestMountCB::ReplaceL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
487 TTestDebug::Printf(_L("CTestMountCB::ReplaceL()\n"));
490 void CTestMountCB::EntryL(const TDesC& aName, TEntry& aEntry) const
491 /// Gets the data associated with the specified file.
493 const TTestFile* e = iDir.Find(aName);
500 aEntry.iName = _L("");
503 aEntry.iType = TUidType();
504 TTestDebug::Printf(_L("CTestMountCB::EntryL(%S) leave KErrNotFound\n"), &aName);
505 User::Leave(KErrNone);
507 TTestDebug::Printf(_L("CTestMountCB::EntryL(%S, %S)\n"), &aName, &aEntry.iName);
510 void CTestMountCB::SetEntryL(const TDesC& aName, const TTime& aTime, TUint aSetAttMask, TUint aClearAttMask)
513 TTestDebug::Printf(_L("CTestMountCB::SetEntryL(%S, %.8X, %.8X, %.8X)\n"),
514 &aName, aTime.Int64(), aSetAttMask, aClearAttMask);
517 void CTestMountCB::FileOpenL(const TDesC& aName, TUint aMode, TFileOpen aOpen, CFileCB* aFile)
518 /// Opens a file in the specified mode (the mode is ignored after this,
519 /// both read and write will work with any open file). If a file is opened
520 /// for writing then it will be overwritten without comment. The timestamp
521 /// of the file will be set when it is opened for writing.
522 /// @param aName Name of the file.
523 /// @param aMode Read, write etc.
525 /// @param aFile Pointer to the already allocated file descriptor area.
527 TTestDebug::Printf(_L("CTestMountCB::FileOpenL(%S, %.8X, %.8X, %.8X)\n"),
528 &aName, aMode, aOpen, aFile);
529 CTestFileCB* file = (CTestFileCB*)aFile;
530 if (aMode & EFileWrite)
532 TTestDebug::Printf(_L("Open for writing\n"));
533 file->iFile = iDir.Find(aName);
535 file->iFile = iDir.Create(aName);
540 file->iFile->iTime = now.DateTime();
541 file->iData = file->iFile->iData;
544 User::Leave(KErrDiskFull);
548 TTestDebug::Printf(_L("Open for reading\n"));
549 file->iFile = iDir.Find(aName);
552 file->iData = file->iFile->iData;
553 aFile->SetSize(file->iFile->iSize);
556 User::Leave(KErrNotFound);
560 void CTestMountCB::DirOpenL(const TDesC& aName, CDirCB* aDir)
561 /// Opens the directory for reading etc.
562 /// @param aName Name to look for.
563 /// @param aDir Pointer to already allocated directory descriptor area.
565 CTestDirCB& dir = *(CTestDirCB*)aDir;
569 TTestDebug::Printf(_L("CTestMountCB::DirOpenL(%S)\n"), &aName);
572 void CTestMountCB::RawReadL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aDes*/,
573 TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) const
576 TTestDebug::Printf(_L("CTestMountCB::RawReadL()\n"));
579 void CTestMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aDes*/,
580 TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/)
583 TTestDebug::Printf(_L("CTestMountCB::RawWriteL()\n"));
586 void CTestMountCB::ReadUidL(const TDesC& /*aName*/,TEntry& /*anEntry*/) const
589 TTestDebug::Printf(_L("CTestMountCB::ReadUidL()\n"));
592 void CTestMountCB::GetShortNameL(const TDesC& /*aLongName*/,TDes& /*aShortName*/)
595 TTestDebug::Printf(_L("CTestMountCB::GetShortNameL()\n"));
598 void CTestMountCB::GetLongNameL(const TDesC& /*aShortName*/,TDes& /*aLongName*/)
601 TTestDebug::Printf(_L("CTestMountCB::GetLongNameL()\n"));
604 void CTestMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& /*aFileStart*/)
607 TTestDebug::Printf(_L("CTestMountCB::IsFileInRom()\n"));
610 void CTestMountCB::ReadSectionL(const TDesC& /*aName*/,TInt /*aPos*/,TAny* /*aTrg*/,
611 TInt /*aLength*/,const RMessagePtr2& /*aMessage*/)
614 TTestDebug::Printf(_L("CTestMountCB::ReadSectionL()\n"));
618 //////////////////////////////////////////////////////////////
620 CTestDirCB::CTestDirCB() : CDirCB()
622 TTestDebug::Printf(_L("CTestDirCB::CTestDirCB()\n"));
625 CTestDirCB::~CTestDirCB()
627 TTestDebug::Printf(_L("CTestDirCB::~CTestDirCB()\n"));
630 void CTestDirCB::ReadL(TEntry& aEntry)
631 /// Read a directory entry. It looks for the next entry which has
632 /// a name starting with the name specified when opening the directory
633 /// (this may be a pathname, for instance).
636 TInt len = iName.Length();
637 while ((e = iDir->Entry(iIndex))!=0 &&
638 (e->iName.Length() <= len || e->iName.Left(len) != iName))
649 aEntry.iName = _L("");
652 aEntry.iType = TUidType();
653 TTestDebug::Printf(_L("CTestDirCB::ReadL() leave KErrNotFound"));
654 User::Leave(KErrNone);
656 TTestDebug::Printf(_L("CTestDirCB::ReadL(%S)\n"), &aEntry.iName);
660 //////////////////////////////////////////////////////////////
662 CTestFormatCB::CTestFormatCB() : CFormatCB()
664 TTestDebug::Printf(_L("CTestFormatCB::CTestFormatCB()\n"));
667 CTestFormatCB::~CTestFormatCB()
669 TTestDebug::Printf(_L("CTestFormatCB::~CTestFormatCB()\n"));
672 void CTestFormatCB::DoFormatStepL()
675 TTestDebug::Printf(_L("CTestFormatCB::DoFormatStepL()\n"));
678 //////////////////////////////////////////////////////////////
682 EXPORT_C CFileSystem* CreateFileSystem()
684 /// Create a new file system.
687 TTestDebug::Printf(_L("CreateFileSystem()\n"));
688 return(CTestFileSystem::NewL());