os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_raw.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_raw.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,221 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32\sfile\sf_raw.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "sf_std.h"
    1.22 +#include "sf_file_cache.h"
    1.23 +
    1.24 +LOCAL_C CRawDiskCB* GetRawDiskFromHandle(TInt aHandle, CSessionFs* aSession)
    1.25 +//
    1.26 +// Get the rawdisk control block from aHandle
    1.27 +//
    1.28 +	{
    1.29 +	return((CRawDiskCB*)(SessionObjectFromHandle(aHandle,RawDisks->UniqueID(),aSession)));
    1.30 +	}
    1.31 +
    1.32 +LOCAL_C void DoFsRawDiskOpenL(TInt& aHandle,CRawDiskCB*& aRawDisk, CFsRequest* aRequest)
    1.33 +//
    1.34 +// Do the bits that can leave
    1.35 +//
    1.36 +	{
    1.37 +
    1.38 +	aRawDisk=new(ELeave) CRawDiskCB;
    1.39 +	RawDisks->AddL(aRawDisk,ETrue);
    1.40 +	aRawDisk->InitL(&aRequest->Drive()->CurrentMount(),aRequest->Drive()->IsWriteProtected());
    1.41 +	// modify resource counter after initialisation to ensure correct cleanup in object destruction
    1.42 +	AddDiskAccess(aRequest->Drive()->CurrentMount());
    1.43 +	aHandle=aRequest->Session()->Handles().AddL(aRawDisk,ETrue);
    1.44 +	}
    1.45 +
    1.46 +TInt TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)
    1.47 +//
    1.48 +// Open direct disk access channel
    1.49 +//
    1.50 +	{
    1.51 +	__PRINT(_L("TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)"));
    1.52 +		
    1.53 +	TInt r=aRequest->Drive()->CheckMount();
    1.54 +	if (r==KErrNone && aRequest->Drive()->CurrentMount().LockStatus()<0)
    1.55 +		return(KErrInUse);
    1.56 +	if (r!=KErrNone)
    1.57 +		return(r);
    1.58 +
    1.59 +	__ASSERT_DEBUG( aRequest->Drive()->CurrentMount().LockStatus()==0,Fault(ESvrRawDiskOpenFailed));
    1.60 +
    1.61 +	TInt handle;
    1.62 +	CRawDiskCB* rawDisk=NULL;
    1.63 +	TRAPD(ret,DoFsRawDiskOpenL(handle,rawDisk,aRequest));
    1.64 +	if (ret!=KErrNone)
    1.65 +		{
    1.66 +		if(rawDisk)
    1.67 +			rawDisk->Close();
    1.68 +		return(ret);
    1.69 +		}
    1.70 +
    1.71 +	r = rawDisk->Drive().FlushCachedFileInfo();
    1.72 +	if (r != KErrNone)
    1.73 +		return(r);
    1.74 +
    1.75 +	// Empty the closed file container
    1.76 +	TClosedFileUtils::Remove();
    1.77 +
    1.78 +	TPtrC8 pH((TUint8*)&handle,sizeof(TInt));
    1.79 +	aRequest->WriteL(KMsgPtr3,pH);
    1.80 +	aRequest->Session()->IncResourceCount();
    1.81 +	return(KErrNone);
    1.82 +	}
    1.83 +
    1.84 +TInt TFsRawDiskOpen::Initialise(CFsRequest* aRequest)
    1.85 +//	
    1.86 +//
    1.87 +	{
    1.88 +	if (!KCapFsRawDiskOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Open")))
    1.89 +		return KErrPermissionDenied;
    1.90 +	TInt driveNo=aRequest->Message().Int0();
    1.91 +	return ValidateDriveDoSubst(driveNo,aRequest);
    1.92 +	}
    1.93 +
    1.94 +
    1.95 +TInt TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)
    1.96 +//
    1.97 +// Do Raw Read
    1.98 +//
    1.99 +	{
   1.100 +	__PRINT(_L("TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)"));
   1.101 +	
   1.102 +	CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
   1.103 +
   1.104 +	TInt r=rawDisk->Drive().CheckMount();
   1.105 +	if (r!=KErrNone && r!=KErrInUse)
   1.106 +		return(r);
   1.107 +	if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
   1.108 +		return(KErrDisMounted);
   1.109 +	TInt64 pos;
   1.110 +	TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
   1.111 +	aRequest->ReadL(KMsgPtr2,tBuf);
   1.112 +	if ( pos < 0 )
   1.113 +		return(KErrArgument);
   1.114 +	TInt length=aRequest->Message().Int1();
   1.115 +	const TAny* pDes=aRequest->Message().Ptr0();
   1.116 +
   1.117 +	TRACETHREADID(aRequest->Message());
   1.118 +	TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadL, EF32TraceUidFileSys, 
   1.119 +		aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
   1.120 +	TRAP(r,rawDisk->Mount().RawReadL(pos,length,pDes,0,aRequest->Message()));
   1.121 +	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadLRet, EF32TraceUidFileSys, r);
   1.122 +
   1.123 +	return(r);
   1.124 +	}
   1.125 +
   1.126 +TInt TFsRawDiskRead::Initialise(CFsRequest* aRequest)
   1.127 +//
   1.128 +//
   1.129 +//
   1.130 +	{
   1.131 +	if (!KCapFsRawDiskRead.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Read")))
   1.132 +		return KErrPermissionDenied;
   1.133 +	CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
   1.134 +	if(!rawDisk)
   1.135 +		return(KErrBadHandle);
   1.136 +	aRequest->SetDrive(&rawDisk->Drive());
   1.137 +	aRequest->SetScratchValue((TUint)rawDisk);
   1.138 +	return KErrNone;
   1.139 +	}
   1.140 +
   1.141 +
   1.142 +TInt TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)
   1.143 +//
   1.144 +// Do Raw write
   1.145 +//
   1.146 +	{
   1.147 +	__PRINT(_L("TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)"));
   1.148 +	
   1.149 +	CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
   1.150 +	
   1.151 +	TInt r=rawDisk->Drive().CheckMount();
   1.152 +	if (r!=KErrNone && r!=KErrInUse)
   1.153 +		return(r);
   1.154 +	if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
   1.155 +		return(KErrDisMounted);
   1.156 +	TInt64 pos;
   1.157 +	TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
   1.158 +	aRequest->ReadL(KMsgPtr2,tBuf);
   1.159 +	if ( pos < 0 )
   1.160 +		return(KErrArgument);
   1.161 +	TInt length=aRequest->Message().Int1();
   1.162 +	const TAny* pDes=aRequest->Message().Ptr0();
   1.163 +
   1.164 +	TRACETHREADID(aRequest->Message());
   1.165 +	TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteL, EF32TraceUidFileSys, 
   1.166 +		aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
   1.167 +	TRAP(r,rawDisk->Mount().RawWriteL(pos,length,pDes,0,aRequest->Message()));
   1.168 +	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteLRet, EF32TraceUidFileSys, r);
   1.169 +
   1.170 +	rawDisk->SetChanged();
   1.171 +	return(r);
   1.172 +	}
   1.173 +
   1.174 +TInt TFsRawDiskWrite::Initialise(CFsRequest* aRequest)
   1.175 +//
   1.176 +//
   1.177 +//
   1.178 +	{
   1.179 +	if (!KCapFsRawDiskWrite.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Write")))
   1.180 +		return KErrPermissionDenied;
   1.181 +	CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
   1.182 +	if(!rawDisk)
   1.183 +		return(KErrBadHandle);
   1.184 +	if(rawDisk->IsWriteProtected())
   1.185 +		return(KErrAccessDenied);
   1.186 +	aRequest->SetDrive(&rawDisk->Drive());
   1.187 +	aRequest->SetScratchValue((TUint)rawDisk);
   1.188 +	return KErrNone;
   1.189 +	}
   1.190 +
   1.191 +CRawDiskCB::CRawDiskCB()
   1.192 +//
   1.193 +// Constructor
   1.194 +//
   1.195 +	{
   1.196 +	}
   1.197 +
   1.198 +CRawDiskCB::~CRawDiskCB()
   1.199 +//
   1.200 +// Destructor
   1.201 +//
   1.202 +	{
   1.203 +	if(iMount)
   1.204 +		{
   1.205 +		__ASSERT_DEBUG(iMount->LockStatus()>0,Fault(ERawDiskBadAccessCount));
   1.206 +		RemoveDiskAccess(*iMount);
   1.207 +		if(IsChanged())
   1.208 +			iMount->Drive().SetChanged(ETrue);
   1.209 +		iMount->Close();
   1.210 +		}
   1.211 +	}
   1.212 +
   1.213 +void CRawDiskCB::InitL(CMountCB* aMount,TBool aIsWriteProtected)
   1.214 +//
   1.215 +// Initialise
   1.216 +//
   1.217 +	{
   1.218 +	DoInitL(aMount->Drive().DriveNumber());
   1.219 +	iMount=aMount;
   1.220 +	if(aIsWriteProtected)
   1.221 +		SetWriteProtected();
   1.222 +	User::LeaveIfError(iMount->Open());
   1.223 +	}
   1.224 +