sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "sf_std.h" sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Default constructor. sl@0: */ sl@0: EXPORT_C CMountCB::CMountCB() sl@0: :iMountQ(_FOFF(CFileCB,iMountLink)) sl@0: { sl@0: __PRINT1(_L("CMountCB::CMountCB()[0x%x]"),this); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C CMountCB::~CMountCB() sl@0: { sl@0: __PRINT1(_L("CMountCB::~CMountCB()[0x%x]"),this); sl@0: delete iBody; sl@0: delete iVolumeName; sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Compares the specified mount control block with this one for inequality. sl@0: sl@0: Two mount control blocks are different if either the addresses of sl@0: the mount control blocks ar different, or their iMountNumber values sl@0: are different. sl@0: sl@0: @param aMount The mount control block to be compared. sl@0: sl@0: @return True, if the mount control blocks are different, false otherwise. sl@0: */ sl@0: EXPORT_C TBool CMountCB::operator!=(const CMountCB& aMount) const sl@0: { sl@0: sl@0: if (this==(&aMount) && MountNumber()==aMount.MountNumber()) sl@0: return(FALSE); sl@0: return(TRUE); sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Tests whether the given attribute mask matches given criteria (specified sl@0: in another mask). sl@0: sl@0: This function is used when filtering entries. aMatt specifies the criteria sl@0: to be matched by anAtt. sl@0: sl@0: Volumes are ignored, so if anAtt has the volume attribute set then sl@0: the function returns false. sl@0: sl@0: If aMatt does not have a hidden (KEntryAttHidden), system (KEntryAttSystem), sl@0: or directory (KEntryAttDir) attribute set and anAtt does have sl@0: the corresponding attribute set, then the function returns false. sl@0: Alternatively, if aMatt has KEntryAttMustBeFile set and anAtt has sl@0: the directory attribute set, then the function also returns EFalse. sl@0: sl@0: Further matching behaviour can be implemented using sl@0: KEntryAttMatchExclusive and KEntryAttMatchExclude. sl@0: sl@0: @param anAtt Attribute mask to be tested. sl@0: @param aMatt The attribute match mask. sl@0: sl@0: @return True, if the anAtt entry attributes match, false otherwise. sl@0: sl@0: @see KEntryAttHidden sl@0: @see KEntryAttSystem sl@0: @see KEntryAttDir sl@0: @see KEntryAttMustBeFile sl@0: @see KEntryAttMatchExclusive sl@0: @see KEntryAttMatchExclude sl@0: */ sl@0: EXPORT_C TBool CMountCB::MatchEntryAtt(TUint anAtt,TUint aMatt) const sl@0: { sl@0: if (aMatt&KEntryAttMatchExclude) sl@0: { // Include any except sl@0: if ((anAtt&aMatt)==0) sl@0: return(ETrue); sl@0: return(EFalse); sl@0: } sl@0: sl@0: anAtt&=KEntryAttMaskSupported; sl@0: if ((aMatt&KEntryAttMustBeFile) && (anAtt&KEntryAttIllegal)) sl@0: return(EFalse); // Not a file sl@0: sl@0: if ((aMatt&KEntryAttHidden)==0 && (anAtt&KEntryAttHidden)) sl@0: return(EFalse); // Ignore hidden unless requested sl@0: if ((aMatt&KEntryAttSystem)==0 && (anAtt&KEntryAttSystem)) sl@0: return(EFalse); // Ignore system unless requested sl@0: if ((aMatt&KEntryAttDir)==0 && (anAtt&KEntryAttDir)) sl@0: return(EFalse); // Ignore directory unless requested sl@0: if (anAtt&KEntryAttVolume) sl@0: return(EFalse); // Ignore volumes sl@0: sl@0: anAtt&=(~(KEntryAttHidden|KEntryAttSystem)); // remove hidden and system sl@0: sl@0: if (aMatt&KEntryAttMatchExclusive) sl@0: { // Exclude all except sl@0: if ((anAtt&aMatt)!=0) sl@0: return(ETrue); sl@0: return(EFalse); sl@0: } sl@0: return(ETrue); sl@0: } sl@0: sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Gets the address of the specified file if it is found in ROM. sl@0: sl@0: The default implementation sets aFileStart to NULL, and this should only sl@0: be overridden by ROM file systems. sl@0: sl@0: @param aFileName A reference to a descriptor containing the full file name. sl@0: @param aFileStart On return, the address of the file, aFileName. sl@0: The default implementation returns NULL. sl@0: */ sl@0: EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart) sl@0: { sl@0: sl@0: aFileStart=NULL; sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Notifies the file server that the free disk space of the mounted volume sl@0: has changed outside of the standard file system operations. sl@0: sl@0: For example, the background thread of the log flash file system will call sl@0: this function after a background roll-forward. sl@0: sl@0: @param aFreeSpace New free disk space value. sl@0: */ sl@0: EXPORT_C void CMountCB::SetDiskSpaceChange(TInt64 aFreeSpace) sl@0: { sl@0: const TInt drv=Drive().DriveNumber(); sl@0: __ASSERT_ALWAYS(aFreeSpace>=0,Fault(ESvrFreeDiskSpace)); sl@0: __PRINT3(_L("CMountCB::SetDiskSpaceChange(%LU) drv:%d, %dKB"), aFreeSpace, drv, (TUint32)(aFreeSpace>>10)); sl@0: sl@0: // Notifying involves memory de-allocation on the file server's heap - sl@0: // check if we need to switch heaps. sl@0: RAllocator* current_alloc = &User::Heap(); sl@0: RAllocator* svr_alloc = ServerThreadAllocator; sl@0: if (current_alloc != svr_alloc) sl@0: User::SwitchHeap(svr_alloc); sl@0: sl@0: FsNotify::HandleDiskSpace(drv, aFreeSpace); sl@0: sl@0: if (current_alloc != svr_alloc) sl@0: User::SwitchHeap(current_alloc); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Initialize the MountCB object. sl@0: sl@0: @param aDrive TDrive object that will be used by the mount for drive access sl@0: @param apFileSystem pointer to the File System object that has produced this CMountCB sl@0: */ sl@0: EXPORT_C void CMountCB::InitL(TDrive& aDrive, CFileSystem* apFileSystem) sl@0: { sl@0: __PRINT3(_L("CMountCB::InitL()[0x%x] drv:%d, FS:0x%x"), this, aDrive.DriveNumber(), apFileSystem); sl@0: ASSERT(apFileSystem); sl@0: sl@0: sl@0: SetDrive(&aDrive); sl@0: DoInitL(aDrive.DriveNumber()); sl@0: sl@0: // see whether the file system supports the CFileCB extended API sl@0: MFileAccessor* fileAccessor = NULL; sl@0: sl@0: GetInterfaceTraced(CMountCB::EFileAccessor, (void*&) fileAccessor, NULL); sl@0: sl@0: MFileExtendedInterface* fileExtInterface = NULL; sl@0: GetInterface(CMountCB::EFileExtendedInterface, (void*&) fileExtInterface, NULL); sl@0: sl@0: if(!iBody) sl@0: { sl@0: iBody = new(ELeave)CMountBody(this, fileAccessor, fileExtInterface); sl@0: } sl@0: else sl@0: { sl@0: //-- some file systems can call this method several times for the same mount. sl@0: //-- composite FS, for example. sl@0: __PRINT1(_L("CMountCB::InitL !!re-initialisation!! iBody:0x%x"), iBody); sl@0: } sl@0: sl@0: SetFileSystem(apFileSystem); //-- associate MountCB object with the file system it belongs to; this relies on iBody sl@0: } sl@0: sl@0: /** sl@0: Reports whether the specified interface is supported - if it is, sl@0: the a supplied interface object is modified to it sl@0: sl@0: @param aInterfaceId The interface of interest sl@0: @param aInterface The interface object sl@0: @return KErrNone if the interface is supported, otherwise KErrNotFound sl@0: */ sl@0: EXPORT_C TInt CMountCB::GetInterface(TInt /*aInterfaceId*/,TAny*& /*aInterface*/,TAny* /*aInput*/) sl@0: { sl@0: return(KErrNotSupported); sl@0: } sl@0: sl@0: /** sl@0: Creates a clamp for the named file, and provides clamp handle data to the caller. sl@0: sl@0: @param aDriveNo The number of the drive on which the file can be found sl@0: @param aName Name of the file to clamp sl@0: @param aHandle Pointer to the clamp handle data sl@0: @return KErrNone if successful, otherwise one of the systme-wide eror codes. sl@0: */ sl@0: TInt CMountCB::ClampFile(const TInt aDriveNo, const TDesC& aName, TAny* aHandle) sl@0: { sl@0: return(iBody?iBody->ClampFile(aDriveNo,aName,aHandle):KErrNotSupported); sl@0: }; sl@0: sl@0: /** sl@0: Reports whether the named file is clamped. sl@0: sl@0: @param aName Name of the file to clamp sl@0: @return 0 if the file is not clamped, 1 if it is, or a system-wide error code. sl@0: */ sl@0: EXPORT_C TInt CMountCB::IsFileClamped(/*const TDesC& aName,*/ const TInt64 aUniqueId) sl@0: { sl@0: return(iBody?iBody->IsFileClamped(aUniqueId):KErrNotSupported); sl@0: }; sl@0: sl@0: /** sl@0: Removes the clamp indicated by the specified handle. sl@0: If this was the last clamp for the drive, any pending dismount is performed. sl@0: sl@0: @param aHandle Pointer to the clamp handle data sl@0: @return KErrNone if successful, a system-wide error code otherwise sl@0: */ sl@0: TInt CMountCB::UnclampFile(RFileClamp* aHandle) sl@0: { sl@0: return(iBody?iBody->UnclampFile(aHandle):KErrNotSupported); sl@0: }; sl@0: sl@0: /** sl@0: Returns the current number of clamps sl@0: sl@0: @return the number of clamps sl@0: */ sl@0: TInt CMountCB::NoOfClamps() sl@0: { sl@0: return(iBody?iBody->NoOfClamps():KErrNotSupported); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the sub type name of mounted file system (e.g. FAT12, FAT16 or FAT32 of Fat file system). sl@0: Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. sl@0: The real implementations is done by classes multiple inherited from both CMountCB and sl@0: MFileSystemSubType that have implemented MFileSystemSubType::SubType() virtual function. sl@0: File system that do not support sub types will have KErrNotSupported returned. sl@0: sl@0: @param aSubTypeName A descriptor contains return of the sub type name. sl@0: @return KErrNone if successful; otherwise another of the system wide error codes; sl@0: KErrNotSupported if sub type is not supported by mounted file system; sl@0: sl@0: @see MFileSystemSubType::SubType() sl@0: */ sl@0: TInt CMountCB::FileSystemSubType(TDes& aName) sl@0: { sl@0: MFileSystemSubType* interface = NULL; sl@0: TAny* dummy = NULL; sl@0: TInt rel = GetInterfaceTraced(EGetFileSystemSubType, (TAny*&)(interface), dummy); sl@0: if((interface != NULL) && (rel == KErrNone)) sl@0: { sl@0: rel = interface->SubType(aName); sl@0: } sl@0: sl@0: return rel; sl@0: } sl@0: sl@0: /** sl@0: Gets the cluster size of mounted file system. sl@0: Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. sl@0: The real implementation is done by classes multiple inherited from both CMountCB and sl@0: MFileSystemClusterSize that have implemented MFileSystemClusterSize::ClusterSize() function. sl@0: File system that do not support concept of 'clusters' will have the default KErrNotSupported returned. sl@0: sl@0: @return Cluster size value if successful; otherwise another of the system wide error codes; sl@0: KErrNotSupported if cluster is not supported by mounted file system; sl@0: sl@0: @see MFileSystemClusterSize::ClusterSize() sl@0: */ sl@0: TInt CMountCB::FileSystemClusterSize() sl@0: { sl@0: MFileSystemClusterSize* interface = NULL; sl@0: TAny* dummy = NULL; sl@0: TInt rel = GetInterfaceTraced(EGetClusterSize, (TAny*&)(interface), dummy); sl@0: if((interface != NULL) && (rel == KErrNone)) sl@0: { sl@0: rel = interface->ClusterSize(); sl@0: } sl@0: sl@0: return rel; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @prototype sl@0: sl@0: Reads a specified section of the file, regardless of the file's lock state. sl@0: sl@0: Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. sl@0: The real implementation is done by classes multiple inherited from both CMountCB and sl@0: MFileSystemExtendedInterface that have implemented MFileSystemExtendedInterface::ExtendedReadSectionL() function. sl@0: File system that do not support large file will implement the default CMountCB::ReadSectionL() function. sl@0: sl@0: @see CMountCB::ReadSectionL() sl@0: sl@0: @see MFileSystemExtendedInterface::ExtendedReadSectionL() sl@0: */ sl@0: void CMountCB::ReadSection64L(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) sl@0: { sl@0: iBody->iFileExtendedInterface->ReadSection64L(aName, aPos, aTrg, aLength, aMessage); sl@0: } sl@0: sl@0: TInt CMountCB::GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId) sl@0: { sl@0: return (iBody->iFileAccessor->GetFileUniqueId(aName, aUniqueId)); sl@0: } sl@0: sl@0: TInt CMountCB::Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2) sl@0: { sl@0: return (iBody->iFileAccessor->Spare3(aVal, aPtr1, aPtr2)); sl@0: } sl@0: sl@0: TInt CMountCB::Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2) sl@0: { sl@0: return (iBody->iFileAccessor->Spare2(aVal, aPtr1, aPtr2)); sl@0: } sl@0: sl@0: TInt CMountCB::Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2) sl@0: { sl@0: return (iBody->iFileAccessor->Spare1(aVal, aPtr1, aPtr2)); sl@0: } sl@0: sl@0: TInt CMountCB::GetInterfaceTraced(TInt aInterfaceId, TAny*& aInterface, TAny* aInput) sl@0: { sl@0: TRACE3(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterface, EF32TraceUidFileSys, sl@0: DriveNumber(), aInterfaceId, aInput); sl@0: sl@0: TInt r = GetInterface(aInterfaceId, aInterface, aInput); sl@0: sl@0: TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterfaceRet, EF32TraceUidFileSys, r, aInterface); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Get the file system name. I.e. The name of the file system that produced this object of CMountCB sl@0: @param aName buffer for the name sl@0: */ sl@0: void CMountCB::FileSystemName(TDes& aName) sl@0: { sl@0: aName = FileSystem()->Name(); sl@0: } sl@0: sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Associate CFileSystem object (the factory) and the produced CMountCB object. sl@0: @param aFS pointer to the file system that produced this mount. sl@0: */ sl@0: void CMountCB::SetFileSystem(CFileSystem* aFS) sl@0: { sl@0: ASSERT(iBody); sl@0: iBody->SetFileSystem(aFS); sl@0: } sl@0: sl@0: /** sl@0: Get reference to the filesystem, associated with this mount. sl@0: */ sl@0: EXPORT_C CFileSystem* CMountCB::FileSystem() const sl@0: { sl@0: ASSERT(iBody); sl@0: CFileSystem* pFSys = iBody->GetFileSystem(); sl@0: ASSERT(pFSys); sl@0: return pFSys; sl@0: } sl@0: sl@0: void CMountCB::SetProxyDriveDismounted() sl@0: { sl@0: iBody->SetProxyDriveDismounted(); sl@0: } sl@0: sl@0: TBool CMountCB::ProxyDriveDismounted() sl@0: { sl@0: return iBody->ProxyDriveDismounted(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Factory method. Produces CFileCB object. sl@0: */ sl@0: CFileCB* CMountCB::NewFileL() const sl@0: { sl@0: return FileSystem()->NewFileL(); sl@0: } sl@0: sl@0: /** sl@0: Factory method. Produces CDirCB object. sl@0: */ sl@0: CDirCB* CMountCB::NewDirL() const sl@0: { sl@0: return FileSystem()->NewDirL(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Factory method. Produces CFormatCB object. sl@0: */ sl@0: CFormatCB* CMountCB::NewFormatL() const sl@0: { sl@0: return FileSystem()->NewFormatL(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: