First public contribution.
1 // Copyright (c) 1996-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfile\sf_raw.cpp
19 #include "sf_file_cache.h"
21 LOCAL_C CRawDiskCB* GetRawDiskFromHandle(TInt aHandle, CSessionFs* aSession)
23 // Get the rawdisk control block from aHandle
26 return((CRawDiskCB*)(SessionObjectFromHandle(aHandle,RawDisks->UniqueID(),aSession)));
29 LOCAL_C void DoFsRawDiskOpenL(TInt& aHandle,CRawDiskCB*& aRawDisk, CFsRequest* aRequest)
31 // Do the bits that can leave
35 aRawDisk=new(ELeave) CRawDiskCB;
36 RawDisks->AddL(aRawDisk,ETrue);
37 aRawDisk->InitL(&aRequest->Drive()->CurrentMount(),aRequest->Drive()->IsWriteProtected());
38 // modify resource counter after initialisation to ensure correct cleanup in object destruction
39 AddDiskAccess(aRequest->Drive()->CurrentMount());
40 aHandle=aRequest->Session()->Handles().AddL(aRawDisk,ETrue);
43 TInt TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)
45 // Open direct disk access channel
48 __PRINT(_L("TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)"));
50 TInt r=aRequest->Drive()->CheckMount();
51 if (r==KErrNone && aRequest->Drive()->CurrentMount().LockStatus()<0)
56 __ASSERT_DEBUG( aRequest->Drive()->CurrentMount().LockStatus()==0,Fault(ESvrRawDiskOpenFailed));
59 CRawDiskCB* rawDisk=NULL;
60 TRAPD(ret,DoFsRawDiskOpenL(handle,rawDisk,aRequest));
68 r = rawDisk->Drive().FlushCachedFileInfo();
72 // Empty the closed file container
73 TClosedFileUtils::Remove();
75 TPtrC8 pH((TUint8*)&handle,sizeof(TInt));
76 aRequest->WriteL(KMsgPtr3,pH);
77 aRequest->Session()->IncResourceCount();
81 TInt TFsRawDiskOpen::Initialise(CFsRequest* aRequest)
85 if (!KCapFsRawDiskOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Open")))
86 return KErrPermissionDenied;
87 TInt driveNo=aRequest->Message().Int0();
88 return ValidateDriveDoSubst(driveNo,aRequest);
92 TInt TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)
97 __PRINT(_L("TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)"));
99 CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
101 TInt r=rawDisk->Drive().CheckMount();
102 if (r!=KErrNone && r!=KErrInUse)
104 if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
105 return(KErrDisMounted);
107 TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
108 aRequest->ReadL(KMsgPtr2,tBuf);
110 return(KErrArgument);
111 TInt length=aRequest->Message().Int1();
112 const TAny* pDes=aRequest->Message().Ptr0();
114 TRACETHREADID(aRequest->Message());
115 TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadL, EF32TraceUidFileSys,
116 aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
117 TRAP(r,rawDisk->Mount().RawReadL(pos,length,pDes,0,aRequest->Message()));
118 TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadLRet, EF32TraceUidFileSys, r);
123 TInt TFsRawDiskRead::Initialise(CFsRequest* aRequest)
128 if (!KCapFsRawDiskRead.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Read")))
129 return KErrPermissionDenied;
130 CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
132 return(KErrBadHandle);
133 aRequest->SetDrive(&rawDisk->Drive());
134 aRequest->SetScratchValue((TUint)rawDisk);
139 TInt TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)
144 __PRINT(_L("TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)"));
146 CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
148 TInt r=rawDisk->Drive().CheckMount();
149 if (r!=KErrNone && r!=KErrInUse)
151 if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
152 return(KErrDisMounted);
154 TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
155 aRequest->ReadL(KMsgPtr2,tBuf);
157 return(KErrArgument);
158 TInt length=aRequest->Message().Int1();
159 const TAny* pDes=aRequest->Message().Ptr0();
161 TRACETHREADID(aRequest->Message());
162 TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteL, EF32TraceUidFileSys,
163 aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
164 TRAP(r,rawDisk->Mount().RawWriteL(pos,length,pDes,0,aRequest->Message()));
165 TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteLRet, EF32TraceUidFileSys, r);
167 rawDisk->SetChanged();
171 TInt TFsRawDiskWrite::Initialise(CFsRequest* aRequest)
176 if (!KCapFsRawDiskWrite.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Write")))
177 return KErrPermissionDenied;
178 CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
180 return(KErrBadHandle);
181 if(rawDisk->IsWriteProtected())
182 return(KErrAccessDenied);
183 aRequest->SetDrive(&rawDisk->Drive());
184 aRequest->SetScratchValue((TUint)rawDisk);
188 CRawDiskCB::CRawDiskCB()
195 CRawDiskCB::~CRawDiskCB()
202 __ASSERT_DEBUG(iMount->LockStatus()>0,Fault(ERawDiskBadAccessCount));
203 RemoveDiskAccess(*iMount);
205 iMount->Drive().SetChanged(ETrue);
210 void CRawDiskCB::InitL(CMountCB* aMount,TBool aIsWriteProtected)
215 DoInitL(aMount->Drive().DriveNumber());
217 if(aIsWriteProtected)
219 User::LeaveIfError(iMount->Open());