os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_drv.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfat\sl_drv.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "sl_std.h"
sl@0
    19
#include "sl_cache.h"
sl@0
    20
sl@0
    21
const TInt KMaxRecoverableRetries=10;
sl@0
    22
const TInt KMaxCriticalRetries=10;
sl@0
    23
sl@0
    24
sl@0
    25
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
    26
sl@0
    27
sl@0
    28
TDriveInterface::TDriveInterface() 
sl@0
    29
                   :iMount(NULL)
sl@0
    30
{
sl@0
    31
}
sl@0
    32
sl@0
    33
/**
sl@0
    34
    Initialise the interface object.
sl@0
    35
    @param  aMount the CFatMountCB that owns this object
sl@0
    36
*/
sl@0
    37
TBool TDriveInterface::Init(CFatMountCB* aMount)
sl@0
    38
{
sl@0
    39
    ASSERT(aMount);
sl@0
    40
    iMount = aMount;
sl@0
    41
	aMount->LocalDrive()->SetMount(aMount);
sl@0
    42
    return iProxyDrive.Init(aMount->LocalDrive());
sl@0
    43
}
sl@0
    44
sl@0
    45
/**
sl@0
    46
    pseudo-destructor. 
sl@0
    47
*/
sl@0
    48
void TDriveInterface::Close()
sl@0
    49
{
sl@0
    50
	 if(iMount)
sl@0
    51
		iMount->LocalDrive()->SetMount(NULL);
sl@0
    52
     iMount = NULL;
sl@0
    53
}
sl@0
    54
sl@0
    55
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
    56
sl@0
    57
/**
sl@0
    58
    Read data from the media via CProxyDrive interface.
sl@0
    59
    This is non-critical read: on error Non-critical notifier is involved
sl@0
    60
sl@0
    61
    @param  aPos        absolute media position
sl@0
    62
    @param  aLength     how many bytes to read
sl@0
    63
    @param  aTrg        data descriptor
sl@0
    64
sl@0
    65
    @return KErrNone - success
sl@0
    66
    @return KErrNotReady - non-critical error
sl@0
    67
    @return KErrCorrupt - an illegal write is detected
sl@0
    68
    @return KErrBadPower - failure due to low power
sl@0
    69
sl@0
    70
*/
sl@0
    71
