os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_mnt.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "sf_std.h"
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
/**
sl@0
    22
Default constructor.
sl@0
    23
*/
sl@0
    24
EXPORT_C CMountCB::CMountCB()
sl@0
    25
	              :iMountQ(_FOFF(CFileCB,iMountLink))
sl@0
    26
	{
sl@0
    27
    __PRINT1(_L("CMountCB::CMountCB()[0x%x]"),this);
sl@0
    28
	}
sl@0
    29
sl@0
    30
sl@0
    31
sl@0
    32
sl@0
    33
EXPORT_C CMountCB::~CMountCB()
sl@0
    34
	{
sl@0
    35
	__PRINT1(_L("CMountCB::~CMountCB()[0x%x]"),this);
sl@0
    36
	delete iBody;
sl@0
    37
	delete iVolumeName;
sl@0
    38
	}
sl@0
    39
sl@0
    40
sl@0
    41
//-----------------------------------------------------------------------------
sl@0
    42
sl@0
    43
/**
sl@0
    44
    Compares the specified mount control block with this one for inequality.
sl@0
    45
sl@0
    46
    Two mount control blocks are different if either the addresses of
sl@0
    47
    the mount control blocks ar different, or their iMountNumber values
sl@0
    48
    are different.
sl@0
    49
sl@0
    50
    @param aMount The mount control block to be compared.
sl@0
    51
sl@0
    52
    @return True, if the mount control blocks are different, false otherwise.
sl@0
    53
*/
sl@0
    54
EXPORT_C TBool CMountCB::operator!=(const CMountCB& aMount) const
sl@0
    55
	{
sl@0
    56
sl@0
    57
	if (this==(&aMount) && MountNumber()==aMount.MountNumber())
sl@0
    58
		return(FALSE);
sl@0
    59
	return(TRUE);
sl@0
    60
	}
sl@0
    61
sl@0
    62
sl@0
    63
//-----------------------------------------------------------------------------
sl@0
    64
sl@0
    65
/**
sl@0
    66
    Tests whether the given attribute mask matches given criteria (specified
sl@0
    67
    in another mask).
sl@0
    68
sl@0
    69
    This function is used when filtering entries. aMatt specifies the criteria
sl@0
    70
    to be matched by anAtt.
sl@0
    71
sl@0
    72
    Volumes are ignored, so if anAtt has the volume attribute set then
sl@0
    73
    the function returns false.
sl@0
    74
sl@0
    75
    If aMatt does not have a hidden (KEntryAttHidden), system (KEntryAttSystem),
sl@0
    76
    or directory (KEntryAttDir) attribute set and anAtt does have
sl@0
    77
    the corresponding attribute set, then the function returns false.
sl@0
    78
    Alternatively, if aMatt has KEntryAttMustBeFile set and anAtt has
sl@0
    79
    the directory attribute set, then the function also returns EFalse.
sl@0
    80
sl@0
    81
    Further matching behaviour can be implemented using
sl@0
    82
    KEntryAttMatchExclusive and KEntryAttMatchExclude.
sl@0
    83
sl@0
    84
    @param anAtt Attribute mask to be tested.
sl@0
    85
    @param aMatt The attribute match mask.
sl@0
    86
sl@0
    87
    @return True, if the anAtt entry attributes match, false otherwise.
sl@0
    88
sl@0
    89
    @see KEntryAttHidden
sl@0
    90
    @see KEntryAttSystem
sl@0
    91
    @see KEntryAttDir
sl@0
    92
    @see KEntryAttMustBeFile
sl@0
    93
    @see KEntryAttMatchExclusive
sl@0
    94
    @see KEntryAttMatchExclude
sl@0
    95
*/
sl@0
    96
