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