| author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> | 
| Thu, 07 Jan 2010 13:38:45 +0200 | |
| changeset 6 | 0173bcd7697c | 
| parent 0 | a41df078684a | 
| child 8 | 538db54a451d | 
| permissions | -rw-r--r-- | 
| 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\sfile\sf_drv.cpp | |
| 15 | // | |
| 16 | // | |
| 17 | ||
| 18 | #include "sf_std.h" | |
| 19 | #include "sf_file_cache.h" | |
| 20 | ||
| 21 | ||
| 22 | //const TInt KMaxNotifierAttempts=4; // not used anywhere | |
| 23 | ||
| 24 | static TPtrC StripBackSlash(const TDesC& aName) | |
| 25 | // | |
| 26 | // If aName ends in a backslash, strip it. | |
| 27 | // | |
| 28 | 	{
 | |
| 29 | ||
| 30 | __ASSERT_DEBUG(aName.Length(),Fault(EStripBackSlashBadName)); | |
| 31 | if (aName[aName.Length()-1]==KPathDelimiter) | |
| 32 | return(aName.Left(aName.Length()-1)); | |
| 33 | return(aName); | |
| 34 | } | |
| 35 | ||
| 36 | static void CheckSubClose(CFsObject* anObj,TInt aHandle, CSessionFs* aSession) | |
| 37 | // | |
| 38 | // Close anObj if its not NULL. | |
| 39 | // | |
| 40 | 	{
 | |
| 41 | 	__PRINT1(_L("CheckSubClose() session 0x0%x"),aSession);
 | |
| 42 | 	__PRINT1(_L("CheckSubClose() anObj 0x0%x"),anObj);
 | |
| 43 | ||
| 44 | if(!anObj) | |
| 45 | return; | |
| 46 | ||
| 47 | if(aHandle==0) | |
| 48 | 		{
 | |
| 49 | // can't have been added to the object index | |
| 50 | __ASSERT_DEBUG(KErrNotFound==aSession->Handles().At(anObj,ETrue),Fault(ESubOpenBadHandle)); | |
| 51 | anObj->Close(); | |
| 52 | } | |
| 53 | else | |
| 54 | aSession->Handles().Remove(aHandle,ETrue); | |
| 55 | } | |
| 56 | ||
| 57 | TInt ValidateDrive(TInt aDriveNumber,CFsRequest* aRequest) | |
| 58 | // | |
| 59 | // Validate a drive number and set iTheDrive. | |
| 60 | // | |
| 61 | 	{
 | |
| 62 | __CHECK_MAINTHREAD(); | |
| 63 | if (aDriveNumber==KDefaultDrive) | |
| 64 | aDriveNumber=aRequest->Session()->CurrentDrive(); | |
| 65 | if (!RFs::IsValidDrive(aDriveNumber)) | |
| 66 | return(KErrBadName); | |
| 67 | aRequest->SetDrive(&TheDrives[aDriveNumber]); | |
| 68 | return(KErrNone); | |
| 69 | } | |
| 70 | ||
| 71 | TInt ValidateDriveDoSubst(TInt aDriveNumber,CFsRequest* aRequest) | |
| 72 | // | |
| 73 | // Validate a drive number and set iTheDrive. | |
| 74 | // | |
| 75 | 	{
 | |
| 76 | ||
| 77 | TInt r=ValidateDrive(aDriveNumber,aRequest); | |
| 78 | if (r!=KErrNone) | |
| 79 | return(r); | |
| 80 | if (aRequest->Drive()->IsSubsted()) | |
| 81 | 		{
 | |
| 82 | aRequest->SetSubstedDrive(aRequest->Drive()); | |
| 83 | aRequest->SetDrive(&aRequest->Drive()->SubstedDrive()); | |
| 84 | } | |
| 85 | return(KErrNone); | |
| 86 | } | |
| 87 | ||
| 88 | void ValidateAtts(TUint /*anEntryAtts*/,TUint& aSetAttMask,TUint& aClearAttMask) | |
| 89 | // | |
| 90 | // Do not allow the entry type to be changed | |
| 91 | // | |
| 92 | 	{
 | |
| 93 | const TUint KReadOnlySetAtts = KEntryAttVolume | | |
| 94 | KEntryAttDir | | |
| 95 | KEntryAttRemote; | |
| 96 | ||
| 97 | const TUint KReadOnlyClrAtts = KEntryAttVolume | | |
| 98 | KEntryAttDir | | |
| 99 | KEntryAttRemote | | |
| 100 | KEntryAttModified; | |
| 101 | ||
| 102 | aSetAttMask &= ~KReadOnlySetAtts; | |
| 103 | aClearAttMask &= ~KReadOnlyClrAtts; | |
| 104 | } | |
| 105 | ||
| 106 | void CheckForLeaveAfterOpenL(TInt leaveError, CFsRequest* aRequest, TInt aHandle) | |
| 107 | // | |
| 108 | // Tidy up in the event of a leave after opening a file or directory | |
| 109 | 	{
 | |
| 110 | if (leaveError) | |
| 111 | 		{
 | |
| 112 | CFsObject* anObj=(CFsObject* )aRequest->ScratchValue(); | |
| 113 | CheckSubClose(anObj,aHandle,aRequest->Session()); | |
| 114 | User::Leave(leaveError); | |
| 115 | } | |
| 116 | } | |
| 117 | ||
| 118 | TDrive::TDrive() | |
| 119 | // | |
| 120 | // Constructor. | |
| 121 | // | |
| 122 | : iDriveNumber(0),iAtt(0),iChanged(EFalse), | |
| 123 | iFSys(NULL),iCurrentMount(NULL),iSubstedDrive(NULL),iSubst(NULL), | |
| 124 | iMount(NULL),iDriveFlags(0),iMountFailures(0) | |
| 125 | 	{}
 | |
| 126 | ||
| 127 | void TDrive::CreateL(TInt aDriveNumber) | |
| 128 | // | |
| 129 | // Allocate the drive number and any resources. | |
| 130 | // | |
| 131 | 	{
 | |
| 132 | 	__PRINT1(_L("TDrive::CreateL(%d)"),aDriveNumber);
 | |
| 133 | iDriveNumber=aDriveNumber; | |
| 134 | iMount=TheContainer->CreateL(); | |
| 135 | TInt r=iLock.CreateLocal(); | |
| 136 | User::LeaveIfError(r); | |
| 137 | } | |
| 138 | ||
| 139 | TInt TDrive::CheckMountAndEntryName(const TDesC& aName) | |
| 140 | // | |
| 141 | // Check drive is mounted then check aName is legal | |
| 142 | // | |
| 143 | 	{
 | |
| 144 | ||
| 145 | 	__PRINT1(_L("TDrive::CheckMountAndEntryName Drive%d"),DriveNumber());
 | |
| 146 | TInt r=CheckMount(); | |
| 147 | if (r==KErrNone && IsIllegalFullName(aName)) | |
| 148 | return(KErrBadName); | |
| 149 | return(r); | |
| 150 | } | |
| 151 | ||
| 152 | void TDrive::MultiSlotDriveCheck() | |
| 153 | 	{
 | |
| 154 | // Check whether the current drive is a dual-slot/multi-slot | |
| 155 | // if so, we need to check which drive is connected now and | |
| 156 | // swap the mapping in LocalDrives::iMapping such that the | |
| 157 | // mapping of driveNumber to localDriveNumber is correct. | |
| 158 | ||
| 159 | Lock(); | |
| 160 | //Is this a multislot drive? | |
| 161 | if(LocalDrives::iIsMultiSlotDrive[iDriveNumber]) | |
| 162 | 		{
 | |
| 163 | for(TInt localDrvNum=0; localDrvNum<KMaxLocalDrives; localDrvNum++) | |
| 164 | 			{
 | |
| 165 | // ensure that this local drive is a multi-slot choice for this drive number.. | |
| 166 | if(LocalDrives::iReverseMapping[localDrvNum]==iDriveNumber) | |
| 167 | 				{
 | |
| 168 | // Caps - find out which one is connected | |
| 169 | TLocalDriveCapsBuf capsInfo; | |
| 170 | TInt r = LocalDrives::iLocalDrives[localDrvNum].Caps(capsInfo); | |
| 171 | if(r==KErrNotReady) | |
| 172 | 					{
 | |
| 173 | continue; //go to next localdrive | |
| 174 | } | |
| 175 | //found a connected drive | |
| 176 | //Update mapping | |
| 177 | #ifdef _DEBUG | |
| 178 | 				RDebug::Print(_L("Multislot drive mapping update: DriveNum %d to LocDrv %d"),iDriveNumber,localDrvNum);
 | |
| 179 | #endif | |
| 180 | ||
| 181 | LocalDrives::iMapping[iDriveNumber] = localDrvNum; | |
| 182 | break; // Swap complete - don't look any further | |
| 183 | } | |
| 184 | } | |
| 185 | } | |
| 186 | UnLock(); | |
| 187 | } | |
| 188 | ||
| 189 | TInt TDrive::CheckMount() | |
| 190 | // | |
| 191 | // Check the drive and try to mount a media if not already mounted. | |
| 192 | // | |
| 193 | 	{
 | |
| 194 | 	__PRINT2(_L("TDrive::CheckMount Drive%d, changed:%d"),DriveNumber(), iChanged);
 | |
| 195 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 196 | ||
| 197 | if (!iFSys) | |
| 198 | return KErrNotReady; | |
| 199 | ||
| 200 | if (iChanged) // If a media change has occurred | |
| 201 | 		{
 | |
| 202 | iMountFailures = 0; | |
| 203 | iChanged=EFalse; // Reset the flag | |
| 204 | if (IsMounted()) // Dismount the mount if it is still marked as mounted | |
| 205 | 			{
 | |
| 206 | DoDismount(); | |
| 207 | } | |
| 208 | //If we have a dual/multi removable media slot then we may need to | |
| 209 | //swop the mappings. | |
| 210 | MultiSlotDriveCheck(); | |
| 211 | } | |
| 212 | ||
| 213 | if (!IsMounted()) // Checks that iCurrentMount!=NULL | |
| 214 | 		{
 | |
| 215 | 		__PRINT(_L("TDrive::CheckMount() Not Mounted"));
 | |
| 216 | const TInt KMaxMountFailures = 3; | |
| 217 | // if we've repeatedly failed to mount, give up until a media change | |
| 218 | if (iMountFailures >= KMaxMountFailures) | |
| 219 | 			{
 | |
| 220 | 			__PRINT1(_L("TDrive::CheckMount() retries exceeded, last Err:%d"), iLastMountError);
 | |
| 221 | return iLastMountError; | |
| 222 | } | |
| 223 | ||
| 224 | if (!ReMount()) // Have we just remounted a mount we have previously encountered? | |
| 225 | 			{			
 | |
| 226 | MountFileSystem(EFalse); // If not, mount it for the first time now | |
| 227 | } | |
| 228 | else if(IsWriteProtected() && IsWriteableResource()) | |
| 229 | 			{
 | |
| 230 | DoDismount(); | |
| 231 | return KErrAccessDenied; | |
| 232 | } | |
| 233 | } | |
| 234 | ||
| 235 | if (iReason==KErrNone && CurrentMount().LockStatus() > 0) | |
| 236 | 	    {
 | |
| 237 | //-- this meand that the mount has drive access objetcs opened (RFormat or RRawDisk) | |
| 238 |         __PRINT1(_L("TDrive::CheckMount() Mount is locked! LockStaus:%d"), CurrentMount().LockStatus());
 | |
| 239 | return KErrInUse; | |
| 240 | } | |
| 241 | ||
| 242 | 	__PRINT1(_L("TDrive::CheckMount returned %d "),iReason);
 | |
| 243 | ||
| 244 | return(iReason); | |
| 245 | } | |
| 246 | ||
| 247 | //---------------------------------------------------------------------------- | |
| 248 | /** | |
| 249 | Try and re-mount any of the pending media | |
| 250 | ||
| 251 | @return ETrue if the mount matching media found and been attached back (set as iCurrentMount) | |
| 252 | */ | |
| 253 | TBool TDrive::ReMount() | |
| 254 | 	{
 | |
| 255 | const TInt mCount=Mount().Count(); | |
| 256 |     __PRINT1(_L("TDrive::ReMount() MountCnt:%d"), mCount);
 | |
| 257 | ||
| 258 | const TInt u=(Mount().UniqueID()<<16); | |
| 259 | iReason=KErrNone; | |
| 260 | ||
| 261 | //-- try every instance of CMountCB that is associated with this object of TDrive. | |
| 262 | //-- mounts are stored in the container of mCount elements. | |
| 263 | //-- if some CMountCB recognises the media it belongs, it means that "remount succeded" | |
| 264 | for(TInt i=0; i<mCount; i++) | |
| 265 | 		{
 | |
| 266 | CMountCB* pM=(CMountCB*)Mount().At(u|i); | |
| 267 | ||
| 268 | if (ReMount(*pM)) | |
| 269 | return ETrue; | |
| 270 | } | |
| 271 | ||
| 272 | return EFalse; | |
| 273 | } | |
| 274 | ||
| 275 | //---------------------------------------------------------------------------- | |
| 276 | /** | |
| 277 | Try and re-mount the specified media. | |
| 278 | ||
| 279 | @return ETrue if remounting succeeded - i.e. the CMountCB instance that matches the media is found in the | |
| 280 | mounts container (Mount()) and bound to the media. | |
| 281 | */ | |
| 282 | TBool TDrive::ReMount(CMountCB& aMount) | |
| 283 | 	{
 | |
| 284 | 	__PRINT1(_L("TDrive::ReMount(0x%x)"), &aMount);
 | |
| 285 | iReason=KErrNone; | |
| 286 | ||
| 287 | if (!aMount.IsDismounted() && !aMount.ProxyDriveDismounted()) | |
| 288 | 		{
 | |
| 289 | aMount.SetDrive(this); | |
| 290 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMount, EF32TraceUidFileSys, DriveNumber()); | |
| 291 | ||
| 292 | //-- actually, this is asking CMountCB to see if it belongs to the current media. | |
| 293 | iReason = aMount.ReMount(); | |
| 294 | ||
| 295 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMountRet, EF32TraceUidFileSys, iReason); | |
| 296 | ||
| 297 | if (iReason == KErrNone) // ReMount succeeded | |
| 298 | 			{
 | |
| 299 | aMount.Open(); | |
| 300 | iCurrentMount = &aMount; | |
| 301 | 			__PRINT1(_L("TDrive::ReMount for Mount:0x%x OK!"), &aMount);
 | |
| 302 | return ETrue; | |
| 303 | } | |
| 304 | ||
| 305 | 		__PRINT2(_L("TDrive::ReMount for Mount:0x%x failed iReason=%d"),&aMount,iReason);
 | |