EXPORT_C TBool CMountCB::MatchEntryAtt(TUint anAtt,TUint aMatt) const
sl@0
    97
    {
sl@0
    98
	if (aMatt&KEntryAttMatchExclude)
sl@0
    99
		{ // Include any except
sl@0
   100
		if ((anAtt&aMatt)==0)
sl@0
   101
			return(ETrue);
sl@0
   102
		return(EFalse);
sl@0
   103
		}
sl@0
   104
sl@0
   105
	anAtt&=KEntryAttMaskSupported;
sl@0
   106
	if ((aMatt&KEntryAttMustBeFile) && (anAtt&KEntryAttIllegal))
sl@0
   107
		return(EFalse); // Not a file
sl@0
   108
sl@0
   109
	if ((aMatt&KEntryAttHidden)==0 && (anAtt&KEntryAttHidden))
sl@0
   110
		return(EFalse); // Ignore hidden unless requested
sl@0
   111
	if ((aMatt&KEntryAttSystem)==0 && (anAtt&KEntryAttSystem))
sl@0
   112
		return(EFalse); // Ignore system unless requested
sl@0
   113
	if ((aMatt&KEntryAttDir)==0 && (anAtt&KEntryAttDir))
sl@0
   114
		return(EFalse); // Ignore directory unless requested
sl@0
   115
	if (anAtt&KEntryAttVolume)
sl@0
   116
		return(EFalse); // Ignore volumes
sl@0
   117
sl@0
   118
	anAtt&=(~(KEntryAttHidden|KEntryAttSystem)); // remove hidden and system
sl@0
   119
sl@0
   120
	if (aMatt&KEntryAttMatchExclusive)
sl@0
   121
		{ // Exclude all except
sl@0
   122
		if ((anAtt&aMatt)!=0)
sl@0
   123
			return(ETrue);
sl@0
   124
		return(EFalse);
sl@0
   125
		}
sl@0
   126
	return(ETrue);
sl@0
   127
	}
sl@0
   128
sl@0
   129
sl@0
   130
sl@0
   131
//-----------------------------------------------------------------------------
sl@0
   132
/**
sl@0
   133
    Gets the address of the specified file if it is found in ROM. 
sl@0
   134
sl@0
   135
    The default implementation sets aFileStart to NULL, and this should only
sl@0
   136
    be overridden by ROM file systems.
sl@0
   137
sl@0
   138
    @param aFileName  A reference to a descriptor containing the full file name.
sl@0
   139
    @param aFileStart On return, the address of the file, aFileName.
sl@0
   140
                      The default implementation returns NULL.
sl@0
   141
*/
sl@0
   142
EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart)
sl@0
   143
	{
sl@0
   144
sl@0
   145
	aFileStart=NULL;
sl@0
   146
	}
sl@0
   147
sl@0
   148
sl@0
   149
//-----------------------------------------------------------------------------
sl@0
   150
sl@0
   151
/**
sl@0
   152
    Notifies the file server that the free disk space of the mounted volume
sl@0
   153
    has changed outside of the standard file system operations.
sl@0
   154
sl@0
   155
    For example, the background thread of the log flash file system will call
sl@0
   156
    this function after a background roll-forward.
sl@0
   157
sl@0
   158
    @param aFreeSpace New free disk space value.
sl@0
   159
*/
sl@0
   160
EXPORT_C void CMountCB::SetDiskSpaceChange(TInt64 aFreeSpace)
sl@0
   161
	{
sl@0
   162
	const TInt drv=Drive().DriveNumber();
sl@0
   163
	__ASSERT_ALWAYS(aFreeSpace>=0,Fault(ESvrFreeDiskSpace));
sl@0
   164
	__PRINT3(_L("CMountCB::SetDiskSpaceChange(%LU) drv:%d, %dKB"), aFreeSpace, drv, (TUint32)(aFreeSpace>>10));
sl@0
   165
sl@0
   166
	// Notifying involves memory de-allocation on the file server's heap -
sl@0
   167
	// check if we need to switch heaps.
sl@0
   168
	RAllocator* current_alloc = &User::Heap();
sl@0
   169
	RAllocator* svr_alloc = ServerThreadAllocator;
sl@0
   170
	if (current_alloc != svr_alloc)
sl@0
   171
		User::SwitchHeap(svr_alloc);
sl@0
   172
sl@0
   173
	FsNotify::HandleDiskSpace(drv, aFreeSpace);
sl@0
   174
		
sl@0
   175
		if (current_alloc != svr_alloc)
sl@0
   176
			User::SwitchHeap(current_alloc);
sl@0
   177
	}
sl@0
   178
	
sl@0
   179
//-----------------------------------------------------------------------------
sl@0
   180
/**
sl@0
   181
    Initialize the MountCB object. 
sl@0
   182
    
sl@0
   183
    @param  aDrive          TDrive object that will be used by the mount for drive access
sl@0
   184
    @param  apFileSystem    pointer to the File System object that has produced this CMountCB
sl@0
   185
*/
sl@0
   186
