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