sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\sfile\sf_raw.cpp sl@0: // sl@0: // sl@0: sl@0: #include "sf_std.h" sl@0: #include "sf_file_cache.h" sl@0: sl@0: LOCAL_C CRawDiskCB* GetRawDiskFromHandle(TInt aHandle, CSessionFs* aSession) sl@0: // sl@0: // Get the rawdisk control block from aHandle sl@0: // sl@0: { sl@0: return((CRawDiskCB*)(SessionObjectFromHandle(aHandle,RawDisks->UniqueID(),aSession))); sl@0: } sl@0: sl@0: LOCAL_C void DoFsRawDiskOpenL(TInt& aHandle,CRawDiskCB*& aRawDisk, CFsRequest* aRequest) sl@0: // sl@0: // Do the bits that can leave sl@0: // sl@0: { sl@0: sl@0: aRawDisk=new(ELeave) CRawDiskCB; sl@0: RawDisks->AddL(aRawDisk,ETrue); sl@0: aRawDisk->InitL(&aRequest->Drive()->CurrentMount(),aRequest->Drive()->IsWriteProtected()); sl@0: // modify resource counter after initialisation to ensure correct cleanup in object destruction sl@0: AddDiskAccess(aRequest->Drive()->CurrentMount()); sl@0: aHandle=aRequest->Session()->Handles().AddL(aRawDisk,ETrue); sl@0: } sl@0: sl@0: TInt TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest) sl@0: // sl@0: // Open direct disk access channel sl@0: // sl@0: { sl@0: __PRINT(_L("TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)")); sl@0: sl@0: TInt r=aRequest->Drive()->CheckMount(); sl@0: if (r==KErrNone && aRequest->Drive()->CurrentMount().LockStatus()<0) sl@0: return(KErrInUse); sl@0: if (r!=KErrNone) sl@0: return(r); sl@0: sl@0: __ASSERT_DEBUG( aRequest->Drive()->CurrentMount().LockStatus()==0,Fault(ESvrRawDiskOpenFailed)); sl@0: sl@0: TInt handle; sl@0: CRawDiskCB* rawDisk=NULL; sl@0: TRAPD(ret,DoFsRawDiskOpenL(handle,rawDisk,aRequest)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: if(rawDisk) sl@0: rawDisk->Close(); sl@0: return(ret); sl@0: } sl@0: sl@0: r = rawDisk->Drive().FlushCachedFileInfo(); sl@0: if (r != KErrNone) sl@0: return(r); sl@0: sl@0: // Empty the closed file container sl@0: TClosedFileUtils::Remove(); sl@0: sl@0: TPtrC8 pH((TUint8*)&handle,sizeof(TInt)); sl@0: aRequest->WriteL(KMsgPtr3,pH); sl@0: aRequest->Session()->IncResourceCount(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt TFsRawDiskOpen::Initialise(CFsRequest* aRequest) sl@0: // sl@0: // sl@0: { sl@0: if (!KCapFsRawDiskOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Open"))) sl@0: return KErrPermissionDenied; sl@0: TInt driveNo=aRequest->Message().Int0(); sl@0: return ValidateDriveDoSubst(driveNo,aRequest); sl@0: } sl@0: sl@0: sl@0: TInt TFsRawDiskRead::DoRequestL(CFsRequest* aRequest) sl@0: // sl@0: // Do Raw Read sl@0: // sl@0: { sl@0: __PRINT(_L("TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)")); sl@0: sl@0: CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue(); sl@0: sl@0: TInt r=rawDisk->Drive().CheckMount(); sl@0: if (r!=KErrNone && r!=KErrInUse) sl@0: return(r); sl@0: if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount()) sl@0: return(KErrDisMounted); sl@0: TInt64 pos; sl@0: TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64)); sl@0: aRequest->ReadL(KMsgPtr2,tBuf); sl@0: if ( pos < 0 ) sl@0: return(KErrArgument); sl@0: TInt length=aRequest->Message().Int1(); sl@0: const TAny* pDes=aRequest->Message().Ptr0(); sl@0: sl@0: TRACETHREADID(aRequest->Message()); sl@0: TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadL, EF32TraceUidFileSys, sl@0: aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId)); sl@0: TRAP(r,rawDisk->Mount().RawReadL(pos,length,pDes,0,aRequest->Message())); sl@0: TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadLRet, EF32TraceUidFileSys, r); sl@0: sl@0: return(r); sl@0: } sl@0: sl@0: TInt TFsRawDiskRead::Initialise(CFsRequest* aRequest) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: if (!KCapFsRawDiskRead.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Read"))) sl@0: return KErrPermissionDenied; sl@0: CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session()); sl@0: if(!rawDisk) sl@0: return(KErrBadHandle); sl@0: aRequest->SetDrive(&rawDisk->Drive()); sl@0: aRequest->SetScratchValue((TUint)rawDisk); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest) sl@0: // sl@0: // Do Raw write sl@0: // sl@0: { sl@0: __PRINT(_L("TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)")); sl@0: sl@0: CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue(); sl@0: sl@0: TInt r=rawDisk->Drive().CheckMount(); sl@0: if (r!=KErrNone && r!=KErrInUse) sl@0: return(r); sl@0: if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount()) sl@0: return(KErrDisMounted); sl@0: TInt64 pos; sl@0: TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64)); sl@0: aRequest->ReadL(KMsgPtr2,tBuf); sl@0: if ( pos < 0 ) sl@0: return(KErrArgument); sl@0: TInt length=aRequest->Message().Int1(); sl@0: const TAny* pDes=aRequest->Message().Ptr0(); sl@0: sl@0: TRACETHREADID(aRequest->Message()); sl@0: TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteL, EF32TraceUidFileSys, sl@0: aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId)); sl@0: TRAP(r,rawDisk->Mount().RawWriteL(pos,length,pDes,0,aRequest->Message())); sl@0: TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteLRet, EF32TraceUidFileSys, r); sl@0: sl@0: rawDisk->SetChanged(); sl@0: return(r); sl@0: } sl@0: sl@0: TInt TFsRawDiskWrite::Initialise(CFsRequest* aRequest) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: if (!KCapFsRawDiskWrite.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Write"))) sl@0: return KErrPermissionDenied; sl@0: CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session()); sl@0: if(!rawDisk) sl@0: return(KErrBadHandle); sl@0: if(rawDisk->IsWriteProtected()) sl@0: return(KErrAccessDenied); sl@0: aRequest->SetDrive(&rawDisk->Drive()); sl@0: aRequest->SetScratchValue((TUint)rawDisk); sl@0: return KErrNone; sl@0: } sl@0: sl@0: CRawDiskCB::CRawDiskCB() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: } sl@0: sl@0: CRawDiskCB::~CRawDiskCB() sl@0: // sl@0: // Destructor sl@0: // sl@0: { sl@0: if(iMount) sl@0: { sl@0: __ASSERT_DEBUG(iMount->LockStatus()>0,Fault(ERawDiskBadAccessCount)); sl@0: RemoveDiskAccess(*iMount); sl@0: if(IsChanged()) sl@0: iMount->Drive().SetChanged(ETrue); sl@0: iMount->Close(); sl@0: } sl@0: } sl@0: sl@0: void CRawDiskCB::InitL(CMountCB* aMount,TBool aIsWriteProtected) sl@0: // sl@0: // Initialise sl@0: // sl@0: { sl@0: DoInitL(aMount->Drive().DriveNumber()); sl@0: iMount=aMount; sl@0: if(aIsWriteProtected) sl@0: SetWriteProtected(); sl@0: User::LeaveIfError(iMount->Open()); sl@0: } sl@0: