1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/scomp/sc_comp.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,971 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "sc_std.h"
1.20 +
1.21 +
1.22 +const TInt KMajorVersionNumber=1;
1.23 +const TInt KMinorVersionNumber=1;
1.24 +
1.25 +_LIT(KRofsName,"Rofs");
1.26 +
1.27 +#ifdef __WINS__
1.28 +_LIT(KRomName,"Win32");
1.29 +#else
1.30 +_LIT(KRomName,"Rom");
1.31 +#endif
1.32 +
1.33 +_LIT(KCompositeName,"Composite");
1.34 +
1.35 +
1.36 +static void Fault(TCompFault aFault)
1.37 +//
1.38 +// Report a fault in the composite file system.
1.39 +//
1.40 + {
1.41 + User::Panic(_L("COMPFILESYS"),aFault);
1.42 + }
1.43 +
1.44 +
1.45 +CCompFileSystem::CCompFileSystem()
1.46 + {
1.47 + __PRINT1(_L("CCompFileSystem()[0x%x]"), this);
1.48 + }
1.49 +
1.50 +
1.51 +CCompFileSystem::~CCompFileSystem()
1.52 + {
1.53 + __PRINT1(_L("~CCompFileSystem()[0x%x]"),this);
1.54 + if (iMount)
1.55 + {
1.56 + iMount->NullCompFileSystem();
1.57 + }
1.58 + }
1.59 +
1.60 +
1.61 +TInt CCompFileSystem::Install()
1.62 +//
1.63 +// Install the file system
1.64 +//
1.65 + {
1.66 + __PRINT1(_L("CCompFileSystem::Install()[0x%x]"), this);
1.67 + iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KF32BuildVersionNumber);
1.68 + return(SetName(&KCompositeName));
1.69 + }
1.70 +
1.71 +
1.72 +CMountCB* CCompFileSystem::NewMountL() const
1.73 +//
1.74 +// Create a new mount control block
1.75 +//
1.76 + {
1.77 + __PRINT1(_L("CCompFileSystem::NewMountL()[0x%x]"), this);
1.78 +
1.79 + // Composite FS is a singleton, and can only have one mount.
1.80 + // If it already exists, just return the existin one.
1.81 + if (iMount == NULL)
1.82 + {
1.83 + ((CCompFileSystem*)this)->iMount = new(ELeave) CCompMountCB((CCompFileSystem *)this);
1.84 + TRAPD(err,iMount->NewRomMountL());
1.85 + if(err!=KErrNone)
1.86 + {
1.87 + iMount->Close();
1.88 + User::Leave(err);
1.89 + }
1.90 + }
1.91 +
1.92 + __PRINT1(_L(" created CCompMountCB:0x%x"),iMount);
1.93 +
1.94 + return (iMount);
1.95 + }
1.96 +
1.97 +
1.98 +CFileCB* CCompFileSystem::NewFileL() const
1.99 +//
1.100 +// Create a new file
1.101 +//
1.102 + {
1.103 + __PRINT(_L("CCompFileSystem::NewFileL()"));
1.104 + CFileCB* pFile=new(ELeave) CCompFileCB;
1.105 + __PRINT1(_L("file at 0x%x"),pFile);
1.106 + return(pFile);
1.107 + }
1.108 +
1.109 +
1.110 +CDirCB* CCompFileSystem::NewDirL() const
1.111 +//
1.112 +// create a new directory lister
1.113 +//
1.114 + {
1.115 + __PRINT(_L("CCompFileSystem::NewDirL()"));
1.116 +
1.117 + CCompDirCB* pDir=new (ELeave) CCompDirCB;
1.118 +
1.119 + CleanupStack::PushL(pDir);
1.120 +
1.121 + TInt count = iMount->iMounts.Count();
1.122 + TInt r=KErrNone;
1.123 +
1.124 + for(TInt idx=0; idx<count; idx++)
1.125 + {
1.126 + TRAPD(err, r=pDir->iDirs.Append(iMount->iMounts[idx].iFs->NewDirL()));
1.127 + if(err!= KErrNone || r != KErrNone)
1.128 + {
1.129 + pDir->Close();
1.130 + User::Leave(err == KErrNone ? r : err);
1.131 + }
1.132 + }
1.133 +
1.134 + CleanupStack::Pop(pDir);
1.135 +
1.136 + __PRINT1(_L("dir at 0x%x"),pDir);
1.137 + return(pDir);
1.138 + }
1.139 +
1.140 +
1.141 +CFormatCB* CCompFileSystem::NewFormatL() const
1.142 +//
1.143 +// Create a new media formatter
1.144 +//
1.145 + {
1.146 + User::Leave(KErrAccessDenied);
1.147 + return(NULL);
1.148 + }
1.149 +
1.150 +
1.151 +void CCompFileSystem::DriveInfo(TDriveInfo& anInfo,TInt /*aDriveNumber*/) const
1.152 +//
1.153 +// Return drive info
1.154 +//
1.155 + {
1.156 + __PRINT(_L("CCompFileSystem::DriveInfo()"));
1.157 + anInfo.iMediaAtt=KMediaAttWriteProtected;
1.158 + anInfo.iDriveAtt=KDriveAttRom|KDriveAttInternal;
1.159 + anInfo.iType=EMediaRom;
1.160 + }
1.161 +
1.162 +
1.163 +TInt CCompFileSystem::DefaultPath(TDes& /*aPath*/) const
1.164 +//
1.165 +// Return the initial default path.
1.166 +//
1.167 + {
1.168 + Fault(ECompFsDefaultPath);
1.169 + return(KErrNone);
1.170 + }
1.171 +
1.172 +
1.173 +CFileSystem* CCompFileSystem::NewL()
1.174 +//
1.175 +//
1.176 +//
1.177 + {
1.178 + __PRINT(_L("CCompFileSystem::NewL()"));
1.179 + CCompFileSystem* pFs = new(ELeave) CCompFileSystem;
1.180 +
1.181 + __PRINT1(_L("CompFs=0x%x"),pFs);
1.182 + return (pFs);
1.183 + }
1.184 +
1.185 +CCompMountCB::~CCompMountCB()
1.186 +//
1.187 +//
1.188 +//
1.189 + {
1.190 + __PRINT1(_L("~CCompMountCB() this=0x%x"),this);
1.191 +
1.192 +
1.193 + for(TInt mount=iMounts.Count(); mount--;)
1.194 + iMounts[mount].iMount->Close();
1.195 +
1.196 + iMounts.Close();
1.197 +
1.198 + if (iFileSystem)
1.199 + {
1.200 + iFileSystem->NullMount();
1.201 + }
1.202 + }
1.203 +
1.204 +void CCompMountCB::NewRomMountL()
1.205 +//
1.206 +// Creates a new ROM mount, and adds it to the list.
1.207 +//
1.208 +{
1.209 + CFileSystem* romFs= GetFileSystem(KRomName);
1.210 + if(!romFs)
1.211 + {
1.212 + User::Leave(KErrNotFound);
1.213 + }
1.214 +
1.215 + CMountCB* romMount = romFs->NewMountL();
1.216 + User::LeaveIfError(iMounts.Append(TCompMount(romFs,romMount)));
1.217 +}
1.218 +
1.219 +
1.220 +
1.221 +void CCompMountCB::MountL(TBool aForceMount)
1.222 +//
1.223 +// Mount a media. Only allowed to leave with KErrNoMemory,KErrNotReady,KErrCorrupt,KErrUnknown.
1.224 +//
1.225 +//
1.226 + {
1.227 + __PRINT(_L("CCompMountCB::MountL()"));
1.228 + // First mount rom
1.229 + RomMount()->SetDrive(&Drive());
1.230 + RomMount()->MountL(aForceMount);
1.231 +
1.232 + // Mounts count starts at 1, as ROMFS starts in slot one.
1.233 + // If its still 1 on mount, then no mounts have been added.
1.234 + // To maintain compatibility with the previous version of this API,
1.235 + // (where you couldn't specifically add mounts) in this case we mount
1.236 + // ROFS by default.
1.237 + // (There would be little point mounting it with only one FS)
1.238 +
1.239 + if (iMounts.Count()==1)
1.240 + {
1.241 + CFileSystem* rofsFs = GetFileSystem(KRofsName);
1.242 + if(!rofsFs)
1.243 + User::Leave(KErrUnknown);
1.244 +
1.245 + AddFsToCompositeMount(rofsFs);
1.246 + }
1.247 +
1.248 + SetVolumeName(_L("RomDrive").AllocL());
1.249 +
1.250 + // combine sizes
1.251 + for(TInt mount=iMounts.Count(); mount--;)
1.252 + iSize+= iMounts[mount].iMount->Size();
1.253 +
1.254 + // no need to update iUniqueID since 0 in both rom and rofs
1.255 + }
1.256 +
1.257 +
1.258 + TInt CCompMountCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
1.259 + {
1.260 + // aInterfaceId : If EAddFsToCompositeMount, method mounts a media and adds to CompFS.
1.261 + // : Local drive mapping for this mount's drive (CompFS's)
1.262 + // should be alterd to indicate the local drive to be added.
1.263 + // aIntput : CFileSystem* for the mount to be added.
1.264 + // aInterFace : Unused.
1.265 + switch(aInterfaceId)
1.266 + {
1.267 + case CMountCB::EFileAccessor:
1.268 + ((CMountCB::MFileAccessor*&) aInterface) = this;
1.269 + return KErrNone;
1.270 +
1.271 + case EAddFsToCompositeMount:
1.272 + return(AddFsToCompositeMount((CFileSystem*) aInput));
1.273 +
1.274 + case CMountCB::ELocalBufferSupport:
1.275 + {
1.276 + CCompFileCB* file = (CCompFileCB*) aInput;
1.277 + return file?file->TrueFile()->Mount().LocalBufferSupport():KErrNone;
1.278 + }
1.279 +
1.280 + default:
1.281 + return (CMountCB::GetInterface(aInterfaceId,aInterface,aInput));
1.282 + }
1.283 + }
1.284 +
1.285 +/**
1.286 + Mounts a media with the provided filesystem and adds to the composite mount.
1.287 + Local drive mapping for this mount's drive (CompFS's) should be altered to indicate the local drive to be added.
1.288 +*/
1.289 +TInt CCompMountCB::AddFsToCompositeMount(CFileSystem* aFileSystem)
1.290 + {
1.291 + __PRINT1(_L("CCompMountCB::AddFsToCompositeMount(0x%x)"), aFileSystem);
1.292 +
1.293 + CMountCB* newMount=NULL;
1.294 + TRAPD(err,newMount = aFileSystem->NewMountL());
1.295 + if (err==KErrNone)
1.296 + {
1.297 + newMount->InitL(Drive(), aFileSystem);
1.298 + TRAP(err,newMount->MountL(EFalse));
1.299 + if (err==KErrNone)
1.300 + {
1.301 + err = iMounts.Append(TCompMount(aFileSystem,newMount));
1.302 + if (err!=KErrNone)
1.303 + return err;
1.304 +
1.305 + TInt r = newMount->AddToCompositeMount(iMounts.Count()-1);
1.306 +
1.307 + if(r == KErrNotSupported)
1.308 + r = KErrNone;
1.309 +
1.310 + return r;
1.311 + }
1.312 +
1.313 + }
1.314 +
1.315 + return err;
1.316 + }
1.317 +
1.318 +TInt CCompMountCB::ReMount()
1.319 +//
1.320 +// Try and remount this media.
1.321 +//
1.322 + {
1.323 + return(0);
1.324 + }
1.325 +
1.326 +
1.327 +void CCompMountCB::Dismounted()
1.328 +//
1.329 +// Dummy implementation of pure virtual function
1.330 +//
1.331 + {}
1.332 +
1.333 +
1.334 +void CCompMountCB::VolumeL(TVolumeInfo& aVolume) const
1.335 +//
1.336 +//
1.337 +// Return the volume info.
1.338 +//
1.339 + {
1.340 + __PRINT(_L("CCompMountCB::VolumeL()"));
1.341 + aVolume.iFree=0;
1.342 + }
1.343 +
1.344 +
1.345 +void CCompMountCB::SetVolumeL(TDes& /*aName*/)
1.346 +//
1.347 +//
1.348 +// Set the volume label.
1.349 +//
1.350 + {
1.351 + User::Leave(KErrAccessDenied);
1.352 + }
1.353 +
1.354 +void CCompMountCB::MkDirL(const TDesC& /*aName*/)
1.355 +//
1.356 +// Make a directory.
1.357 +//
1.358 + {
1.359 + User::Leave(KErrAccessDenied);
1.360 + }
1.361 +
1.362 +void CCompMountCB::RmDirL(const TDesC& /*aName*/)
1.363 +//
1.364 +// Remove a directory.
1.365 +//
1.366 + {
1.367 + User::Leave(KErrAccessDenied);
1.368 + }
1.369 +
1.370 +void CCompMountCB::DeleteL(const TDesC& /*aName*/)
1.371 +//
1.372 +// Delete a file.
1.373 +//
1.374 + {
1.375 + User::Leave(KErrAccessDenied);
1.376 + }
1.377 +
1.378 +void CCompMountCB::RenameL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
1.379 +//
1.380 +// Rename a file or directory.
1.381 +//
1.382 + {
1.383 + User::Leave(KErrAccessDenied);
1.384 + }
1.385 +
1.386 +void CCompMountCB::ReplaceL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
1.387 +//
1.388 +// Atomic replace.
1.389 +//
1.390 + {
1.391 + User::Leave(KErrAccessDenied);
1.392 + }
1.393 +
1.394 +
1.395 +void CCompMountCB::EntryL(const TDesC& aName,TEntry& anEntry) const
1.396 +//
1.397 +// Get entry details.
1.398 +//
1.399 + {
1.400 + __PRINT(_L("CCompMountCB::EntryL()"));
1.401 + TInt lesserErr = KErrNone;
1.402 + TInt err = KErrPathNotFound;
1.403 + TInt idx = iMounts.Count();
1.404 +
1.405 + // Look for entry on each mount, until it finds one, starting at the top.
1.406 + while(idx--)
1.407 + {
1.408 + TRAP(err, iMounts[idx].iMount->EntryL(aName,anEntry));
1.409 +
1.410 + // There will often be more then one error encountered when trying
1.411 + // to find an entry. If the entry is not found on any mount, but it
1.412 + // did find its path, it should not return a path error.
1.413 + // To ensure this, the last non-path related error must be remembered.
1.414 + if ((err != KErrPathNotFound) && (err != KErrPathHidden))
1.415 + lesserErr=err;
1.416 +
1.417 + // It can stop looking for the entry when it either finds it
1.418 + // or discovers its hidden. (ie An error other then NotFound)
1.419 + if((err != KErrNotFound) && (err != KErrPathNotFound))
1.420 + break;
1.421 + }
1.422 +
1.423 + if (err!=KErrNone)
1.424 + User::Leave(lesserErr?lesserErr:err);
1.425 + }
1.426 +
1.427 +
1.428 +void CCompMountCB::SetEntryL(const TDesC& /*aName*/,const TTime& /*aTime*/,TUint /*aSetAttMask*/,TUint /*aClearAttMask*/)
1.429 +//
1.430 +// Set entry details.
1.431 +//
1.432 + {
1.433 + User::Leave(KErrAccessDenied);
1.434 + }
1.435 +
1.436 +
1.437 +static TInt InitFile(CFileCB* aCompFile, CFileCB* aTrueFile,CMountCB* aRealMount,TUint8 aQueOffset)
1.438 +//
1.439 +// Initialise the true file object with values set in the composite file object
1.440 +// by TDrive
1.441 +//
1.442 + {
1.443 + TRAPD(r,aTrueFile->InitL(&aCompFile->Drive(),&aCompFile->Drive(),aCompFile->FileName().Des().AllocL() ) );
1.444 + if(r!=KErrNone)
1.445 + return(r);
1.446 +
1.447 + aTrueFile->SetMount(aRealMount);
1.448 + aTrueFile->SetShare(aCompFile->Share());
1.449 + r=aTrueFile->Mount().Open();
1.450 + if(r==KErrNone)
1.451 + {
1.452 + // destructor for CFileCB only calls close on the mount if iMountLink set
1.453 + TDblQue<CFileCB>* pQue=(TDblQue<CFileCB>*)((TUint8*)aRealMount+aQueOffset);
1.454 + pQue->AddLast(*aTrueFile);
1.455 + }
1.456 + return(r);
1.457 + }
1.458 +
1.459 +
1.460 +void CCompMountCB::FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile)
1.461 +//
1.462 +// Open a file on the current mount.
1.463 +//
1.464 + {
1.465 + __PRINT1(_L("CCompMountCB::FileOpenL() %S"), &aName);
1.466 +
1.467 +
1.468 + TInt err = KErrPathNotFound;
1.469 + TInt lesserErr = KErrNone;
1.470 + CFileCB* pTrueFile = NULL;
1.471 + TInt idx = iMounts.Count();
1.472 +
1.473 + // Look for file on each mount, until it finds one, starting at the top.
1.474 + while(idx--)
1.475 + {
1.476 + CMountCB* mount = iMounts[idx].iMount;
1.477 + pTrueFile = iMounts[idx].iFs->NewFileL();
1.478 + TUint8 offset=(TUint8)(((TUint8*)&iMountQ-(TUint8*)this));
1.479 + err = InitFile(aFile,pTrueFile,mount,offset);
1.480 +
1.481 + if(err == KErrNone)
1.482 + TRAP(err, mount->FileOpenL(aName,aMode,anOpen,pTrueFile));
1.483 +
1.484 + __PRINT2(_L("opening file on mount %d [err=%d]"),idx,err);
1.485 +
1.486 + // If success, stop looking.
1.487 + if (err == KErrNone)
1.488 + break;
1.489 +
1.490 + // Not opened, so use Close() to cause file object to be deleted
1.491 + pTrueFile->Close();
1.492 +
1.493 + // If the file is not found on any mount, but it did find its path,
1.494 + // it should not return a path error.
1.495 + // To ensure this, the last non-path related error must be remembered.
1.496 + if ((err != KErrPathNotFound) && (err != KErrPathHidden))
1.497 + lesserErr=err;
1.498 +
1.499 + // Stop search if error other than file cannot be found.
1.500 + // A common error for this will be one of the hidden errors.
1.501 + // Note that for these, the lesser error calculation above
1.502 + // is still needed for these.
1.503 + if(err != KErrNotFound && err != KErrPathNotFound)
1.504 + break;
1.505 + }
1.506 +
1.507 + if (err!=KErrNone)
1.508 + User::Leave(lesserErr?lesserErr:err);
1.509 +
1.510 + aFile->SetSize(pTrueFile->Size());
1.511 + aFile->SetAtt(pTrueFile->Att());
1.512 + aFile->SetModified(pTrueFile->Modified());
1.513 + ((CCompFileCB*)aFile)->SetTrueFile(pTrueFile);
1.514 + }
1.515 +
1.516 +
1.517 +TInt CCompMountCB::GetFileUniqueId(const TDesC& /* aName */, TInt64& aUniqueId)
1.518 + {
1.519 + // Get unique identifier for the file - for Composite File System will just return zero
1.520 + aUniqueId = MAKE_TINT64(0,0);
1.521 + return KErrNone;
1.522 + }
1.523 +
1.524 +TInt CCompMountCB::Spare3(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.525 + {
1.526 + return KErrNotSupported;
1.527 + }
1.528 +
1.529 +TInt CCompMountCB::Spare2(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.530 + {
1.531 + return KErrNotSupported;
1.532 + }
1.533 +
1.534 +TInt CCompMountCB::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.535 + {
1.536 + return KErrNotSupported;
1.537 + }
1.538 +
1.539 +
1.540 +
1.541 +static void SetAtt(CDirCB* aDir,TUint8 aOffset,TUint aValue)
1.542 +//
1.543 +//
1.544 +//
1.545 + {
1.546 + TUint8* pA=(TUint8*)aDir+aOffset;
1.547 + *(TUint*)pA=aValue;
1.548 + }
1.549 +
1.550 +
1.551 +static void SetUid(CDirCB* aDir,TUint8 aOffset,TUidType aValue)
1.552 +//
1.553 +//
1.554 +//
1.555 + {
1.556 + TUint8* pU=(TUint8*)aDir+aOffset;
1.557 + *(TUidType*)pU=aValue;
1.558 + }
1.559 +
1.560 +
1.561 +TInt CCompDirCB::InitDir(CDirCB* aTrg,CMountCB* aMount)
1.562 +//
1.563 +//
1.564 +//
1.565 + {
1.566 + TRAPD(r,aTrg->InitL(&Drive()));
1.567 + if(r!=KErrNone)
1.568 + return(r);
1.569 + aTrg->SetMount(aMount);
1.570 + r=aTrg->Mount().Open();
1.571 + if(r!=KErrNone)
1.572 + {
1.573 + aTrg->SetMount(NULL);
1.574 + return(r);
1.575 + }
1.576 + SetAtt(aTrg,(TUint8)((TUint8*)&iAtt-(TUint8*)this),iAtt);
1.577 + SetUid(aTrg,(TUint8)((TUint8*)&iUidType-(TUint8*)this),iUidType);
1.578 + aTrg->Mount().DecLock();
1.579 + return(KErrNone);
1.580 + }
1.581 +
1.582 +
1.583 +void CCompMountCB::DirOpenL(const TDesC& aName,CDirCB* aDir)
1.584 +//
1.585 +// Open a directory on the current mount.
1.586 +//
1.587 + {
1.588 + __PRINT(_L("CCompMountCB::DirOpenL()"));
1.589 + CCompDirCB* pD=(CCompDirCB*)aDir;
1.590 + pD->iMatch=aName.AllocL();
1.591 +
1.592 + TInt err = KErrPathNotFound;
1.593 + TInt idx = iMounts.Count();
1.594 + TBool anyFound = EFalse;
1.595 + pD->iCurrentDir = -1;
1.596 +
1.597 + while(idx) // Open dir on every mount it exists.
1.598 + {
1.599 + idx--;
1.600 + CDirCB* theDir = pD->iDirs[idx];
1.601 + CMountCB* theMount = iMounts[idx].iMount;
1.602 + err = pD->InitDir(theDir, theMount);
1.603 + if(err == KErrNone)
1.604 + TRAP(err, theMount->DirOpenL(aName,theDir));
1.605 +
1.606 + if(err == KErrNone)
1.607 + {
1.608 + if(!anyFound)
1.609 + {
1.610 + anyFound = ETrue;
1.611 + pD->iCurrentDir = idx;
1.612 + }
1.613 + continue;
1.614 + }
1.615 +
1.616 + pD->iDirs[idx]->Close(); // deletes object
1.617 + pD->iDirs[idx] = NULL;
1.618 +
1.619 + if (err == KErrPathHidden)
1.620 + {
1.621 + // Dont look for anythng below this hidden dir.
1.622 + break;
1.623 + }
1.624 + else if (err != KErrPathNotFound)
1.625 + {
1.626 + // An unexpected error - make it report this to caller!
1.627 + anyFound = EFalse;
1.628 + break;
1.629 + }
1.630 + }
1.631 +
1.632 + // If we broke before bottom, close the remaining
1.633 + while (idx--)
1.634 + {
1.635 + pD->iDirs[idx]->Close();
1.636 + pD->iDirs[idx] = NULL;
1.637 + }
1.638 +
1.639 + // If we didnt find anythng at all, or some other error, leave.
1.640 + if(!anyFound)
1.641 + User::Leave(err);
1.642 +
1.643 + }
1.644 +
1.645 +
1.646 +void CCompMountCB::RawReadL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aTrg*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) const
1.647 +//
1.648 +// Read up to aLength data directly
1.649 +//
1.650 + {
1.651 + User::Leave(KErrAccessDenied);
1.652 + }
1.653 +
1.654 +
1.655 +void CCompMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aSrc*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/)
1.656 +//
1.657 +// Write aLength data
1.658 +//
1.659 + {
1.660 + User::Leave(KErrAccessDenied);
1.661 + }
1.662 +
1.663 +
1.664 +void CCompMountCB::GetShortNameL(const TDesC& /*aLongName*/,TDes& /*aShortName*/)
1.665 +//
1.666 +// Return the short name associated with aLongName
1.667 +// Assumes all rom names are 8.3
1.668 +//
1.669 + {
1.670 + User::Leave(KErrNotSupported);
1.671 + }
1.672 +
1.673 +
1.674 +void CCompMountCB::GetLongNameL(const TDesC& /*aShortName*/,TDes& /*aLongName*/)
1.675 +//
1.676 +// Return the short name associated with aLongName
1.677 +// Assumes all rom names are 8.3
1.678 +//
1.679 + {
1.680 + User::Leave(KErrNotSupported);
1.681 + }
1.682 +
1.683 +
1.684 +void CCompMountCB::IsFileInRom(const TDesC& aFileName,TUint8*& aFileStart)
1.685 +//
1.686 +// Return the address of the file if it is in rom
1.687 +//
1.688 + {
1.689 + __PRINT(_L("CCompMountCB::IsFileInRom()"));
1.690 + TEntry entry;
1.691 + aFileStart=NULL;
1.692 + TInt idx = iMounts.Count();
1.693 +
1.694 + while(idx--)
1.695 + {
1.696 + TRAPD(r,iMounts[idx].iMount->EntryL(aFileName,entry));
1.697 + if(r==KErrNone)
1.698 + {
1.699 + // File exists on mount, check whether it is rom-based
1.700 + iMounts[idx].iMount->IsFileInRom(aFileName,aFileStart);
1.701 + break;
1.702 + }
1.703 + else if(r != KErrNotFound && r != KErrPathNotFound)
1.704 + {
1.705 + break;
1.706 + }
1.707 + }
1.708 + }
1.709 +
1.710 +
1.711 +void CCompMountCB::ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage)
1.712 +//
1.713 +// Starting from aPos, read aLength bytes of a file into a Trg,
1.714 +// regardless of lock state
1.715 +//
1.716 + {
1.717 + __PRINT(_L("CCompMountCB::ReadSectionL()"));
1.718 + TInt lesserErr = KErrNone;
1.719 + TInt err = KErrPathNotFound;
1.720 + TInt idx = iMounts.Count();
1.721 +
1.722 + // Look for file on each mount, until it finds one, starting at the top.
1.723 + while(idx--)
1.724 + {
1.725 + TRAP(err, iMounts[idx].iMount->ReadSectionL(aName,aPos,aTrg,aLength,aMessage));
1.726 +
1.727 + // If the file is not found on any mount, but it did find its path,
1.728 + // it should not return a path error.
1.729 + // To ensure this, the last non-path related error must be remembered.
1.730 + if ((err != KErrPathNotFound) && (err != KErrPathHidden))
1.731 + lesserErr=err;
1.732 +
1.733 + // Break if file was found, it was hidden, or some unexpected error
1.734 + // (ie break if file or pathe not found)
1.735 + // Note: If hidden, lesserErr calulation above still needed.
1.736 + if ((err != KErrNotFound) && (err != KErrPathNotFound))
1.737 + break;
1.738 + }
1.739 +
1.740 + if (err!=KErrNone)
1.741 + User::Leave(lesserErr?lesserErr:err);
1.742 + }
1.743 +
1.744 +
1.745 +CCompFileCB::CCompFileCB()
1.746 + {}
1.747 +
1.748 +
1.749 +CCompFileCB::~CCompFileCB()
1.750 + {
1.751 + __PRINT1(_L("~CCompFileCB()[0x%x]"),this);
1.752 + if(TrueFile())
1.753 + TrueFile()->Close();
1.754 + }
1.755 +
1.756 +
1.757 +void CCompFileCB::RenameL(const TDesC& /*aNewName*/)
1.758 +//
1.759 +// Rename the file.
1.760 +//
1.761 + {
1.762 + User::Leave(KErrAccessDenied);
1.763 + }
1.764 +
1.765 +
1.766 +void CCompFileCB::ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage)
1.767 +//
1.768 +// Read from the file.
1.769 +//
1.770 + {
1.771 + __PRINT(_L("CCompFileCB::ReadL()"));
1.772 + TrueFile()->ReadL(aPos,aLength,aDes,aMessage);
1.773 + }
1.774 +
1.775 +
1.776 +void CCompFileCB::WriteL(TInt /*aPos*/,TInt& /*aLength*/,const TAny* /*aDes*/,const RMessagePtr2& /*aMessage*/)
1.777 +//
1.778 +// Write to the file.
1.779 +//
1.780 + {
1.781 + User::Leave(KErrAccessDenied);
1.782 + }
1.783 +
1.784 +
1.785 +TInt CCompFileCB::Address(TInt& aPos) const
1.786 +//
1.787 +// Return address of the file at aPos
1.788 +//
1.789 + {
1.790 + __PRINT(_L("CCompFileCB::Address()"));
1.791 + return(TrueFile()->Address(aPos));
1.792 + }
1.793 +
1.794 +
1.795 +void CCompFileCB::SetSizeL(TInt /*aSize*/)
1.796 +//
1.797 +// Set the file size.
1.798 +//
1.799 + {
1.800 + User::Leave(KErrAccessDenied);
1.801 + }
1.802 +
1.803 +
1.804 +void CCompFileCB::SetEntryL(const TTime& /*aTime*/,TUint /*aSetAttMask*/,TUint /*aClearAttMask*/)
1.805 +//
1.806 +// Set the entry's attributes and modified time.
1.807 +//
1.808 + {
1.809 + User::Leave(KErrAccessDenied);
1.810 + }
1.811 +
1.812 +
1.813 +void CCompFileCB::FlushDataL()
1.814 +//
1.815 +// Commit any buffered date to the media.
1.816 +//
1.817 + {
1.818 + User::Leave(KErrAccessDenied);
1.819 + }
1.820 +
1.821 +
1.822 +void CCompFileCB::FlushAllL()
1.823 +//
1.824 +// Commit any buffered date to the media.
1.825 +//
1.826 + {
1.827 + User::Leave(KErrAccessDenied);
1.828 + }
1.829 +
1.830 +
1.831 +TInt CCompFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
1.832 + {
1.833 + if (TrueFile())
1.834 + return TrueFile()->GetInterface(aInterfaceId, aInterface, aInput);
1.835 + else
1.836 + return KErrNotSupported;
1.837 + }
1.838 +
1.839 +
1.840 +CCompDirCB::CCompDirCB()
1.841 +//
1.842 +//
1.843 +//
1.844 + {}
1.845 +
1.846 +
1.847 +CCompDirCB::~CCompDirCB()
1.848 +//
1.849 +//
1.850 +//
1.851 + {
1.852 + __PRINT1(_L("~CCompDirCB() [0x%x]"),this);
1.853 + for(TInt dir=iDirs.Count(); dir--;)
1.854 + {
1.855 + if (iDirs[dir])
1.856 + iDirs[dir]->Close();
1.857 + }
1.858 + iDirs.Close();
1.859 + delete iMatch;
1.860 + }
1.861 +
1.862 +
1.863 +void CCompDirCB::ReadL(TEntry& anEntry)
1.864 +//
1.865 +// Reads the next directory entry.
1.866 +//
1.867 + {
1.868 + __PRINT(_L("CCompDirCB::ReadL()"));
1.869 +
1.870 + if(Pending())
1.871 + {
1.872 + CDirCB* pDir = iDirs[iCurrentDir];
1.873 + pDir->SetPending(ETrue);
1.874 + TRAPD(r,pDir->ReadL(anEntry));
1.875 + __ASSERT_ALWAYS(r!=KErrEof,Fault(ECompDirReadPending));
1.876 + SetPending(pDir->Pending());
1.877 + User::LeaveIfError(r);
1.878 + return;
1.879 + }
1.880 +
1.881 + if(iCurrentDir < 0)
1.882 + User::Leave(KErrEof);
1.883 +
1.884 + TFileName match(*iMatch);
1.885 + TInt namePos=match.LocateReverse(KPathDelimiter)+1; // There is always a path delimiter
1.886 + TPtrC dirName=match.Left(namePos);
1.887 + TFileName filename;
1.888 + TInt err;
1.889 +
1.890 + do
1.891 + {
1.892 + CDirCB* theDir = iDirs[iCurrentDir];
1.893 + if(theDir)
1.894 + {
1.895 + FOREVER // loop until we can read no more (EOF or other err)
1.896 + // If non-duplicate entry found, it returns.
1.897 + {
1.898 + TRAP(err, theDir->ReadL(anEntry));
1.899 +
1.900 + if(err != KErrNone)
1.901 + break;
1.902 +
1.903 + __PRINT2(_L("CCompDirCB:: ReadL got = '%S' from dir %d"),&anEntry.iName, iCurrentDir);
1.904 +
1.905 + filename=dirName;
1.906 + filename+=anEntry.iName;
1.907 +
1.908 + if (!IsDuplicate(filename))
1.909 + return;
1.910 + }
1.911 +
1.912 + // We have either reached EOF for CurrentDir or encounted an error.
1.913 +
1.914 + __PRINT1(_L("CCompDirCB:: ReadL err = %d"),err);
1.915 +
1.916 + if(err != KErrEof)
1.917 + {
1.918 + User::Leave(err);
1.919 + }
1.920 + }
1.921 + }
1.922 +
1.923 + while (iCurrentDir--);
1.924 +
1.925 + User::Leave(KErrEof);
1.926 + }
1.927 +
1.928 +
1.929 +TBool CCompDirCB::IsDuplicate(TFileName& aFilename)
1.930 +//
1.931 +// Is used by ReadL to determine if a file name read is a duplicate of
1.932 +// a filename already read bit it.
1.933 +//
1.934 + {
1.935 + RArray<TCompMount> &mounts = ((CCompMountCB*)&Mount())->iMounts;
1.936 + TInt count = mounts.Count();
1.937 + TEntry tmpEntry;
1.938 + __PRINT1(_L("theMount->iMounts.Count() = %d"),count);
1.939 +
1.940 + for (TInt idx = iCurrentDir+1; idx < count; idx++)
1.941 + {
1.942 + TRAPD(r, mounts[idx].iMount->EntryL(aFilename,tmpEntry));
1.943 +
1.944 + if ((r == KErrNone) || (r == KErrHidden) || (r == KErrPathHidden))
1.945 + {
1.946 + __PRINT1(_L("CCompDirCB:: Duplicate (r=%d)"),r);
1.947 + return (ETrue);
1.948 + }
1.949 + }
1.950 + return (EFalse);
1.951 + }
1.952 +
1.953 +
1.954 +void CCompDirCB::StoreLongEntryNameL(const TDesC& aName)
1.955 +//
1.956 +// Stores the Long Entry Name
1.957 +//
1.958 + {
1.959 + __ASSERT_ALWAYS(iCurrentDir >= 0 && iDirs[iCurrentDir] != NULL, Fault(ECompDirStoreLongEntryNameL));
1.960 + iDirs[iCurrentDir]->StoreLongEntryNameL(aName);
1.961 + }
1.962 +
1.963 +
1.964 +extern "C" {
1.965 +
1.966 +EXPORT_C CFileSystem* CreateFileSystem()
1.967 +//
1.968 +// Create a new file system
1.969 +//
1.970 + {
1.971 + return(CCompFileSystem::NewL());
1.972 + }
1.973 +}
1.974 +