TInt TDriveInterface::ReadNonCritical(TInt64 aPos, TInt aLength, TDes8& aTrg) const
sl@0
    72
{
sl@0
    73
    TInt nRes = KErrNone;
sl@0
    74
    TInt cntRetry = KMaxRecoverableRetries;
sl@0
    75
sl@0
    76
    //__PRINT2(_L("#=+++ Read_nc1: pos:%LU, len:%u"), aPos, aLength);
sl@0
    77
sl@0
    78
    for(;;)
sl@0
    79
    {
sl@0
    80
        nRes = iProxyDrive.Read(aPos,aLength,aTrg);
sl@0
    81
        if (nRes==KErrNone)
sl@0
    82
            break;
sl@0
    83
sl@0
    84
        __PRINT4(_L("TDriveInterface::ReadNonCritical() failure! drv:%d Posl=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos, aLength, nRes);
sl@0
    85
        
sl@0
    86
        if(--cntRetry <= 0)
sl@0
    87
        {
sl@0
    88
            nRes = KErrCorrupt;
sl@0
    89
            break;
sl@0
    90
        }
sl@0
    91
sl@0
    92
        nRes = HandleRecoverableError(nRes);
sl@0
    93
        if (nRes !=ERetry)
sl@0
    94
            break;
sl@0
    95
    }
sl@0
    96
sl@0
    97
    return nRes;
sl@0
    98
}
sl@0
    99
sl@0
   100
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   101
sl@0
   102
/**
sl@0
   103
    Read data from the media via CProxyDrive interface. 
sl@0
   104
    This is non-critical read: on error Non-critical notifier is involved
sl@0
   105
sl@0
   106
    @param  aPos        absolute media position
sl@0
   107
    @param  aLength     how many bytes to read
sl@0
   108
    @param  aTrg        data descriptor
sl@0
   109
    @param  aMessage
sl@0
   110
    @param  anOffset
sl@0
   111
sl@0
   112
    @return KErrNone - success
sl@0
   113
    @return KErrNotReady - non-critical error
sl@0
   114
    @return KErrCorrupt - an illegal write is detected
sl@0
   115
    @return KErrBadPower - failure due to low power
sl@0
   116
sl@0
   117
*/
sl@0
   118
TInt TDriveInterface::ReadNonCritical(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const
sl@0
   119
{
sl@0
   120
    //__PRINT2(_L("#=+++ Read_nc2: pos:%LU, len:%u"), aPos, aLength);
sl@0
   121
sl@0
   122
    TInt nRes = KErrNone;
sl@0
   123
    TInt cntRetry = KMaxRecoverableRetries;
sl@0
   124
sl@0
   125
    for(;;)
sl@0
   126
    {
sl@0
   127
        nRes = iProxyDrive.Read(aPos, aLength, aTrg, aMessage, anOffset);
sl@0
   128
        if (nRes==KErrNone)
sl@0
   129
            break;
sl@0
   130
sl@0
   131
        __PRINT4(_L("TDriveInterface::ReadNonCritical() Failure! drv:%d aPosl=%d len=%d anOffset=%d"), iMount->DriveNumber(), aPos,aLength, anOffset);
sl@0
   132
        
sl@0
   133
        if(--cntRetry <= 0)
sl@0
   134
        {
sl@0
   135
            nRes = KErrCorrupt;
sl@0
   136
            break;
sl@0
   137
        }
sl@0
   138
sl@0
   139
        nRes = HandleRecoverableError(nRes);
sl@0
   140
        if (nRes !=ERetry)
sl@0
   141
            break;
sl@0
   142
    }
sl@0
   143
sl@0
   144
    return nRes;
sl@0
   145
}
sl@0
   146
sl@0
   147
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   148
sl@0
   149
/**
sl@0
   150
    Read data from the media via CProxyDrive interface with a critical notifier.
sl@0
   151
    This method shall be used to read critical filesystem data, such as directory entries, FAT data.
sl@0
   152
sl@0
   153
    @param  aPos        absolute media position
sl@0
   154
    @param  aLength     how many bytes to read
sl@0
   155
    @param  aTrg        data descriptor
sl@0
   156
sl@0
   157
    @return KErrNone - success
sl@0
   158
    @return KErrNotReady - non-critical error
sl@0
   159
    @return KErrCorrupt - an illegal write is detected
sl@0
   160
    @return KErrAbort - user aborted read
sl@0
   161
*/
sl@0
   162
TInt TDriveInterface::ReadCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const
sl@0
   163
{
sl@0
   164
    //__PRINT2(_L("#=+++ Read_C: pos:%LU, len:%u"), aPos, aLength);
sl@0
   165
sl@0
   166
    TInt nRes = KErrNone;
sl@0
   167
sl@0
   168
    for(;;)
sl@0
   169
    {
sl@0
   170
        nRes = iProxyDrive.Read(aPos, aLength, aTrg);
sl@0
   171
		if(nRes == KErrNone)
sl@0
   172
            break;
sl@0
   173
sl@0
   174
		__PRINT4(_L("TDriveInterface::ReadCritical() Error! drv:%d Posl=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos, aLength, nRes);
sl@0
   175
		
sl@0
   176
        nRes=HandleCriticalError(nRes);
sl@0
   177
		if (nRes != ERetry)
sl@0
   178
            break;
sl@0
   179
    }
sl@0
   180
sl@0
   181
    return nRes;
sl@0
   182
}
sl@0
   183
sl@0
   184
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   185
sl@0
   186
/**
sl@0
   187
    Write data to the media via CProxyDrive interface.
sl@0
   188
    
sl@0
   189
    @param  aPos        absolute media position
sl@0
   190
    @param  aLength     how many bytes to write
sl@0
   191
    @param  aSrc        pointer to the data 
sl@0
   192
    @param  aMessage
sl@0
   193
    @param  anOffset
sl@0
   194
    
sl@0
   195
    @return KErrNone - success
sl@0
   196
    @return KErrNotReady - non-critical error
sl@0
   197
    @return KErrBadPower - write not attempted due to low batteries
sl@0
   198
    @return KErrCorrupt - an illegal write is detected
sl@0
   199
    @return KErrAccessDenied - write to protected media
sl@0
   200
*/
sl@0
   201
TInt TDriveInterface::WriteNonCritical(TInt64 aPos, TInt aLength, const TAny* aSrc, const RMessagePtr2 &aMessage, TInt anOffset)
sl@0
   202
{
sl@0
   203
    //__PRINT2(_L("#=+++ Write_NC: pos:%LU, len:%u"), aPos, aLength);
sl@0
   204
sl@0
   205
    
sl@0
   206
    TInt nRes = KErrNone;
sl@0
   207
    TInt cntRetry = KMaxRecoverableRetries;
sl@0
   208
sl@0
   209
    for(;;)
sl@0
   210
    {
sl@0
   211
        iMount->OpenMountForWrite(); //-- make a callback to CFatMountCB to perform some actions on 1st write.
sl@0
   212
        nRes = iProxyDrive.Write(aPos, aLength, aSrc, aMessage, anOffset);
sl@0
   213
        if (nRes==KErrNone)
sl@0
   214
            break;
sl@0
   215
sl@0
   216
        __PRINT4(_L("TDriveInterface::WriteNonCritical() failure! drv:%d, Pos=%LU len=%d anOffset=%d"), iMount->DriveNumber(), aPos, aLength, anOffset);
sl@0
   217
        
sl@0
   218
        if(--cntRetry <= 0)
sl@0
   219
        {
sl@0
   220
            nRes = KErrCorrupt;
sl@0
   221
            break;
sl@0
   222
        }
sl@0
   223
sl@0
   224
        nRes = HandleRecoverableError(nRes);
sl@0
   225
        if (nRes !=ERetry)
sl@0
   226
            break;
sl@0
   227
    }
sl@0
   228
sl@0
   229
sl@0
   230
    return nRes;
sl@0
   231
}
sl@0
   232
sl@0
   233
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   234
sl@0
   235
/**
sl@0
   236
    Write data to the media via CProxyDrive interface. On error this method can invoke a critical notifier.
sl@0
   237
    This method is intended to be called for the filesstem critical data, i.e. FAT metadata, such as directory entries,
sl@0
   238
    FAT table etc.
sl@0
   239
    
sl@0
   240
    @param  aPos  absolute media position
sl@0
   241
    @param  aSrc  descriptor with the source data
sl@0
   242
    
sl@0
   243
    @return KErrNone - success
sl@0
   244
    @return KErrNotReady - non-critical error
sl@0
   245
    @return KErrBadPower - write not attempted due to low batteries
sl@0
   246
    @return KErrCorrupt - an illegal write is detected
sl@0
   247
    @return KErrAccessDenied - write to protected media
sl@0
   248
*/
sl@0
   249
TInt TDriveInterface::WriteCritical(TInt64 aPos, const TDesC8& aSrc)
sl@0
   250
{
sl@0
   251
    //__PRINT2(_L("#=+++ Write_C: pos:%LU, len:%u"), aPos, aSrc.Length());
sl@0
   252
sl@0
   253
    TInt nRes = KErrNone;
sl@0
   254
sl@0
   255
#ifdef _DEBUG
sl@0
   256
    
sl@0
   257
    TBool simulatedWriteFailure = EFalse; //-- if true it means that the write failure has been simulated
sl@0
   258
sl@0
   259
    //-- debug interface to simulate write failure
sl@0
   260
	if(iMount->IsWriteFail())
sl@0
   261
    {
sl@0
   262
		if(iMount->WriteFailCount() != 0)
sl@0
   263
        {
sl@0
   264
            iMount->DecWriteFailCount();
sl@0
   265
        }
sl@0
   266
        else
sl@0
   267
		{//-- simulate write failure
sl@0
   268
			if(iMount->WriteFailError()==-99)
sl@0
   269
				UserSvr::ResetMachine(EStartupWarmReset);
sl@0
   270
			else
sl@0
   271
			{
sl@0
   272
			    //-- invalidate caches, because actual write to the drive isn't going to happen
sl@0
   273
                if(iMount->RawDisk().DirCacheInterface())
sl@0
   274
                    iMount->RawDisk().DirCacheInterface()->InvalidateCache();
sl@0
   275
sl@0
   276
                iMount->SetWriteFail(EFalse);
sl@0
   277
				
sl@0
   278
                TRAP_IGNORE(iMount->RawDisk().InvalidateUidCache()); //-- invalidate whole UID data cache
sl@0
   279
                TRAP_IGNORE(iMount->FAT().InvalidateCacheL());       //-- invalidate whole FAT cache
sl@0
   280
                
sl@0
   281
                iMount->InvalidateLeafDirCache();
sl@0
   282
sl@0
   283
                nRes = iMount->WriteFailError(); 
sl@0
   284
                simulatedWriteFailure = ETrue; //-- won't perform actual write later
sl@0
   285
                __PRINT4(_L("TDriveInterface::WriteCritical() Simulating write failure. drv:%d, aPos=%LU len=%d Code=%d"), iMount->DriveNumber(), aPos,aSrc.Length(),nRes);
sl@0
   286
sl@0
   287
			}
sl@0
   288
		}
sl@0
   289
    }//if(iMount->IsWriteFail())
sl@0
   290
sl@0
   291
    if(!simulatedWriteFailure)
sl@0
   292
#endif // _DEBUG
sl@0
   293
    {
sl@0
   294
        //-- try to write data until success or user gives up
sl@0
   295
	    for(;;)
sl@0
   296
	    {
sl@0
   297
            for(TInt i=0; i<KMaxCriticalRetries; i++)
sl@0
   298
            {
sl@0
   299
                iMount->OpenMountForWrite();  //-- make a callback to CFatMountCB to perform some actions on 1st write.
sl@0
   300
                nRes=iProxyDrive.Write(aPos,aSrc);
sl@0
   301
			    if (nRes==KErrNone)
sl@0
   302
                    return nRes;
sl@0
   303
		    }
sl@0
   304
sl@0
   305
            //-- write error occured
sl@0
   306
            __PRINT4(_L("TDriveInterface::WriteCritical() failure! drv:%d, aPos=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos,aSrc.Length(),nRes);
sl@0
   307
sl@0
   308
            nRes=HandleCriticalError(nRes);
sl@0
   309
            if (nRes!=ERetry)
sl@0
   310
                break;
sl@0
   311
sl@0
   312
	    }//for(;;)
sl@0
   313
    
sl@0
   314
    }// if(!simulatedWriteFailure)
sl@0
   315
    
sl@0
   316
    return nRes;
sl@0
   317
}
sl@0
   318
sl@0
   319
sl@0
   320
/**
sl@0
   321
    Get Last Error Info from the proxy drive
sl@0
   322
        
sl@0
   323
    @param  aErrorInfo data descriptor for the error info.
sl@0
   324
    @return KErrNone - success, interrogate aErrorInfo for further info
sl@0
   325
    @return KErrNotSupported - media driver does not support
sl@0
   326
*/
sl@0
   327
TInt TDriveInterface::GetLastErrorInfo(TDes8& aErrorInfo) const
sl@0
   328
{
sl@0
   329
    return iProxyDrive.GetLastErrorInfo(aErrorInfo);
sl@0
   330
}
sl@0
   331
sl@0
   332
sl@0
   333
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   334
sl@0
   335
/**
sl@0
   336
    Handle critical error
sl@0
   337
sl@0
   338
    @param aResult result from the media driver (error code)
sl@0
   339
sl@0
   340
    @return ERetry - Attempt operation again
sl@0
   341
    @return KErrAbort - User aborted notifier
sl@0
   342
    @return KErrAccessDenied - media is read only
sl@0
   343
    @return KErrCorrupt - cf-card is corrupt
sl@0
   344
*/
sl@0
   345
TInt TDriveInterface::HandleCriticalError(TInt aResult) const
sl@0
   346
	{
sl@0
   347
    __PRINT2(_L("TDriveInterface::HandleCriticalError drv:%d, code:%d"), iMount->DriveNumber(),aResult);
sl@0
   348
sl@0
   349
	TLocaleMessage line1;
sl@0
   350
	TLocaleMessage line2;
sl@0
   351
sl@0
   352
	TInt r=KErrAbort;
sl@0
   353
sl@0
   354
	if (aResult==KErrLocked)
sl@0
   355
	{
sl@0
   356
		r=KErrLocked;
sl@0
   357
		goto End;
sl@0
   358
	}
sl@0
   359
sl@0
   360
	if (aResult==KErrAccessDenied)
sl@0
   361
		{
sl@0
   362
		r=KErrAccessDenied;
sl@0
   363
		goto End;
sl@0
   364
		}
sl@0
   365
	
sl@0
   366
	if (aResult==KErrArgument || aResult==KErrBadDescriptor)
sl@0
   367
		{
sl@0
   368
		r=KErrCorrupt;
sl@0
   369
		goto End;
sl@0
   370
		}
sl@0
   371
sl@0
   372
	if (iMount->Drive().IsChanged())
sl@0
   373
		{//-- check if the media we accessing is the same as it used to be
sl@0
   374
          if(iMount->CheckVolumeTheSame())
sl@0
   375
        	{//-- the media is the same
sl@0
   376
			if(!IsDriveWriteProtected())
sl@0
   377
				{
sl@0
   378
				iMount->Drive().SetChanged(EFalse);
sl@0
   379
				r=ERetry;
sl@0
   380
				goto End;
sl@0
   381
				}
sl@0
   382
			}
sl@0
   383
		}
sl@0
   384
sl@0
   385
	if (aResult==KErrAbort && !iMount->Drive().IsChanged())
sl@0
   386
		{
sl@0
   387
		r=ERetry;
sl@0
   388
		goto End;
sl@0
   389
		}
sl@0
   390
sl@0
   391
	if (aResult==KErrBadPower)
sl@0
   392
		{
sl@0
   393
		line1=EFileServer_LowPowerLine1;
sl@0
   394
		line2=EFileServer_LowPowerLine2;
sl@0
   395
		}
sl@0
   396
	else if (iMount->Drive().IsChanged())
sl@0
   397
		{
sl@0
   398
		line1=EFileServer_PutTheCardBackLine1;
sl@0
   399
		line2=EFileServer_PutTheCardBackLine2;
sl@0
   400
		}
sl@0
   401
	else
sl@0
   402
		{
sl@0
   403
		line1=EFileServer_DiskErrorLine1;
sl@0
   404
		line2=EFileServer_DiskErrorLine2;
sl@0
   405
		}
sl@0
   406
	
sl@0
   407
	if (NotifyUser())
sl@0
   408
		{
sl@0
   409
		FOREVER
sl@0
   410
			{
sl@0
   411
			TInt buttonVal;
sl@0
   412
			TInt ret=iMount->Notifier()->Notify(TLocaleMessageText(line1),
sl@0
   413
												TLocaleMessageText(line2),
sl@0
   414
												TLocaleMessageText(EFileServer_Button1),
sl@0
   415
												TLocaleMessageText(EFileServer_Button2),
sl@0
   416
												buttonVal);
sl@0
   417
			if (ret!=KErrNone)
sl@0
   418
				break; 
sl@0
   419
			if (buttonVal!=1)
sl@0
   420
				break; // Abort
sl@0
   421
sl@0
   422
			if (iMount->Drive().IsChanged())
sl@0
   423
				{
sl@0
   424
//
sl@0
   425
// Without this code, retry will indiscriminately write over whatever disk happens to be present.
sl@0
   426
// However if the write error is to the bootsector remounting will always fail because the boot
sl@0
   427
// sector will have changed and hence the disk is useless.
sl@0
   428
// 
sl@0
   429
                if(!iMount->CheckVolumeTheSame())
sl@0
   430
                    continue; //-- the media isn't the same as originally mounted; continue asking
sl@0
   431
sl@0
   432
                if(IsDriveWriteProtected())
sl@0
   433
                    continue; //-- still can not write to the drive
sl@0
   434
sl@0
   435
sl@0
   436
				iMount->Drive().SetChanged(EFalse);
sl@0
   437
				}
sl@0
   438
sl@0
   439
			r=ERetry; // Retry
sl@0
   440
			break;
sl@0
   441
			}
sl@0
   442
		}
sl@0
   443
End:
sl@0
   444
	return(r);
sl@0
   445
	}
sl@0
   446
sl@0
   447
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   448
sl@0
   449
/**
sl@0
   450
    Handle recoverable error
sl@0
   451
sl@0
   452
    @param aResult result from the media driver (error code)
sl@0
   453
sl@0
   454
    @return ERetry - retry write
sl@0
   455
    @return KErrCorrupt - media is corrupt
sl@0
   456
    @return KErrBadPower - low power failure
sl@0
   457
    @return KErrNotReady - non-critical error
sl@0
   458
*/
sl@0
   459
TInt TDriveInterface::HandleRecoverableError(TInt aResult) const
sl@0
   460
	{
sl@0
   461
	__PRINT2(_L("TDriveInterface::HandleRecoverableError drv:%d, code:%d"), iMount->DriveNumber(),aResult);
sl@0
   462
sl@0
   463
	if (aResult==KErrAccessDenied)
sl@0
   464
		return(KErrAccessDenied);
sl@0
   465
	if (aResult == KErrLocked)
sl@0
   466
		return KErrLocked;
sl@0
   467
	if (aResult==KErrArgument || aResult==KErrBadDescriptor)
sl@0
   468
		return(KErrCorrupt);
sl@0
   469
	if (aResult==KErrBadPower)
sl@0
   470
		return(KErrBadPower);
sl@0
   471
	if (aResult==KErrDied)	// client thread died
sl@0
   472
		return(KErrDied);
sl@0
   473
	if (iMount->Drive().IsChanged())
sl@0
   474
		{
sl@0
   475
sl@0
   476
        if(! iMount->CheckVolumeTheSame())
sl@0
   477
            {//-- the media is different now.
sl@0
   478
            return KErrNotReady;
sl@0
   479
			}
sl@0
   480
		else if(!IsRecoverableRemount())
sl@0
   481
			{
sl@0
   482
			return KErrAccessDenied;
sl@0
   483
			}
sl@0
   484
		}
sl@0
   485
	return(ERetry);
sl@0
   486
	}	
sl@0
   487
sl@0
   488
/** @return true if the mount can be remounted for a recoverable error */
sl@0
   489
TBool TDriveInterface::IsRecoverableRemount() const
sl@0
   490
	{
sl@0
   491
	if(IsDriveWriteProtected()&&(iMount->Drive().IsWriteableResource()||iMount->Drive().IsCurrentWriteFunction()))
sl@0
   492
		return(EFalse);
sl@0
   493
	return(ETrue);
sl@0
   494
	}
sl@0
   495
sl@0
   496
/** return true if the media is write protected */
sl@0
   497
TBool TDriveInterface::IsDriveWriteProtected() const
sl@0
   498
	{
sl@0
   499
	TLocalDriveCapsV2Buf localDriveCaps;
sl@0
   500
    TInt r=iProxyDrive.Caps(localDriveCaps);
sl@0
   501
sl@0
   502
	if(r!=KErrNone)
sl@0
   503
		return(EFalse);
sl@0
   504
sl@0
   505
	return((localDriveCaps().iMediaAtt&KMediaAttWriteProtected)!=0);
sl@0
   506
	}
sl@0
   507
sl@0
   508
sl@0
   509
sl@0
   510
//---------------------------------------------------------------------------------------------------------------------------------------
sl@0
   511
sl@0
   512
TDriveInterface::XProxyDriveWrapper::XProxyDriveWrapper() 
sl@0
   513
                   :iLocalDrive(0) 
sl@0
   514
{
sl@0
   515
    TInt nRes = iLock.CreateLocal();
sl@0
   516
    ASSERT(nRes == KErrNone);
sl@0
   517
    (void)nRes; 
sl@0
   518
}
sl@0
   519
sl@0
   520
sl@0
   521
TDriveInterface::XProxyDriveWrapper::~XProxyDriveWrapper() 
sl@0
   522
{
sl@0
   523
    iLock.Close();
sl@0
   524
}
sl@0
   525
sl@0
   526
/** 
sl@0
   527
    Initialise interface wrapper.
sl@0
   528
    @param  aProxyDrive pointer to the raw drive access interface
sl@0
   529
    @return true on success
sl@0
   530
*/
sl@0
   531
TBool TDriveInterface::XProxyDriveWrapper::Init(CProxyDrive* aProxyDrive) 
sl@0
   532
{
sl@0
   533
    ASSERT(aProxyDrive);
sl@0
   534
    if(!iLock.Handle()) //-- the mutex must have been created by constructor
sl@0
   535
        return EFalse;
sl@0
   536
    
sl@0
   537
    iLocalDrive = aProxyDrive;
sl@0
   538
    return ETrue;
sl@0
   539
}
sl@0
   540
sl@0
   541
//-- see original TDriveInterface methods
sl@0
   542
sl@0
   543
TInt TDriveInterface::XProxyDriveWrapper::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const
sl@0
   544
{
sl@0
   545
    EnterCriticalSection();
sl@0
   546
    TInt nRes = iLocalDrive->Read(aPos, aLength, aTrg, aMessage.Handle(), anOffset);
sl@0
   547
    LeaveCriticalSection();
sl@0
   548
    return nRes;
sl@0
   549
}
sl@0
   550
       
sl@0
   551
TInt TDriveInterface::XProxyDriveWrapper::Read(TInt64 aPos,TInt aLength,TDes8& aTrg) const
sl@0
   552
{
sl@0
   553
    EnterCriticalSection();
sl@0
   554
    TInt nRes = iLocalDrive->Read(aPos, aLength, aTrg);
sl@0
   555
    LeaveCriticalSection();
sl@0
   556
    return nRes;
sl@0
   557
}
sl@0
   558
sl@0
   559
TInt TDriveInterface::XProxyDriveWrapper::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset)
sl@0
   560
{
sl@0
   561
    EnterCriticalSection();
sl@0
   562
    TInt nRes = iLocalDrive->Write(aPos, aLength, aSrc, aMessage.Handle(), anOffset);
sl@0
   563
    LeaveCriticalSection();
sl@0
   564
    return nRes;
sl@0
   565
}
sl@0
   566
sl@0
   567
TInt TDriveInterface::XProxyDriveWrapper::Write(TInt64 aPos, const TDesC8& aSrc)
sl@0
   568
{
sl@0
   569
    EnterCriticalSection();
sl@0
   570
    TInt nRes = iLocalDrive->Write(aPos, aSrc);
sl@0
   571
    LeaveCriticalSection();
sl@0
   572
    return nRes;
sl@0
   573
}
sl@0
   574
sl@0
   575
TInt TDriveInterface::XProxyDriveWrapper::GetLastErrorInfo(TDes8& aErrorInfo) const
sl@0
   576
{
sl@0
   577
    EnterCriticalSection();
sl@0
   578
    TInt nRes = iLocalDrive->GetLastErrorInfo(aErrorInfo);
sl@0
   579
    LeaveCriticalSection();
sl@0
   580
    return nRes;
sl@0
   581
}
sl@0
   582
sl@0
   583
TInt TDriveInterface::XProxyDriveWrapper::Caps(TDes8& anInfo) const
sl@0
   584
{
sl@0
   585
    EnterCriticalSection();
sl@0
   586
    TInt nRes = iLocalDrive->Caps(anInfo);
sl@0
   587
    LeaveCriticalSection();
sl@0
   588
    return nRes;
sl@0
   589
}
sl@0
   590
sl@0
   591
sl@0
   592
sl@0
   593
sl@0
   594
sl@0
   595
sl@0
   596
sl@0
   597
sl@0
   598
sl@0
   599
sl@0
   600
sl@0
   601