EXPORT_C void CMountCB::InitL(TDrive& aDrive, CFileSystem* apFileSystem)
sl@0
   187
	{
sl@0
   188
	__PRINT3(_L("CMountCB::InitL()[0x%x] drv:%d, FS:0x%x"), this, aDrive.DriveNumber(),  apFileSystem);
sl@0
   189
    ASSERT(apFileSystem);
sl@0
   190
    
sl@0
   191
sl@0
   192
    SetDrive(&aDrive);
sl@0
   193
    DoInitL(aDrive.DriveNumber());
sl@0
   194
sl@0
   195
	// see whether the file system supports the CFileCB extended API 
sl@0
   196
	MFileAccessor* fileAccessor = NULL;
sl@0
   197
sl@0
   198
	GetInterfaceTraced(CMountCB::EFileAccessor, (void*&) fileAccessor, NULL);
sl@0
   199
sl@0
   200
	MFileExtendedInterface* fileExtInterface = NULL;
sl@0
   201
	GetInterface(CMountCB::EFileExtendedInterface, (void*&) fileExtInterface, NULL);
sl@0
   202
sl@0
   203
    if(!iBody)
sl@0
   204
        {
sl@0
   205
        iBody = new(ELeave)CMountBody(this, fileAccessor, fileExtInterface);
sl@0
   206
        }
sl@0
   207
    else
sl@0
   208
        {
sl@0
   209
        //-- some file systems can call this method several times for the same mount.
sl@0
   210
        //-- composite FS, for example.
sl@0
   211
        __PRINT1(_L("CMountCB::InitL !!re-initialisation!! iBody:0x%x"), iBody);
sl@0
   212
        }
sl@0
   213
	
sl@0
   214
    SetFileSystem(apFileSystem); //-- associate MountCB object with the file system it belongs to; this relies on iBody
sl@0
   215
    }
sl@0
   216
sl@0
   217
/**
sl@0
   218
Reports whether the specified interface is supported - if it is,
sl@0
   219
the a supplied interface object is modified to it
sl@0
   220
sl@0
   221
@param aInterfaceId		The interface of interest
sl@0
   222
@param aInterface		The interface object
sl@0
   223
@return					KErrNone if the interface is supported, otherwise KErrNotFound 
sl@0
   224
*/
sl@0
   225
EXPORT_C TInt CMountCB::GetInterface(TInt /*aInterfaceId*/,TAny*& /*aInterface*/,TAny* /*aInput*/)
sl@0
   226
	{
sl@0
   227
	return(KErrNotSupported);
sl@0
   228
	}
sl@0
   229
sl@0
   230
/**
sl@0
   231
Creates a clamp for the named file, and provides clamp handle data to the caller.
sl@0
   232
sl@0
   233
@param aDriveNo		The number of the drive on which the file can be found
sl@0
   234
@param aName		Name of the file to clamp
sl@0
   235
@param aHandle		Pointer to the clamp handle data
sl@0
   236
@return				KErrNone if successful, otherwise one of the systme-wide eror codes.
sl@0
   237
*/
sl@0
   238
TInt CMountCB::ClampFile(const TInt aDriveNo, const TDesC& aName, TAny* aHandle)
sl@0
   239
	{
sl@0
   240
	return(iBody?iBody->ClampFile(aDriveNo,aName,aHandle):KErrNotSupported);
sl@0
   241
	};
sl@0
   242
sl@0
   243
/**
sl@0
   244
Reports whether the named file is clamped.
sl@0
   245
sl@0
   246
@param aName		Name of the file to clamp
sl@0
   247
@return				0 if the file is not clamped, 1 if it is, or a system-wide error code.
sl@0
   248
*/
sl@0
   249
EXPORT_C TInt CMountCB::IsFileClamped(/*const TDesC& aName,*/ const TInt64 aUniqueId)
sl@0
   250
	{
sl@0
   251
	return(iBody?iBody->IsFileClamped(aUniqueId):KErrNotSupported);
sl@0
   252
	};
sl@0
   253
sl@0
   254
/**
sl@0
   255
Removes the clamp indicated by the specified handle.
sl@0
   256
If this was the last clamp for the drive, any pending dismount is performed.
sl@0
   257
sl@0
   258
@param aHandle		Pointer to the clamp handle data
sl@0
   259
@return				KErrNone if successful, a system-wide error code otherwise
sl@0
   260
*/
sl@0
   261
TInt CMountCB::UnclampFile(RFileClamp* aHandle)
sl@0
   262
	{
sl@0
   263
	return(iBody?iBody->UnclampFile(aHandle):KErrNotSupported);
sl@0
   264
	};
sl@0
   265
sl@0
   266
/**
sl@0
   267
Returns the current number of clamps 
sl@0
   268
sl@0
   269
@return				the number of clamps
sl@0
   270
*/
sl@0
   271
TInt CMountCB::NoOfClamps()
sl@0
   272
	{
sl@0
   273
	return(iBody?iBody->NoOfClamps():KErrNotSupported);
sl@0
   274
	}
sl@0
   275
sl@0
   276
sl@0
   277
sl@0
   278
sl@0
   279
/**
sl@0
   280
Gets the sub type name of mounted file system (e.g. FAT12, FAT16 or FAT32 of Fat file system).
sl@0
   281
Uses GetInterface() API to avoid binary compatibility break while providing polymorphism.
sl@0
   282
The real implementations is done by classes multiple inherited from both CMountCB and
sl@0
   283
MFileSystemSubType that have implemented MFileSystemSubType::SubType() virtual function.
sl@0
   284
File system that do not support sub types will have KErrNotSupported returned.
sl@0
   285
sl@0
   286
@param aSubTypeName A descriptor contains return of the sub type name.
sl@0
   287
@return KErrNone if successful; otherwise another of the system wide error codes; 
sl@0
   288
		KErrNotSupported if sub type is not supported by mounted file system;
sl@0
   289
sl@0
   290
@see MFileSystemSubType::SubType()
sl@0
   291
*/
sl@0
   292
TInt CMountCB::FileSystemSubType(TDes& aName)
sl@0
   293
	{
sl@0
   294
	MFileSystemSubType* interface = NULL;
sl@0
   295
	TAny* dummy = NULL;
sl@0
   296
	TInt rel = GetInterfaceTraced(EGetFileSystemSubType, (TAny*&)(interface), dummy);
sl@0
   297
	if((interface != NULL) && (rel == KErrNone))
sl@0
   298
		{
sl@0
   299
		rel = interface->SubType(aName);
sl@0
   300
		}
sl@0
   301
	
sl@0
   302
	return rel;
sl@0
   303
	}
sl@0
   304
sl@0
   305
/**
sl@0
   306
Gets the cluster size of mounted file system.
sl@0
   307
Uses GetInterface() API to avoid binary compatibility break while providing polymorphism.
sl@0
   308
The real implementation is done by classes multiple inherited from both CMountCB and
sl@0
   309
MFileSystemClusterSize that have implemented MFileSystemClusterSize::ClusterSize() function.
sl@0
   310
File system that do not support concept of 'clusters' will have the default KErrNotSupported returned.
sl@0
   311
sl@0
   312
@return Cluster size value if successful; otherwise another of the system wide error codes; 
sl@0
   313
		KErrNotSupported if cluster is not supported by mounted file system;
sl@0
   314
sl@0
   315
@see MFileSystemClusterSize::ClusterSize()
sl@0
   316
*/
sl@0
   317
TInt CMountCB::FileSystemClusterSize()
sl@0
   318
	{
sl@0
   319
	MFileSystemClusterSize* interface = NULL;
sl@0
   320
	TAny* dummy = NULL;
sl@0
   321
	TInt rel = GetInterfaceTraced(EGetClusterSize, (TAny*&)(interface), dummy);
sl@0
   322
	if((interface != NULL) && (rel == KErrNone))
sl@0
   323
		{
sl@0
   324
		rel = interface->ClusterSize();
sl@0
   325
		}
sl@0
   326
		
sl@0
   327
	return rel;
sl@0
   328
	}
sl@0
   329
sl@0
   330
sl@0
   331
/**
sl@0
   332
@prototype
sl@0
   333
sl@0
   334
Reads a specified section of the file, regardless of the file's lock state.
sl@0
   335
sl@0
   336
Uses GetInterface() API to avoid binary compatibility break while providing polymorphism.
sl@0
   337
The real implementation is done by classes multiple inherited from both CMountCB and
sl@0
   338
MFileSystemExtendedInterface that have implemented MFileSystemExtendedInterface::ExtendedReadSectionL() function.
sl@0
   339
File system that do not support large file will implement the default CMountCB::ReadSectionL() function.
sl@0
   340
sl@0
   341
@see CMountCB::ReadSectionL()
sl@0
   342
sl@0
   343
@see MFileSystemExtendedInterface::ExtendedReadSectionL()
sl@0
   344
*/
sl@0
   345
void CMountCB::ReadSection64L(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage)
sl@0
   346
	{
sl@0
   347
	iBody->iFileExtendedInterface->ReadSection64L(aName, aPos, aTrg, aLength, aMessage);
sl@0
   348
	}
sl@0
   349
sl@0
   350
TInt CMountCB::GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId)
sl@0
   351
	{
sl@0
   352
	return (iBody->iFileAccessor->GetFileUniqueId(aName, aUniqueId));
sl@0
   353
	}
sl@0
   354
	
sl@0
   355
TInt CMountCB::Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2)
sl@0
   356
	{
sl@0
   357
	return (iBody->iFileAccessor->Spare3(aVal, aPtr1, aPtr2));
sl@0
   358
	}
sl@0
   359
	
sl@0
   360
TInt CMountCB::Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2)
sl@0
   361
	{
sl@0
   362
	return (iBody->iFileAccessor->Spare2(aVal, aPtr1, aPtr2));
sl@0
   363
	}
sl@0
   364
	
sl@0
   365
TInt CMountCB::Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2)
sl@0
   366
	{
sl@0
   367
	return (iBody->iFileAccessor->Spare1(aVal, aPtr1, aPtr2));
sl@0
   368
	}
sl@0
   369
sl@0
   370
TInt CMountCB::GetInterfaceTraced(TInt aInterfaceId, TAny*& aInterface, TAny* aInput)
sl@0
   371
	{
sl@0
   372
	TRACE3(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterface, EF32TraceUidFileSys, 
sl@0
   373
		DriveNumber(), aInterfaceId, aInput);
sl@0
   374
sl@0
   375
	TInt r = GetInterface(aInterfaceId, aInterface, aInput);
sl@0
   376
sl@0
   377
	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterfaceRet, EF32TraceUidFileSys, r, aInterface);
sl@0
   378
sl@0
   379
	return r;
sl@0
   380
	}
sl@0
   381
sl@0
   382
//-----------------------------------------------------------------------------
sl@0
   383
/**
sl@0
   384
    Get the file system name. I.e. The name of the file system that produced this object of CMountCB
sl@0
   385
    @param  aName buffer for the name
sl@0
   386
*/
sl@0
   387
void CMountCB::FileSystemName(TDes& aName)
sl@0
   388
{
sl@0
   389
    aName = FileSystem()->Name();
sl@0
   390
}
sl@0
   391
sl@0
   392
sl@0
   393
sl@0
   394
//-----------------------------------------------------------------------------
sl@0
   395
/**
sl@0
   396
    Associate CFileSystem object (the factory) and the produced CMountCB object.
sl@0
   397
    @param  aFS pointer to the file system that produced this mount.
sl@0
   398
*/
sl@0
   399
void CMountCB::SetFileSystem(CFileSystem* aFS)
sl@0
   400
    {
sl@0
   401
    ASSERT(iBody);
sl@0
   402
    iBody->SetFileSystem(aFS);
sl@0
   403
    }
sl@0
   404
sl@0
   405
/**
sl@0
   406
    Get reference to the filesystem, associated with this mount.
sl@0
   407
*/
sl@0
   408
EXPORT_C CFileSystem* CMountCB::FileSystem() const
sl@0
   409
    {
sl@0
   410
    ASSERT(iBody);
sl@0
   411
    CFileSystem* pFSys = iBody->GetFileSystem();
sl@0
   412
    ASSERT(pFSys);
sl@0
   413
    return pFSys;
sl@0
   414
    }
sl@0
   415
sl@0
   416
void CMountCB::SetProxyDriveDismounted()
sl@0
   417
	{
sl@0
   418
	iBody->SetProxyDriveDismounted();
sl@0
   419
	}
sl@0
   420
sl@0
   421
TBool CMountCB::ProxyDriveDismounted()
sl@0
   422
	{
sl@0
   423
	return iBody->ProxyDriveDismounted();
sl@0
   424
	}
sl@0
   425
sl@0
   426
sl@0
   427
/**
sl@0
   428
    Factory method. Produces CFileCB object.
sl@0
   429
*/
sl@0
   430
CFileCB* CMountCB::NewFileL() const
sl@0
   431
    {
sl@0
   432
    return FileSystem()->NewFileL();
sl@0
   433
    }
sl@0
   434
sl@0
   435
/**
sl@0
   436
    Factory method. Produces CDirCB object.
sl@0
   437
*/
sl@0
   438
CDirCB* CMountCB::NewDirL() const
sl@0
   439
    {
sl@0
   440
    return FileSystem()->NewDirL();
sl@0
   441
    }
sl@0
   442
sl@0
   443
    
sl@0
   444
/**
sl@0
   445
    Factory method. Produces CFormatCB object.
sl@0
   446
*/
sl@0
   447
CFormatCB* CMountCB::NewFormatL() const
sl@0
   448
    {
sl@0
   449
    return FileSystem()->NewFormatL();
sl@0
   450
    }
sl@0
   451
sl@0
   452
sl@0
   453
sl@0
   454
sl@0
   455
sl@0
   456
sl@0
   457
sl@0
   458
sl@0
   459
sl@0
   460
sl@0
   461
sl@0
   462
sl@0
   463
sl@0
   464
sl@0
   465
sl@0
   466