Update contrib.
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_cache.cpp
19 #include <e32std_private.h>
26 const TInt KMaxCachedDirectories=6;
28 TInt RefreshDriveInfo();
29 void DestroyCachedDirectories(TPathListRecord* aPathRec);
30 void DestroyCachedDirectory(TDriveNumber aDrive, TDirectoryCacheHeader* aDirCache);
31 void DestroyCachedDirectory(TDriveNumber aDrive, TPathListRecord* aPathRec);
33 const TInt KCacheHeapGranularity=0x0800; // Allocate heap in 2K chunks
36 TBool gInitCacheCheckDrivesAndAddNotifications = EFalse;
37 TBool gCacheCheckDrives = ETrue;
41 TDriveCacheHeader* gDriveFileNamesCache[KMaxDrives];
43 TPathListRecord* TPathListRecord::First;
44 TPathListRecord* TPathListRecord::LastStatic;
47 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
51 for (drive=EDriveA; drive<=EDriveZ; ((TInt&)drive)++)
53 TDriveCacheHeader* pDH = gDriveFileNamesCache[drive];
54 RDebug::Printf("Dumping Drive %d", drive);
57 RDebug::Printf("Drive %d not cached",drive);
60 TDirectoryCacheHeader* p = pDH->iDirectoryList;
63 RDebug::Printf(" Dumping directory %S", p->iPath->PathName());
64 TFileCacheRecord** pIndexes = p->iCache;
66 for(j=0; j<p->iRecordCount; j++)
68 TFileCacheRecord& f = *pIndexes[j];
69 TBuf8<20> en = _S8("Entry ");
71 f.Dump((const char*)en.Ptr());
78 CCacheNotifyDirChange::CCacheNotifyDirChange(TDriveNumber aDrive, TDirectoryCacheHeader& aDirHead)
79 : CActive(EPriorityHigh), iDrive(aDrive), iDirHead(&aDirHead)
82 CCacheNotifyDirChange::~CCacheNotifyDirChange()
84 __IF_DEBUG(Printf("~CCacheNotifyDirChange"));
88 void CCacheNotifyDirChange::DoCancel()
90 __IF_DEBUG(Printf("DoCancel"));
91 gTheLoaderFs.NotifyChangeCancel(iStatus);
94 void CCacheNotifyDirChange::RunL()
96 __IF_DEBUG(Printf("Pop!! for drive %d path %S (%d)", iDrive, iDirHead->iPath->PathName(), iStatus.Int()));
98 // unlink directory & delete it
99 DestroyCachedDirectory(iDrive, iDirHead);
100 gCacheCheckDrives = ETrue;
103 TInt CCacheNotifyDirChange::RegisterNotification(TPathListRecord* aPathRec, TNotifyType aType)
105 // Notification that a card has been mounted/removed
108 TDriveUnit drive(iDrive);
109 TFileName pathName(drive.Name());
110 pathName.Append('\\');
111 TInt dl = pathName.Length();
112 const TText* ppp = pathName.Ptr() + dl;
113 const TDesC8& p8 = *aPathRec->PathName();
114 TInt p8l = p8.Length();
115 pathName.SetLength(dl + p8l);
116 TPtr pp((TText*)ppp, 0, KMaxFileName - dl);
118 if (pathName[dl + p8l -1] != '\\')
119 pathName.Append('\\');
121 __IF_DEBUG(Printf("RegisterNotification for drive %d path %S", iDrive, &p8));
122 __IF_DEBUG(Print(_L("register notification for %S"), &pathName));
123 gTheLoaderFs.NotifyChange(aType, iStatus, pathName);
126 if (iStatus != KRequestPending) \
127 RDebug::Printf("Notifier Immediate Complete %d", iStatus.Int()); \
132 TInt SetupNotify(TDriveNumber aDrive, TDirectoryCacheHeader& aDirHead)
134 if (aDirHead.iNotify != NULL)
136 __IF_DEBUG(Printf("SetupNotify!! notification already registered on drive %d path %S", aDrive, aDirHead.iPath->PathName()));
140 __IF_DEBUG(Printf("SetupNotify!! on drive %d path %S", aDrive, aDirHead.iPath->PathName()));
141 CCacheNotifyDirChange* pNotifier = new CCacheNotifyDirChange(aDrive, aDirHead);
144 aDirHead.iNotify = pNotifier;
145 CActiveSchedulerLoader::Add(pNotifier);
146 return pNotifier->RegisterNotification(aDirHead.iPath, ENotifyFile);
149 TInt AddNotifications()
152 for (drive=EDriveA; drive<EDriveZ; ((TInt&)drive)++) // Z always read-only so no notifiers required
154 TDriveCacheHeader* pDH = gDriveFileNamesCache[drive];
158 __IF_DEBUG(Printf("AddNotifications on drive %d att=0x%08x", drive, pDH->iDriveAtt));
160 TDirectoryCacheHeader* p = pDH->iDirectoryList;
161 for (; p; p=p->iNext)
163 TInt r = SetupNotify(drive, *p);
166 DestroyCachedDirectory(drive, p);
171 gCacheCheckDrives = EFalse;
175 //=============================== TFileCacheRecord ==================================
177 TInt TFileCacheRecord::Order(const TFileCacheRecord& aL, const TFileCacheRecord& aR)
179 return aL.Name().CompareF(aR.Name());
182 //=============================== TPathListRecord ==================================
184 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
187 RDebug::Printf("Dumping Pathlist");
188 TPathListRecord* p = TPathListRecord::First;
190 for (; p; p=p->iNext, ++count)
191 RDebug::Printf("Pathlist pos %d %S",count,p->PathName());
195 _LIT8(KDirSystemPrograms, "System\\Programs");
196 _LIT8(KDirSystemLibs, "System\\Libs");
197 _LIT8(KDirSystemBin, "System\\Bin");
198 _LIT8(KDirSysBin, "Sys\\Bin");
200 TInt TPathListRecord::Init()
202 if (!AddToPathList(KDirSysBin, ETrue))
204 if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
206 if (!AddToPathList(KDirSystemPrograms, ETrue))
208 if (!AddToPathList(KDirSystemLibs, ETrue))
210 if (!AddToPathList(KDirSystemBin, ETrue))
216 void TPathListRecord::MoveToHead()
218 if (iKeep || this == LastStatic->iNext)
220 TPathListRecord* p = First;
221 // the record is always in the list
222 for (; p && p->iNext!=this; p=p->iNext) {}
223 __ASSERT_DEBUG(p, User::Invariant());
225 iNext = LastStatic->iNext;
226 LastStatic->iNext = this;
229 TPathListRecord* TPathListRecord::FindPathNameInList(const TDesC8& aPath)
231 __IF_DEBUG(Printf("TPathListRecord::FindPathNameInList %S",&aPath));
232 TPathListRecord* p = DoFindPathNameInList(aPath);
234 p = AddToPathList(aPath, EFalse);
238 TPathListRecord* TPathListRecord::DoFindPathNameInList(const TDesC8& aPath)
240 // Accesses pathname list to retrieve pathname record
241 TPathListRecord* p = First;
242 for (; p; p=p->iNext)
244 if (p->PathName()->CompareF(aPath) == 0)
253 TPathListRecord* TPathListRecord::AddToPathList(const TDesC8& aPath, TBool aKeep)
255 __LDRTRACE(dumpPathList());
256 __IF_DEBUG(Printf("Pathlist adding path %S keep %d",&aPath,aKeep));
258 TPathListRecord* n = TPathListRecord::New(aPath, aKeep);
261 TPathListRecord* p = First;
262 TPathListRecord* q = NULL;
264 for (; p && ++count<KMaxCachedDirectories; q=p, p=p->iNext) {}
267 // need to kill off entry pointed to by p
268 __IF_DEBUG(Printf("In AddToPathList killing %S", p->PathName()));
269 __ASSERT_ALWAYS(!aKeep, User::Invariant());
271 DestroyCachedDirectories(p);
277 // add to front of list
285 // add new entry to front of dynamic list
286 n->iNext = LastStatic->iNext;
287 LastStatic->iNext = n;
290 // Refresh cache now we've added a new path
291 gCacheCheckDrives = ETrue;
293 __LDRTRACE(dumpPathList());
297 TPathListRecord* TPathListRecord::New(const TDesC8& aPath, TBool aKeep)
299 TInt l = aPath.Length();
300 TInt size = sizeof(TPathListRecord) + Align4(l) + sizeof(TDesC8);
301 TPathListRecord* p = (TPathListRecord*)User::Alloc(size);
306 TInt* pb = (TInt*)(p+1);
308 memcpy(pb+1, aPath.Ptr(), l);
313 void DestroyCachedDirectory(TDriveNumber aDrive, TPathListRecord* aPathRec)
315 __IF_DEBUG(Printf("DestroyCachedDirectory drive=%d path=%S",aDrive,aPathRec->PathName()));
316 TDriveCacheHeader* pDH = gDriveFileNamesCache[aDrive];
317 TDirectoryCacheHeader* p = pDH->iDirectoryList;
318 TDirectoryCacheHeader* q = 0;
319 for (; p && p->iPath!=aPathRec; q=p, p=p->iNext) {}
322 __IF_DEBUG(Printf(" unlinking directory %S",p->iPath->PathName()));
326 pDH->iDirectoryList = p->iNext;
327 __IF_DEBUG(Printf(" deleting directory %S",p->iPath->PathName()));
332 void DestroyCachedDirectory(TDriveNumber aDrive, TDirectoryCacheHeader* aDirCache)
334 // First see if it contained in our list
335 __IF_DEBUG(Printf("DestroyCachedDirectory drive=%d path=%S", aDrive, aDirCache->iPath->PathName()));
337 TDriveCacheHeader* pDH = gDriveFileNamesCache[aDrive];
338 TDirectoryCacheHeader* p = pDH->iDirectoryList;
339 TDirectoryCacheHeader* q = 0;
340 for (; p && p!=aDirCache; q=p, p=p->iNext) {}
343 __IF_DEBUG(Printf(" unlinking directory %S",p->iPath->PathName()));
347 pDH->iDirectoryList = p->iNext;
349 __IF_DEBUG(Printf(" deleting directory %S", aDirCache->iPath->PathName()));
353 void DestroyCachedDirectories(TPathListRecord* aPathRec)
355 __IF_DEBUG(Printf("DestroyCachedDirectories %S",aPathRec->PathName()));
357 for (drive=EDriveA; drive<=EDriveZ; ((TInt&)drive)++)
359 TDriveCacheHeader* pDH = gDriveFileNamesCache[drive];
362 __IF_DEBUG(Printf("DestroyCachedDirectories drive=%d driveatt=0x%08x",drive,pDH->iDriveAtt));
363 DestroyCachedDirectory(drive, aPathRec);
368 //=============================== TCacheHeapList ==================================
370 TCacheHeapList::TCacheHeapList(TInt aSize)
371 : iAllocated(Align4(sizeof(TCacheHeapList))),
375 TAny* TCacheHeapList::Allocate(TInt aBytes)
377 __IF_DEBUG(Printf("TCacheHeapList::Allocate used=%d request=%d",iAllocated,aBytes));
378 TInt req = Align4(aBytes);
379 if (iAllocated+req > iSize)
381 TAny* p = PtrAdd(this, iAllocated);
387 //=============================== TDriveCacheHeader==================================
389 TDriveCacheHeader::TDriveCacheHeader()
390 : iDirectoryList(NULL)
393 TDriveCacheHeader::~TDriveCacheHeader()
395 __IF_DEBUG(Printf("~TDriveCacheHeader"));
396 while (iDirectoryList)
398 TDirectoryCacheHeader* p = iDirectoryList;
399 iDirectoryList = p->iNext;
400 __IF_DEBUG(Printf(" deleting directory %S",p->iPath->PathName()));
405 TDirectoryCacheHeader* TDriveCacheHeader::FindDirCache(TPathListRecord* aPath)
407 TDirectoryCacheHeader* p = iDirectoryList;
408 for (; p && p->iPath!=aPath; p=p->iNext) {}
412 TInt TDriveCacheHeader::GetDirCache(TDirectoryCacheHeader*& aCache, TPathListRecord* aPath, const TDesC8& aDriveAndPath)
414 __IF_DEBUG(Printf(">GetDirCache %S", &aDriveAndPath));
415 aCache = FindDirCache(aPath);
418 __IF_DEBUG(Printf("<GetDirCache already exists %08x", aCache));
421 TDirectoryCacheHeader* p = new TDirectoryCacheHeader(aPath);
424 TInt r = p->PopulateFromDrive(aDriveAndPath);
425 __IF_DEBUG(Printf("PopulateFromDrive ret %d", r));
426 if (r != KErrNoMemory && r != KErrLocked && iDriveNumber != EDriveZ)
427 r = SetupNotify((TDriveNumber)iDriveNumber, *p);
428 if (r == KErrNoMemory || r == KErrLocked)
433 // Ignore other errors and keep created entry anyway, so for things like 'path not found'
434 // we have an empty directory cache which will get updated (via notification) if it get created.
435 // This empty entry also allows for a quicker check the second time around.
437 p->iNext = iDirectoryList;
439 __IF_DEBUG(Printf("<GetDirCache new %08x", p));
444 //============================= TDirectoryCacheHeader================================
446 TDirectoryCacheHeader::TDirectoryCacheHeader(TPathListRecord* aPath)
447 : iFirstHeapBlock(NULL), iPath(aPath), iRecordCount(0), iCache(NULL),
448 iNotPresent(ETrue), iNotify(NULL)
451 TDirectoryCacheHeader::~TDirectoryCacheHeader()
453 __IF_DEBUG(Printf("~TDirectoryCacheHeader %S",iPath->PathName()));
457 while (iFirstHeapBlock)
459 TCacheHeapList* p = iFirstHeapBlock;
460 iFirstHeapBlock = p->iNext;
465 TInt TDirectoryCacheHeader::GetMoreHeap()
467 TAny* mem = User::Alloc(KCacheHeapGranularity);
470 TCacheHeapList* n = new (mem) TCacheHeapList(KCacheHeapGranularity);
471 n->iNext = iFirstHeapBlock;
476 TAny* TDirectoryCacheHeader::Allocate(const TInt aBytes)
478 TAny* p = iFirstHeapBlock ? iFirstHeapBlock->Allocate(aBytes) : NULL;
481 if (GetMoreHeap()!=KErrNone)
483 p = iFirstHeapBlock->Allocate(aBytes);
488 TFileCacheRecord* TDirectoryCacheHeader::NewRecord(const TDesC8& aName, TUint32 aAttr, TUint32 aVer, const TEntry& aEntry)
490 TInt l = aName.Length();
491 TInt minsize = l + sizeof(TFileCacheRecord);
492 TInt extra = aEntry.iSize >> 12; // allow for 8 exports per 4K of file
495 TInt size = (minsize + extra + 15) &~ 15;
497 TFileCacheRecord* p = (TFileCacheRecord*)Allocate(size);
500 memclr(p, sizeof(TFileCacheRecord));
502 p->iModuleVersion = aVer;
503 p->iExportDirCount = size - minsize;
505 p->iExportDescType = (aEntry.iAtt & KEntryAttXIP) ? KImageHdr_ExpD_Xip : KImageHdr_ExpD_NoHoles; // for now
507 memcpy(p+1, aName.Ptr(), l);
512 TFileCacheRecord* TDirectoryCacheHeader::NewRecord(const TFileCacheRecord& aRecord, TInt aEDS)
514 TInt l = aRecord.Name().Length();
515 TInt minsize = l + sizeof(TFileCacheRecord);
516 TInt extra = aEDS + 2;
517 TInt size = (minsize + extra + 15) &~ 15;
519 TFileCacheRecord* p = (TFileCacheRecord*)Allocate(size);
522 memcpy(p, &aRecord, minsize);
523 memclr((TUint8*)p + minsize, size - minsize);
528 TInt TDirectoryCacheHeader::PopulateFromDrive(const TDesC8& aPathName)
530 // Wildcard searches through a named directory on a drive.
531 // Creates and fills records to newly populate the drive cache..
533 // only want gen-u-ine files
537 __IF_DEBUG(Print(_L("Opening Directory %S"), &dp));
540 TInt r=d.Open(gTheLoaderFs, dp, KEntryAttMatchExclude|KEntryAttDir|KEntryAttVolume);
541 __IF_DEBUG(Printf("Returns %d", r));
548 TInt sizeofIndexArray=0;
549 TFileCacheRecord** pIndexes=NULL;
553 if (r==KErrNone || r==KErrEof)
555 TInt count=array.Count();
558 TInt newSize=currentIndex+count;
559 // Round alloc granularity up to the size of the cache cells, to avoid heap fragmentation when
560 // indexing large dirs (z:\sys\bin) - interference effect is minimised by allocating in larger blocks and by
561 // ensuring the freed memory can be reused for cache cells. See INC065949 for original defect.
562 const TInt arrayGranularity = KCacheHeapGranularity + RHeap::EAllocCellSize;
563 sizeofIndexArray = (sizeof(TFileCacheRecord*)*newSize + arrayGranularity - 1) / arrayGranularity * arrayGranularity;
564 TFileCacheRecord** p=(TFileCacheRecord**)User::ReAlloc(pIndexes,sizeofIndexArray);
574 const TEntry& e = array[i++];
575 TInt nl = e.iName.Length();
576 if (nl > KMaxKernelName)
578 __IF_DEBUG(Printf("Name length %d - too long", nl));
581 TBuf8<KMaxKernelName> n8;
582 r = CheckedCollapse(n8, e.iName);
585 __IF_DEBUG(Printf("Non-ASCII name"));
592 __IF_DEBUG(Printf("Bad name"));
595 TBuf8<KMaxKernelName> rootname;
596 fni.GetName(rootname, TFileNameInfo::EIncludeBaseExt);
597 TUint32 attr = fni.VerLen() ? ECodeSegAttExpVer : 0;
598 TFileCacheRecord* pR = NewRecord(rootname, attr, fni.Version(), e);
604 pIndexes[currentIndex] = pR;
608 } while (r==KErrNone);
613 iNotPresent = EFalse;
614 iCache = (TFileCacheRecord**)User::ReAlloc(pIndexes,sizeof(TFileCacheRecord*)*currentIndex);
615 iRecordCount = currentIndex;
618 // don't sort an empty list, or a list with only 1 element
619 RPointerArray<TFileCacheRecord> rarray(iCache, iRecordCount);
620 rarray.Sort(&TFileCacheRecord::Order);
624 RDebug::Printf("RArray sorted"); \
626 for (i=0; i<iRecordCount; i++) \
628 TFileCacheRecord* f = iCache[i]; \
629 const TDesC8& name = f->Name(); \
630 RDebug::Printf("%d: Entry=%S att %08x ver %08x", i, &name, f->iAttr, f->iModuleVersion); \
636 TInt RefreshDriveInfo()
638 // Find out what drives are present
639 __IF_DEBUG(Printf(">RefreshDriveInfo"));
641 TInt r = gTheLoaderFs.DriveList(list);
648 for (drive=EDriveA; drive<=EDriveZ; ((TInt&)drive)++)
650 TInt att = list[drive];
653 r = gTheLoaderFs.Drive(d,drive);
656 if ((d.iDriveAtt & KDriveAttRemote) || (d.iDriveAtt & KDriveAttSubsted))
657 continue; //Don't cache remote or substituted drives
658 if (gDriveFileNamesCache[drive] == NULL)
660 __IF_DEBUG(Printf("In RefreshDriveInfo adding drive %d, drive= 0x%08x media=0x%08x", drive, d.iDriveAtt, d.iMediaAtt));
661 TDriveCacheHeader* pDH = new TDriveCacheHeader;
664 gDriveFileNamesCache[drive] = pDH;
665 pDH->iDriveAtt = d.iDriveAtt;
666 pDH->iDriveNumber = drive;
670 TDriveCacheHeader* pDH = gDriveFileNamesCache[drive];
672 gDriveFileNamesCache[drive] = NULL;
674 __IF_DEBUG(Printf("<RefreshDriveInfo"));
679 void InitializeFileNameCache()
681 __IF_DEBUG(Printf("InitializeFileNameCache"));
682 gInitCacheCheckDrivesAndAddNotifications = EFalse;
683 gCacheCheckDrives = ETrue;
684 __ASSERT_ALWAYS(TPathListRecord::Init()==KErrNone, User::Invariant());
687 TInt CheckLoaderCacheInit()
690 if(RefreshZDriveCache)
692 // force z: drive cache to be refreshed
693 __IF_DEBUG(Print(_L("Deleting z: drive cache\r\n")));
694 TDriveCacheHeader* pDH=gDriveFileNamesCache[EDriveZ];
696 gDriveFileNamesCache[EDriveZ]=NULL;
697 gCacheCheckDrives=ETrue;
698 RefreshZDriveCache=EFalse;
700 if (gCacheCheckDrives)
702 __IF_DEBUG(Printf("Refreshing cache"));
703 r = RefreshDriveInfo(); // refreshing is a 'once-only' operation after setting
704 gCacheCheckDrives = EFalse; // gCacheCheckDrives so as to prevent excessive refreshing
706 if (!gInitCacheCheckDrivesAndAddNotifications && StartupInitCompleted)
708 __IF_DEBUG(Printf("Refreshing cache and adding notifications after FS initialisation"));
709 r = RefreshDriveInfo(); // this is to provide an extra refresh to explicitly find
710 r = AddNotifications(); // all drives set up during FS initialisation
711 gInitCacheCheckDrivesAndAddNotifications = ETrue;
716 TFileCacheRecordSearch::TFileCacheRecordSearch(const TDesC8& aSearchName)
718 iNameLength = aSearchName.Length();
719 if(iNameLength>sizeof(iSearchName))
721 memcpy(iSearchName, aSearchName.Ptr(), iNameLength);
724 TInt RImageFinder::SearchSingleDir()
726 __IF_DEBUG(Printf("SearchSingleDir %S drive %d", &iCurrentPath, iCurrentDrive));
728 TDriveCacheHeader* pDH = gDriveFileNamesCache[iCurrentDrive];
731 __IF_DEBUG(Printf("No such drive"));
735 TInt pl = iCurrentPath.Length();
740 if (iCurrentPath[0] == '\\')
742 if (len>0 && iCurrentPath[start + len - 1] == '\\')
745 TPtrC8 path(iCurrentPath.Mid(start, len));
746 __IF_DEBUG(Printf("Normalised path %S", &path));
748 RFs::DriveToChar(iCurrentDrive, c);
749 TBuf8<KMaxFileName> drive_and_path = _S8("?:\\");
750 drive_and_path[0] = (TText8)c;
751 drive_and_path.Append(path);
752 if (drive_and_path[drive_and_path.Length()-1] != '\\')
753 drive_and_path.Append('\\');
755 TPathListRecord* prec = TPathListRecord::FindPathNameInList(path);
758 TDirectoryCacheHeader* dch = NULL;
759 TInt r = pDH->GetDirCache(dch, prec, drive_and_path);
760 if (r != KErrNone || dch->iNotPresent || dch->iRecordCount==0)
765 // set up to search for root name
766 __IF_DEBUG(Printf("Search directory for %S", &iRootName));
767 TFileCacheRecordSearch search(iRootName);
768 __LDRTRACE({const TDesC8& sr = search.Name(); RDebug::Printf("Search record %S", &sr);});
769 RPointerArray<TFileCacheRecord> rarray(dch->iCache, dch->iRecordCount);
770 TInt first = rarray.SpecificFindInOrder(&search, &TFileCacheRecord::Order, EArrayFindMode_First);
771 TInt last = rarray.SpecificFindInOrder(&search, &TFileCacheRecord::Order, EArrayFindMode_Last);
772 __IF_DEBUG(Printf("First %d Last %d", first, last));
774 for (ix = first; ix < last; ++ix)
776 TFileCacheRecord* f = dch->iCache[ix];
779 if (!f->ExtrasValid())
781 r = f->GetImageInfo(img_info, drive_and_path, dch, ix);
782 if (r == KErrNoMemory)
784 f = dch->iCache[ix]; // may have been moved
789 r = Try(img_info, f->Name(), drive_and_path);
790 if (r == KErrNoMemory)
795 f->iCacheStatus = img_info.iCacheStatus;
800 if (r==KErrCompletion)
806 // Populate the 'extras' in the cache record by reading the file header
807 // aPathName must be of the form ?:\dir\...\dir\ so that a fully qualified file name is obtained by
808 // appending the file name.
809 TInt TFileCacheRecord::GetImageInfo(RImageInfo& aInfo, const TDesC8& aPathName, TDirectoryCacheHeader* aDirHead, TInt aIndex)
811 const TDesC8& rootname = Name();
812 TBuf8<KMaxFileName> fn = aPathName;
814 fni.Set(rootname, 0);
815 fni.iVersion = iModuleVersion;
816 TUint flags = (iAttr & ECodeSegAttExpVer) ? TFileNameInfo::EForceVer : 0;
817 fni.GetName(fn, TFileNameInfo::EIncludeBaseExt | flags);
818 __IF_DEBUG(Printf("Opening file %S", &fn));
819 TInt r = OpenFile8(aInfo.iFile, fn);
820 __IF_DEBUG(Printf("Open file returns %d", r));
824 r = aInfo.iFile.Seek(ESeekAddress, address);
825 if (r!=KErrNotSupported)
827 __IF_DEBUG(Printf("ROM file at %08x", address));
829 r = aInfo.iFile.Att(att);
835 if (att & KEntryAttXIP)
837 const TRomImageHeader& rih = *(const TRomImageHeader*)address;
838 __IF_DEBUG(Printf("XIP file"));
840 if ((iAttr & ECodeSegAttExpVer) && iModuleVersion != rih.iModuleVersion)
842 // version in file name does not match version in header
846 iModuleVersion = rih.iModuleVersion;
848 iExportDirCount = (TUint16)rih.iExportDirCount;
849 iExportDescType = (TUint8)KImageHdr_ExpD_Xip;
850 iAttr |= rih.iFlags & (KRomImageFlagFixedAddressExe|KRomImageABIMask);
851 __LDRTRACE(Dump("Cached Info XIP"));
855 TFileCacheRecord* t = this;
856 r = E32ImageHeader::New(aInfo.iHeader, aInfo.iFile);
860 __IF_DEBUG(Printf("E32ImageHeader::New returns %d", r));
863 E32ImageHeader* h = aInfo.iHeader;
864 if ((iAttr & ECodeSegAttExpVer) && iModuleVersion != h->iModuleVersion)
866 // version in file name does not match version in header
870 wordmove(iUid, &h->iUid1, sizeof(iUid));
871 iModuleVersion = h->ModuleVersion();
872 h->GetSecurityInfo(iS);
873 iAttr |= (h->iFlags & ECodeSegAttFixed) | h->ABI();
874 if(h->iFlags&KImageNmdExpData)
875 iAttr |= ECodeSegAttNmdExpData;
876 TUint avail = iExportDirCount;
877 iExportDirCount = (TUint16)h->iExportDirCount;
878 iExportDescType = KImageHdr_ExpD_NoHoles;
880 // get export description...
881 E32ImageHeaderV* v = (E32ImageHeaderV*)h;
882 iExportDescType = v->iExportDescType;
883 TUint eds = v->iExportDescSize;
886 // must reallocate this entry
887 t = aDirHead->NewRecord(*this, eds);
893 aDirHead->iCache[aIndex] = t;
895 TUint8* xd = (TUint8*)t->ExportDescription();
897 xd[1] = (TUint8)(eds>>8);
898 memcpy(xd+2, v->iExportDesc, eds);
900 __LDRTRACE(t->Dump("Cached Info"));
904 RImageInfo& RImageInfo::operator=(const TFileCacheRecord& aRecord)
906 wordmove(this, &aRecord, sizeof(TImageInfo));
907 if (aRecord.ExtrasValid())
911 iRomImageHeader = aRecord.RomImageHeader();
912 wordmove(iUid, &iRomImageHeader->iUid1, sizeof(iUid));
914 else if (iExportDescType != KImageHdr_ExpD_NoHoles)
916 const TUint8* xd = (TUint8*)aRecord.ExportDescription();
917 iExportDescSize = (TUint16)(xd[0] | (xd[1]<<8));
918 iExportDesc = xd + 2;
925 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
926 extern void memory_dump(const TAny* a, TUint l);
928 void TFileCacheRecord::Dump(const char* aTitle)
930 RDebug::Printf(aTitle);
931 TUint32 uid1 = iUid[0];
932 TBool xip = (uid1 != (TUint32)KExecutableImageUidValue && uid1 != (TUint32)KDynamicLibraryUidValue);
933 const TDesC8& name = Name();
936 const TRomImageHeader* rih = RomImageHeader();
937 RDebug::Printf("Name: %S Ver %08x Attr %08x", &name, rih->iModuleVersion, iAttr);
938 RDebug::Printf("UIDS %08x %08x %08x SID %08x CAP %08x %08x", rih->iUid1, rih->iUid2, rih->iUid3,
939 rih->iS.iSecureId, rih->iS.iCaps[1], rih->iS.iCaps[0]);
940 RDebug::Printf("ExportDirCount %d ExportDescType %02x", rih->iExportDirCount, iExportDescType);
944 RDebug::Printf("Name: %S Ver %08x Attr %08x", &name, iModuleVersion, iAttr);
945 RDebug::Printf("UIDS %08x %08x %08x SID %08x CAP %08x %08x", iUid[0], iUid[1], iUid[2],
946 iS.iSecureId, iS.iCaps[1], iS.iCaps[0]);
947 RDebug::Printf("ExportDirCount %d ExportDescType %02x", iExportDirCount, iExportDescType);
948 if (iExportDescType != KImageHdr_ExpD_NoHoles)
950 const TUint8* xd = ExportDescription();
951 TUint eds = (xd[1]<<8) | xd[0];
952 RDebug::Printf("ExportDescSize %04x", eds);
953 memory_dump(xd+2, eds);