author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 41 | 0ffb4e86fcc9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2002-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 |
// |
|
15 |
||
16 |
#include "sf_std.h" |
|
17 |
#include "e32cmn.h" |
|
18 |
||
19 |
#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
20 |
#include "sf_notifier.h" |
|
21 |
#endif |
|
22 |
||
23 |
GLREF_C CProxyDriveFactory* GetExtension(const TDesC& aName); |
|
24 |
GLREF_C CExtProxyDriveFactory* GetProxyDriveFactory(const TDesC& aName); |
|
25 |
||
26 |
TBusLocalDrive LocalDrives::iLocalDrives[KMaxLocalDrives]; |
|
27 |
TInt LocalDrives::iMapping[KMaxDrives]; |
|
28 |
TInt LocalDrives::iReverseMapping[KMaxLocalDrives]; |
|
29 |
TBool LocalDrives::iMappingSet; |
|
30 |
LocalDrives::TSocketDesc LocalDrives::iSocketDescs[KMaxPBusSockets]; |
|
31 |
CExtProxyDrive* LocalDrives::iProxyDriveMapping[KMaxProxyDrives]; |
|
32 |
TBool LocalDrives::iIsMultiSlotDrive[KMaxDrives]; |
|
33 |
const TInt KInvalidSocketNumber = -1; |
|
34 |
||
35 |
void LocalDrives::Initialise() |
|
36 |
// |
|
37 |
// |
|
38 |
// |
|
39 |
{ |
|
40 |
iMappingSet = EFalse; |
|
41 |
TInt i; |
|
42 |
Mem::FillZ((TAny*)iProxyDriveMapping,sizeof(CExtProxyDriveFactory*)*KMaxProxyDrives); |
|
43 |
// initialise mapping from drive number to local drive |
|
44 |
for(i=0;i<KMaxDrives;i++) |
|
45 |
{ |
|
46 |
iMapping[i] = KDriveInvalid; |
|
47 |
iIsMultiSlotDrive[i] = EFalse; |
|
48 |
} |
|
49 |
// initialise reverse mapping from local drive to drive. |
|
50 |
for(i=0;i<KMaxLocalDrives;i++) |
|
51 |
{ |
|
52 |
iReverseMapping[i] = KDriveInvalid; |
|
53 |
} |
|
54 |
// initialise mapping from socket number to drive numbers |
|
55 |
for(i=0;i<KMaxPBusSockets;++i) |
|
56 |
{ |
|
57 |
TSocketDesc& socketDesc = iSocketDescs[i]; |
|
58 |
socketDesc.iMediaType = EInvalidMedia; |
|
59 |
socketDesc.iControllerRelativeSocket = KInvalidSocketNumber; |
|
60 |
for(TInt j=0;j<KMaxDrivesPerSocket;++j) |
|
61 |
socketDesc.iDriveNumbers[j]=KDriveInvalid; |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
// Searches for a local socket which matches the media type and |
|
66 |
// controller relative socket number. |
|
67 |
// If none is found then this function returns a new socket number. |
|
68 |
// If no more free sockets available, returns KErrNoMemory |
|
69 |
TInt LocalDrives::GetLocalSocket(TInt aControllerRelativeSocket, TMediaDevice aMediaType) |
|
70 |
{ |
|
71 |
TInt i; |
|
72 |
TSocketDesc* socketDesc = NULL; |
|
73 |
for (i=0; i<KMaxPBusSockets; i++) |
|
74 |
{ |
|
75 |
socketDesc = &iSocketDescs[i]; |
|
76 |
TMediaDevice mediaType = socketDesc->iMediaType; |
|
77 |
if (mediaType == aMediaType && socketDesc->iControllerRelativeSocket == aControllerRelativeSocket) |
|
78 |
return i; |
|
79 |
if (mediaType == EInvalidMedia) // socket unassigned ? |
|
80 |
break; |
|
81 |
} |
|
82 |
if (i == KMaxPBusSockets) |
|
83 |
return KErrNoMemory; |
|
84 |
||
85 |
// assign a new local socket for this controller relative socket number & media type |
|
86 |
socketDesc->iMediaType = aMediaType; |
|
87 |
socketDesc->iControllerRelativeSocket = aControllerRelativeSocket; |
|
88 |
||
89 |
return i; |
|
90 |
} |
|
91 |
||
92 |
TBusLocalDrive& LocalDrives::GetLocalDrive(TInt aDrive) |
|
93 |
// |
|
94 |
// Export localdrives |
|
95 |
// |
|
96 |
{ |
|
97 |
__ASSERT_DEBUG(aDrive>=0 && aDrive<KMaxDrives,Fault(EGetLocalDrive1)); |
|
98 |
__ASSERT_DEBUG(iMapping[aDrive]!=KDriveInvalid && iMapping[aDrive]<KMaxLocalDrives,Fault(EGetLocalDrive2)); |
|
99 |
return(iLocalDrives[iMapping[aDrive]]); |
|
100 |
} |
|
101 |
||
102 |
||
103 |
TInt LocalDrives::GetLocalDriveNumber(TBusLocalDrive* aLocDrv) |
|
104 |
// |
|
105 |
// Get the local drive number for the local drive object passed in |
|
106 |
// |
|
107 |
{ |
|
108 |
for(TInt i=0;i<KMaxLocalDrives;++i) |
|
109 |
if(&iLocalDrives[i]==aLocDrv) |
|
110 |
return(i); |
|
111 |
return(KDriveInvalid); |
|
112 |
} |
|
113 |
||
114 |
||
115 |
||
116 |
CExtProxyDrive* LocalDrives::GetProxyDrive(TInt aDrive) |
|
117 |
{ |
|
118 |
__ASSERT_DEBUG(aDrive>=0 && aDrive<KMaxDrives,Fault(EGetProxyDriveMapping1)); |
|
119 |
__ASSERT_DEBUG(iMapping[aDrive]!=KDriveInvalid && iMapping[aDrive]>=KMaxLocalDrives && iMapping[aDrive]<KMaxDrives,Fault(EGetProxyDriveMapping1)); |
|
120 |
return iProxyDriveMapping[iMapping[aDrive]-KMaxLocalDrives]; |
|
121 |
} |
|
122 |
||
123 |
||
124 |
LOCAL_C TBool DriveNumberIsInRange(TInt aDrive) |
|
125 |
{ |
|
126 |
||
127 |
return((aDrive>=0) && (aDrive<KMaxDrives)); |
|
128 |
} |
|
129 |
||
130 |
||
131 |
TBool LocalDrives::IsValidDriveMapping(TInt aDrive) |
|
132 |
// |
|
133 |
// Is the drive number to local drive mapping valid? |
|
134 |
// |
|
135 |
{ |
|
136 |
||
137 |
__ASSERT_DEBUG(DriveNumberIsInRange(aDrive),Fault(EIsValidDriveMapping)); |
|
138 |
return(iMapping[aDrive]!=KDriveInvalid); |
|
139 |
} |
|
140 |
||
141 |
||
142 |
TInt LocalDrives::DriveNumberToLocalDriveNumber(TInt aDrive) |
|
143 |
// |
|
144 |
// Get the mapping from drive number to local drive |
|
145 |
// |
|
146 |
{ |
|
147 |
return(iMapping[aDrive]); |
|
148 |
} |
|
149 |
||
150 |
||
151 |
TInt LocalDrives::SetDriveMappingL(CFsRequest* aRequest) |
|
152 |
// |
|
153 |
// |
|
154 |
// |
|
155 |
{ |
|
156 |
||
157 |
__PRINT(_L("LocalDrives::SetDriveMappingL()")); |
|
158 |
if (iMappingSet) |
|
159 |
return(KErrAccessDenied); |
|
160 |
||
161 |
TLocalDriveMappingInfoBuf mBuf; |
|
162 |
mBuf.FillZ(); |
|
163 |
aRequest->ReadL(KMsgPtr0,mBuf); |
|
164 |
TLocalDriveMappingInfo& ldmi=mBuf(); |
|
165 |
||
166 |
if (ldmi.iOperation==TLocalDriveMappingInfo::ESwapIntMappingAndSet) |
|
167 |
{ |
|
168 |
// Only the 1st two entries of the mapping table are valid - holding the drive numbers to be swapped |
|
169 |
TInt r=KErrNone; |
|
170 |
if (DriveNumberIsInRange(ldmi.iDriveMapping[0]) && DriveNumberIsInRange(ldmi.iDriveMapping[1])) |
|
171 |
r=SwapDriveMapping(ldmi.iDriveMapping[0],ldmi.iDriveMapping[1]); |
|
172 |
iMappingSet=ETrue; |
|
173 |
return(r); |
|
174 |
} |
|
175 |
||
176 |
// That just leaves EWriteMappingsAndSet and EWriteMappingsNoSet |
|
177 |
for (TInt i=0;i<KMaxLocalDrives;++i) |
|
178 |
{ |
|
179 |
TInt driveLetter=ldmi.iDriveMapping[i]; |
|
180 |
if(driveLetter==KDriveInvalid) |
|
181 |
continue; |
|
182 |
if ( !DriveNumberIsInRange(driveLetter)) |
|
183 |
{ |
|
184 |
// invalid mapping list passed in, clear all mappings set up |
|
185 |
for(TInt j=0;j<KMaxDrives;j++) |
|
186 |
iMapping[j] = KDriveInvalid; |
|
187 |
return(KErrArgument); |
|
188 |
} |
|
189 |
__PRINT2(_L("drive letter %d -> local drive %d"),driveLetter,i); |
|
190 |
||
191 |
// If this mapping (letter -> localdrive) is already set then |
|
192 |
// this must be a multislot device. Save this mapping as an |
|
193 |
// alternative mapping (by storing it in iReverseMapping) |
|
194 |
if(iMapping[driveLetter] != KDriveInvalid) |
|
195 |
{ |
|
196 |
iIsMultiSlotDrive[driveLetter] = ETrue; |
|
197 |
} |
|
198 |
// first time we've seen this drive letter |
|
199 |
iMapping[driveLetter]=i; |
|
200 |
// following mapping is used when we want to swap back again. |
|
201 |
iReverseMapping[i]=driveLetter; |
|
202 |
} |
|
203 |
||
204 |
InitDriveMapping(); |
|
205 |
if (ldmi.iOperation==TLocalDriveMappingInfo::EWriteMappingsAndSet) |
|
206 |
iMappingSet=ETrue; |
|
207 |
return(KErrNone); |
|
208 |
} |
|
209 |
||
210 |
// Changes here must be reflected in SwapDriveMapping() |
|
211 |
void LocalDrives::InitDriveMapping() |
|
212 |
{ |
|
213 |
__PRINT(_L("InitDriveMapping()")); |
|
214 |
TDriveInfoV1Buf driveInfo; |
|
215 |
TInt r=UserHal::DriveInfo(driveInfo); |
|
216 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EInitDriveMappingDriveInfo)); |
|
217 |
||
218 |
// initialise the local drives |
|
219 |
TInt i; |
|
220 |
for(i=0;i<KMaxLocalDrives;++i) |
|
221 |
{ |
|
222 |
TInt driveNo = iReverseMapping[i]; |
|
223 |
if(driveNo!=KDriveInvalid) |
|
224 |
{ |
|
225 |
r=iLocalDrives[i].Connect(i,TheDrives[driveNo].iChanged); |
|
226 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EInitConnectLocalDrive)); |
|
227 |
__PRINT2(_L("connect to locdrv %d using drive %d"),i,driveNo); |
|
228 |
//If this is a multislot then we need to set the iChanged to True |
|
229 |
//So that we are mapped to the correct drive when we're booted. |
|
230 |
if(iIsMultiSlotDrive[driveNo]) |
|
231 |
{ |
|
232 |
TheDrives[driveNo].iChanged = ETrue; |
|
233 |
} |
|
234 |
if (driveInfo().iDriveName[i].Length()==0) |
|
235 |
continue; |
|
236 |
TheDriveNames[driveNo]=driveInfo().iDriveName[i].Alloc(); |
|
237 |
__ASSERT_ALWAYS(TheDriveNames[driveNo],Fault(EInitCreateDriveName)); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
TInt drivesPerSocket[KMaxPBusSockets]; |
|
242 |
Mem::FillZ(&drivesPerSocket,KMaxPBusSockets*sizeof(TInt)); |
|
243 |
TInt nSockets=driveInfo().iTotalSockets; |
|
244 |
for(i=0;i<KMaxLocalDrives;++i) |
|
245 |
{ |
|
246 |
TInt socket; |
|
247 |
if(iLocalDrives[i].Handle()==0 || !iLocalDrives[i].IsRemovable(socket)) |
|
248 |
{ |
|
249 |
TInt driveNo = iReverseMapping[i]; |
|
250 |
// Non-removable drive so shouldn't be listed as a Multislot drive |
|
251 |
// Drives such as composite drives may have been |
|
252 |
// set to true as the drive letter had been encountered before. |
|
253 |
// make sure those drives are set to false here. |
|
254 |
iIsMultiSlotDrive[driveNo]=EFalse; |
|
255 |
continue; |
|
256 |
} |
|
257 |
__ASSERT_ALWAYS(socket>=0 && socket<nSockets,Fault(EInitDriveMappingSocketNo)); |
|
258 |
TInt drv=GetDriveFromLocalDrive(i); |
|
259 |
// get local socket number |
|
260 |
TMediaDevice mediaDevice = iLocalDrives[i].MediaDevice(); |
|
261 |
TInt localSocket = LocalDrives::GetLocalSocket(socket, mediaDevice); |
|
262 |
__ASSERT_ALWAYS(localSocket>=0 && localSocket<KMaxPBusSockets,Fault(EInitDriveMappingSocketNo)); |
|
263 |
__PRINT4(_L("InitDriveMapping(), i = %d, , mediaDevice = %d, socket = %d, localSocket = %d"), |
|
264 |
i, mediaDevice, socket, localSocket); |
|
265 |
__PRINT2(_L("drv = %d (%C:)"), drv, 'A' + drv); |
|
266 |
||
267 |
TSocketDesc& socketDesc = iSocketDescs[localSocket]; |
|
268 |
if(drv!=KDriveInvalid) |
|
269 |
{ |
|
270 |
TInt& count = drivesPerSocket[localSocket]; |
|
271 |
// setup up socket to drive mapping |
|
272 |
__ASSERT_ALWAYS(count < KMaxDrivesPerSocket,Fault(ETooManyDrivesPerSocket)); |
|
273 |
socketDesc.iDriveNumbers[count]=drv; |
|
274 |
if(count==0) |
|
275 |
{ |
|
276 |
// setup media change notifier if this is first local drive found on socket |
|
277 |
CNotifyMediaChange* pN=new CNotifyMediaChange(&iLocalDrives[i],localSocket); |
|
278 |
__ASSERT_ALWAYS(pN!=NULL,Fault(EInitCreateMediaChangeNotifier)); |
|
279 |
__PRINT2(_L("created CNotifyMediaChange media 0x%x using local drive %d"), localSocket,i); |
|
280 |
socketDesc.iMediaChanges = pN; |
|
281 |
CActiveSchedulerFs::Add(pN); |
|
282 |
pN->RunL(); |
|
283 |
} |
|
284 |
++count; |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
TInt LocalDrives::InitProxyDrive(CFsRequest* aRequest) |
|
290 |
{ |
|
291 |
__PRINT(_L("LocalDrives::InitProxyDrive")); |
|
292 |
||
293 |
TInt drive = aRequest->Message().Int0() ; |
|
294 |
||
295 |
if (drive < 0 || drive >= KMaxDrives) |
|
296 |
return KErrArgument; |
|
297 |
||
298 |
if (drive!=EDriveZ && iMapping[drive]!=KDriveInvalid) |
|
299 |
return KErrInUse; // Z is special case for composite |
|
300 |
||
301 |
TFullName extname; |
|
302 |
aRequest->ReadL(KMsgPtr1,extname); |
|
303 |
||
304 |
// leave info thing for now |
|
305 |
CExtProxyDriveFactory* pF = GetProxyDriveFactory(extname); |
|
306 |
if (!pF) |
|
307 |
return KErrArgument; // that extension has not been added |
|
308 |
FsThreadManager::LockDrive(drive); |
|
309 |
// find a free mapping to place this drive into |
|
310 |
TInt i; |
|
311 |
for (i=0; i <KMaxProxyDrives; i++) |
|
312 |
{ |
|
313 |
if (!iProxyDriveMapping[i]) |
|
314 |
break; |
|
315 |
} |
|
316 |
FsThreadManager::UnlockDrive(drive); |
|
317 |
if (i==KMaxProxyDrives) |
|
318 |
return KErrInUse; // there are no free proxy drives left |
|
319 |
||
320 |
// Create the actual proxy drive... |
|
321 |
CProxyDrive* pD = NULL; |
|
322 |
TInt r = pF->CreateProxyDrive(pD, NULL); |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
323 |
if (r != KErrNone) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
324 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
325 |
delete pD; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
326 |
return r; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
327 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
328 |
if (pD == NULL) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
329 |
return KErrNoMemory; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
330 |
|
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
331 |
// Create the proxy drive body... which is used to store the library handle |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
332 |
CProxyDriveBody* pBody = new CProxyDriveBody(); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
333 |
if (pBody == NULL) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
334 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
335 |
delete pD; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
336 |
return KErrNoMemory; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
337 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
338 |
pD->iBody = pBody; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
339 |
|
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
340 |
// Re-open the library so that it is safe to call RFs::RemoveProxyDrive() before the proxy drive has been deleted - |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
341 |
// which can happen if the file system is dismounted with open file handles |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
342 |
r = pD->SetAndOpenLibrary(pF->Library()); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
343 |
if (r != KErrNone) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
344 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
345 |
delete pD; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
346 |
return r; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
347 |
} |
0 | 348 |
|
349 |
iMapping[drive] = i+KMaxLocalDrives; |
|
350 |
||
351 |
aRequest->SetDrive(&TheDrives[drive]); |
|
352 |
aRequest->SetScratchValue((TUint)pD); |
|
353 |
||
354 |
return KErrNone; |
|
355 |
} |
|
356 |
||
357 |
TInt LocalDrives::MountProxyDrive(CFsRequest* aRequest) |
|
358 |
{ |
|
359 |
CExtProxyDrive* pProxyDrive = (CExtProxyDrive*)aRequest->ScratchValue(); |
|
360 |
__ASSERT_ALWAYS(pProxyDrive != NULL, User::Panic(_L("MountProxyDrive has NULL proxy extension class"), -999)); |
|
361 |
||
362 |
TInt driveNumber = aRequest->Drive()->DriveNumber(); |
|
363 |
||
364 |
||
365 |
TInt proxyDriveNo = iMapping[driveNumber] - KMaxLocalDrives; |
|
366 |
FsThreadManager::LockDrive(driveNumber); |
|
367 |
iProxyDriveMapping[proxyDriveNo] = pProxyDrive; |
|
368 |
pProxyDrive->SetDriveNumber(driveNumber); |
|
369 |
FsThreadManager::UnlockDrive(driveNumber); |
|
370 |
// |
|
371 |
// Pass initialisation information onto the extension to allow it to initialise |
|
372 |
// |
|
373 |
TInt err = pProxyDrive->SetInfo(aRequest->Message(), |
|
374 |
(TAny*)aRequest->Message().Ptr2(), |
|
375 |
(TAny*)aRequest->Message().Ptr3()); |
|
376 |
if (err != KErrNone) |
|
377 |
{ |
|
378 |
// |
|
379 |
// If we fail to initialise the extension, then close the drive (destroying the thread) |
|
380 |
// and remove the mapping so we can attempt to mount again in the future. |
|
381 |
// |
|
382 |
FsThreadManager::LockDrive(driveNumber); |
|
383 |
FsThreadManager::CloseDrive(driveNumber); |
|
384 |
ClearProxyDriveMapping(driveNumber); |
|
385 |
FsThreadManager::UnlockDrive(driveNumber); |
|
386 |
return err; |
|
387 |
} |
|
388 |
||
389 |
return(iMapping[driveNumber]); |
|
390 |
} |
|
391 |
||
392 |
TBool LocalDrives::IsProxyDrive(TInt aDrive) |
|
393 |
{ |
|
394 |
__ASSERT_ALWAYS(aDrive>=0 && aDrive<KMaxDrives,Fault(EIsProxyDrive)); |
|
395 |
return (iMapping[aDrive] >= KMaxLocalDrives); |
|
396 |
} |
|
397 |
||
398 |
TBool LocalDrives::IsProxyDriveInUse(CExtProxyDriveFactory* aDevice) |
|
399 |
{ |
|
400 |
for (TInt i=0; i < KMaxProxyDrives; i++) |
|
401 |
if (iProxyDriveMapping[i] && (iProxyDriveMapping[i]->FactoryP() == aDevice)) |
|
402 |
return(ETrue); |
|
403 |
||
404 |
return(EFalse); |
|
405 |
} |
|
406 |
||
407 |
void LocalDrives::ClearProxyDriveMapping(TInt aDrive) |
|
408 |
{ |
|
409 |
__ASSERT_ALWAYS(aDrive>=0 && aDrive<KMaxDrives,Fault(EClearProxyDriveMapping1)); |
|
410 |
__ASSERT_DEBUG(iMapping[aDrive]>= KMaxLocalDrives && iProxyDriveMapping[iMapping[aDrive]-KMaxLocalDrives],Fault(EClearProxyDriveMapping2)); |
|
411 |
TInt idx = iMapping[aDrive]-KMaxLocalDrives; |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
if (iProxyDriveMapping[idx]->Mount() == NULL) // don't delete if it's still owned by its mount |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
413 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
414 |
RLibrary lib = iProxyDriveMapping[idx]->GetLibrary(); |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
delete iProxyDriveMapping[idx]; |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
416 |
lib.Close(); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
417 |
} |
0 | 418 |
iProxyDriveMapping[idx] = NULL; |
419 |
iMapping[aDrive] = KDriveInvalid; |
|
420 |
} |
|
421 |
||
422 |
TInt LocalDrives::SetupMediaChange(TInt aDrive) |
|
423 |
{ |
|
424 |
CExtProxyDrive* pProxyDrive = LocalDrives::GetProxyDrive(aDrive); |
|
425 |
__ASSERT_ALWAYS(pProxyDrive != NULL,User::Panic(_L("SetupMediaChange - pProxyDrive == NULL"), ESetupMediaChange)); |
|
426 |
||
427 |
return pProxyDrive->SetupMediaChange(); |
|
428 |
} |
|
429 |
||
430 |
void LocalDrives::NotifyChangeCancel(TInt aDrive) |
|
431 |
{ |
|
432 |
CExtProxyDrive* pProxyDrive = LocalDrives::GetProxyDrive(aDrive); |
|
433 |
__ASSERT_ALWAYS(pProxyDrive != NULL,User::Panic(_L("NotifyChangeCancel - pProxyDrive == NULL"), ECancelNotifyChange)); |
|
434 |
||
435 |
pProxyDrive->NotifyChangeCancel(); |
|
436 |
} |
|
437 |
||
438 |
TInt LocalDrives::SwapDriveMapping(TInt aFirstDrive,TInt aSecondDrive) |
|
439 |
{ |
|
440 |
||
441 |
__PRINT(_L("SwapDriveMapping()")); |
|
442 |
TInt firstLocalDrv=iMapping[aFirstDrive]; |
|
443 |
TInt secondLocalDrv=iMapping[aSecondDrive]; |
|
444 |
||
445 |
// First, check this swap doesn't affect removable drives |
|
446 |
TInt socket; |
|
447 |
if (iLocalDrives[firstLocalDrv].Handle()!=0 && iLocalDrives[firstLocalDrv].IsRemovable(socket)) |
|
448 |
return(KErrAccessDenied); |
|
449 |
if (iLocalDrives[secondLocalDrv].Handle()!=0 && iLocalDrives[secondLocalDrv].IsRemovable(socket)) |
|
450 |
return(KErrAccessDenied); |
|
451 |
||
452 |
// Now swap the mappings over |
|
453 |
iMapping[aFirstDrive]=secondLocalDrv; |
|
454 |
iMapping[aSecondDrive]=firstLocalDrv; |
|
455 |
||
456 |
iReverseMapping[firstLocalDrv]=aSecondDrive; |
|
457 |
iReverseMapping[secondLocalDrv]=aFirstDrive; |
|
458 |
||
459 |
// Finally, swap the drive names over |
|
460 |
HBufC* drvName=TheDriveNames[aSecondDrive]; |
|
461 |
TheDriveNames[aSecondDrive]=TheDriveNames[aFirstDrive]; |
|
462 |
TheDriveNames[aFirstDrive]=drvName; |
|
463 |
return(KErrNone); |
|
464 |
} |
|
465 |
||
466 |
void LocalDrives::CompleteNotifications(TInt aSocket) |
|
467 |
// |
|
468 |
// |
|
469 |
// |
|
470 |
{ |
|
471 |
__ASSERT_DEBUG(aSocket>=0 && aSocket<KMaxPBusSockets && iSocketDescs[aSocket].iDriveNumbers[0]!=KDriveInvalid,Fault(ECompleteNotifSocketNo)); |
|
472 |
TInt i=0; |
|
473 |
||
474 |
// In a data-paging environment, the local media subsytem will only update the TDrive::iChanged flag |
|
475 |
// for drives which have a CNotifyMediaChange object, i.e. for drives which call TBusLocalDrive::NotifyChange(). |
|
476 |
// Since we only create ONE CNotifyMediaChange object for each socket (no matter how many partitions/local drives |
|
477 |
// are associated with that socket), we need to propagate the TDrive::iChanged flag to all drives on the socket. |
|
478 |
TBool changedFlag = TheDrives[iSocketDescs[aSocket].iDriveNumbers[0]].IsChanged(); |
|
479 |
||
480 |
while(i<KMaxDrivesPerSocket && iSocketDescs[aSocket].iDriveNumbers[i]!=KDriveInvalid) |
|
481 |
{ |
|
482 |
TheDrives[iSocketDescs[aSocket].iDriveNumbers[i]].SetChanged(changedFlag); |
|
483 |
CompleteDriveNotifications(iSocketDescs[aSocket].iDriveNumbers[i++]); |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
void LocalDrives::CompleteDriveNotifications(TInt aDrive) |
|
488 |
// |
|
489 |
// |
|
490 |
// |
|
491 |
{ |
|
492 |
// If the drive is hung, then don't complete any disk change |
|
493 |
// notifications until the request causing the hang completes |
|
494 |
if(FsThreadManager::IsDriveHung(aDrive)) |
|
495 |
FsThreadManager::SetMediaChangePending(aDrive); |
|
496 |
else |
|
497 |
{ |
|
498 |
FsNotify::DiskChange(aDrive); |
|
499 |
||
500 |
#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
501 |
if(FsNotificationManager::IsInitialised()) |
|
502 |
{ |
|
503 |
__PRINT3(_L("LocalDrives::CompleteDriveNotifications() Initialised=%d, Count=%d, Drive=%d"),FsNotificationManager::IsInitialised(),FsNotificationManager::Count(), aDrive); |
|
504 |
TBuf<2> driveDes; |
|
505 |
driveDes.Append((TChar)aDrive+(TChar)'A'); |
|
506 |
driveDes.Append((TChar)':'); |
|
507 |
FsNotificationManager::HandleChange(NULL,driveDes,TFsNotification::EMediaChange); |
|
508 |
} |
|
509 |
#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
510 |
||
511 |
//If this is a multislot device we should update mappings here. |
|
512 |
TheDrives[aDrive].MultiSlotDriveCheck(); |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
TInt LocalDrives::GetDriveFromLocalDrive(TInt aLocDrv) |
|
517 |
// |
|
518 |
// |
|
519 |
// |
|
520 |
{ |
|
521 |
return iReverseMapping[aLocDrv]; |
|
522 |
} |
|
523 |
||
524 |
||
525 |
CNotifyMediaChange::CNotifyMediaChange(RLocalDrive* aDrive,TInt aSocketNo) |
|
526 |
// |
|
527 |
// Constructor |
|
528 |
// |
|
529 |
: CActive(EPriorityHigh), iDrive(aDrive), iSocket(aSocketNo) |
|
530 |
{} |
|
531 |
||
532 |
void CNotifyMediaChange::RunL() |
|
533 |
// |
|
534 |
// Notification that a card has been mounted/removed |
|
535 |
// |
|
536 |
{ |
|
537 |
LocalDrives::CompleteNotifications(iSocket); |
|
538 |
iDrive->NotifyChange(&iStatus); |
|
539 |
SetActive(); |
|
540 |
} |
|
541 |
||
542 |
||
543 |
CExtNotifyMediaChange::CExtNotifyMediaChange(CExtProxyDrive* aDrive) |
|
544 |
// |
|
545 |
// Constructor |
|
546 |
// |
|
547 |
: CActive(EPriorityHigh), |
|
548 |
iDrive(aDrive), |
|
549 |
iPtr((TUint8*)&TheDrives[aDrive->DriveNumber()].iChanged,sizeof(TBool)) |
|
550 |
{ |
|
551 |
} |
|
552 |
||
553 |
||
554 |
CExtNotifyMediaChange* CExtNotifyMediaChange::NewL(CExtProxyDrive* aDrive) |
|
555 |
{ |
|
556 |
CExtNotifyMediaChange* pSelf = new(ELeave) CExtNotifyMediaChange(aDrive); |
|
557 |
||
558 |
CleanupStack::PushL(pSelf); |
|
559 |
pSelf->ConstructL(); |
|
560 |
CleanupStack::Pop(); |
|
561 |
||
562 |
return pSelf; |
|
563 |
} |
|
564 |
||
565 |
void CExtNotifyMediaChange::ConstructL() |
|
566 |
{ |
|
567 |
CActiveSchedulerFs::Add(this); |
|
568 |
||
569 |
TRAPD(err, RunL()); |
|
570 |
if(err != KErrNone) |
|
571 |
Deque(); |
|
572 |
||
573 |
User::LeaveIfError(err); |
|
574 |
} |
|
575 |
||
576 |
CExtNotifyMediaChange::~CExtNotifyMediaChange() |
|
577 |
{ |
|
578 |
Cancel(); |
|
579 |
} |
|
580 |
||
581 |
void CExtNotifyMediaChange::RequestL() |
|
582 |
{ |
|
583 |
if (!IsActive()) |
|
584 |
{ |
|
585 |
User::LeaveIfError(iDrive->NotifyChange(iPtr, &iStatus)); |
|
586 |
SetActive(); |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
void CExtNotifyMediaChange::DoCancel() |
|
591 |
{ |
|
592 |
iDrive->NotifyChangeCancel(); |
|
593 |
} |
|
594 |
||
595 |
void CExtNotifyMediaChange::RunL() |
|
596 |
{ |
|
597 |
if(iStatus==KErrDisconnected || iStatus==KErrCancel) |
|
598 |
return; |
|
599 |
||
600 |
TInt driveNum = iDrive->DriveNumber(); |
|
601 |
LocalDrives::CompleteDriveNotifications(driveNum); |
|
602 |
||
603 |
/* NOTE: We need SetChanged here though the iChanged variable is set in the MSC, since the cache is not getting cleared |
|
604 |
(inside the CompleteDriveNotifications call) during the initial first notification */ |
|
605 |
TheDrives[driveNum].SetChanged(ETrue); |
|
606 |
||
607 |
if(iStatus != KErrNotSupported) |
|
608 |
{ |
|
609 |
RequestL(); |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
||
614 |