| 306 | } | |
| 307 | else | |
| 308 | 		{
 | |
| 309 | 		__PRINT1(_L("TDrive::ReMount() failed - Mount:0x%x is dismounted"), &aMount);
 | |
| 310 | } | |
| 311 | ||
| 312 | return EFalse; | |
| 313 | } | |
| 314 | ||
| 315 | ||
| 316 | ||
| 317 | //---------------------------------------------------------------------------- | |
| 318 | /** | |
| 319 | Mount the media on the drive. Optionally force a bad media to be mounted. | |
| 320 | ||
| 321 | @param apMount out: pointer to the produced CMountCB object; NULL if the CMountCB is not constructed | |
| 322 | @param aForceMount if ETrue, the filesystem will be forcedly mounted on the drive, disregarding what it contains. | |
| 323 | @param aFsNameHash file system name hash; see TDrive::MountFileSystem() | |
| 324 | */ | |
| 325 | void TDrive::DoMountFileSystemL(CMountCB*& apMount, TBool aForceMount, TUint32 aFsNameHash) | |
| 326 | 	{
 | |
| 327 | CFileSystem* pMountsFs = NULL; //-- reference to the filesystem that will be producing CMountCB | |
| 328 | ||
| 329 | apMount = NULL; | |
| 330 | ||
| 331 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 332 | ||
| 333 | //-- construct a new CmountCB object. | |
| 334 | //-- on return pMountsFs will be the pointer to the factory object of CFileSystem that produced this mount | |
| 335 | apMount = FSys().NewMountExL(this, &pMountsFs, aForceMount, aFsNameHash); | |
| 336 | ||
| 337 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, KErrNone, apMount); | |
| 338 | 	__PRINT2(_L("TDrive::MountMediaL created mount:0x%x FileSys:0x%x"), apMount, pMountsFs);
 | |
