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\sfile\sf_raw.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "sf_std.h"
|
sl@0
|
19 |
#include "sf_file_cache.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
LOCAL_C CRawDiskCB* GetRawDiskFromHandle(TInt aHandle, CSessionFs* aSession)
|
sl@0
|
22 |
//
|
sl@0
|
23 |
// Get the rawdisk control block from aHandle
|
sl@0
|
24 |
//
|
sl@0
|
25 |
{
|
sl@0
|
26 |
return((CRawDiskCB*)(SessionObjectFromHandle(aHandle,RawDisks->UniqueID(),aSession)));
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
LOCAL_C void DoFsRawDiskOpenL(TInt& aHandle,CRawDiskCB*& aRawDisk, CFsRequest* aRequest)
|
sl@0
|
30 |
//
|
sl@0
|
31 |
// Do the bits that can leave
|
sl@0
|
32 |
//
|
sl@0
|
33 |
{
|
sl@0
|
34 |
|
sl@0
|
35 |
aRawDisk=new(ELeave) CRawDiskCB;
|
sl@0
|
36 |
RawDisks->AddL(aRawDisk,ETrue);
|
sl@0
|
37 |
aRawDisk->InitL(&aRequest->Drive()->CurrentMount(),aRequest->Drive()->IsWriteProtected());
|
sl@0
|
38 |
// modify resource counter after initialisation to ensure correct cleanup in object destruction
|
sl@0
|
39 |
AddDiskAccess(aRequest->Drive()->CurrentMount());
|
sl@0
|
40 |
aHandle=aRequest->Session()->Handles().AddL(aRawDisk,ETrue);
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
TInt TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)
|
sl@0
|
44 |
//
|
sl@0
|
45 |
// Open direct disk access channel
|
sl@0
|
46 |
//
|
sl@0
|
47 |
{
|
sl@0
|
48 |
__PRINT(_L("TFsRawDiskOpen::DoRequestL(CFsRequest* aRequest)"));
|
sl@0
|
49 |
|
sl@0
|
50 |
TInt r=aRequest->Drive()->CheckMount();
|
sl@0
|
51 |
if (r==KErrNone && aRequest->Drive()->CurrentMount().LockStatus()<0)
|
sl@0
|
52 |
return(KErrInUse);
|
sl@0
|
53 |
if (r!=KErrNone)
|
sl@0
|
54 |
return(r);
|
sl@0
|
55 |
|
sl@0
|
56 |
__ASSERT_DEBUG( aRequest->Drive()->CurrentMount().LockStatus()==0,Fault(ESvrRawDiskOpenFailed));
|
sl@0
|
57 |
|
sl@0
|
58 |
TInt handle;
|
sl@0
|
59 |
CRawDiskCB* rawDisk=NULL;
|
sl@0
|
60 |
TRAPD(ret,DoFsRawDiskOpenL(handle,rawDisk,aRequest));
|
sl@0
|
61 |
if (ret!=KErrNone)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
if(rawDisk)
|
sl@0
|
64 |
rawDisk->Close();
|
sl@0
|
65 |
return(ret);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
r = rawDisk->Drive().FlushCachedFileInfo();
|
sl@0
|
69 |
if (r != KErrNone)
|
sl@0
|
70 |
return(r);
|
sl@0
|
71 |
|
sl@0
|
72 |
// Empty the closed file container
|
sl@0
|
73 |
TClosedFileUtils::Remove();
|
sl@0
|
74 |
|
sl@0
|
75 |
TPtrC8 pH((TUint8*)&handle,sizeof(TInt));
|
sl@0
|
76 |
aRequest->WriteL(KMsgPtr3,pH);
|
sl@0
|
77 |
aRequest->Session()->IncResourceCount();
|
sl@0
|
78 |
return(KErrNone);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
TInt TFsRawDiskOpen::Initialise(CFsRequest* aRequest)
|
sl@0
|
82 |
//
|
sl@0
|
83 |
//
|
sl@0
|
84 |
{
|
sl@0
|
85 |
if (!KCapFsRawDiskOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Open")))
|
sl@0
|
86 |
return KErrPermissionDenied;
|
sl@0
|
87 |
TInt driveNo=aRequest->Message().Int0();
|
sl@0
|
88 |
return ValidateDriveDoSubst(driveNo,aRequest);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
|
sl@0
|
92 |
TInt TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)
|
sl@0
|
93 |
//
|
sl@0
|
94 |
// Do Raw Read
|
sl@0
|
95 |
//
|
sl@0
|
96 |
{
|
sl@0
|
97 |
__PRINT(_L("TFsRawDiskRead::DoRequestL(CFsRequest* aRequest)"));
|
sl@0
|
98 |
|
sl@0
|
99 |
CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
|
sl@0
|
100 |
|
sl@0
|
101 |
TInt r=rawDisk->Drive().CheckMount();
|
sl@0
|
102 |
if (r!=KErrNone && r!=KErrInUse)
|
sl@0
|
103 |
return(r);
|
sl@0
|
104 |
if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
|
sl@0
|
105 |
return(KErrDisMounted);
|
sl@0
|
106 |
TInt64 pos;
|
sl@0
|
107 |
TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
|
sl@0
|
108 |
aRequest->ReadL(KMsgPtr2,tBuf);
|
sl@0
|
109 |
if ( pos < 0 )
|
sl@0
|
110 |
return(KErrArgument);
|
sl@0
|
111 |
TInt length=aRequest->Message().Int1();
|
sl@0
|
112 |
const TAny* pDes=aRequest->Message().Ptr0();
|
sl@0
|
113 |
|
sl@0
|
114 |
TRACETHREADID(aRequest->Message());
|
sl@0
|
115 |
TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadL, EF32TraceUidFileSys,
|
sl@0
|
116 |
aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
|
sl@0
|
117 |
TRAP(r,rawDisk->Mount().RawReadL(pos,length,pDes,0,aRequest->Message()));
|
sl@0
|
118 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawReadLRet, EF32TraceUidFileSys, r);
|
sl@0
|
119 |
|
sl@0
|
120 |
return(r);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
TInt TFsRawDiskRead::Initialise(CFsRequest* aRequest)
|
sl@0
|
124 |
//
|
sl@0
|
125 |
//
|
sl@0
|
126 |
//
|
sl@0
|
127 |
{
|
sl@0
|
128 |
if (!KCapFsRawDiskRead.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Read")))
|
sl@0
|
129 |
return KErrPermissionDenied;
|
sl@0
|
130 |
CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
|
sl@0
|
131 |
if(!rawDisk)
|
sl@0
|
132 |
return(KErrBadHandle);
|
sl@0
|
133 |
aRequest->SetDrive(&rawDisk->Drive());
|
sl@0
|
134 |
aRequest->SetScratchValue((TUint)rawDisk);
|
sl@0
|
135 |
return KErrNone;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
|
sl@0
|
139 |
TInt TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)
|
sl@0
|
140 |
//
|
sl@0
|
141 |
// Do Raw write
|
sl@0
|
142 |
//
|
sl@0
|
143 |
{
|
sl@0
|
144 |
__PRINT(_L("TFsRawDiskWrite::DoRequestL(CFsRequest* aRequest)"));
|
sl@0
|
145 |
|
sl@0
|
146 |
CRawDiskCB* rawDisk=(CRawDiskCB*)aRequest->ScratchValue();
|
sl@0
|
147 |
|
sl@0
|
148 |
TInt r=rawDisk->Drive().CheckMount();
|
sl@0
|
149 |
if (r!=KErrNone && r!=KErrInUse)
|
sl@0
|
150 |
return(r);
|
sl@0
|
151 |
if (&rawDisk->Mount()!=&rawDisk->Drive().CurrentMount())
|
sl@0
|
152 |
return(KErrDisMounted);
|
sl@0
|
153 |
TInt64 pos;
|
sl@0
|
154 |
TPtr8 tBuf((TUint8*)&pos,sizeof(TInt64));
|
sl@0
|
155 |
aRequest->ReadL(KMsgPtr2,tBuf);
|
sl@0
|
156 |
if ( pos < 0 )
|
sl@0
|
157 |
return(KErrArgument);
|
sl@0
|
158 |
TInt length=aRequest->Message().Int1();
|
sl@0
|
159 |
const TAny* pDes=aRequest->Message().Ptr0();
|
sl@0
|
160 |
|
sl@0
|
161 |
TRACETHREADID(aRequest->Message());
|
sl@0
|
162 |
TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteL, EF32TraceUidFileSys,
|
sl@0
|
163 |
aRequest->DriveNumber(), I64LOW(pos), I64HIGH(pos), length, pDes, 0, I64LOW(threadId));
|
sl@0
|
164 |
TRAP(r,rawDisk->Mount().RawWriteL(pos,length,pDes,0,aRequest->Message()));
|
sl@0
|
165 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRawWriteLRet, EF32TraceUidFileSys, r);
|
sl@0
|
166 |
|
sl@0
|
167 |
rawDisk->SetChanged();
|
sl@0
|
168 |
return(r);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
TInt TFsRawDiskWrite::Initialise(CFsRequest* aRequest)
|
sl@0
|
172 |
//
|
sl@0
|
173 |
//
|
sl@0
|
174 |
//
|
sl@0
|
175 |
{
|
sl@0
|
176 |
if (!KCapFsRawDiskWrite.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Raw Disk Write")))
|
sl@0
|
177 |
return KErrPermissionDenied;
|
sl@0
|
178 |
CRawDiskCB* rawDisk=GetRawDiskFromHandle(aRequest->Message().Int3(),aRequest->Session());
|
sl@0
|
179 |
if(!rawDisk)
|
sl@0
|
180 |
return(KErrBadHandle);
|
sl@0
|
181 |
if(rawDisk->IsWriteProtected())
|
sl@0
|
182 |
return(KErrAccessDenied);
|
sl@0
|
183 |
aRequest->SetDrive(&rawDisk->Drive());
|
sl@0
|
184 |
aRequest->SetScratchValue((TUint)rawDisk);
|
sl@0
|
185 |
return KErrNone;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
CRawDiskCB::CRawDiskCB()
|
sl@0
|
189 |
//
|
sl@0
|
190 |
// Constructor
|
sl@0
|
191 |
//
|
sl@0
|
192 |
{
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
CRawDiskCB::~CRawDiskCB()
|
sl@0
|
196 |
//
|
sl@0
|
197 |
// Destructor
|
sl@0
|
198 |
//
|
sl@0
|
199 |
{
|
sl@0
|
200 |
if(iMount)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
__ASSERT_DEBUG(iMount->LockStatus()>0,Fault(ERawDiskBadAccessCount));
|
sl@0
|
203 |
RemoveDiskAccess(*iMount);
|
sl@0
|
204 |
if(IsChanged())
|
sl@0
|
205 |
iMount->Drive().SetChanged(ETrue);
|
sl@0
|
206 |
iMount->Close();
|
sl@0
|
207 |
}
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
void CRawDiskCB::InitL(CMountCB* aMount,TBool aIsWriteProtected)
|
sl@0
|
211 |
//
|
sl@0
|
212 |
// Initialise
|
sl@0
|
213 |
//
|
sl@0
|
214 |
{
|
sl@0
|
215 |
DoInitL(aMount->Drive().DriveNumber());
|
sl@0
|
216 |
iMount=aMount;
|
sl@0
|
217 |
if(aIsWriteProtected)
|
sl@0
|
218 |
SetWriteProtected();
|
sl@0
|
219 |
User::LeaveIfError(iMount->Open());
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|