0
|
1 |
// Copyright (c) 1995-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\srom\sr_rom.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "sr_std.h"
|
|
19 |
|
|
20 |
#if defined(_UNICODE)
|
|
21 |
#define __SIZE(len) ((len)<<1)
|
|
22 |
#else
|
|
23 |
#define __SIZE(len) (len)
|
|
24 |
#endif
|
|
25 |
|
|
26 |
const TRomHeader* CRom::iRomHeaderAddress=(TRomHeader*)UserSvr::RomHeaderAddress();
|
|
27 |
|
|
28 |
TInt TRomDir::BinarySearch(const TDesC& aName, TInt aLengthLimit, TInt aMode, TBool aDir) const
|
|
29 |
{
|
|
30 |
// RDebug::Print(_L("BinarySearch %S ll=%d m=%d dir=%d"), &aName, aLengthLimit, aMode, aDir);
|
|
31 |
const TRomDirSortInfo* s = SortInfo();
|
|
32 |
TInt l = aDir ? 0 : s->iSubDirCount;
|
|
33 |
TInt r = aDir ? s->iSubDirCount : s->iSubDirCount + s->iFileCount;
|
|
34 |
TBool found = EFalse;
|
|
35 |
while (r>l)
|
|
36 |
{
|
|
37 |
TInt m=(l+r)>>1;
|
|
38 |
const TRomEntry* e = SortedEntry(m);
|
|
39 |
TInt nl = Min(e->iNameLength, aLengthLimit);
|
|
40 |
TPtrC en((const TText*)&e->iName[0], nl);
|
|
41 |
TInt k = CRomMountCB::Compare(aName, en);
|
|
42 |
if (k==0)
|
|
43 |
{
|
|
44 |
if (aMode == EArrayFindMode_Any)
|
|
45 |
{
|
|
46 |
// RDebug::Printf("Found %d", m);
|
|
47 |
return m;
|
|
48 |
}
|
|
49 |
found = ETrue;
|
|
50 |
if (aMode == EArrayFindMode_First)
|
|
51 |
r=m;
|
|
52 |
else
|
|
53 |
l=m+1;
|
|
54 |
}
|
|
55 |
else if (k>0)
|
|
56 |
l=m+1;
|
|
57 |
else
|
|
58 |
r=m;
|
|
59 |
}
|
|
60 |
// RDebug::Printf("Found=%d r=%d", found, r);
|
|
61 |
return found ? r : KErrNotFound;
|
|
62 |
}
|
|
63 |
|
|
64 |
// Navigate the path to find the leaf directory, starting at this.
|
|
65 |
const TRomDir* TRomDir::FindLeafDir(const TDesC& aPath) const
|
|
66 |
{
|
|
67 |
TLex lex(aPath);
|
|
68 |
TInt r;
|
|
69 |
const TRomDir* d = this;
|
|
70 |
FOREVER
|
|
71 |
{
|
|
72 |
lex.Inc(); // Skip the file separator
|
|
73 |
lex.Mark();
|
|
74 |
r=lex.Remainder().Locate(KPathDelimiter);
|
|
75 |
if (r==KErrNotFound)
|
|
76 |
r=lex.Remainder().Length();
|
|
77 |
if (r==0) // End of the path
|
|
78 |
break;
|
|
79 |
lex.Inc(r); // Set the token length
|
|
80 |
TInt ix = d->BinarySearch(lex.MarkedToken(), KMaxTInt, EArrayFindMode_Any, ETrue);
|
|
81 |
if (ix<0)
|
|
82 |
return NULL;
|
|
83 |
const TRomEntry* e = d->SortedEntry(ix);
|
|
84 |
// if (!(e->iAtt & KEntryAttDir))
|
|
85 |
// return NULL;
|
|
86 |
d = (const TRomDir*)e->iAddressLin;
|
|
87 |
}
|
|
88 |
return d;
|
|
89 |
}
|
|
90 |
|
|
91 |
LOCAL_C void Fault(TFault aFault)
|
|
92 |
//
|
|
93 |
// Report a fault in the rom file system.
|
|
94 |
//
|
|
95 |
{
|
|
96 |
|
|
97 |
User::Panic(_L("ROMFILESYS"),aFault);
|
|
98 |
}
|
|
99 |
|
|
100 |
CRomMountCB::CRomMountCB(const CRom* aRom)
|
|
101 |
//
|
|
102 |
// Constructor
|
|
103 |
//
|
|
104 |
: iRom(aRom)
|
|
105 |
{
|
|
106 |
}
|
|
107 |
|
|
108 |
void CRomMountCB::Dismounted()
|
|
109 |
//
|
|
110 |
// Dummy implementation of pure virtual function
|
|
111 |
//
|
|
112 |
{}
|
|
113 |
|
|
114 |
void CRomMountCB::IsFileInRom(const TDesC& aName,TUint8*& aFileStart)
|
|
115 |
//
|
|
116 |
// Return the address of the file if it is in rom
|
|
117 |
//
|
|
118 |
{
|
|
119 |
|
|
120 |
TLinAddr dir;
|
|
121 |
TLinAddr entry=0;
|
|
122 |
aFileStart=NULL;
|
|
123 |
TRAPD(r,FindEntryL(aName,KEntryAttNormal,ETrue,dir,entry));
|
|
124 |
if (r!=KErrNone)
|
|
125 |
return;
|
|
126 |
aFileStart=(TUint8*)((const TRomEntry*)entry)->iAddressLin;
|
|
127 |
}
|
|
128 |
|
|
129 |
TInt CRomMountCB::Compare(const TDesC& aLeft, const TDesC& aRight)
|
|
130 |
//
|
|
131 |
//Compares two filenames. Folds ASCII characters to uppercase
|
|
132 |
//
|
|
133 |
{
|
|
134 |
|
|
135 |
TInt ll = aLeft.Length();
|
|
136 |
TInt rl = aRight.Length();
|
|
137 |
TInt len = Min(ll, rl);
|
|
138 |
const TText* l = aLeft.Ptr();
|
|
139 |
const TText* r = aRight.Ptr();
|
|
140 |
while (len--)
|
|
141 |
{
|
|
142 |
TText lc = *l++;
|
|
143 |
TText rc = *r++;
|
|
144 |
if (lc >= 'A' && lc <= 'Z')
|
|
145 |
lc += ('a' - 'A');
|
|
146 |
if (rc >= 'A' && rc <= 'Z')
|
|
147 |
rc += ('a' - 'A');
|
|
148 |
TInt x = lc - rc;
|
|
149 |
if (x)
|
|
150 |
return x;
|
|
151 |
}
|
|
152 |
// match up to end of shorter string, now compare lengths
|
|
153 |
return ll - rl;
|
|
154 |
}
|
|
155 |
|
|
156 |
void CRomMountCB::FindBinaryL(const TDesC& aName, TUint aAtt, TBool aAttKnown, TLinAddr aDir, TLinAddr& aEntry, TInt aError) const
|
|
157 |
//
|
|
158 |
//Identical to FindL, but uses binary search for faster performance.
|
|
159 |
//However, can't deal with wildcards, whereas FindL can.
|
|
160 |
//
|
|
161 |
{
|
|
162 |
|
|
163 |
//Although the value of aEntry is not used, we expect it to be zero,
|
|
164 |
__ASSERT_DEBUG(aEntry==0,Fault(ERomInvalidArgument));
|
|
165 |
const TRomDir* d = (const TRomDir*)aDir;
|
|
166 |
TBool ix;
|
|
167 |
if (aAttKnown)
|
|
168 |
ix = d->BinarySearch(aName, KMaxTInt, EArrayFindMode_Any, aAtt & KEntryAttDir);
|
|
169 |
else
|
|
170 |
{
|
|
171 |
//We don't know whether we're looking for a file or a directory, so
|
|
172 |
//look through both
|
|
173 |
ix = d->BinarySearch(aName, KMaxTInt, EArrayFindMode_Any, EFalse);
|
|
174 |
if (ix<0 || !MatchEntryAtt(d->SortedEntry(ix)->iAtt, aAtt) )
|
|
175 |
ix = d->BinarySearch(aName, KMaxTInt, EArrayFindMode_Any, ETrue);
|
|
176 |
}
|
|
177 |
if (ix>=0)
|
|
178 |
{
|
|
179 |
const TRomEntry* e = d->SortedEntry(ix);
|
|
180 |
if (MatchEntryAtt(e->iAtt, aAtt))
|
|
181 |
{
|
|
182 |
aEntry = (TLinAddr)e;
|
|
183 |
return;
|
|
184 |
}
|
|
185 |
}
|
|
186 |
User::Leave(aError);
|
|
187 |
}
|
|
188 |
|
|
189 |
void CRomMountCB::FindL(const TDesC& aName, TUint anAtt, TLinAddr aDir, TLinAddr& anEntry, TInt anError) const
|
|
190 |
//
|
|
191 |
// Scan from aDir looking for aName.
|
|
192 |
// If found return the result in anEntry.
|
|
193 |
//
|
|
194 |
{
|
|
195 |
const TRomDir* pD = (const TRomDir*)aDir;
|
|
196 |
const TRomEntry* pE;
|
|
197 |
if (anEntry==0)
|
|
198 |
pE = &pD->iEntry;
|
|
199 |
else
|
|
200 |
{
|
|
201 |
pE = (const TRomEntry*)anEntry;
|
|
202 |
pE = PtrAdd(pE, Align4(__SIZE(pE->iNameLength) + KRomEntrySize));
|
|
203 |
}
|
|
204 |
const TRomEntry* pEnd = PtrAdd(&pD->iEntry, pD->iSize);
|
|
205 |
while (pE<pEnd)
|
|
206 |
{
|
|
207 |
TPtrC name = TPtrC((const TText*)&pE->iName[0], pE->iNameLength);
|
|
208 |
if (name.MatchF(aName)!=KErrNotFound && MatchEntryAtt(pE->iAtt, anAtt))
|
|
209 |
{
|
|
210 |
anEntry = (TLinAddr)pE;
|
|
211 |
return;
|
|
212 |
}
|
|
213 |
pE = PtrAdd(pE, Align4(__SIZE(pE->iNameLength) + KRomEntrySize));
|
|
214 |
}
|
|
215 |
User::Leave(anError);
|
|
216 |
}
|
|
217 |
|
|
218 |
void CRomMountCB::FindEntryL(const TDesC& aName, TUint anAtt, TBool aAttKnown, TLinAddr& aDir, TLinAddr& anEntry) const
|
|
219 |
//
|
|
220 |
// Locate an entry from its full path name.
|
|
221 |
//
|
|
222 |
{
|
|
223 |
|
|
224 |
TInt namePos=aName.LocateReverse(KPathDelimiter)+1; // There is always a path delimiter
|
|
225 |
const TRomDir* d = ((const TRomDir*)RomRootDirectory())->FindLeafDir(aName.Left(namePos));
|
|
226 |
if (!d)
|
|
227 |
User::Leave(KErrPathNotFound);
|
|
228 |
anEntry=0;
|
|
229 |
aDir = (TLinAddr)d;
|
|
230 |
FindBinaryL(aName.Mid(namePos),anAtt,aAttKnown,aDir,anEntry,KErrNotFound);
|
|
231 |
}
|
|
232 |
|
|
233 |
void CRomMountCB::MountL(TBool /*aForceMount*/)
|
|
234 |
//
|
|
235 |
// Mount a media. Only allowed to leave with KErrNoMemory,KErrNotReady,KErrCorrupt,KErrUnknown.
|
|
236 |
//
|
|
237 |
{
|
|
238 |
|
|
239 |
iUniqueID=0;
|
|
240 |
iSize=(TUint)RomHeader().iUncompressedSize;
|
|
241 |
SetVolumeName(_L("RomDrive").AllocL());
|
|
242 |
}
|
|
243 |
|
|
244 |
TInt CRomMountCB::ReMount()
|
|
245 |
//
|
|
246 |
// Try and remount this media.
|
|
247 |
//
|
|
248 |
{
|
|
249 |
|
|
250 |
Fault(ERomReMountNotSupported);
|
|
251 |
return(0);
|
|
252 |
}
|
|
253 |
|
|
254 |
void CRomMountCB::VolumeL(TVolumeInfo& aVolume) const
|
|
255 |
//
|
|
256 |
// Return the volume info.
|
|
257 |
//
|
|
258 |
{
|
|
259 |
|
|
260 |
aVolume.iFree=0;
|
|
261 |
}
|
|
262 |
|
|
263 |
void CRomMountCB::SetVolumeL(TDes& /*aName*/)
|
|
264 |
//
|
|
265 |
// Set the volume label.
|
|
266 |
//
|
|
267 |
{
|
|
268 |
|
|
269 |
User::Leave(KErrAccessDenied);
|
|
270 |
}
|
|
271 |
|
|
272 |
void CRomMountCB::MkDirL(const TDesC& /*aName*/)
|
|
273 |
//
|
|
274 |
// Make a directory.
|
|
275 |
//
|
|
276 |
{
|
|
277 |
|
|
278 |
User::Leave(KErrAccessDenied);
|
|
279 |
}
|
|
280 |
|
|
281 |
void CRomMountCB::RmDirL(const TDesC& /*aName*/)
|
|
282 |
//
|
|
283 |
// Remove a directory.
|
|
284 |
//
|
|
285 |
{
|
|
286 |
|
|
287 |
User::Leave(KErrAccessDenied);
|
|
288 |
}
|
|
289 |
|
|
290 |
void CRomMountCB::DeleteL(const TDesC& /*aName*/)
|
|
291 |
//
|
|
292 |
// Delete a file.
|
|
293 |
//
|
|
294 |
{
|
|
295 |
|
|
296 |
User::Leave(KErrAccessDenied);
|
|
297 |
}
|
|
298 |
|
|
299 |
void CRomMountCB::RenameL(const TDesC& /*anOldName*/,const TDesC& /*aNewName*/)
|
|
300 |
//
|
|
301 |
// Rename a file or directory.
|
|
302 |
//
|
|
303 |
{
|
|
304 |
|
|
305 |
User::Leave(KErrAccessDenied);
|
|
306 |
}
|
|
307 |
|
|
308 |
void CRomMountCB::ReplaceL(const TDesC& /*anOldName*/,const TDesC& /*aNewName*/)
|
|
309 |
//
|
|
310 |
// Atomic replace.
|
|
311 |
//
|
|
312 |
{
|
|
313 |
|
|
314 |
User::Leave(KErrAccessDenied);
|
|
315 |
}
|
|
316 |
|
|
317 |
void CRomMountCB::EntryL(const TDesC& aName,TEntry& anEntry) const
|
|
318 |
//
|
|
319 |
// Get entry details.
|
|
320 |
//
|
|
321 |
{
|
|
322 |
|
|
323 |
TLinAddr dir;
|
|
324 |
TLinAddr entry;
|
|
325 |
FindEntryL(aName,KEntryAttMaskSupported,EFalse,dir,entry);
|
|
326 |
const TRomEntry* pE = (const TRomEntry*)entry;
|
|
327 |
anEntry.iAtt=pE->iAtt;
|
|
328 |
anEntry.iSize=pE->iSize;
|
|
329 |
anEntry.iModified=RomHeader().iTime;
|
|
330 |
anEntry.iName.Des().Copy((TText*)&pE->iName[0],pE->iNameLength);
|
|
331 |
ReadUidL(pE->iAddressLin,anEntry);
|
|
332 |
}
|
|
333 |
|
|
334 |
void CRomMountCB::SetEntryL(const TDesC& /*aName*/,const TTime& /*aTime*/,TUint /*aMask*/,TUint /*aVal*/)
|
|
335 |
//
|
|
336 |
// Set entry details.
|
|
337 |
//
|
|
338 |
{
|
|
339 |
|
|
340 |
User::Leave(KErrAccessDenied);
|
|
341 |
}
|
|
342 |
|
|
343 |
void CRomMountCB::FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile)
|
|
344 |
//
|
|
345 |
// Open a file on the current mount.
|
|
346 |
//
|
|
347 |
{
|
|
348 |
|
|
349 |
if (aMode&EFileWrite)
|
|
350 |
User::Leave(KErrAccessDenied);
|
|
351 |
switch (anOpen)
|
|
352 |
{
|
|
353 |
case EFileCreate:
|
|
354 |
case EFileReplace:
|
|
355 |
User::Leave(KErrAccessDenied);
|
|
356 |
case EFileOpen:
|
|
357 |
break;
|
|
358 |
default:
|
|
359 |
User::Leave(KErrAccessDenied);
|
|
360 |
}
|
|
361 |
TLinAddr dir;
|
|
362 |
TLinAddr entry;
|
|
363 |
FindEntryL(aName,KEntryAttMustBeFile,ETrue,dir,entry);
|
|
364 |
const TRomEntry* pE = (const TRomEntry*)entry;
|
|
365 |
CRomFileCB& file=(*((CRomFileCB*)aFile));
|
|
366 |
file.SetSize(pE->iSize);
|
|
367 |
file.SetAtt(pE->iAtt);
|
|
368 |
file.SetModified(RomHeader().iTime);
|
|
369 |
file.SetBase((const TUint8*)pE->iAddressLin);
|
|
370 |
}
|
|
371 |
|
|
372 |
void CRomMountCB::DirOpenL(const TDesC& aName, CDirCB* aDir)
|
|
373 |
//
|
|
374 |
// Open a file on the current mount.
|
|
375 |
//
|
|
376 |
{
|
|
377 |
|
|
378 |
TFileName fileName=aName;
|
|
379 |
TInt namePos=aName.LocateReverse(KPathDelimiter)+1; // Exclude path delimiter
|
|
380 |
if (namePos==aName.Length())
|
|
381 |
fileName+=_L("*");
|
|
382 |
const TRomDir* d = ((const TRomDir*)RomRootDirectory())->FindLeafDir(aName.Left(namePos));
|
|
383 |
if (!d)
|
|
384 |
User::Leave(KErrPathNotFound);
|
|
385 |
CRomDirCB& dirCB = *(CRomDirCB*)aDir;
|
|
386 |
dirCB.SetDir((TLinAddr)d, NULL, fileName.Mid(namePos));
|
|
387 |
}
|
|
388 |
|
|
389 |
void CRomMountCB::RawReadL(TInt64 aPos,TInt aLength,const TAny* aDes,TInt anOffset,const RMessagePtr2& aMessage) const
|
|
390 |
//
|
|
391 |
// Read up to aLength data directly from the ROM
|
|
392 |
//
|
|
393 |
{
|
|
394 |
|
|
395 |
TUint romSize=RomHeader().iUncompressedSize;
|
|
396 |
if (I64LOW(aPos)>=romSize)
|
|
397 |
aMessage.WriteL(2,TPtrC8(NULL,0),anOffset);
|
|
398 |
else
|
|
399 |
{
|
|
400 |
TInt len=Min((TInt)(romSize-I64LOW(aPos)),aLength);
|
|
401 |
aMessage.WriteL(2,TPtrC8((TUint8*)RomHeader().iRomBase,len),anOffset);
|
|
402 |
}
|
|
403 |
}
|
|
404 |
|
|
405 |
void CRomMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aDes*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/)
|
|
406 |
//
|
|
407 |
// Write aLength data to ROM (?)
|
|
408 |
//
|
|
409 |
{
|
|
410 |
|
|
411 |
User::Leave(KErrAccessDenied);
|
|
412 |
}
|
|
413 |
|
|
414 |
void CRomMountCB::ReadUidL(TLinAddr anAddr,TEntry& anEntry) const
|
|
415 |
//
|
|
416 |
// Read a uid if present.
|
|
417 |
//
|
|
418 |
{
|
|
419 |
// Need to consider zero-length files (for which anAddr is 0)
|
|
420 |
// and files too small to have a UID
|
|
421 |
if (anEntry.iSize >= (TInt) sizeof(TCheckedUid))
|
|
422 |
{
|
|
423 |
TCheckedUid entryUid(TPtrC8((TUint8*)anAddr, sizeof(TCheckedUid)));
|
|
424 |
anEntry.iType=entryUid.UidType();
|
|
425 |
}
|
|
426 |
else
|
|
427 |
{
|
|
428 |
anEntry.iType=KNullUid;
|
|
429 |
}
|
|
430 |
}
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
void CRomMountCB::ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage)
|
|
435 |
{
|
|
436 |
|
|
437 |
__PRINT(Print(_L("CRomMountCB::ReadSectionL")));
|
|
438 |
|
|
439 |
TLinAddr dir;
|
|
440 |
TLinAddr entry;
|
|
441 |
FindEntryL(aName,KEntryAttMustBeFile,ETrue,dir,entry);
|
|
442 |
const TRomEntry* pE = (TRomEntry*)entry;
|
|
443 |
TInt size=pE->iSize;
|
|
444 |
|
|
445 |
const TText8* baseAddress = (const TText8*)pE->iAddressLin;
|
|
446 |
|
|
447 |
if (size>=(aPos+aLength)) //|| (size>aPos)
|
|
448 |
{
|
|
449 |
TPtrC8 section((baseAddress+aPos),aLength);
|
|
450 |
aMessage.WriteL(0,section,0);
|
|
451 |
}
|
|
452 |
else if (size>aPos)
|
|
453 |
{
|
|
454 |
aLength=(size-aPos);
|
|
455 |
TPtrC8 section((baseAddress+aPos),aLength);
|
|
456 |
aMessage.WriteL(0,section,0);
|
|
457 |
}
|
|
458 |
else
|
|
459 |
User::Leave(KErrEof);
|
|
460 |
|
|
461 |
}
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
void CRomMountCB::GetShortNameL(const TDesC& /*aLongName*/,TDes& /*aShortName*/)
|
|
466 |
//
|
|
467 |
// Return the short name associated with aLongName
|
|
468 |
// Assumes all rom names are 8.3
|
|
469 |
//
|
|
470 |
{
|
|
471 |
|
|
472 |
User::Leave(KErrNotSupported);
|
|
473 |
}
|
|
474 |
|
|
475 |
void CRomMountCB::GetLongNameL(const TDesC& /*aShortName*/,TDes& /*aLongName*/)
|
|
476 |
//
|
|
477 |
// Return the short name associated with aLongName
|
|
478 |
// Assumes all rom names are 8.3
|
|
479 |
//
|
|
480 |
{
|
|
481 |
|
|
482 |
User::Leave(KErrNotSupported);
|
|
483 |
}
|
|
484 |
|
|
485 |
TInt CRomMountCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
|
|
486 |
//
|
|
487 |
// Access the specified interface; behaviour is interface-specific
|
|
488 |
//
|
|
489 |
{
|
|
490 |
switch(aInterfaceId)
|
|
491 |
{
|
|
492 |
case (CMountCB::EFileAccessor):
|
|
493 |
{
|
|
494 |
((CMountCB::MFileAccessor*&) aInterface) = this;
|
|
495 |
return KErrNone;
|
|
496 |
}
|
|
497 |
default:
|
|
498 |
return (CMountCB::GetInterface(aInterfaceId,aInterface,aInput));
|
|
499 |
}
|
|
500 |
}
|
|
501 |
|
|
502 |
TInt CRomMountCB::GetFileUniqueId(const TDesC& /* aName */, TInt64& aUniqueId)
|
|
503 |
{
|
|
504 |
// Get unique identifier for the file - for ROM File System will just return zero
|
|
505 |
aUniqueId = MAKE_TINT64(0,0);
|
|
506 |
return KErrNone;
|
|
507 |
}
|
|
508 |
|
|
509 |
TInt CRomMountCB::Spare3(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
|
|
510 |
{
|
|
511 |
return KErrNotSupported;
|
|
512 |
}
|
|
513 |
|
|
514 |
TInt CRomMountCB::Spare2(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
|
|
515 |
{
|
|
516 |
return KErrNotSupported;
|
|
517 |
}
|
|
518 |
|
|
519 |
TInt CRomMountCB::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
|
|
520 |
{
|
|
521 |
return KErrNotSupported;
|
|
522 |
}
|
|
523 |
|
|
524 |
|
|
525 |
CRomFileCB::CRomFileCB(const CRom* aRom)
|
|
526 |
//
|
|
527 |
// Constructor
|
|
528 |
//
|
|
529 |
: iRom(aRom)
|
|
530 |
{
|
|
531 |
}
|
|
532 |
|
|
533 |
void CRomFileCB::ReadL(TInt aPos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage)
|
|
534 |
//
|
|
535 |
// Read from the file.
|
|
536 |
//
|
|
537 |
{
|
|
538 |
|
|
539 |
__PRINT(Print(_L("CRomFileCB::ReadL")));
|
|
540 |
|
|
541 |
if (aPos>=iSize)
|
|
542 |
{
|
|
543 |
TPtrC8 nullBuf(NULL,0);
|
|
544 |
aMessage.WriteL(0,nullBuf,0);
|
|
545 |
aLength=0;
|
|
546 |
}
|
|
547 |
else
|
|
548 |
{
|
|
549 |
TInt len=Min((iSize-aPos),aLength);
|
|
550 |
TPtrC8 romBuf(iBase+aPos,len);
|
|
551 |
// thread->WriteL(aTrg,romBuf,0);
|
|
552 |
aMessage.WriteL(0,romBuf,0);
|
|
553 |
aLength=len;
|
|
554 |
}
|
|
555 |
}
|
|
556 |
|
|
557 |
void CRomFileCB::WriteL(TInt /*aPos*/,TInt& /*aLength*/,const TAny* /*aDes*/,const RMessagePtr2& /*aMessage*/)
|
|
558 |
//
|
|
559 |
// Write to the file.
|
|
560 |
//
|
|
561 |
{
|
|
562 |
|
|
563 |
User::Leave(KErrAccessDenied);
|
|
564 |
}
|
|
565 |
|
|
566 |
void CRomFileCB::RenameL(const TDesC& /*aDes*/)
|
|
567 |
//
|
|
568 |
// Rename the file.
|
|
569 |
//
|
|
570 |
{
|
|
571 |
|
|
572 |
User::Leave(KErrAccessDenied);
|
|
573 |
}
|
|
574 |
|
|
575 |
void CRomFileCB::SetSizeL(TInt /*aSize*/)
|
|
576 |
//
|
|
577 |
// Set the file size.
|
|
578 |
//
|
|
579 |
{
|
|
580 |
|
|
581 |
User::Leave(KErrAccessDenied);
|
|
582 |
}
|
|
583 |
|
|
584 |
void CRomFileCB::SetEntryL(const TTime& /*aTime*/,TUint /*aMask*/,TUint /*aVal*/)
|
|
585 |
//
|
|
586 |
// Set the entry's attributes and modified time.
|
|
587 |
//
|
|
588 |
{
|
|
589 |
|
|
590 |
User::Leave(KErrAccessDenied);
|
|
591 |
}
|
|
592 |
|
|
593 |
void CRomFileCB::FlushAllL()
|
|
594 |
//
|
|
595 |
// Commit any buffered date to the media.
|
|
596 |
//
|
|
597 |
{
|
|
598 |
|
|
599 |
User::Leave(KErrAccessDenied);
|
|
600 |
}
|
|
601 |
|
|
602 |
void CRomFileCB::FlushDataL()
|
|
603 |
//
|
|
604 |
// Commit any buffered date to the media.
|
|
605 |
//
|
|
606 |
{
|
|
607 |
|
|
608 |
User::Leave(KErrAccessDenied);
|
|
609 |
}
|
|
610 |
|
|
611 |
TInt CRomFileCB::Address(TInt& aPos) const
|
|
612 |
//
|
|
613 |
// Return address of the file at aPos. Default implementation.
|
|
614 |
//
|
|
615 |
{
|
|
616 |
|
|
617 |
if (aPos>=iSize)
|
|
618 |
return(KErrEof);
|
|
619 |
aPos=(TInt)(iBase+aPos);
|
|
620 |
return(KErrNone);
|
|
621 |
}
|
|
622 |
|
|
623 |
CRomDirCB::CRomDirCB(const CRom* aRom)
|
|
624 |
//
|
|
625 |
// Constructor
|
|
626 |
//
|
|
627 |
: iRom(aRom)
|
|
628 |
{
|
|
629 |
}
|
|
630 |
|
|
631 |
CRomDirCB::~CRomDirCB()
|
|
632 |
//
|
|
633 |
// Destruct
|
|
634 |
//
|
|
635 |
{
|
|
636 |
|
|
637 |
delete iMatch;
|
|
638 |
}
|
|
639 |
|
|
640 |
TBool CRomDirCB::MatchUid()
|
|
641 |
//
|
|
642 |
// Match the uid ?
|
|
643 |
//
|
|
644 |
{
|
|
645 |
|
|
646 |
if (iUidType[0]!=TUid::Null() || iUidType[1]!=TUid::Null() || iUidType[2]!=TUid::Null())
|
|
647 |
return(ETrue);
|
|
648 |
return(EFalse);
|
|
649 |
}
|
|
650 |
|
|
651 |
LOCAL_C TBool CompareUid(const TUidType& aUidTrg, const TUidType& aUidSuitor)
|
|
652 |
//
|
|
653 |
// Compare the suitor to the target pattern
|
|
654 |
//
|
|
655 |
{
|
|
656 |
|
|
657 |
if (aUidTrg[0]!=TUid::Null() && aUidTrg[0]!=aUidSuitor[0])
|
|
658 |
return(EFalse);
|
|
659 |
if (aUidTrg[1]!=TUid::Null() && aUidTrg[1]!=aUidSuitor[1])
|
|
660 |
return(EFalse);
|
|
661 |
if (aUidTrg[2]!=TUid::Null() && aUidTrg[2]!=aUidSuitor[2])
|
|
662 |
return(EFalse);
|
|
663 |
return(ETrue);
|
|
664 |
}
|
|
665 |
|
|
666 |
void CRomDirCB::ReadL(TEntry& anEntry)
|
|
667 |
//
|
|
668 |
// Read the next entry from the directory.
|
|
669 |
//
|
|
670 |
{
|
|
671 |
|
|
672 |
CRomMountCB& mount=(CRomMountCB&)Mount();
|
|
673 |
const TRomEntry* pE;
|
|
674 |
FOREVER
|
|
675 |
{
|
|
676 |
//
|
|
677 |
//May be called with wildcards in the path, so we need
|
|
678 |
//to call the slow, sequential FindL
|
|
679 |
//
|
|
680 |
if (!iPending)
|
|
681 |
mount.FindL(*iMatch,iAtt,iDir,iNext,KErrEof);
|
|
682 |
iPending=EFalse;
|
|
683 |
pE = (const TRomEntry*)iNext;
|
|
684 |
iEntry.iName.Des().Copy((TText*)&pE->iName[0],pE->iNameLength);
|
|
685 |
iEntry.iAtt=pE->iAtt;
|
|
686 |
iEntry.iSize=pE->iSize;
|
|
687 |
iEntry.iModified=RomHeader().iTime;
|
|
688 |
anEntry=iEntry;
|
|
689 |
if (MatchUid())
|
|
690 |
{
|
|
691 |
mount.ReadUidL(pE->iAddressLin,anEntry);
|
|
692 |
if (CompareUid(iUidType,anEntry.iType))
|
|
693 |
break;
|
|
694 |
}
|
|
695 |
else
|
|
696 |
break;
|
|
697 |
}
|
|
698 |
if (iAtt&KEntryAttAllowUid && (anEntry.iAtt&KEntryAttDir)==0 && MatchUid()==EFalse)
|
|
699 |
mount.ReadUidL(pE->iAddressLin,anEntry);
|
|
700 |
}
|
|
701 |
|
|
702 |
void CRomDirCB::SetDir(TLinAddr aDir,TLinAddr anEntry,const TDesC& aName)
|
|
703 |
//
|
|
704 |
// Set the directory and entry that we are on after open.
|
|
705 |
//
|
|
706 |
{
|
|
707 |
|
|
708 |
iDir=aDir;
|
|
709 |
iNext=anEntry;
|
|
710 |
iMatch=aName.AllocL();
|
|
711 |
iPending=(anEntry!=NULL);
|
|
712 |
}
|
|
713 |
|
|
714 |
CRom::CRom()
|
|
715 |
//
|
|
716 |
// Constructor
|
|
717 |
//
|
|
718 |
{
|
|
719 |
}
|
|
720 |
|
|
721 |
CRom::~CRom()
|
|
722 |
//
|
|
723 |
// Destruct
|
|
724 |
//
|
|
725 |
{
|
|
726 |
}
|
|
727 |
|
|
728 |
TInt CRom::Install()
|
|
729 |
//
|
|
730 |
// Install the file system.
|
|
731 |
//
|
|
732 |
{
|
|
733 |
|
|
734 |
iVersion=TVersion(KF32MajorVersionNumber,KF32MinorVersionNumber,KF32BuildVersionNumber);
|
|
735 |
TPtrC name=_L("Rom");
|
|
736 |
return(SetName(&name));
|
|
737 |
}
|
|
738 |
|
|
739 |
CMountCB* CRom::NewMountL() const
|
|
740 |
//
|
|
741 |
// Create a new mount control block.
|
|
742 |
//
|
|
743 |
{
|
|
744 |
|
|
745 |
return(new(ELeave) CRomMountCB(this));
|
|
746 |
}
|
|
747 |
|
|
748 |
CFileCB* CRom::NewFileL() const
|
|
749 |
//
|
|
750 |
// Create a new file.
|
|
751 |
//
|
|
752 |
{
|
|
753 |
|
|
754 |
return(new(ELeave) CRomFileCB(this));
|
|
755 |
}
|
|
756 |
|
|
757 |
CDirCB* CRom::NewDirL() const
|
|
758 |
//
|
|
759 |
// Create a new directory lister.
|
|
760 |
//
|
|
761 |
{
|
|
762 |
|
|
763 |
return(new(ELeave) CRomDirCB(this));
|
|
764 |
}
|
|
765 |
|
|
766 |
CFormatCB* CRom::NewFormatL() const
|
|
767 |
//
|
|
768 |
// Create a new media formatter.
|
|
769 |
//
|
|
770 |
{
|
|
771 |
|
|
772 |
User::Leave(KErrAccessDenied);
|
|
773 |
return(NULL);
|
|
774 |
}
|
|
775 |
|
|
776 |
void CRom::DriveInfo(TDriveInfo& anInfo,TInt /*aDriveNumber*/) const
|
|
777 |
//
|
|
778 |
// Return the drive info.
|
|
779 |
//
|
|
780 |
{
|
|
781 |
anInfo.iDriveAtt=KDriveAttRom|KDriveAttInternal;
|
|
782 |
anInfo.iMediaAtt=KMediaAttWriteProtected;
|
|
783 |
anInfo.iType=EMediaRom;
|
|
784 |
}
|
|
785 |
|
|
786 |
GLDEF_C void InstallRomFileSystemL()
|
|
787 |
//
|
|
788 |
// Create the ROM file system.
|
|
789 |
//
|
|
790 |
{
|
|
791 |
|
|
792 |
CFileSystem* pS=new(ELeave) CRom;
|
|
793 |
CleanupStack::PushL(pS);
|
|
794 |
User::LeaveIfError(InstallFileSystem(pS,RLibrary()));
|
|
795 |
CleanupStack::Pop(1, pS);
|
|
796 |
}
|
|
797 |
|
|
798 |
GLDEF_C const TRomHeader *RomHeader(CFileSystem *aFsys)
|
|
799 |
//
|
|
800 |
// Return the ROM header
|
|
801 |
//
|
|
802 |
{
|
|
803 |
|
|
804 |
return &((CRom *)aFsys)->RomHeader();
|
|
805 |
}
|
|
806 |
|