| 339 | ||
| 340 | ASSERT(pMountsFs && apMount); | |
| 341 | ||
| 342 | apMount->SetMountNumber(iMountNumber++); | |
| 343 | apMount->InitL(*this, pMountsFs); //-- initialise Mount | |
| 344 | apMount->MountL(aForceMount); //-- mount the file system | |
| 345 | Mount().AddL(apMount,EFalse); //-- add mount object to the mounts container. | |
| 346 | ||
| 347 | iCurrentMount=apMount; | |
| 348 | } | |
| 349 | ||
| 350 | ||
| 351 | //---------------------------------------------------------------------------- | |
| 352 | /* | |
| 353 | Mount file system on the drive. | |
| 354 | @param aForceMount if EFalse, will try to mount the file system normally, the file system implementation will decide if it can work on this drive or not. | |
| 355 | if ETrue, will mount the file suystem by force, this is used mostly for formatting unrecognisable media. | |
| 356 | ||
| 357 | @param aFsNameHash optional parameter. Can specify the concrete file system name (hash). It can be used to force mounting some specific | |
| 358 | file system. Default value '0' means "not specified / not used" | |
| 359 | ||
| 360 | ||
| 361 | TDrive::iReason on return contains the operation result code. | |
| 362 | */ | |
| 363 | void TDrive::MountFileSystem(TBool aForceMount, TUint32 aFsNameHash /*=0*/ ) | |
| 364 | 	{
 | |
| 365 | 	__PRINT2(_L("TDrive::MountFileSystem aForceMount=%d, FSNameHash:0x%x"),aForceMount, aFsNameHash);
 | |
| 366 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 367 | ||
| 368 | iCurrentMount=NULL; | |
| 369 | if(!iFSys) | |
| 370 | 		{
 | |
| 371 | iReason=KErrNotReady; | |
| 372 | return; | |
| 373 | } | |
| 374 | ||
| 375 | CMountCB* pM=NULL; | |
| 376 | TRAP(iReason, DoMountFileSystemL(pM, aForceMount, aFsNameHash)); | |
| 377 | if (iReason == KErrNone) | |
| 378 | 		{
 | |
| 379 | iMountFailures = 0; | |
| 380 | ASSERT(iCurrentMount); | |
| 381 | } | |
| 382 | else | |
| 383 | 		{
 | |
| 384 | iLastMountError = iReason; | |
| 385 | iMountFailures++; | |
| 386 | 		__PRINT2(_L("TDrive::MountFileSystem 0x%x failed iReason=%d"),pM,iReason);
 | |
| 387 | if(pM) | |
| 388 | pM->Close(); | |
| 389 | ||
| 390 | ASSERT(!iCurrentMount); | |
| 391 | } | |
| 392 | } | |
| 393 | ||
| 394 | ||
| 395 | //---------------------------------------------------------------------------- | |
| 396 | /** | |
| 397 | Generic mount control method. | |
| 398 | @param aLevel specifies the operation to perfrom on the mount | |
| 399 | @param aOption specific option for the given operation | |
| 400 | @param aParam pointer to generic parameter, its meaning depends on aLevel and aOption | |
| 401 | ||
| 402 | @return standard error code. | |
| 403 | */ | |
| 404 | TInt TDrive::MountControl(TInt aLevel, TInt aOption, TAny* aParam) | |
| 405 |     {
 | |
| 406 | TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControl, EF32TraceUidFileSys, DriveNumber(), aLevel, aOption, aParam); | |
| 407 | TInt r = CurrentMount().MountControl(aLevel, aOption, aParam); | |
| 408 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControlRet, EF32TraceUidFileSys, r); | |
| 409 | ||
| 410 | return r; | |
| 411 | } | |
| 412 | ||
| 413 | //---------------------------------------------------------------------------- | |
| 414 | /** | |
| 415 | Request aFreeSpaceRequired free bytes from the mount associated with this drive. | |
| 416 | The volume free space on for some filesystems can be changing (usually increasing) after it has been mounted. | |
| 417 | If the mount supports this functionality, it can block this call until certain number of free bytes encounted if its free | |
| 418 | space calculation activity hasn't finished yet. | |
| 419 | ||
| 420 | @param aFreeSpaceRequired required free space, bytes. | |
| 421 | ||
| 422 | @return KErrNone on success and if there is at least aFreeSpaceRequired bytes on the volume | |
| 423 | KErrDiskFull on success and if there is no aFreeSpaceRequired bytes on the volume | |
| 424 | system-wide error code otherwise | |
| 425 | */ | |
| 426 | TInt TDrive::RequestFreeSpaceOnMount(TUint64 aFreeSpaceRequired) | |
| 427 |     {
 | |
| 428 | TInt nRes; | |
| 429 | ||
| 430 | nRes = CheckMount(); | |
| 431 | if(nRes != KErrNone) | |
| 432 | return nRes; | |
| 433 | ||
| 434 | //-- 1. Try mount-specific request first. If the mount is still performing free space calculations, | |
| 435 | //-- the caller will be suspended until aFreeSpaceRequired bytes is available or scanning process finishes | |
| 436 |     {
 | |
| 437 | TUint64 freeSpaceReq = aFreeSpaceRequired; | |
| 438 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpace, EF32TraceUidFileSys, DriveNumber()); | |
| 439 | nRes = CurrentMount().RequestFreeSpace(freeSpaceReq); | |
| 440 | TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(freeSpaceReq), I64HIGH(freeSpaceReq)); | |
| 441 | if(nRes == KErrNone) | |
| 442 |             {
 | |
| 443 | return (freeSpaceReq >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull; | |
| 444 | } | |
| 445 | } | |
| 446 | ||
| 447 | //-- given Mount doesn't support this functionality, use legacy method | |
| 448 | TVolumeInfo volInfo; | |
| 449 | nRes = Volume(volInfo); | |
| 450 | if(nRes !=KErrNone) | |
| 451 | return nRes; | |
| 452 | ||
| 453 | return ((TUint64)volInfo.iFree >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull; | |
| 454 | } | |
| 455 | ||
| 456 | //---------------------------------------------------------------------------- | |
| 457 | /** | |
| 458 | Get size of the mounted volume. It can be less than physical volume size because FileSystem data may occupy some space. | |
| 459 | ||
| 460 | @param aSize on success mounted volume size in bytes will be returned there | |
| 461 | @return KErrNone on success, standard error code otherwise | |
| 462 | */ | |
| 463 | TInt TDrive::MountedVolumeSize(TUint64& aSize) | |
| 464 |     {
 | |
| 465 | TInt nRes; | |
| 466 | ||
| 467 | nRes = CheckMount(); | |
| 468 | if(nRes != KErrNone) | |
| 469 | return nRes; | |
| 470 | ||
| 471 | //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do if some background activity is going on the mount | |
| 472 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, DriveNumber()); | |
| 473 | nRes = CurrentMount().MountedVolumeSize(aSize); | |
| 474 | TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, nRes, I64LOW(aSize), I64HIGH(aSize)); | |
| 475 | if(nRes == KErrNone) | |
| 476 | return nRes; | |
| 477 | ||
| 478 | //-- given Mount doesn't support this functionality, use legacy method | |
| 479 | TVolumeInfo volInfo; | |
| 480 | nRes = Volume(volInfo); | |
| 481 | if(nRes == KErrNone) | |
| 482 |         {
 | |
| 483 | aSize = volInfo.iSize; | |
| 484 | } | |
| 485 | ||
| 486 | return nRes; | |
| 487 | } | |
| 488 | ||
| 489 | //---------------------------------------------------------------------------- | |
| 490 | /** | |
| 491 | Get _current_ amount of free space on the volume. Some mounts implementations can be updating the amount of free space | |
| 492 | in background. | |
| 493 | ||
| 494 | @param aFreeDiskSpace on success will contain a current amount of free space | |
| 495 | @return KErrNone on success, standard error code otherwise | |
| 496 | ||
| 497 | */ | |
| 498 | TInt TDrive::FreeDiskSpace(TInt64& aFreeDiskSpace) | |
| 499 | 	{
 | |
| 500 | TInt nRes; | |
| 501 | ||
| 502 | nRes = CheckMount(); | |
| 503 | if(nRes != KErrNone) | |
| 504 | return nRes; | |
| 505 | ||
| 506 | //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do | |
| 507 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpace, EF32TraceUidFileSys, DriveNumber()); | |
| 508 | nRes = CurrentMount().GetCurrentFreeSpaceAvailable(aFreeDiskSpace); | |
| 509 | TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(aFreeDiskSpace), I64HIGH(aFreeDiskSpace)); | |
| 510 | if(nRes == KErrNone) | |
| 511 | return nRes; | |
| 512 | ||
| 513 | //-- given Mount doesn't support this functionality, use legacy method | |
| 514 | TVolumeInfo volInfo; | |
| 515 | nRes = Volume(volInfo); | |
| 516 | if(nRes == KErrNone) | |
| 517 |         {
 | |
| 518 | aFreeDiskSpace = volInfo.iFree; | |
| 519 | } | |
| 520 | ||
| 521 | return nRes; | |
| 522 | } | |
| 523 | ||
| 524 | //---------------------------------------------------------------------------- | |
| 525 | /** | |
| 526 | Finalise drive (the mount). | |
| 527 | ||
| 528 | @param aOperation describes finalisation operation ,see RFs::TFinaliseDrvMode | |
| 529 | @param aParam1 not used, for future expansion | |
| 530 | @param aParam2 not used, for future expansion | |
| 531 | ||
| 532 | @return Standard error code | |
| 533 | */ | |
| 534 | TInt TDrive::FinaliseMount(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) | |
| 535 | 	{
 | |
| 536 | TInt r=CheckMount(); | |
| 537 | if (r!=KErrNone) | |
| 538 | return(r); | |
| 539 | ||
| 540 | r = FlushCachedFileInfo(); | |
| 541 | if (r!=KErrNone) | |
| 542 | return(r); | |
| 543 | ||
| 544 | if(IsWriteProtected()) | |
| 545 | return(KErrAccessDenied); | |
| 546 | ||
| 547 | TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); | |
| 548 | TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2)); | |
| 549 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2Ret, EF32TraceUidFileSys, r); | |
| 550 | ||
| 551 | return r; | |
| 552 | } | |
| 553 | ||
| 554 | //---------------------------------------------------------------------------- | |
| 555 | /** old implementation */ | |
| 556 | TInt TDrive::FinaliseMount() | |
| 557 | 	{
 | |
| 558 | TInt r=CheckMount(); | |
| 559 | if (r!=KErrNone) | |
| 560 | return(r); | |
| 561 | ||
| 562 | r = FlushCachedFileInfo(); | |
| 563 | if (r!=KErrNone) | |
| 564 | return(r); | |
| 565 | ||
| 566 | if(IsWriteProtected()) | |
| 567 | return(KErrAccessDenied); | |
| 568 | ||
| 569 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1, EF32TraceUidFileSys, DriveNumber()); | |
| 570 | TRAP(r,CurrentMount().FinaliseMountL()); | |
| 571 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1Ret, EF32TraceUidFileSys, r); | |
| 572 | ||
| 573 | return r; | |
| 574 | } | |
| 575 | ||
| 576 | ||
| 577 | ||
| 578 | CFileCB* TDrive::LocateFile(const TDesC& aName) | |
| 579 | // | |
| 580 | // Locate a file of the same name already open on the drive. | |
| 581 | // | |
| 582 | 	{
 | |
| 583 | TDblQueIter<CFileCB> q(CurrentMount().iMountQ); | |
| 584 | CFileCB* pF; | |
| 585 | // early out for normal case, list is empty | |
| 586 | if(q==NULL) | |
| 587 | return NULL; | |
| 588 | ||
| 589 | // strip off trailing dots | |
| 590 | TInt length= aName.Length(); | |
| 591 | while((length !=0) && (aName[length-1]==KExtDelimiter)) | |
| 592 | 		{
 | |
| 593 | length--; | |
| 594 | } | |
| 595 | ||
| 596 | TPtrC temp(aName.Ptr(),length); | |
| 597 | ||
| 598 | TFileName tempName; | |
| 599 | tempName.CopyF(temp); | |
| 600 | TUint32 nameHash=CalcNameHash(tempName); | |
| 601 | ||
| 602 | while ((pF=q++)!=NULL) | |
| 603 | 		{
 | |
| 604 | if(nameHash==pF->NameHash()) | |
| 605 | 			{
 | |
| 606 | if (pF->FileNameF().Match(tempName)==KErrNone) | |
| 607 | return(pF); | |
| 608 | } | |
| 609 | } | |
| 610 | return(NULL); | |
| 611 | } | |
| 612 | ||
| 613 | ||
| 614 | CFileCache* TDrive::LocateClosedFile(const TDesC& aName, TBool aResurrect) | |
| 615 | // | |
| 616 | // Locate a recently closed file of the same name on the drive. | |
| 617 | // | |
| 618 | 	{
 | |
| 619 | // strip off trailing dots | |
| 620 | TInt length= aName.Length(); | |
| 621 | while((length !=0) && (aName[length-1]==KExtDelimiter)) | |
| 622 | 		{
 | |
| 623 | length--; | |
| 624 | } | |
| 625 | ||
| 626 | TPtrC temp(aName.Ptr(),length); | |
| 627 | ||
| 628 | TFileName tempName; | |
| 629 | tempName.CopyF(temp); | |
| 630 | TUint32 nameHash=CalcNameHash(tempName); | |
| 631 | ||
| 632 | CFileCache* pF = NULL; | |
| 633 | CMountCB* currentMount = &CurrentMount(); | |
| 634 | ||
| 635 | ||
| 636 | TClosedFileUtils::Lock(); | |
| 637 | ||
| 638 | TInt count = TClosedFileUtils::Count(); | |
| 639 | while(count--) | |
| 640 | 		{
 | |
| 641 | CFileCache* fileCache = TClosedFileUtils::At(count); | |
| 642 | if (&fileCache->Drive() == this && | |
| 643 | fileCache->NameHash()== nameHash && | |
| 644 | fileCache->FileNameF().Match(tempName)==KErrNone && | |
| 645 | &fileCache->Mount() == currentMount) | |
| 646 | 			{
 | |
| 647 | __ASSERT_DEBUG(TClosedFileUtils::IsClosed(fileCache), Fault(EObjRemoveContainerNotFound)); | |
| 648 | 			__CACHE_PRINT2(_L("CLOSEDFILES: LocateClosedFile(%S, %d\n"), &fileCache->FileNameF(), aResurrect);
 | |
| 649 | if (aResurrect) | |
| 650 | 				{
 | |
| 651 | TClosedFileUtils::ReOpen(fileCache, EFalse); | |
| 652 | } | |
| 653 | pF = fileCache; | |
| 654 | break; | |
| 655 | } | |
| 656 | ||
| 657 | } | |
| 658 | TClosedFileUtils::Unlock(); | |
| 659 | ||
| 660 | if (pF != NULL && !aResurrect) | |
| 661 | 		{
 | |
| 662 | pF->Close(); | |
| 663 | pF = NULL; | |
| 664 | } | |
| 665 | ||
| 666 | return(pF); | |
| 667 | } | |
| 668 | ||
| 669 | ||
| 670 | static TBool IsSubDir(const TDesC& aFullName,const TDesC& aParent) | |
| 671 | // | |
| 672 | // Returns ETrue if aFullName is a subdirectory of aParent | |
| 673 | // Assumes aParent is a path name with the trailing backslash removed | |
| 674 | // | |
| 675 | 	{
 | |
| 676 | ||
| 677 | __ASSERT_DEBUG(aParent.Length() && aParent[aParent.Length()-1]!=KPathDelimiter,Fault(EIsSubDirBadDes)); | |
| 678 | TPtrC entryFullName(NULL,0); | |
| 679 | TPtrC entryParent(NULL,0); | |
| 680 | TInt posFullName=0; | |
| 681 | TInt posParent=0; | |
| 682 | ||
| 683 | FOREVER | |
| 684 | 		{
 | |
| 685 | NextInPath(aParent,entryParent,posParent); | |
| 686 | if (entryParent.Length()==0) | |
| 687 | break; | |
| 688 | NextInPath(aFullName,entryFullName,posFullName); | |
| 689 | if (entryParent!=entryFullName) | |
| 690 | return(EFalse); | |
| 691 | } | |
| 692 | ||
| 693 | if (aFullName.Length()<=posFullName) | |
| 694 | return(EFalse); | |
| 695 | if (aFullName[posFullName]!=KPathDelimiter) | |
| 696 | return(EFalse); | |
| 697 | return(ETrue); | |
| 698 | } | |
| 699 | ||
| 700 | CFileCB* TDrive::LocateFileByPath(const TDesC& aPath) | |
| 701 | // | |
| 702 | // Locate a file opened in a subdirectory of aPath | |
| 703 | // | |
| 704 | 	{
 | |
| 705 | ||
| 706 | TDblQueIter<CFileCB> q(CurrentMount().iMountQ); | |
| 707 | CFileCB* pF; | |
| 708 | while ((pF=q++)!=NULL) | |
| 709 | 		{
 | |
| 710 | if (IsSubDir(pF->FileName(),aPath)) | |
| 711 | return(pF); | |
| 712 | } | |
| 713 | return(NULL); | |
| 714 | } | |
| 715 | ||
| 716 | void TDrive::FlushCachedFileInfoL() | |
| 717 | // | |
| 718 | // Flush data stored in the file control blocks | |
| 719 | // | |
| 720 | 	{
 | |
| 721 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 722 | TDblQueIter<CFileCB> q(CurrentMount().iMountQ); | |
| 723 | CFileCB* pF; | |
| 724 | while ((pF=q++)!=NULL) | |
| 725 | 		{
 | |
| 726 | if (pF->iAtt&KEntryAttModified) | |
| 727 | pF->FlushAllL(); | |
| 728 | } | |
| 729 | } | |
| 730 | ||
| 731 | /** | |
| 732 | Flushes (asynchronously) all dirty data on this drive and optionally | |
| 733 | purges non-dirty data | |
| 734 | ||
| 735 | aPurgeCache - purges all file caches on this drive AFTER dirty data has ben flushed | |
| 736 | ||
| 737 | returns KErrNone if complete | |
| 738 | CFsRequest::EReqActionBusy if flushing is in progress | |
| 739 | otherwise one of the other system-wide error codes. | |
| 740 | */ | |
| 741 | TInt TDrive::FlushCachedFileInfo(TBool aPurgeCache) | |
| 742 | 	{
 | |
| 743 | if (iCurrentMount == NULL) | |
| 744 | return KErrNone; | |
| 745 | ||
| 746 | TBool driveThread = FsThreadManager::IsDriveThread(iDriveNumber,EFalse); | |
| 747 | ||
| 748 | Lock(); | |
| 749 | ||
| 750 | ||
| 751 | TInt ret = KErrNone; | |
| 752 | ||
| 753 | TDblQueIter<CFileCB> q(iCurrentMount->iMountQ); | |
| 754 | CFileCB* pF; | |
| 755 | while ((pF=q++)!=NULL) | |
| 756 | 		{
 | |
| 757 | CFileCache* fileCache = pF->FileCache(); | |
| 758 | ||
| 759 | // Write dirty data if there is a file cache | |
| 760 | TInt flushDirtyRetCode = CFsRequest::EReqActionComplete; | |
| 761 | if (fileCache) | |
| 762 | 			{
 | |
| 763 | flushDirtyRetCode = fileCache->FlushDirty(); | |
| 764 | if (flushDirtyRetCode == CFsRequest::EReqActionComplete) // nothing to flush | |
| 765 | 				{
 | |
| 766 | if (aPurgeCache) | |
| 767 | fileCache->Purge(EFalse); | |
| 768 | } | |
| 769 | else if (flushDirtyRetCode == CFsRequest::EReqActionBusy) // flushing | |
| 770 | 				{
 | |
| 771 | ret = flushDirtyRetCode; | |
| 772 | } | |
| 773 | else // error | |
| 774 | 				{
 | |
| 775 | ret = flushDirtyRetCode; | |
| 776 | break; | |
| 777 | } | |
| 778 | } | |
| 779 | // if no file cache or no dirty data left, update the file entry & attributes | |
| 780 | if (driveThread && (pF->iAtt&KEntryAttModified) && flushDirtyRetCode == CFsRequest::EReqActionComplete ) | |
| 781 | 			{
 | |
| 782 | TRAP(ret, pF->FlushAllL()); | |
| 783 | if (ret != KErrNone) | |
| 784 | break; | |
| 785 | } | |
| 786 | } | |
| 787 | ||
| 788 | UnLock(); | |
| 789 | ||
| 790 | ||
| 791 | return ret; | |
| 792 | } | |
| 793 | ||
| 794 | //---------------------------------------------------------------------------- | |
| 795 | /** | |
| 796 | Purge dirty cache data associated with all files on a given mount | |
| 797 | */ | |
| 798 | void TDrive::PurgeDirty(CMountCB& aMount) | |
| 799 | 	{
 | |
| 800 | TDblQueIter<CFileCB> q(aMount.iMountQ); | |
| 801 | CFileCB* pF; | |
| 802 | while ((pF=q++)!=NULL) | |
| 803 | 		{
 | |
| 804 | CFileCache* fileCache = pF->FileCache(); | |
| 805 | if (fileCache) | |
| 806 | 		    {
 | |
| 807 | fileCache->Purge(ETrue); | |
| 808 | fileCache->MarkFileClean(); | |
| 809 | } | |
| 810 | } | |
| 811 | } | |
| 812 | ||
| 813 | //---------------------------------------------------------------------------- | |
| 814 | TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare) | |
| 815 | // | |
| 816 | // Check that the sharing rules are obeyed. | |
| 817 | // | |
| 818 | 	{
 | |
| 819 | ||
| 820 | switch (aReqShare) | |
| 821 | 		{
 | |
| 822 | case EFileShareExclusive: | |
| 823 | case EFileShareReadersOnly: | |
| 824 | case EFileShareAny: | |
| 825 | case EFileShareReadersOrWriters: | |
| 826 | break; | |
| 827 | default: | |
| 828 | return(KErrArgument); | |
| 829 | } | |
| 830 | switch (aFile.iShare) | |
| 831 | 		{
 | |
| 832 | case EFileShareExclusive: | |
| 833 | return(KErrInUse); | |
| 834 | ||
| 835 | case EFileShareReadersOnly: | |
| 836 | case EFileShareAny: | |
| 837 | if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters) | |
| 838 | return(KErrInUse); | |
| 839 | break; | |
| 840 | ||
| 841 | case EFileShareReadersOrWriters: | |
| 842 | if (aReqShare==EFileShareExclusive) | |
| 843 | return(KErrInUse); | |
| 844 | // | |
| 845 | // If the file is currently open as EFileShareReadersOrWriters then | |
| 846 | // promote the share to the requested share mode. | |
| 847 | // | |
| 848 | // If the requested share is EFileShareReadersOnly, verfiy that no | |
| 849 | // other share has the file open for writing. | |
| 850 | // | |
| 851 | ||
| 852 | if (aReqShare == EFileShareReadersOnly) | |
| 853 | 			{
 | |
| 854 | FileShares->Lock(); | |
| 855 | TInt count = FileShares->Count(); | |
| 856 | while(count--) | |
| 857 | 				{
 | |
| 858 | CFileShare* share = (CFileShare*)(*FileShares)[count]; | |
| 859 | if (&share->File() == &aFile) | |
| 860 | 					{
 | |
| 861 | if(share->iMode & EFileWrite) | |
| 862 | 						{
 | |
| 863 | FileShares->Unlock(); | |
| 864 | return KErrInUse; | |
| 865 | } | |
| 866 | } | |
| 867 | } | |
| 868 | FileShares->Unlock(); | |
| 869 | } | |
| 870 | break; | |
| 871 | ||
| 872 | default: | |
| 873 | Fault(EDrvIllegalShareValue); | |
| 874 | break; | |
| 875 | } | |
| 876 | return(KErrNone); | |
| 877 | } | |
| 878 | ||
| 879 | void TDrive::DriveInfo(TDriveInfo& anInfo) | |
| 880 | // | |
| 881 | // Get the drive info. | |
| 882 | // | |
| 883 | 	{
 | |
| 884 | anInfo.iType=EMediaNotPresent; | |
| 885 | anInfo.iMediaAtt=0; | |
| 6 
0173bcd7697c
Revision: 201001
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
0diff
changeset | 886 | anInfo.iBattery=EBatNotSupported; | 
| 
0173bcd7697c
Revision: 201001
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
0diff
changeset | 887 | anInfo.iConnectionBusType=EConnectionBusInternal; | 
| 0 | 888 | |
| 889 | if(iFSys) | |
| 890 | 		{
 | |
| 891 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfo, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 892 | FSys().DriveInfo(anInfo,DriveNumber()); | |
| 893 | TRACE3(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfoRet, EF32TraceUidFileSys, | |
| 894 | anInfo.iType, anInfo.iDriveAtt, anInfo.iMediaAtt); | |
| 895 | } | |
| 896 | ||
| 897 | anInfo.iDriveAtt=Att(); | |
| 898 | } | |
| 899 | ||
| 900 | TInt TDrive::Volume(TVolumeInfo& aVolume) | |
| 901 | // | |
| 902 | // Get the drive volume info. | |
| 903 | // | |
| 904 | 	{
 | |
| 905 | TInt r=CheckMount(); | |
| 906 | if (r==KErrNone) | |
| 907 | 		{
 | |
| 908 | DriveInfo(aVolume.iDrive); | |
| 909 | CMountCB& m=CurrentMount(); | |
| 910 | aVolume.iName=m.VolumeName(); | |
| 911 | aVolume.iUniqueID=m.iUniqueID; | |
| 912 | aVolume.iSize=m.iSize; | |
| 913 | ||
| 914 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeL, EF32TraceUidFileSys, DriveNumber()); | |
| 915 | TRAP(r,m.VolumeL(aVolume)) | |
| 916 | TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeLRet, EF32TraceUidFileSys, | |
| 917 | r, aVolume.iUniqueID, I64LOW(aVolume.iSize), I64HIGH(aVolume.iSize), | |
| 918 | I64LOW(aVolume.iFree), I64HIGH(aVolume.iFree), aVolume.iFileCacheFlags); | |
| 919 | ||
| 920 | } | |
| 921 | return(r); | |
| 922 | } | |
| 923 | ||
| 924 | ||
| 925 | void TDrive::SetVolumeL(const TDesC& aName,HBufC*& aBuf) | |
| 926 | // | |
| 927 | // Set the volume name. | |
| 928 | // | |
| 929 | 	{
 | |
| 930 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 931 | aBuf=aName.AllocL(); | |
| 932 | TPtr volumeName=aBuf->Des(); | |
| 933 | ||
| 934 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeL, EF32TraceUidFileSys, DriveNumber(), aName); | |
| 935 | CurrentMount().SetVolumeL(volumeName); | |
| 936 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeLRet, EF32TraceUidFileSys, KErrNone); | |
| 937 | ||
| 938 | ||
| 939 | delete &CurrentMount().VolumeName(); | |
| 940 | CurrentMount().SetVolumeName(aBuf); | |
| 941 | } | |
| 942 | ||
| 943 | TInt TDrive::SetVolume(const TDesC& aName) | |
| 944 | // | |
| 945 | // Set the volume name. | |
| 946 | // | |
| 947 | 	{
 | |
| 948 | TInt r=CheckMount(); | |
| 949 | HBufC* pV=NULL; | |
| 950 | if (r==KErrNone) | |
| 951 | 		{
 | |
| 952 | if(IsWriteProtected()) | |
| 953 | return(KErrAccessDenied); | |
| 954 | TRAP(r,SetVolumeL(aName,pV)) | |
| 955 | if (r!=KErrNone) | |
| 956 | delete pV; | |
| 957 | } | |
| 958 | return(r); | |
| 959 | } | |
| 960 | ||
| 961 | TInt TDrive::MkDir(const TDesC& aName) | |
| 962 | // | |
| 963 | // Make a directory. | |
| 964 | // | |
| 965 | 	{
 | |
| 966 | TInt r=CheckMount(); | |
| 967 | if (r!=KErrNone) | |
| 968 | return(r); | |
| 969 | if(IsWriteProtected()) | |
| 970 | return(KErrAccessDenied); | |
| 971 | TParse newDirName; | |
| 972 | newDirName.Set(aName,NULL,NULL); | |
| 973 | ||
| 974 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirL, EF32TraceUidFileSys, DriveNumber(), aName); | |
| 975 | TRAP(r,CurrentMount().MkDirL(newDirName.FullName())) | |
| 976 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirLRet, EF32TraceUidFileSys, r); | |
| 977 | ||
| 978 | return(r); | |
| 979 | } | |
| 980 | ||
| 981 | TInt TDrive::RmDir(const TDesC& aName) | |
| 982 | // | |
| 983 | // Remove a directory. | |
| 984 | // | |
| 985 | 	{
 | |
| 986 | TInt r=CheckMount(); | |
| 987 | if (r!=KErrNone) | |
| 988 | return(r); | |
| 989 | TEntry entry; | |
| 990 | r=Entry(aName,entry); | |
| 991 | if (r!=KErrNone) | |
| 992 | return(r); | |
| 993 | if (entry.IsDir()==EFalse) | |
| 994 | return(KErrPathNotFound); | |
| 995 | if ((entry.iAtt&KEntryAttReadOnly) || IsWriteProtected()) | |
| 996 | return(KErrAccessDenied); | |
| 997 | ||
| 998 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirL, EF32TraceUidFileSys, DriveNumber(), aName); | |
| 999 | TRAP(r,CurrentMount().RmDirL(aName)) | |
| 1000 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirLRet, EF32TraceUidFileSys, r); | |
| 1001 | ||
| 1002 | return(r); | |
| 1003 | } | |
| 1004 | ||
| 1005 | TInt TDrive::Delete(const TDesC& aName) | |
| 1006 | // | |
| 1007 | // Delete files allowing wild cards. | |
| 1008 | // | |
| 1009 | 	{
 | |
| 1010 | TInt r=CheckMountAndEntryName(aName); | |
| 1011 | if (r!=KErrNone) | |
| 1012 | return(r); | |
| 1013 | CFileCB* pF=LocateFile(aName); | |
| 1014 | if (pF!=NULL) | |
| 1015 | return(KErrInUse); | |
| 1016 | ||
| 1017 | // remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected... | |
| 1018 | LocateClosedFile(aName, EFalse); | |
| 1019 | ||
| 1020 | TEntry entry; | |
| 1021 | r=Entry(aName,entry); | |
| 1022 | if (r!=KErrNone) | |
| 1023 | return(r); | |
| 1024 | if (entry.IsDir() || IsWriteProtected() || entry.IsReadOnly()) | |
| 1025 | return(KErrAccessDenied); | |
| 1026 | ||
| 1027 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), aName); | |
| 1028 | TRAP(r,CurrentMount().DeleteL(aName)) | |
| 1029 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r); | |
| 1030 | ||
| 1031 | return(r); | |
| 1032 | } | |
| 1033 | ||
| 1034 | TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName) | |
| 1035 | // | |
| 1036 | // Check mount, that neither is open, and that both names are legal. | |
| 1037 | // | |
| 1038 | 	{
 | |
| 1039 | ||
| 1040 | TInt r=CheckMountAndEntryName(anOldName); | |
| 1041 | if (r!=KErrNone) | |
| 1042 | return(r); | |
| 1043 | if (IsIllegalFullName(aNewName)) | |
| 1044 | return(KErrBadName); | |
| 1045 | return(KErrNone); | |
| 1046 | } | |
| 1047 | ||
| 1048 | TInt TDrive::CheckDirectories(const TDesC& anOldName,const TDesC& aNewName) | |
| 1049 | // | |
| 1050 | // Return KErrAlreadyExists if aNewName exists and | |
| 1051 | // KErrAccessDenied if anOldName is a directory being moved to a subdirectory of itself | |
| 1052 | // | |
| 1053 | 	{
 | |
| 1054 | ||
| 1055 | TEntry entry; | |
| 1056 | TInt r=Entry(anOldName,entry); | |
| 1057 | if (r!=KErrNone) | |
| 1058 | return(r); | |
| 1059 | if (entry.IsDir()) | |
| 1060 | 		{
 | |
| 1061 | //-- check the length of the destination directory name. It shall not exceed 253 characters. | |
| 1062 | //-- aNewName looks like "\\dir1" i.e. drive letter and ':' is removed from the name and there is no trailing '\\' in this case. | |
| 1063 | ||
| 1064 | const TInt maxDirNameLength = KMaxFileName - 3; | |
| 1065 | if(aNewName.Length() > maxDirNameLength) | |
| 1066 | return KErrBadName; | |
| 1067 | if(IsSubDir(aNewName,anOldName)) | |
| 1068 | return(KErrInUse); // rename into a subdir of itself | |
| 1069 | if (LocateFileByPath(anOldName)) | |
| 1070 | return(KErrInUse); // a file inside anOldName is open | |
| 1071 | } | |
| 1072 | else if (LocateFile(anOldName)) | |
| 1073 | return(KErrInUse); | |
| 1074 | ||
| 1075 | r=Entry(aNewName,entry); | |
| 1076 | if (r!=KErrNone && r!=KErrNotFound) | |
| 1077 | return(r); | |
| 1078 | return(KErrNone); | |
| 1079 | } | |
| 1080 | ||
| 1081 | TInt TDrive::Rename(const TDesC& anOldName,const TDesC& aNewName) | |
| 1082 | // | |
| 1083 | // Rename files or directories. No wild cards. | |
| 1084 | // | |
| 1085 | 	{
 | |
| 1086 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1087 | TInt r=CheckMountAndEntryNames(anOldName,aNewName); | |
| 1088 | if (r!=KErrNone) | |
| 1089 | return(r); | |
| 1090 | TPtrC oldEntryName(StripBackSlash(anOldName)); | |
| 1091 | TPtrC newEntryName(StripBackSlash(aNewName)); | |
| 1092 | r=CheckDirectories(oldEntryName,newEntryName); | |
| 1093 | if (r!=KErrNone) | |
| 1094 | return(r); | |
| 1095 | if(IsWriteProtected()) | |
| 1096 | return(KErrAccessDenied); | |
| 1097 | ||
| 1098 | // remove from closed queue | |
| 1099 | LocateClosedFile(anOldName, EFalse); | |
| 1100 | LocateClosedFile(aNewName, EFalse); | |
| 1101 | ||
| 1102 | TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameL, EF32TraceUidFileSys, DriveNumber(), oldEntryName,newEntryName); | |
| 1103 | TRAP(r,CurrentMount().RenameL(oldEntryName,newEntryName)) | |
| 1104 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameLRet, EF32TraceUidFileSys, r); | |
| 1105 | ||
| 1106 | return(r); | |
| 1107 | } | |
| 1108 | ||
| 1109 | TInt TDrive::Replace(const TDesC& anOldName,const TDesC& aNewName) | |
| 1110 | // | |
| 1111 | // Replace anOldName with aNewName atomically. No wild cards. No directories | |
| 1112 | // | |
| 1113 | 	{
 | |
| 1114 | TInt r=CheckMountAndEntryNames(anOldName,aNewName); | |
| 1115 | if (r!=KErrNone) | |
| 1116 | return(r); | |
| 1117 | TEntry entry; | |
| 1118 | r=Entry(aNewName,entry); | |
| 1119 | if (r!=KErrNotFound) | |
| 1120 | 		{
 | |
| 1121 | if (r!=KErrNone) | |
| 1122 | return(r); | |
| 1123 | if (entry.IsDir() || entry.IsReadOnly()) | |
| 1124 | return(KErrAccessDenied); | |
| 1125 | if (LocateFile(aNewName)) | |
| 1126 | return(KErrInUse); | |
| 1127 | } | |
| 1128 | r=Entry(anOldName,entry); | |
| 1129 | if (r!=KErrNone) | |
| 1130 | return(r); | |
| 1131 | if (entry.IsDir() || IsWriteProtected()) | |
| 1132 | return(KErrAccessDenied); | |
| 1133 | if (LocateFile(anOldName)) | |
| 1134 | return(KErrInUse); | |
| 1135 | ||
| 1136 | // remove from closed queue | |
| 1137 | LocateClosedFile(anOldName, EFalse); | |
| 1138 | LocateClosedFile(aNewName, EFalse); | |
| 1139 | ||
| 1140 | TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceL, EF32TraceUidFileSys, DriveNumber(), anOldName, aNewName); | |
| 1141 | TRAP(r,CurrentMount().ReplaceL(anOldName,aNewName)) | |
| 1142 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceLRet, EF32TraceUidFileSys, r); | |
| 1143 | ||
| 1144 | return(r); | |
| 1145 | } | |
| 1146 | ||
| 1147 | TInt TDrive::Entry(const TDesC& aName,TEntry& anEntry) | |
| 1148 | // | |
| 1149 | // Get the entry details. | |
| 1150 | // | |
| 1151 | 	{
 | |
| 1152 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1153 | TInt r=CheckMountAndEntryName(aName); | |
| 1154 | if (r!=KErrNone) | |
| 1155 | return(r); | |
| 1156 | TPtrC entryName(StripBackSlash(aName)); | |
| 1157 | TRAP(r,DoEntryL(entryName,anEntry)); | |
| 1158 | ||
| 1159 | if (r==KErrHidden) | |
| 1160 | r=KErrNotFound; | |
| 1161 | else if (r==KErrPathHidden) | |
| 1162 | r=KErrPathNotFound; | |
| 1163 | ||
| 1164 | return(r); | |
| 1165 | } | |
| 1166 | ||
| 1167 | void TDrive::DoEntryL(const TDesC& aName, TEntry& anEntry) | |
| 1168 | // | |
| 1169 | // Get entry details | |
| 1170 | // | |
| 1171 | 	{
 | |
| 1172 | FlushCachedFileInfoL(); | |
| 1173 | ||
| 1174 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryL, EF32TraceUidFileSys, DriveNumber(), aName); | |
| 1175 | CurrentMount().EntryL(aName,anEntry); | |
| 1176 | TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryLRet, EF32TraceUidFileSys, | |
| 1177 | KErrNone, anEntry.iAtt, | |
| 1178 | I64LOW(anEntry.iModified.Int64()), I64HIGH(anEntry.iModified.Int64()), | |
| 1179 | anEntry.iSize); | |
| 1180 | ||
| 1181 | } | |
| 1182 | ||
| 1183 | TInt TDrive::CheckAttributes(const TDesC& aName,TUint& aSetAttMask,TUint& aClearAttMask) | |
| 1184 | // | |
| 1185 | // Validate the changes against the current entry attributes | |
| 1186 | // | |
| 1187 | 	{
 | |
| 1188 | ||
| 1189 | TEntry entry; | |
| 1190 | TRAPD(r,DoEntryL(aName,entry)); | |
| 1191 | if (r!=KErrNone) | |
| 1192 | return(r); | |
| 1193 | ValidateAtts(entry.iAtt,aSetAttMask,aClearAttMask); | |
| 1194 | return(KErrNone); | |
| 1195 | } | |
| 1196 | ||
| 1197 | TInt TDrive::SetEntry(const TDesC& aName,const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask) | |
| 1198 | // | |
| 1199 | // Set the entry details. | |
| 1200 | // | |
| 1201 | 	{
 | |
| 1202 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1203 | TInt r=CheckMountAndEntryName(aName); | |
| 1204 | if (r!=KErrNone) | |
| 1205 | return(r); | |
| 1206 | TPtrC entryName(StripBackSlash(aName)); | |
| 1207 | CFileCB* pF=LocateFile(entryName); | |
| 1208 | if (pF!=NULL) | |
| 1209 | return(KErrInUse); | |
| 1210 | r=CheckAttributes(entryName,aSetAttMask,aClearAttMask); | |
| 1211 | if (r!=KErrNone) | |
| 1212 | return(r); | |
| 1213 | if (IsWriteProtected()) | |
| 1214 | return(KErrAccessDenied); | |
| 1215 | TTime nullTime(0); | |
| 1216 | if (aTime!=nullTime) | |
| 1217 | aSetAttMask|=KEntryAttModified; | |
| 1218 | ||
| 1219 | TRACEMULT6(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryL, EF32TraceUidFileSys, | |
| 1220 | DriveNumber(), aName, I64LOW(aTime.Int64()), I64HIGH(aTime.Int64()), aSetAttMask, aClearAttMask); | |
| 1221 | TRAP(r,CurrentMount().SetEntryL(entryName,aTime,aSetAttMask,aClearAttMask)) | |
| 1222 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryLRet, EF32TraceUidFileSys, r); | |
| 1223 | ||
| 1224 | return(r); | |
| 1225 | } | |
| 1226 | ||
| 1227 | TInt TDrive::FileTemp(CFsRequest* aRequest,TInt& aHandle,const TDesC& aPath,TDes& aName,TUint aMode) | |
| 1228 | // | |
| 1229 | // Create a temporary file and return the file name. | |
| 1230 | // | |
| 1231 | 	{
 | |
| 1232 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1233 | aName=aPath; | |
| 1234 | TInt len=aName.Length(); | |
| 1235 | TInt t=User::TickCount()&0xfffff; | |
| 1236 | aMode|=EFileWrite; | |
| 1237 | for (TInt retry=0;retry<KMaxTempNameAttempts;retry++) | |
| 1238 | 		{
 | |
| 1239 | aName.SetLength(len); | |
| 1240 | 		aName.AppendFormat(_L("TMP%05x.$$$"),t);
 | |
| 1241 | TEntry e; | |
| 1242 | TInt r=Entry(aName,e); | |
| 1243 | if (r!=KErrNone) | |
| 1244 | 			{
 | |
| 1245 | if (r!=KErrNotFound) | |
| 1246 | return(r); | |
| 1247 | return(FileOpen(aRequest,aHandle,aName,aMode,EFileCreate)); | |
| 1248 | } | |
| 1249 | t=((t|1)*13)&0xfffff; | |
| 1250 | } | |
| 1251 | return(KErrGeneral); | |
| 1252 | } | |
| 1253 | ||
| 1254 | LOCAL_C HBufC* CreateFileNameL(const TDesC& aName) | |
| 1255 | // | |
| 1256 | // Create a HBufC from aName | |
| 1257 | // Converts _L("\\F32.\\GROUP\\release.") to _L("\\F32\\GROUP\\release")
 | |
| 1258 | // | |
| 1259 | 	{
 | |
| 1260 | ||
| 1261 | TParsePtrC name(aName); | |
| 1262 | TFileName fileName; | |
| 1263 | fileName.Append(KPathDelimiter); | |
| 1264 | ||
| 1265 | if (name.Path().Length()) | |
| 1266 | 		{
 | |
| 1267 | TInt pos=0; | |
| 1268 | TPtrC entry(NULL,0); | |
| 1269 | FOREVER | |
| 1270 | 			{
 | |
| 1271 | NextInPath(name.Path(),entry,pos); | |
| 1272 | if (entry.Length()==0) | |
| 1273 | break; | |
| 1274 | fileName.Append(entry); | |
| 1275 | fileName.Append(KPathDelimiter); | |
| 1276 | } | |
| 1277 | } | |
| 1278 | ||
| 1279 | fileName.Append(name.Name()); | |
| 1280 | if (name.Ext().Length()>1) | |
| 1281 | fileName.Append(name.Ext()); | |
| 1282 | return(fileName.AllocL()); | |
| 1283 | } | |
| 1284 | ||
| 1285 | void TDrive::FileOpenL(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB*& aFileCB,CFileShare*& aFileShare) | |
| 1286 | // | |
| 1287 | // Open/Create/Replace a file. | |
| 1288 | // | |
| 1289 | 	{
 | |
| 1290 | aFileCB=NULL; | |
| 1291 | aFileShare=NULL; | |
| 1292 | TInt r = CheckMount(); | |
| 1293 | if (r!=KErrNone) | |
| 1294 | User::Leave(r); | |
| 1295 | ||
| 1296 | if (IsIllegalFullName(aRequest->Src())) | |
| 1297 | User::Leave(KErrBadName); | |
| 1298 | ||
| 1299 | if (CurrentMount().Locked()) | |
| 1300 | User::Leave(KErrInUse); | |
| 1301 | ||
| 1302 | if ((aMode & EFileWrite) != 0) | |
| 1303 | 		{
 | |
| 1304 | TDriveInfo driveInfo; | |
| 1305 | DriveInfo(driveInfo); | |
| 1306 | if (driveInfo.iType==EMediaRom || (driveInfo.iMediaAtt&KMediaAttWriteProtected)!=0) | |
| 1307 | User::Leave(KErrAccessDenied); | |
| 1308 | } | |
| 1309 | ||
| 1310 | TShare share=(TShare)(aMode&KFileShareMask); | |
| 1311 | if (share==EFileShareReadersOnly && (aMode&EFileWrite)!=0) | |
| 1312 | User::Leave(KErrArgument); | |
| 1313 | ||
| 1314 | if (aMode & EFileReadAsyncAll) | |
| 1315 | 		{
 | |
| 1316 | // Async read all mode is not compatible with EFileShareExclusive or EFileShareReadersOnly, | |
| 1317 | // as these modes prevent a writer from accessing the file and completing the request. | |
| 1318 | if(share == EFileShareExclusive || share == EFileShareReadersOnly) | |
| 1319 | User::Leave(KErrArgument); | |
| 1320 | } | |
| 1321 | ||
| 1322 | // check for silly cache on / off combinations | |
| 1323 | const TUint KBadWriteMode = EFileWriteBuffered | EFileWriteDirectIO; | |
| 1324 | const TUint KBadReadMode = EFileReadBuffered | EFileReadDirectIO; | |
| 1325 | const TUint KBadReadAheadMode = EFileReadAheadOn | EFileReadAheadOff; | |
| 1326 | const TUint KBadReadAheadMode2 = EFileReadDirectIO | EFileReadAheadOn; | |
| 1327 | if (((aMode & KBadWriteMode) == KBadWriteMode) || | |
| 1328 | ((aMode & KBadReadMode) == KBadReadMode) || | |
| 1329 | ((aMode & KBadReadAheadMode) == KBadReadAheadMode) || | |
| 1330 | ((aMode & KBadReadAheadMode2) == KBadReadAheadMode2)) | |
| 1331 | 		{
 | |
| 1332 | User::Leave(KErrArgument); | |
| 1333 | } | |
| 1334 | ||
| 1335 | // Only allow delete on close for a newly created file. | |
| 1336 | if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate)) | |
| 1337 | User::Leave(KErrArgument); | |
| 1338 | ||
| 1339 | CFileCB* pF=LocateFile(aName); | |
| 1340 | CFileCache* pFileCache = NULL; | |
| 1341 | TBool openFile=EFalse; | |
| 1342 | if (pF!=NULL) | |
| 1343 | 		{
 | |
| 1344 | if (pF->iShare==EFileShareReadersOnly && (aMode&EFileWrite)!=0) | |
| 1345 | User::Leave(KErrInUse); | |
| 1346 | if (anOpen==EFileCreate) | |
| 1347 | User::Leave(KErrAlreadyExists); | |
| 1348 | TInt r=ValidateShare(*pF,share); | |
| 1349 | if (r!=KErrNone) | |
| 1350 | User::Leave(r); | |
| 1351 | if ((r=pF->Open())!=KErrNone) | |
| 1352 | User::Leave(r); | |
| 1353 | aFileCB=pF; | |
| 1354 | pFileCache = pF->FileCache(); | |
| 1355 | } | |
| 1356 | else | |
| 1357 | 		{
 | |
| 1358 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 1359 | ||
| 1360 | //-- construct CFileCB object, belonging to the corresponding mount | |
| 1361 | pF = aFileCB = CurrentMount().NewFileL(); | |
| 1362 | ||
| 1363 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileLRet, EF32TraceUidFileSys, r, pF); | |
| 1364 | TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive(); | |
| 1365 | ||
| 1366 | HBufC* fileName = CreateFileNameL(aName); | |
| 1367 | ||
| 1368 | pF->InitL(this, createdDrive, fileName); | |
| 1369 | ||
| 1370 | ||
| 1371 | pF->iShare = share; | |
| 1372 | openFile=ETrue; | |
| 1373 | CurrentMount().iMountQ.AddLast(*pF); | |
| 1374 | Files->AddL(pF,ETrue); | |
| 1375 | } | |
| 1376 | ||
| 1377 | CFileShare* pS=aFileShare=new(ELeave) CFileShare(pF); | |
| 1378 | ||
| 1379 | // We need to call CFileCB::PromoteShare immediately after the CFileShare | |
| 1380 | // instance is created since the destructor calls CFileCB::DemoteShare() | |
| 1381 | // which checks the share count is non-zero | |
| 1382 | pS->iMode=aMode; | |
| 1383 | pF->PromoteShare(pS); | |
| 1384 | ||
| 1385 | pS->InitL(); | |
| 1386 | aFileCB=NULL; | |
| 1387 | FileShares->AddL(pS,ETrue); | |
| 1388 | aHandle=aRequest->Session()->Handles().AddL(pS,ETrue); | |
| 1389 | ||
| 1390 | ||
| 1391 | if (openFile) | |
| 1392 | 		{
 | |
| 1393 | TRACEMULT5(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenL, EF32TraceUidFileSys, DriveNumber(), aName, aMode, (TUint) anOpen, (TUint) pF); | |
| 1394 | CurrentMount().FileOpenL(aName,aMode,anOpen,pF); | |
| 1395 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenLRet, EF32TraceUidFileSys, KErrNone); | |
| 1396 | ||
| 1397 | // Delete on close may now be safely flagged if required. | |
| 1398 | // The file did not exist on the media prior to the | |
| 1399 | // CMountCB::FileOpenL() call for the case of a create. | |
| 1400 | if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate)) | |
| 1401 | pF->SetDeleteOnClose(); | |
| 1402 | ||
| 1403 | TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pF) == KErrNone)?(TBool)ETrue:(TBool)EFalse; | |
| 1404 | pF->SetLocalBufferSupport(localBufferSuppport); | |
| 1405 | if (localBufferSuppport) | |
| 1406 | 			{
 | |
| 1407 | // if file exists on closed queue resurrect it or discard it, | |
| 1408 | // depending on the file open mode | |
| 1409 | pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse); | |
| 1410 | if (pFileCache) | |
| 1411 | 				{
 | |
| 1412 | pFileCache = pFileCache->ReNewL(*pS); // NB may return NULL if caching not enabled | |
| 1413 | } | |
| 1414 | else | |
| 1415 | 				{
 | |
| 1416 | pFileCache = CFileCache::NewL(*pS); // NB may return NULL if caching not enabled | |
| 1417 | } | |
| 1418 | if (pFileCache) | |
| 1419 | // set the cached size to be the same as the uncached size | |
| 1420 | pF->SetCachedSize64(pF->Size64()); | |
| 1421 | } | |
| 1422 | else | |
| 1423 | 			{
 | |
| 1424 | 			__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported"));
 | |
| 1425 | } | |
| 1426 | } | |
| 1427 | ||
| 1428 | // initialize share mode flags | |
| 1429 | if (pFileCache != NULL) | |
| 1430 | pFileCache->Init(*pS); | |
| 1431 | } | |
| 1432 | ||
| 1433 | TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen) | |
| 1434 | // | |
| 1435 | // Open/Create/Replace a file. | |
| 1436 | // | |
| 1437 | 	{
 | |
| 1438 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1439 | CFileCB* pF=NULL; | |
| 1440 | CFileShare* pS=NULL; | |
| 1441 | aHandle=0; | |
| 1442 | TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS)) | |
| 1443 | ||
| 1444 | // Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode | |
| 1445 | if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig()))) | |
| 1446 | r = KErrTooBig; | |
| 1447 | ||
| 1448 | if (r!=KErrNone) | |
| 1449 | 		{
 | |
| 1450 | if (r==KErrHidden) | |
| 1451 | r=KErrNotFound; | |
| 1452 | else if (r==KErrPathHidden) | |
| 1453 | r=KErrPathNotFound; | |
| 1454 | ||
| 1455 | if(pF && !pS) | |
| 1456 | pF->Close(); | |
| 1457 | CheckSubClose(pS,aHandle,aRequest->Session()); | |
| 1458 | } | |
| 1459 | return(r); | |
| 1460 | } | |
| 1461 | ||
| 1462 | void TDrive::DirOpenL(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType,CDirCB*& aDir) | |
| 1463 | // | |
| 1464 | // Open a directory listing. Leave on error. | |
| 1465 | // | |
| 1466 | 	{
 | |
| 1467 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 1468 | ||
| 1469 | CDirCB* pD = aDir = CurrentMount().NewDirL(); //-- construct CDirCB object, belonging to the corresponding mount | |
| 1470 | ||
| 1471 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirLRet, EF32TraceUidFileSys, KErrNone, pD); | |
| 1472 | pD->InitL(this); | |
| 1473 | // modify resource counter after initialisation to ensure correct cleanup | |
| 1474 | AddResource(CurrentMount()); | |
| 1475 | pD->iAtt=anAtt; | |
| 1476 | pD->iUidType=aUidType; | |
| 1477 | Dirs->AddL(pD,ETrue); | |
| 1478 | aHandle=aSession->Handles().AddL(pD,ETrue); | |
| 1479 | ||
| 1480 | TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenL, EF32TraceUidFileSys, DriveNumber(), aName, (TUint) pD); | |
| 1481 | CurrentMount().DirOpenL(aName,pD); | |
| 1482 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenLRet, EF32TraceUidFileSys, KErrNone); | |
| 1483 | } | |
| 1484 | ||
| 1485 | TInt TDrive::DirOpen(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType) | |
| 1486 | // | |
| 1487 | // Open a directory listing. | |
| 1488 | // | |
| 1489 | 	{
 | |
| 1490 | TInt r=CheckMountAndEntryName(aName); | |
| 1491 | if (r!=KErrNone) | |
| 1492 | return(r); | |
| 1493 | if (CurrentMount().Locked()) | |
| 1494 | return(KErrInUse); | |
| 1495 | CDirCB* pD=NULL; | |
| 1496 | aHandle=0; | |
| 1497 | TRAP(r,DirOpenL(aSession,aHandle,aName,anAtt,aUidType,pD)); | |
| 1498 | ||
| 1499 | if (r==KErrHidden) | |
| 1500 | r=KErrNotFound; | |
| 1501 | else if (r==KErrPathHidden) | |
| 1502 | r=KErrPathNotFound; | |
| 1503 | ||
| 1504 | if (r!=KErrNone) | |
| 1505 | CheckSubClose(pD,aHandle,aSession); | |
| 1506 | return(r); | |
| 1507 | } | |
| 1508 | ||
| 1509 | ||
| 1510 | TInt TDrive::ReadFileSection(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) | |
| 1511 | // | |
| 1512 | // Starting from aPos, read aLength bytes of a file into a Trg, | |
| 1513 | // regardless of lock state | |
| 1514 | // | |
| 1515 | 	{
 | |
| 1516 | return ReadFileSection64(aName, aPos, aTrg, aLength, aMessage); | |
| 1517 | } | |
| 1518 | ||
| 1519 | ||
| 1520 | TInt TDrive::ReadFileSection64(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) | |
| 1521 | // | |
| 1522 | // Starting from aPos, read aLength bytes of a file into a Trg, | |
| 1523 | // regardless of lock state | |
| 1524 | // | |
| 1525 | 	{
 | |
| 1526 | ||
| 1527 | // flush dirty data if already open | |
| 1528 | CFileCB* file; | |
| 1529 | IsFileOpen(aName, file); | |
| 1530 | if (file && file->FileCache()) | |
| 1531 | 		{
 | |
| 1532 | if (file->FileCache()->FlushDirty() == CFsRequest::EReqActionBusy) | |
| 1533 | return CFsRequest::EReqActionBusy; | |
| 1534 | } | |
| 1535 | ||
| 1536 | 	__PRINT(_L("TDrive::ReadSection"));
 | |
| 1537 | TInt r=CheckMountAndEntryName(aName); | |
| 1538 | if (r!=KErrNone) | |
| 1539 | return(r); | |
| 1540 | TPtrC entryName(StripBackSlash(aName)); | |
| 1541 | ||
| 1542 | TRACETHREADID(aMessage); | |
| 1543 | TRACEMULT7(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionL, EF32TraceUidFileSys, | |
| 1544 | DriveNumber(), aName, I64LOW(aPos), I64HIGH(aPos), (TUint) aTrg, aLength, I64LOW(threadId)); | |
| 1545 | TRAP(r,ReadSectionL(entryName,aPos,aTrg,aLength,aMessage)); | |
| 1546 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionLRet, EF32TraceUidFileSys, r); | |
| 1547 | ||
| 1548 | if (r==KErrHidden) | |
| 1549 | r=KErrNotFound; | |
| 1550 | else if (r==KErrPathHidden) | |
| 1551 | r=KErrPathNotFound; | |
| 1552 | ||
| 1553 | return(r); | |
| 1554 | } | |
| 1555 | ||
| 1556 | ||
| 1557 | void TDrive::ReadSectionL(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) | |
| 1558 | // | |
| 1559 | // Starting from aPos, read aLength bytes of a file into a Trg, | |
| 1560 | // regardless of lock state | |
| 1561 | // | |
| 1562 | 	{
 | |
| 1563 | 	__PRINT(_L("TDrive::ReadSectionL"));
 | |
| 1564 | ||
| 1565 | FlushCachedFileInfoL(); | |
| 1566 | CurrentMount().ReadSection64L(aName,aPos,aTrg,aLength,aMessage); | |
| 1567 | } | |
| 1568 | ||
| 1569 | /** | |
| 1570 | Check the disk's integrity | |
| 1571 | */ | |
| 1572 | TInt TDrive::CheckDisk() | |
| 1573 | 	{
 | |
| 1574 | TInt r=CheckMount(); | |
| 1575 | if (r==KErrNone) | |
| 1576 | TRAP(r,FlushCachedFileInfoL()); | |
| 1577 | if (r==KErrNone) | |
| 1578 | 		{
 | |
| 1579 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1, EF32TraceUidFileSys, DriveNumber()); | |
| 1580 | r=CurrentMount().CheckDisk(); | |
| 1581 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1Ret, EF32TraceUidFileSys, r); | |
| 1582 | } | |
| 1583 | return(r); | |
| 1584 | } | |
| 1585 | ||
| 1586 | /** | |
| 1587 | @prototype | |
| 1588 | */ | |
| 1589 | TInt TDrive::CheckDisk(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) | |
| 1590 |     {
 | |
| 1591 | TInt r=CheckMount(); | |
| 1592 | if (r==KErrNone) | |
| 1593 | TRAP(r,FlushCachedFileInfoL()); | |
| 1594 | if (r==KErrNone) | |
| 1595 | 		{
 | |
| 1596 | TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); | |
| 1597 | r=CurrentMount().CheckDisk(aOperation, aParam1, aParam2); | |
| 1598 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2Ret, EF32TraceUidFileSys, r); | |
| 1599 | } | |
| 1600 | ||
| 1601 | return(r); | |
| 1602 | } | |
| 1603 | ||
| 1604 | TInt TDrive::ScanDrive() | |
| 1605 | 	{
 | |
| 1606 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1607 | TInt r=CheckMount(); | |
| 1608 | if(r==KErrNone) | |
| 1609 | 		{
 | |
| 1610 | if(IsWriteProtected()) | |
| 1611 | return(KErrAccessDenied); | |
| 1612 | TRAP(r,FlushCachedFileInfoL()); | |
| 1613 | } | |
| 1614 | if(r!=KErrNone) | |
| 1615 | return r; | |
| 1616 | ||
| 1617 | // Empty closed file queue | |
| 1618 | TClosedFileUtils::Remove(DriveNumber()); | |
| 1619 | ||
| 1620 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1, EF32TraceUidFileSys, DriveNumber()); | |
| 1621 | r = CurrentMount().ScanDrive(); | |
| 1622 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1Ret, EF32TraceUidFileSys, r); | |
| 1623 | ||
| 1624 | return r; | |
| 1625 | } | |
| 1626 | ||
| 1627 | ||
| 1628 | /** | |
| 1629 | @prototype | |
| 1630 | */ | |
| 1631 | TInt TDrive::ScanDrive(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) | |
| 1632 | 	{
 | |
| 1633 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1634 | TInt r=CheckMount(); | |
| 1635 | if(r==KErrNone) | |
| 1636 | 		{
 | |
| 1637 | if(IsWriteProtected()) | |
| 1638 | return(KErrAccessDenied); | |
| 1639 | TRAP(r,FlushCachedFileInfoL()); | |
| 1640 | } | |
| 1641 | if(r!=KErrNone) | |
| 1642 | return r; | |
| 1643 | ||
| 1644 | // Empty closed file queue | |
| 1645 | TClosedFileUtils::Remove(DriveNumber()); | |
| 1646 | ||
| 1647 | TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); | |
| 1648 | r = CurrentMount().ScanDrive(aOperation, aParam1, aParam2); | |
| 1649 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2Ret, EF32TraceUidFileSys, r); | |
| 1650 | ||
| 1651 | return r; | |
| 1652 | } | |
| 1653 | ||
| 1654 | ||
| 1655 | TInt TDrive::GetShortName(const TDesC& aName,TDes& aShortName) | |
| 1656 | // | |
| 1657 | // Get the short name associated with a long file name | |
| 1658 | // | |
| 1659 | 	{
 | |
| 1660 | TInt r=CheckMountAndEntryName(aName); | |
| 1661 | if (r!=KErrNone) | |
| 1662 | return(r); | |
| 1663 | TPtrC entryName(StripBackSlash(aName)); | |
| 1664 | ||
| 1665 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameL, EF32TraceUidFileSys, DriveNumber(), entryName); | |
| 1666 | TRAP(r,CurrentMount().GetShortNameL(entryName,aShortName)); | |
| 1667 | TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameLRet, EF32TraceUidFileSys, r, aShortName); | |
| 1668 | ||
| 1669 | return(r); | |
| 1670 | } | |
| 1671 | ||
| 1672 | TInt TDrive::GetLongName(const TDesC& aShortName,TDes& aLongName) | |
| 1673 | // | |
| 1674 | // Get the long name associated with a short file name | |
| 1675 | // | |
| 1676 | 	{
 | |
| 1677 | TInt r=CheckMountAndEntryName(aShortName); | |
| 1678 | if (r!=KErrNone) | |
| 1679 | return(r); | |
| 1680 | TPtrC entryName(StripBackSlash(aShortName)); | |
| 1681 | ||
| 1682 | TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameL, EF32TraceUidFileSys, DriveNumber(), entryName); | |
| 1683 | TRAP(r,CurrentMount().GetLongNameL(entryName,aLongName)); | |
| 1684 | TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameLRet, EF32TraceUidFileSys, r, aLongName); | |
| 1685 | ||
| 1686 | return(r); | |
| 1687 | } | |
| 1688 | ||
| 1689 | TInt TDrive::IsFileOpen(const TDesC& aFileName,CFileCB*& aFileCB) | |
| 1690 | // | |
| 1691 | // Query whether the file is open or not. | |
| 1692 | // | |
| 1693 | 	{
 | |
| 1694 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1695 | ||
| 1696 | aFileCB = NULL; | |
| 1697 | ||
| 1698 | TEntry dumEntry; | |
| 1699 | TInt r=Entry(aFileName,dumEntry); | |
| 1700 | if (r!=KErrNone) | |
| 1701 | return(r); | |
| 1702 | if(dumEntry.iAtt&KEntryAttDir) | |
| 1703 | return KErrArgument; | |
| 1704 | ||
| 1705 | Files->Lock(); | |
| 1706 | TInt count=Files->Count(); | |
| 1707 | ||
| 1708 | // create a hash to speed up the search | |
| 1709 | ||
| 1710 | TFileName foldedName; | |
| 1711 | TUint32 nameHash=0; | |
| 1712 | if (count > 0) | |
| 1713 | 		{
 | |
| 1714 | foldedName.CopyF(aFileName); | |
| 1715 | nameHash=CalcNameHash(foldedName); | |
| 1716 | } | |
| 1717 | ||
| 1718 | while(count--) | |
| 1719 | 		{
 | |
| 1720 | CFileCB* file=(CFileCB*)(*Files)[count]; | |
| 1721 | ||
| 1722 | if ((&file->Drive()==this) && nameHash == file->NameHash() && file->FileNameF().Match(foldedName)!=KErrNotFound) | |
| 1723 | 			{
 | |
| 1724 | aFileCB = file; | |
| 1725 | break; | |
| 1726 | } | |
| 1727 | } | |
| 1728 | Files->Unlock(); | |
| 1729 | return(KErrNone); | |
| 1730 | } | |
| 1731 | ||
| 1732 | TInt TDrive::IsFileInRom(const TDesC& aFileName,TUint8*& aFileStart) | |
| 1733 | // | |
| 1734 | // Return the start of the file if it is in rom | |
| 1735 | // | |
| 1736 | 	{
 | |
| 1737 | TInt r=CheckMount(); | |
| 1738 | if (r==KErrNone) | |
| 1739 | CurrentMount().IsFileInRom(aFileName,aFileStart); | |
| 1740 | return(r); | |
| 1741 | } | |
| 1742 | ||
| 1743 | TBool TDrive::IsWriteProtected() | |
| 1744 | // | |
| 1745 | // return true if the media is write protected | |
| 1746 | // | |
| 1747 | 	{
 | |
| 1748 | // __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1749 | TDriveInfo drvInfo; | |
| 1750 | drvInfo.iMediaAtt=0; | |
| 1751 | if(Att() && iFSys) | |
| 1752 | FSys().DriveInfo(drvInfo,DriveNumber()); | |
| 1753 | return((drvInfo.iMediaAtt&KMediaAttWriteProtected)!=0); | |
| 1754 | } | |
| 1755 | ||
| 1756 | ||
| 1757 | ||
| 1758 | ||
| 1759 | /** | |
| 1760 | Checks whether any resource that could write to disk is open on | |
| 1761 | the current mount. | |
| 1762 | ||
| 1763 | @return True, if a resource that could write to disk is open on | |
| 1764 | the current mount, false otherwise. | |
| 1765 | */ | |
| 1766 | EXPORT_C TBool TDrive::IsWriteableResource() const | |
| 1767 | 	{
 | |
| 1768 | // __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1769 | if(iCurrentMount==NULL) | |
| 1770 | return(EFalse); | |
| 1771 | if(iCurrentMount->LockStatus()>0) | |
| 1772 | 		{
 | |
| 1773 | // check format subsessions | |
| 1774 | Formats->Lock(); | |
| 1775 | TInt count=Formats->Count(); | |
| 1776 | while(count--) | |
| 1777 | 			{
 | |
| 1778 | CFormatCB* format=(CFormatCB*)(*Formats)[count]; | |
| 1779 | if(&format->Mount()==iCurrentMount) | |
| 1780 | 				{
 | |
| 1781 | Formats->Unlock(); | |
| 1782 | return(ETrue); | |
| 1783 | } | |
| 1784 | } | |
| 1785 | Formats->Unlock(); | |
| 1786 | // check raw disk subsessions | |
| 1787 | RawDisks->Lock(); | |
| 1788 | count=RawDisks->Count(); | |
| 1789 | while(count--) | |
| 1790 | 			{
 | |
| 1791 | CRawDiskCB* rawDisk=(CRawDiskCB*)(*RawDisks)[count]; | |
| 1792 | if(&rawDisk->Mount()==iCurrentMount && !rawDisk->IsWriteProtected()) | |
| 1793 | 				{
 | |
| 1794 | Formats->Unlock(); | |
| 1795 | return(ETrue); | |
| 1796 | } | |
| 1797 | } | |
| 1798 | Formats->Unlock(); | |
| 1799 | } | |
| 1800 | else if(iCurrentMount->LockStatus()<0) | |
| 1801 | 		{
 | |
| 1802 | // check file share subsessions | |
| 1803 | FileShares->Lock(); | |
| 1804 | TInt count=FileShares->Count(); | |
| 1805 | while(count--) | |
| 1806 | 			{
 | |
| 1807 | CFileShare* fileShare=(CFileShare*)(*FileShares)[count]; | |
| 1808 | if (&fileShare->File().Mount()==iCurrentMount && ((fileShare->iMode&EFileWrite)!=0)) | |
| 1809 | 				{
 | |
| 1810 | FileShares->Unlock(); | |
| 1811 | return(ETrue); | |
| 1812 | } | |
| 1813 | } | |
| 1814 | FileShares->Unlock(); | |
| 1815 | } | |
| 1816 | return(EFalse); | |
| 1817 | } | |
| 1818 | ||
| 1819 | ||
| 1820 | ||
| 1821 | ||
| 1822 | /** | |
| 1823 | Tests whether the current function can cause a write to disk. | |
| 1824 | ||
| 1825 | @return True, if the current function can cause a write to disk, | |
| 1826 | false otherwise. | |
| 1827 | */ | |
| 1828 | EXPORT_C TBool TDrive::IsCurrentWriteFunction() const | |
| 1829 | 	{
 | |
| 1830 | // __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1831 | CDriveThread* pT=NULL; | |
| 1832 | TInt r=FsThreadManager::GetDriveThread(iDriveNumber, &pT); | |
| 1833 | __ASSERT_ALWAYS(r==KErrNone && pT,Fault(EDriveCurrentWriteFunction)); | |
| 1834 | return(pT->IsRequestWriteable()); | |
| 1835 | } | |
| 1836 | ||
| 1837 | ||
| 1838 | ||
| 1839 | ||
| 1840 | TInt TDrive::ForceRemountDrive(const TDesC8* aMountInfo,TInt aMountInfoMessageHandle,TUint aFlags) | |
| 1841 | // | |
| 1842 | // Force a remount of the drive | |
| 1843 | // | |
| 1844 | 	{
 | |
| 1845 | 	__PRINT(_L("TDrive::ForceRemountDrive"));
 | |
| 1846 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1847 | if(iFSys==NULL) | |
| 1848 | return(KErrNotReady); | |
| 1849 | TInt r; | |
| 1850 | CMountCB* pM=NULL; | |
| 1851 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 1852 | TRAP(r,pM=FSys().NewMountL()); | |
| 1853 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); | |
| 1854 | if(r!=KErrNone) | |
| 1855 | return(r); | |
| 1856 | pM->SetDrive(this); | |
| 1857 | ||
| 1858 | TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDrive, EF32TraceUidFileSys, | |
| 1859 | DriveNumber(), aMountInfo, aMountInfoMessageHandle, aFlags); | |
| 1860 | r=pM->ForceRemountDrive(aMountInfo,aMountInfoMessageHandle,aFlags); | |
| 1861 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDriveRet, EF32TraceUidFileSys, r); | |
| 1862 | ||
| 1863 | pM->Close(); | |
| 1864 | return(r); | |
| 1865 | } | |
| 1866 | ||
| 1867 | TBool TDrive::IsExtensionMounted(CProxyDriveFactory* aFactory) | |
| 1868 | // | |
| 1869 | // return ETrue if extension mounted on the drive | |
| 1870 | // | |
| 1871 | 	{
 | |
| 1872 | for(TInt i=0;i<iExtInfo.iCount;++i) | |
| 1873 | 		{
 | |
| 1874 | if(iExtInfo.iInfo[i].iFactory==aFactory) | |
| 1875 | return(ETrue); | |
| 1876 | } | |
| 1877 | return(EFalse); | |
| 1878 | } | |
| 1879 | ||
| 1880 | TInt TDrive::MountExtension(CProxyDriveFactory* aFactory,TBool aIsPrimary) | |
| 1881 | // | |
| 1882 | // Mount an extension | |
| 1883 | // | |
| 1884 | 	{
 | |
| 1885 | 	__PRINT1(_L("TDrive::MountExtension aIsPrimary=%d"),aIsPrimary);
 | |
| 1886 | if(aIsPrimary) | |
| 1887 | 		{
 | |
| 1888 | __CHECK_MAINTHREAD(); | |
| 1889 | // primary extension mounted before file system since it must be present | |
| 1890 | // for successful mount | |
| 1891 | __ASSERT_ALWAYS(!iFSys,Fault(EMountExtensionFSys)); | |
| 1892 | if(iExtInfo.iCount!=0) | |
| 1893 | return(KErrAccessDenied); | |
| 1894 | iExtInfo.iInfo[iExtInfo.iCount].iFactory=aFactory; | |
| 1895 | iExtInfo.iInfo[iExtInfo.iCount++].iIsPrimary=ETrue; | |
| 1896 | return(KErrNone); | |
| 1897 | } | |
| 1898 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1899 | // must be a secondary extension | |
| 1900 | if(iFSys==NULL) | |
| 1901 | return(KErrNotReady); | |
| 1902 | TBool extSupported = iFSys->IsExtensionSupported(); | |
| 1903 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileSystemIsExtensionSupported, EF32TraceUidFileSys, extSupported); | |
| 1904 | if(!extSupported) | |
| 1905 | return(KErrNotSupported); | |
| 1906 | if(IsExtensionMounted(aFactory)) | |
| 1907 | return(KErrAlreadyExists); | |
| 1908 | if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1)) | |
| 1909 | return(KErrInUse); | |
| 1910 | if(iExtInfo.iCount>=KMaxExtensionCount) | |
| 1911 | return(KErrAccessDenied); | |
| 1912 | iExtInfo.iInfo[iExtInfo.iCount].iFactory=aFactory; | |
| 1913 | iExtInfo.iInfo[iExtInfo.iCount++].iIsPrimary=EFalse; | |
| 1914 | // now dismount and mount so that the extension incorporated | |
| 1915 | Dismount(); | |
| 1916 | TInt r=CheckMount(); | |
| 1917 | // if mount fails then remove the secondary extension | |
| 1918 | if(r!=KErrNone) | |
| 1919 | 		{
 | |
| 1920 | --iExtInfo.iCount; | |
| 1921 | __ASSERT_DEBUG(iExtInfo.iCount>=0,Fault(EExtensionInfoCount0)); | |
| 1922 | } | |
| 1923 | return(r); | |
| 1924 | } | |
| 1925 | ||
| 1926 | TInt TDrive::DismountExtension(CProxyDriveFactory* aFactory, TBool /*aIsPrimary*/) | |
| 1927 | // | |
| 1928 | // Dismount an extension | |
| 1929 | // | |
| 1930 | 	{
 | |
| 1931 | 	 __PRINT(_L("TDrive::DismountExtension"));
 | |
| 1932 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1933 | ||
| 1934 | // Empty closed file queue | |
| 1935 | TClosedFileUtils::Remove(DriveNumber()); | |
| 1936 | ||
| 1937 | if(iExtInfo.iCount==0) | |
| 1938 | return(KErrNotFound); | |
| 1939 | if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1)) | |
| 1940 | return(KErrInUse); | |
| 1941 | for(TInt i=0;i<iExtInfo.iCount;++i) | |
| 1942 | 		{
 | |
| 1943 | if(iExtInfo.iInfo[i].iFactory==aFactory) | |
| 1944 | 			{
 | |
| 1945 | // cannot dismount a primary extension without dismounting the file system | |
| 1946 | if(i==0 && iExtInfo.iInfo[i].iIsPrimary) | |
| 1947 | return(KErrAccessDenied); | |
| 1948 | // slide any remaining extensions down | |
| 1949 | for(TInt j=i+1;j<iExtInfo.iCount;++j) | |
| 1950 | iExtInfo.iInfo[j-1].iFactory=iExtInfo.iInfo[j].iFactory; | |
| 1951 | iExtInfo.iCount--; | |
| 1952 | __ASSERT_DEBUG(iExtInfo.iCount>=0,Fault(EExtensionInfoCount1)); | |
| 1953 | Dismount(); | |
| 1954 | return(KErrNone); | |
| 1955 | } | |
| 1956 | } | |
| 1957 | return(KErrNotFound); | |
| 1958 | } | |
| 1959 | ||
| 1960 | TInt TDrive::ExtensionName(TDes& aExtensionName,TInt aPos) | |
| 1961 | // | |
| 1962 | // Return the extension name | |
| 1963 | // | |
| 1964 | 	{
 | |
| 1965 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1966 | ||
| 1967 | if(iFSys==NULL) | |
| 1968 | return(KErrNotReady); | |
| 1969 | ||
| 1970 | if(aPos<iExtInfo.iCount) | |
| 1971 | 		{
 | |
| 1972 | aExtensionName=iExtInfo.iInfo[aPos].iFactory->Name(); | |
| 1973 | return(KErrNone); | |
| 1974 | } | |
| 1975 | return(KErrNotFound); | |
| 1976 | } | |
| 1977 | ||
| 1978 | #if defined(_LOCKABLE_MEDIA) | |
| 1979 | ||
| 1980 | TInt TDrive::LockDevice(TMediaPassword& aOld,TMediaPassword& aNew,TBool aStore) | |
| 1981 | // | |
| 1982 | // Lock media device | |
| 1983 | // | |
| 1984 | 	{
 | |
| 1985 | 	__PRINT(_L("TDrive::LockDevice"));
 | |
| 1986 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 1987 | if(iFSys==NULL) | |
| 1988 | return(KErrNotReady); | |
| 1989 | TInt r; | |
| 1990 | CMountCB* pM=NULL; | |
| 1991 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 1992 | TRAP(r,pM=FSys().NewMountL()); | |
| 1993 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); | |
| 1994 | if(r!=KErrNone) | |
| 1995 | return(r); | |
| 1996 | pM->SetDrive(this); | |
| 1997 | ||
| 1998 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBLock, EF32TraceUidFileSys, DriveNumber(), aStore); | |
| 1999 | r=pM->Lock(aOld,aNew,aStore); | |
| 2000 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBLockRet, EF32TraceUidFileSys, r); | |
| 2001 | ||
| 2002 | pM->Close(); | |
| 2003 | return(r); | |
| 2004 | } | |
| 2005 | ||
| 2006 | TInt TDrive::UnlockDevice(TMediaPassword& aPassword,TBool aStore) | |
| 2007 | // | |
| 2008 | // Unlock media device | |
| 2009 | // | |
| 2010 | 	{
 | |
| 2011 | 	__PRINT(_L("TDrive::UnlockDevice"));
 | |
| 2012 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 2013 | if(iFSys==NULL) | |
| 2014 | return(KErrNotReady); | |
| 2015 | TInt r; | |
| 2016 | CMountCB* pM=NULL; | |
| 2017 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 2018 | TRAP(r,pM=FSys().NewMountL()); | |
| 2019 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); | |
| 2020 | if(r!=KErrNone) | |
| 2021 | return(r); | |
| 2022 | ||
| 2023 | // reset mount failure count - which is likely to be non-zero if drive is locked | |
| 2024 | iMountFailures = 0; | |
| 2025 | ||
| 2026 | pM->SetDrive(this); | |
| 2027 | ||
| 2028 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlock, EF32TraceUidFileSys, DriveNumber(), aStore); | |
| 2029 | r=pM->Unlock(aPassword,aStore); | |
| 2030 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlockRet, EF32TraceUidFileSys, r); | |
| 2031 | ||
| 2032 | pM->Close(); | |
| 2033 | return(r); | |
| 2034 | } | |
| 2035 | ||
| 2036 | TInt TDrive::ClearDevicePassword(TMediaPassword& aPassword) | |
| 2037 | // | |
| 2038 | // Clear password of media device | |
| 2039 | // | |
| 2040 | 	{
 | |
| 2041 | 	__PRINT(_L("TDrive::ClearDevicePassword"));
 | |
| 2042 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 2043 | if(iFSys==NULL) | |
| 2044 | return(KErrNotReady); | |
| 2045 | TInt r; | |
| 2046 | CMountCB* pM=NULL; | |
| 2047 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 2048 | TRAP(r,pM=FSys().NewMountL()); | |
| 2049 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); | |
| 2050 | if(r!=KErrNone) | |
| 2051 | return(r); | |
| 2052 | pM->SetDrive(this); | |
| 2053 | ||
| 2054 | // ClearPassword() will only work if the card is already unlocked. | |
| 2055 | // If the stack powers down, the card will become locked, so now that TBusLocalDrive::Caps() | |
| 2056 | // no longer powers up ths stack, we need to unlock the card first - but ignore the error as | |
| 2057 | // the stack may unlock from the password store. | |
| 2058 | TDriveInfo info; | |
| 2059 | DriveInfo(info); | |
| 2060 | if (info.iMediaAtt & KMediaAttLocked) | |
| 2061 | UnlockDevice(aPassword, EFalse); | |
| 2062 | ||
| 2063 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPassword, EF32TraceUidFileSys, DriveNumber()); | |
| 2064 | r=pM->ClearPassword(aPassword); | |
| 2065 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPasswordRet, EF32TraceUidFileSys, r); | |
| 2066 | ||
| 2067 | pM->Close(); | |
| 2068 | return(r); | |
| 2069 | } | |
| 2070 | ||
| 2071 | TInt TDrive::EraseDevicePassword() | |
| 2072 | // | |
| 2073 | // Erase password from the media device | |
| 2074 | // | |
| 2075 | 	{
 | |
| 2076 | 	__PRINT(_L("TDrive::EraseDevicePassword"));
 | |
| 2077 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 2078 | if(iFSys==NULL) | |
| 2079 | return(KErrNotReady); | |
| 2080 | TInt r; | |
| 2081 | CMountCB* pM=NULL; | |
| 2082 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 2083 | TRAP(r,pM=FSys().NewMountL()); | |
| 2084 | TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); | |
| 2085 | if(r!=KErrNone) | |
| 2086 | return(r); | |
| 2087 | pM->SetDrive(this); | |
| 2088 | ||
| 2089 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePassword, EF32TraceUidFileSys, DriveNumber()); | |
| 2090 | r=pM->ErasePassword(); | |
| 2091 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePasswordRet, EF32TraceUidFileSys, r); | |
| 2092 | ||
| 2093 | pM->Close(); | |
| 2094 | return(r); | |
| 2095 | } | |
| 2096 | ||
| 2097 | #else | |
| 2098 | ||
| 2099 | TInt TDrive::LockDevice(TMediaPassword& /*aOld*/,TMediaPassword& /*aNew*/,TBool /*aStore*/) | |
| 2100 | // | |
| 2101 | // Lock media device | |
| 2102 | // | |
| 2103 | 	{
 | |
| 2104 | return(KErrNotSupported); | |
| 2105 | } | |
| 2106 | ||
| 2107 | TInt TDrive::UnlockDevice(TMediaPassword& /*aPassword*/,TBool /*aStore*/) | |
| 2108 | // | |
| 2109 | // Unlock media device | |
| 2110 | // | |
| 2111 | 	{
 | |
| 2112 | return(KErrNotSupported); | |
| 2113 | } | |
| 2114 | ||
| 2115 | TInt TDrive::ClearDevicePassword(TMediaPassword& /*aPassword*/) | |
| 2116 | // | |
| 2117 | // Clear password of media device | |
| 2118 | // | |
| 2119 | 	{
 | |
| 2120 | return(KErrNotSupported); | |
| 2121 | } | |
| 2122 | ||
| 2123 | TInt TDrive::EraseDevicePassword(TMediaPassword& /*aPassword*/) | |
| 2124 | // | |
| 2125 | // Clear password of media device | |
| 2126 | // | |
| 2127 | 	{
 | |
| 2128 | return(KErrNotSupported); | |
| 2129 | } | |
| 2130 | ||
| 2131 | #endif | |
| 2132 | ||
| 2133 | ||
| 2134 | ||
| 2135 | ||
| 2136 | /** | |
| 2137 | Gets the current notification state, which indicates whether the client | |
| 2138 | is notified of any read or write failures. | |
| 2139 | ||
| 2140 | The notification status is a property of the current session with | |
| 2141 | the file server, the value of which is stored in CSessionFs::iNotifyUser. | |
| 2142 | If set to ETrue, the client will receive notifications from the file system. | |
| 2143 | ||
| 2144 | Called by CMountCB::GetNotifyUser(). | |
| 2145 | ||
| 2146 | @return True, if the client receives notifications from the file system, | |
| 2147 | false otherwise. | |
| 2148 | ||
| 2149 | @see CMountCB | |
| 2150 | */ | |
| 2151 | EXPORT_C TBool TDrive::GetNotifyUser() | |
| 2152 | 	{
 | |
| 2153 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 2154 | if(iDriveFlags & ENotifyOff) | |
| 2155 | return(EFalse); | |
| 2156 | else | |
| 2157 | 		{
 | |
| 2158 | CDriveThread* pT=NULL; | |
| 2159 | ||
| 2160 | const TInt r=FsThreadManager::GetDriveThread(iDriveNumber,&pT); | |
| 2161 | ||
| 2162 | //-- if this drive is synchronous, i.e. all requests are processed in the main FS thread, | |
| 2163 | //-- pretend that user notifications are turned off to avoid panic in the assert below. | |
| 2164 | //-- for synch. drives pT will always be NULL and it's not possible to obtain CSessionFs by drive number. | |
| 2165 | if(r == KErrAccessDenied) | |
| 2166 | return EFalse; | |
| 2167 | ||
| 2168 | __ASSERT_ALWAYS(r==KErrNone && pT,Fault(EDriveGetNotifyUser)); | |
| 2169 | return(pT->IsSessionNotifyUser()); | |
| 2170 | } | |
| 2171 | } | |
| 2172 | ||
| 2173 | ||
| 2174 | ||
| 2175 | ||
| 2176 | /** | |
| 2177 | Dismounts the current mount. This is method is called from outside, so do some finalisation work on mount. | |
| 2178 | After calling this function there is no current mount on the drive. | |
| 2179 | */ | |
| 2180 | EXPORT_C void TDrive::Dismount() | |
| 2181 | 	{
 | |
| 2182 | 	__PRINT1(_L("TDrive::Dismount() iCurrentMount:0x%x"),iCurrentMount);
 | |
| 2183 | ||
| 2184 | iMountFailures = 0; | |
| 2185 | if (!iCurrentMount) | |
| 2186 | return; | |
| 2187 | ||
| 2188 | TRAP_IGNORE(FlushCachedFileInfoL()); | |
| 2189 | ||
| 2190 | //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data) | |
| 2191 | TRAP_IGNORE(iCurrentMount->FinaliseMountL()); | |
| 2192 | ||
| 2193 | DoDismount(); | |
| 2194 | } | |
| 2195 | ||
| 2196 | ||
| 2197 | ||
| 2198 | ||
| 2199 | /** | |
| 2200 | Forcibly dismounts the current mount and prevents it being remounted. | |
| 2201 | After calling this function there is no current mount on the drive. | |
| 2202 | */ | |
| 2203 | void TDrive::ForceDismount() | |
| 2204 | 	{
 | |
| 2205 | 	__PRINT1(_L("TDrive::ForceDismount() iCurrentMount:0x%x"),iCurrentMount);
 | |
| 2206 | ||
| 2207 | iMountFailures = 0; | |
| 2208 | ||
| 2209 | if(!iCurrentMount) | |
| 2210 | return; | |
| 2211 | ||
| 2212 | TRAP_IGNORE(FlushCachedFileInfoL()); | |
| 2213 | iCurrentMount->SetDismounted(); //! this affects TDrive::ReMount() | |
| 2214 | DoDismount(); | |
| 2215 | } | |
| 2216 | ||
| 2217 | /** | |
| 2218 | An internal method. Dismounts and closes a current mount. | |
| 2219 | This method must not involve writing data to the media, because it could have beeen physically changed before. | |
| 2220 | Called only from TDrive::CheckMount(). | |
| 2221 | */ | |
| 2222 | void TDrive::DoDismount() | |
| 2223 |     {
 | |
| 2224 |     __PRINT1(_L("TDrive::DoDismount() iCurrentMount:0x%x"),iCurrentMount);
 | |
| 2225 | ||
| 2226 | iMountFailures = 0; | |
| 2227 | ||
| 2228 | if (!iCurrentMount) | |
| 2229 | return; | |
| 2230 | ||
| 2231 | TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismounted, EF32TraceUidFileSys, DriveNumber()); | |
| 2232 | iCurrentMount->Dismounted(); | |
| 2233 | TRACE0(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismountedRet, EF32TraceUidFileSys); | |
| 2234 | ||
| 2235 | iCurrentMount->Close(); | |
| 2236 | iCurrentMount=NULL; | |
| 2237 | } | |
| 2238 | ||
| 2239 | ||
| 2240 | /** | |
| 2241 | Return the number of active mounts associated with this drive. | |
| 2242 | (inactive mounts are those that have been forcibly dismounted) | |
| 2243 | */ | |
| 2244 | TInt TDrive::ActiveMounts() const | |
| 2245 | 	{
 | |
| 2246 | TInt activeMounts = 0; | |
| 2247 | ||
| 2248 | TInt idx = Mount().Count(); | |
| 2249 | while(idx--) | |
| 2250 | 		{
 | |
| 2251 | if(((CMountCB*)Mount()[idx])->IsDismounted()) | |
| 2252 | 			{
 | |
| 2253 | activeMounts++; | |
| 2254 | } | |
| 2255 | } | |
| 2256 | ||
| 2257 | 	__PRINT1(_L("TDrive::ActiveMounts = %d"), activeMounts);
 | |
| 2258 | return activeMounts; | |
| 2259 | } | |
| 2260 | ||
| 2261 | ||
| 2262 | ||
| 2263 | ||
| 2264 | /** | |
| 2265 | Reactivate any disactive mounts on the drive following a dismount. | |
| 2266 | (inactive mounts are those that have been foribly dismounted) | |
| 2267 | */ | |
| 2268 | void TDrive::ReactivateMounts() | |
| 2269 | 	{
 | |
| 2270 | 	__PRINT(_L("TDrive::ReactivateMounts"));
 | |
| 2271 | ||
| 2272 | TInt idx = Mount().Count(); | |
| 2273 | while(idx--) | |
| 2274 | 		{
 | |
| 2275 | ((CMountCB*)Mount()[idx])->SetDismounted(EFalse); | |
| 2276 | } | |
| 2277 | } | |
| 2278 | ||
| 2279 | ||
| 2280 | ||
| 2281 | ||
| 2282 | /** | |
| 2283 | Increments the drive dismount lock. This defers dismount | |
| 2284 | of a file system until all clients have notified that it | |
| 2285 | is safe to do so. | |
| 2286 | ||
| 2287 | @see RFs::NotifyDismount | |
| 2288 | */ | |
| 2289 | void TDrive::DismountLock() | |
| 2290 | 	{ iDismountLock++; }
 | |
| 2291 | ||
| 2292 | ||
| 2293 | ||
| 2294 | ||
| 2295 | /** | |
| 2296 | Decrements the drive dismount lock. When the lock count | |
| 2297 | reaches zero, the file system may be unmounted | |
| 2298 | ||
| 2299 | @see RFs::AllowDismount | |
| 2300 | @return The new lock count | |
| 2301 | */ | |
| 2302 | TInt TDrive::DismountUnlock() | |
| 2303 | 	{ 
 | |
| 2304 | return(--iDismountLock); | |
| 2305 | } | |
| 2306 | ||
| 2307 | ||
| 2308 | ||
| 2309 | ||
| 2310 | /** | |
| 2311 | Return the state of the dismount lock. | |
| 2312 | */ | |
| 2313 | TBool TDrive::DismountLocked() const | |
| 2314 | 	{ return(iDismountLock); }
 | |
| 2315 | ||
| 2316 | ||
| 2317 | ||
| 2318 | ||
| 2319 | /** | |
| 2320 | Pending flag - set while waiting for clients to accept the dismount | |
| 2321 | */ | |
| 2322 | void TDrive::SetDismountDeferred(TBool aPending) | |
| 2323 | 	{
 | |
| 2324 | if(aPending) | |
| 2325 | iDriveFlags |= EDismountDeferred; | |
| 2326 | else | |
| 2327 | iDriveFlags &= ~EDismountDeferred; | |
| 2328 | } | |
| 2329 | ||
| 2330 | ||
| 2331 | ||
| 2332 | TInt TDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2) | |
| 2333 | // | |
| 2334 | // General purpose test interface - .FSY specific. | |
| 2335 | // | |
| 2336 | 	{
 | |
| 2337 | TInt r=CheckMount(); | |
| 2338 | if(r==KErrNone || (r==KErrInUse && iReason==KErrNone)) | |
| 2339 | 		{
 | |
| 2340 | TRACETHREADID(aMessage); | |
| 2341 | TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIO, EF32TraceUidFileSys, | |
| 2342 | DriveNumber(), aCommand, aParam1, aParam2, I64LOW(threadId)); | |
| 2343 | r=CurrentMount().ControlIO(aMessage,aCommand,aParam1,aParam2); | |
| 2344 | TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIORet, EF32TraceUidFileSys, r); | |
| 2345 | } | |
| 2346 | return(r); | |
| 2347 | } | |
| 2348 | ||
| 2349 | ||
| 2350 | ||
| 2351 | ||
| 2352 | /** | |
| 2353 | Gets the drive attributes | |
| 2354 | ||
| 2355 | @return The drive attributes. | |
| 2356 | */ | |
| 2357 | EXPORT_C TUint TDrive::Att() | |
| 2358 | 	{
 | |
| 2359 | TUint a=iAtt; | |
| 2360 | return(a); | |
| 2361 | } | |
| 2362 | ||
| 2363 | void TDrive::SetAtt(TUint aValue) | |
| 2364 | // | |
| 2365 | // set drive attributes | |
| 2366 | // | |
| 2367 | 	{
 | |
| 2368 | iAtt=aValue; | |
| 2369 | } | |
| 2370 | ||
| 2371 | EXPORT_C TBool TDrive::IsDriveThread() const | |
| 2372 | // | |
| 2373 | // Return ETrue if the current thread id is the same as that of the drive's drive thread | |
| 2374 | // | |
| 2375 | 	{
 | |
| 2376 | return(FsThreadManager::IsDriveThread(iDriveNumber,ETrue)); | |
| 2377 | } | |
| 2378 | ||
| 2379 | EXPORT_C TBool TDrive::IsMainThread() const | |
| 2380 | // | |
| 2381 | // Reture ETrue if the current thread id is the same as that of the main file server thread | |
| 2382 | // | |
| 2383 | 	{
 | |
| 2384 | return(FsThreadManager::IsMainThread()); | |
| 2385 | } | |
| 2386 | ||
| 2387 | EXPORT_C void TDrive::DriveFault(TBool aDriveError) const | |
| 2388 | // | |
| 2389 | // | |
| 2390 | // | |
| 2391 | 	{
 | |
| 2392 | if(aDriveError) | |
| 2393 | ::Fault(EFsDriveThreadError); | |
| 2394 | else | |
| 2395 | ::Fault(EFsMainThreadError); | |
| 2396 | } | |
| 2397 | ||
| 2398 | TInt TDrive::ClampFile(const TDesC& aName, TAny* aHandle) | |
| 2399 | // | |
| 2400 | // Attempt to clamp file | |
| 2401 | // | |
| 2402 | 	{
 | |
| 2403 | CMountCB* mount = (CMountCB*)&(CurrentMount()); | |
| 2404 | TInt driveNo = DriveNumber(); | |
| 2405 | return(mount->ClampFile(driveNo,aName,aHandle)); | |
| 2406 | } | |
| 2407 | ||
| 2408 | ||
| 2409 | TInt TDrive::UnclampFile(CMountCB* aMount, RFileClamp* aHandle) | |
| 2410 | // | |
| 2411 | // Attempt to unclamp file | |
| 2412 | // | |
| 2413 | 	{
 | |
| 2414 | return(aMount->UnclampFile(aHandle)); | |
| 2415 | } | |
| 2416 | ||
| 2417 | ||
| 2418 | TInt TDrive::ClampsOnDrive() | |
| 2419 | // | |
| 2420 | // Returns the number of clamps on this drive | |
| 2421 | // | |
| 2422 | 	{
 | |
| 2423 | Lock(); | |
| 2424 | TInt clamps = IsMounted()?((CMountCB*)&(CurrentMount()))->NoOfClamps():0; | |
| 2425 | UnLock(); | |
| 2426 | return (clamps); | |
| 2427 | } | |
| 2428 | ||
| 2429 | ||
| 2430 | ||
| 2431 | void TDrive::SetClampFlag(TBool aClamped) | |
| 2432 | // | |
| 2433 | // Indicate if any files are clamped | |
| 2434 | // | |
| 2435 | 	{
 | |
| 2436 | if(aClamped) | |
| 2437 | iDriveFlags |= EClampPresent; | |
| 2438 | else | |
| 2439 | iDriveFlags &= ~EClampPresent; | |
| 2440 | } | |
| 2441 | ||
| 2442 | ||
| 2443 | TBool TDrive::ClampFlag() | |
| 2444 | // | |
| 2445 | // Report if any files are clamped | |
| 2446 | // | |
| 2447 | 	{ return(iDriveFlags & EClampPresent); }
 | |
| 2448 | ||
| 2449 | ||
| 2450 | ||
| 2451 | #if defined(_DEBUG) || defined(_DEBUG_RELEASE) | |
| 2452 | TInt TDrive::ClearDeferredDismount() | |
| 2453 | // debug-only function for testing | |
| 2454 | 	{
 | |
| 2455 | Lock(); | |
| 2456 | FsNotify::HandleDismount(EFsDismountRegisterClient, DriveNumber(), ETrue, KErrNone); | |
| 2457 | SetDismountDeferred(EFalse); | |
| 2458 | UnLock(); | |
| 2459 | return KErrNone; | |
| 2460 | } | |
| 2461 | #endif | |
| 2462 | ||
| 2463 | ||
| 2464 | TInt TDrive::DismountProxyDrive() | |
| 2465 | // | |
| 2466 | // Dismount a proxy drive | |
| 2467 | // | |
| 2468 | 	{
 | |
| 2469 | 	 __PRINT(_L("TDrive::DismountProxyDrive"));
 | |
| 2470 | __CHECK_DRIVETHREAD(iDriveNumber); | |
| 2471 | ||
| 2472 | if (!IsProxyDrive(iDriveNumber) || LocalDrives::DriveNumberToLocalDriveNumber(iDriveNumber) == KDriveInvalid) | |
| 2473 | return KErrArgument; | |
| 2474 | ||
| 2475 | if(iCurrentMount) | |
| 2476 | return(KErrInUse); | |
| 2477 | ||
| 2478 | ||
| 2479 | // Prevent ALL inactive mounts from EVER being remounted as they MAY (& probably do) point to | |
| 2480 | // this proxy-drive which we are about to delete.... | |
| 2481 | // NB We could try to find out which mounts actually use this particular proxy-drive, but that's | |
| 2482 | // a bit tricky to determine if there are extensions present as CMountCB::ProxyDrive() will only | |
| 2483 | // return the first proxy drive in the chain. | |
| 2484 | TInt mCount=Mount().Count(); | |
| 2485 | TInt u=(Mount().UniqueID()<<16); | |
| 2486 | for (TInt i=0;i<mCount;i++) | |
| 2487 | 		{
 | |
| 2488 | CMountCB* pM=(CMountCB*)Mount().At(u|i); | |
| 2489 | pM->SetProxyDriveDismounted(); | |
| 2490 | } | |
| 2491 | ||
| 2492 | FsThreadManager::LockDrive(iDriveNumber); | |
| 2493 | // Proxy drives are responsible for managing the drive threads... | |
| 2494 | FsThreadManager::CloseDrive(iDriveNumber); | |
| 2495 | LocalDrives::ClearProxyDriveMapping(iDriveNumber); | |
| 2496 | FsThreadManager::UnlockDrive(iDriveNumber); | |
| 2497 | ||
| 2498 | return KErrNone; | |
| 2499 | } | |
| 2500 | ||
| 2501 | //---------------------------------------------------------------------------- | |
| 2502 | /** | |
| 2503 | Complete, remove and delete notification requests | |
| 2504 | @param aCompletionCode completion code for some notifications | |
| 2505 | */ | |
| 2506 | void TDrive::DoCompleteDismountNotify(TInt aCompletionCode) | |
| 2507 |     {
 | |
| 2508 | FsNotify::HandleDismount(EFsDismountRegisterClient, iDriveNumber, ETrue, KErrNone); | |
| 2509 | FsNotify::HandleDismount(EFsDismountNotifyClients, iDriveNumber, ETrue, aCompletionCode); | |
| 2510 | FsNotify::HandleDismount(EFsDismountForceDismount, iDriveNumber, ETrue, aCompletionCode); | |
| 2511 | } | |
| 2512 | ||
| 2513 | //---------------------------------------------------------------------------- | |
| 2514 | /** | |
| 2515 | a helper method that allows forced dismounting current mount for volume formatting. | |
| 2516 | */ | |
| 2517 | TInt TDrive::ForceUnmountFileSystemForFormatting() | |
| 2518 |     {
 | |
| 2519 | TInt nRes; | |
| 2520 | ||
| 2521 | //-- check if there are any clamps on this drive | |
| 2522 | nRes = ClampsOnDrive(); | |
| 2523 | if(nRes > 0) | |
| 2524 | return KErrInUse; | |
| 2525 | ||
| 2526 | //-- purge all dirty data in the files associated with this drive's mount | |
| 2527 | CDriveThread* pT=NULL; | |
| 2528 | nRes = FsThreadManager::GetDriveThread(DriveNumber(), &pT); | |
| 2529 | if(nRes == KErrNone && pT) | |
| 2530 |         {
 | |
| 2531 | pT->CompleteReadWriteRequests(); | |
| 2532 | } | |
| 2533 | ||
| 2534 | PurgeDirty(CurrentMount()); | |
| 2535 | ||
| 2536 | //-- | |
| 2537 | ||
| 2538 | ForceDismount(); | |
| 2539 | ||
| 2540 | DoCompleteDismountNotify(KErrDisMounted); //-- complete all dismount notifications | |
| 2541 | ||
| 2542 | return KErrNone; | |
| 2543 | } | |
| 2544 | ||
| 2545 | //----------------------------------------------------------------------------- | |
| 2546 | /** | |
| 2547 | Instantiate CFormatCB object for formatting the file ssytem on the given TDrive. | |
| 2548 | ||
| 2549 | @param aRequest file server request object | |
| 2550 | @param aFmtHandle out: format handle | |
| 2551 | @param aFmtMode format mode | |
| 2552 | @param apLDFormatInfo pointer to legacy parameters structure; NULL means "not used" | |
| 2553 | @param apVolFormatParam pointer to the newparameters structure; NULL means "not used" | |
| 2554 | ||
| 2555 | @return pointer to the instantiated CFormatCB object. | |
| 2556 | */ | |
| 2557 | CFormatCB* TDrive::FormatOpenL(CFsRequest* aRequest, TInt& aFmtHandle, TFormatMode aFmtMode, const TLDFormatInfo* apLDFormatInfo, const TVolFormatParam* apVolFormatParam) | |
| 2558 |     {
 | |
| 2559 | ASSERT(!(apLDFormatInfo && apVolFormatParam)); //-- these parameters are mutually exclusive | |
| 2560 | ||
| 2561 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatL, EF32TraceUidFileSys, &FSys(), DriveNumber()); | |
| 2562 | ||
| 2563 | CFormatCB* pFormat = CurrentMount().NewFormatL(); | |
| 2564 | ||
| 2565 | TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatLRet, EF32TraceUidFileSys, KErrNone, pFormat); | |
| 2566 | ||
| 2567 | Formats->AddL(pFormat, ETrue); | |
| 2568 | pFormat->InitL(this, aFmtMode); | |
| 2569 | ||
| 2570 | if(aFmtMode & ESpecialFormat) | |
| 2571 |         {
 | |
| 2572 | if(apLDFormatInfo) | |
| 2573 |             {//-- the user has specified formatting parameters as TLDFormatInfo
 | |
| 2574 | pFormat->SetFormatParameters(apLDFormatInfo); | |
| 2575 | } | |
| 2576 | else if(apVolFormatParam && apVolFormatParam->SomeParamsSet()) | |
| 2577 |             {//-- the user has specified formatting parameters as TVolFormatParam
 | |
| 2578 | TInt nRes = pFormat->SetFormatParameters(apVolFormatParam); | |
| 2579 | User::LeaveIfError(nRes); //-- the particular file system might not support this feature | |
| 2580 | } | |
| 2581 | else | |
| 2582 |             {//-- this is a special case, ESpecialFormat is set, but no parameters provided at all;
 | |
| 2583 | //-- invalidate CFormatCB::iSpecialInfo to make filesystem not to use it | |
| 2584 | pFormat->SetFormatParameters((TLDFormatInfo*)NULL); | |
| 2585 | } | |
| 2586 | } | |
| 2587 | ||
| 2588 | ||
| 2589 | // modify resource counter after initialised to ensure correct cleanup | |
| 2590 | AddDiskAccess(CurrentMount()); | |
| 2591 | aFmtHandle = aRequest->Session()->Handles().AddL(pFormat, ETrue); | |
| 2592 | ||
| 2593 | return pFormat; | |
| 2594 | } | |
| 2595 | ||
| 2596 | ||
| 2597 | ||
| 2598 | ||
| 2599 | ||
| 2600 | EXPORT_C void UNUSED1() {}
 | |
| 2601 | EXPORT_C void UNUSED2() {}
 | |
| 2602 | EXPORT_C void UNUSED3() {}
 | |
| 2603 | ||
| 2604 | ||
| 2605 | ||
| 2606 | ||
| 2607 | ||
| 2608 | ||
| 2609 | ||
| 2610 | ||
| 2611 |