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 21 | e7d2d738d3c2 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2004-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 |
// CMassStorageFileSystem implementation. |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#include <f32file.h> |
|
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#include <f32ver.h> |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
#include "cusbmassstoragecontroller.h" |
0 | 26 |
#include "cmassstoragefilesystem.h" |
27 |
#include "cmassstoragemountcb.h" |
|
28 |
#include "massstoragedebug.h" |
|
29 |
#include "massstorage.h" |
|
30 |
||
31 |
_LIT(KMsFsyName, "MassStorageFileSystem"); |
|
32 |
_LIT(KMsThreadName, "MassStorageThread"); |
|
33 |
_LIT(KMsDeadThreadName, "MassStorageDeadThread"); |
|
34 |
_LIT(KMsFsysSemName, "MassStorageSemaphore"); |
|
35 |
LOCAL_D const TInt KMsFsyMajorVersionNumber=1; |
|
36 |
LOCAL_D const TInt KMsFsyMinorVersionNumber=0; |
|
37 |
||
38 |
CMassStorageFileSystem::CMassStorageFileSystem() |
|
39 |
{ |
|
40 |
} |
|
41 |
||
42 |
CMassStorageFileSystem::~CMassStorageFileSystem() |
|
43 |
{ |
|
44 |
//Kill the controller thread if it exists |
|
45 |
delete iMassStorageController; |
|
46 |
delete iMediaChanged; |
|
47 |
RThread thread; |
|
48 |
TInt err = thread.Open(KMsThreadName); |
|
49 |
if (err == KErrNone) |
|
50 |
{ |
|
51 |
thread.Kill(1); //Parameter is irrelevant |
|
52 |
} |
|
53 |
thread.Close(); |
|
54 |
iMsDrives.Close(); |
|
55 |
} |
|
56 |
||
57 |
CMassStorageFileSystem* CMassStorageFileSystem::NewL() |
|
58 |
{ |
|
59 |
CMassStorageFileSystem* self = new (ELeave) CMassStorageFileSystem(); |
|
60 |
CleanupStack::PushL(self); |
|
61 |
self->ConstructL(); |
|
62 |
CleanupStack::Pop(self); |
|
63 |
return self; |
|
64 |
} |
|
65 |
||
66 |
void CMassStorageFileSystem::ConstructL() |
|
67 |
{ |
|
68 |
iMediaChanged = new(ELeave) CArrayFixFlat<TBool>(KMaxDrives); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
Set the file system version and name |
|
73 |
||
74 |
@return Any of the standard Symbian error codes. |
|
75 |
*/ |
|
76 |
TInt CMassStorageFileSystem::Install() |
|
77 |
{ |
|
78 |
__PRINT(_L("CMassStorageFileSystem::Install In\n")); |
|
79 |
iVersion=TVersion(KMsFsyMajorVersionNumber, KMsFsyMinorVersionNumber, KF32BuildVersionNumber); |
|
80 |
TInt err = SetName(&KMsFsyName); |
|
81 |
__PRINT(_L("CMassStorageFileSystem::Install Out\n")); |
|
82 |
return err; |
|
83 |
} |
|
84 |
||
85 |
TInt CMassStorageFileSystem::Remove() |
|
86 |
{ |
|
87 |
__PRINT(_L("CMassStorageFileSystem::Remove In\n")); |
|
88 |
TInt err = KErrNone; |
|
89 |
if (iInstalled) |
|
90 |
{ |
|
91 |
// Try connecting to the server to send a shutdown message. |
|
92 |
// - If the class controller has a session in use, this will return KErrInUse |
|
93 |
RUsbMassStorage usbMs; |
|
94 |
err = usbMs.Connect(); |
|
95 |
if(err == KErrNone) |
|
96 |
{ |
|
97 |
err = usbMs.Shutdown(); |
|
98 |
usbMs.Close(); |
|
99 |
||
100 |
if(err == KErrNone) |
|
101 |
{ |
|
102 |
User::WaitForRequest(iThreadStat); |
|
103 |
err = iThreadStat.Int(); |
|
104 |
} |
|
105 |
else |
|
106 |
{ |
|
107 |
__PRINT1(_L("CMassStorageFileSystem::Remove Shutdown Error %d\n"),err); |
|
108 |
} |
|
109 |
} |
|
110 |
else |
|
111 |
{ |
|
112 |
__PRINT1(_L("CMassStorageFileSystem::Remove Connect Error %d\n"),err); |
|
113 |
} |
|
114 |
} |
|
115 |
__PRINT(_L("CMassStorageFileSystem::Remove Out\n")); |
|
116 |
return(err); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
Creates a new Mass Storage mount object. |
|
121 |
||
122 |
@return A new CMassStorageMountCB |
|
123 |
@leave KErrNotReady if the Mass Storage controller is not running. |
|
124 |
*/ |
|
125 |
CMountCB* CMassStorageFileSystem::NewMountL() const |
|
126 |
{ |
|
127 |
if (!iRunning) |
|
128 |
{ |
|
129 |
User::Leave(KErrNotReady); |
|
130 |
} |
|
131 |
return CMassStorageMountCB::NewL(iMsDrives); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
Sets the media attributes and type in the aInfo parameter to those of the specified drive. |
|
136 |
||
137 |
@param anInfo TDriveInfo object to store the drive information. |
|
138 |
@param aDriveNumber The number of the drive to get the information from. |
|
139 |
*/ |
|
140 |
void CMassStorageFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const |
|
141 |
{ |
|
142 |
__PRINT(_L("CMassStorageFileSystem::DriveInfo In\n")); |
|
143 |
TLocalDriveCapsV2Buf caps; |
|
144 |
if (!IsValidLocalDriveMapping(aDriveNumber)) |
|
145 |
{ |
|
146 |
return; |
|
147 |
} |
|
148 |
(void)GetLocalDrive(aDriveNumber).Caps(caps); |
|
149 |
// error ignored as Caps always returns valid Media and Drive attributes |
|
150 |
aInfo.iMediaAtt=caps().iMediaAtt; |
|
151 |
aInfo.iType = ::EMediaNotPresent; // Media is not available to the file system |
|
152 |
aInfo.iDriveAtt=caps().iDriveAtt; |
|
153 |
__PRINT(_L("CMassStorageFileSystem::DriveInfo Out\n")); |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
Returns a reference to the Mass Storage controller. |
|
158 |
||
159 |
@return Reference to the Mass Storage controller. |
|
160 |
*/ |
|
161 |
CUsbMassStorageController& CMassStorageFileSystem::Controller() |
|
162 |
{ |
|
163 |
return *iMassStorageController; |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
Fill iMsDrives with a mapping of lun->drive number for supported mass storage drives |
|
168 |
||
169 |
*/ |
|
170 |
TInt CMassStorageFileSystem::EnumerateMsDrivesL() |
|
171 |
{ |
|
172 |
__PRINT(_L("CMassStorageFileSystem::EnumerateMsDrives In\n")); |
|
173 |
iMsDrives.Reset(); |
|
174 |
TInt driveCount = 0; |
|
175 |
||
176 |
TLocalDriveCapsV2Buf caps; |
|
177 |
for (TInt i = EDriveC; i < KMaxDrives; i++) |
|
178 |
{ |
|
179 |
caps.FillZ(); |
|
180 |
||
181 |
if (IsValidLocalDriveMapping(i)) |
|
182 |
{ |
|
183 |
TInt err = GetLocalDrive(i).Caps(caps); |
|
184 |
TInt locDrvNum = DriveNumberToLocalDriveNumber(i); |
|
185 |
__PRINT2(_L("Caps: err=%d, att=%d\n"), err, caps().iDriveAtt); |
|
186 |
||
187 |
TBool isRemovable = err==KErrNotReady || (caps().iDriveAtt & KDriveAttRemovable); |
|
188 |
__PRINT2(_L("EnumerateMsDrives: Drive %c: is %sremovable\n"), |
|
189 |
'A'+i-EDriveA, |
|
190 |
isRemovable?_S(""):_S("NOT ")); |
|
191 |
||
192 |
if (isRemovable) |
|
193 |
{ |
|
194 |
// |
|
195 |
// STF: Connect to the local drive here. This gives us the media changed flag, and |
|
196 |
// our own TBusLocalDrive object for use by the proxy drive and controller. |
|
197 |
// |
|
198 |
TBool& mediaChanged = (*iMediaChanged).ExtendL(); |
|
199 |
mediaChanged = EFalse; |
|
200 |
TBusLocalDrive* localDrive = new(ELeave) TBusLocalDrive; |
|
201 |
iLocalDriveForMediaFlag.Append(*localDrive); |
|
202 |
||
203 |
TInt err=iLocalDriveForMediaFlag[driveCount].Connect(locDrvNum, mediaChanged); |
|
204 |
if(err == KErrNone) |
|
205 |
{ |
|
206 |
iMsDrives.Append(i); |
|
207 |
} |
|
208 |
driveCount++; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
||
213 |
__PRINT1(_L("CMassStorageFileSystem::EnumerateMsDrives Out, %d MS drives found\n"), driveCount); |
|
214 |
return driveCount; |
|
215 |
} |
|
216 |
||
217 |
TBool CMassStorageFileSystem::IsExtensionSupported() const |
|
218 |
{ |
|
219 |
return ETrue; |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
Creates a TrapCleanup and ActiveScheduler and initializes the Mass Storage controller. |
|
224 |
Start the ActiveScheduler. |
|
225 |
||
226 |
@return Any of the standard Symbian error codes. |
|
227 |
*/ |
|
228 |
TInt CMassStorageFileSystem::InitThread() |
|
229 |
{ |
|
230 |
__PRINT(_L("CMassStorageFileSystem::InitThread In\n")); |
|
231 |
||
232 |
//Give the thread a name so we can kill it later |
|
233 |
User::RenameThread(KMsThreadName); |
|
234 |
||
235 |
CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
236 |
if (cleanup == NULL) |
|
237 |
{ |
|
238 |
return KErrNoMemory; |
|
239 |
} |
|
240 |
||
241 |
TRAPD(err, InitThreadL()); |
|
242 |
||
243 |
delete cleanup; |
|
244 |
||
245 |
__PRINT1(_L("CMassStorageFileSystem::InitThread Out, error=%d\n"), err); |
|
246 |
return err; |
|
247 |
} |
|
248 |
||
249 |
TInt CMassStorageFileSystem::InitThreadL() |
|
250 |
{ |
|
251 |
__PRINT(_L("CMassStorageFileSystem::InitThreadL In\n")); |
|
252 |
||
253 |
RSemaphore gSemThreadReady; |
|
254 |
||
255 |
TInt ret = gSemThreadReady.OpenGlobal(KMsFsysSemName); |
|
256 |
||
257 |
if (ret != KErrNone && ret != KErrAlreadyExists) |
|
258 |
{ |
|
259 |
User::Leave(ret); |
|
260 |
} |
|
261 |
||
262 |
// Determine which drives are available for Mass Storage. |
|
263 |
// (this also creates a local TBusLocalDrive for use by the drive controller) |
|
264 |
EnumerateMsDrivesL(); |
|
265 |
||
266 |
CActiveScheduler* sched = new CActiveScheduler; |
|
267 |
if (sched == NULL) |
|
268 |
{ |
|
269 |
gSemThreadReady.Signal(); |
|
270 |
User::Leave(KErrNoMemory); |
|
271 |
} |
|
272 |
CleanupStack::PushL(sched); |
|
273 |
CActiveScheduler::Install(sched); |
|
274 |
||
275 |
iMassStorageController = new CUsbMassStorageController; |
|
276 |
if (iMassStorageController == NULL) |
|
277 |
{ |
|
278 |
gSemThreadReady.Signal(); |
|
279 |
User::Leave(KErrNoMemory); |
|
280 |
} |
|
281 |
||
282 |
__PRINT(_L("CMassStorageFileSystem::InitThread: Creating Mass Storage Controller\n")); |
|
283 |
TRAPD(err, iMassStorageController->CreateL(iMsDrives)); |
|
284 |
if (err != KErrNone) |
|
285 |
{ |
|
286 |
gSemThreadReady.Signal(); |
|
287 |
CActiveScheduler::Install(NULL); |
|
288 |
User::Leave(err); |
|
289 |
} |
|
290 |
||
291 |
CleanupStack::Pop(sched); |
|
292 |
||
293 |
iRunning = ETrue; |
|
294 |
gSemThreadReady.Signal(); |
|
295 |
gSemThreadReady.Close(); |
|
296 |
CActiveScheduler::Start(); |
|
297 |
||
298 |
//========= stop thread ================ |
|
299 |
delete iMassStorageController; |
|
300 |
iMassStorageController = NULL; |
|
301 |
TInt i=0; |
|
302 |
for (;i<iLocalDriveForMediaFlag.Count();i++) |
|
303 |
{ |
|
304 |
iLocalDriveForMediaFlag[i].Disconnect(); |
|
305 |
} |
|
306 |
iLocalDriveForMediaFlag.Reset(); |
|
307 |
(*iMediaChanged).Reset(); |
|
308 |
delete sched; |
|
309 |
iRunning = EFalse; |
|
310 |
||
311 |
__PRINT(_L("CMassStorageFileSystem::InitThread Out\n")); |
|
312 |
return KErrNone; |
|
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
Not supported in Mass Storage file system. |
|
317 |
||
318 |
@leave KErrNotReady |
|
319 |
*/ |
|
320 |
CFileCB* CMassStorageFileSystem::NewFileL() const |
|
321 |
{ |
|
322 |
__PRINT(_L("CMassStorageFileSystem::NewFileL In\n")); |
|
323 |
User::Leave(KErrNotReady); |
|
324 |
return NULL; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
Not supported in Mass Storage file system. |
|
329 |
||
330 |
@leave KErrNotReady |
|
331 |
*/ |
|
332 |
CDirCB* CMassStorageFileSystem::NewDirL() const |
|
333 |
{ |
|
334 |
User::Leave(KErrNotReady); |
|
335 |
return NULL; |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
Not supported in Mass Storage file system. |
|
340 |
||
341 |
@leave KErrNotReady |
|
342 |
*/ |
|
343 |
CFormatCB* CMassStorageFileSystem::NewFormatL() const |
|
344 |
{ |
|
345 |
User::Leave(KErrNotReady); |
|
346 |
return NULL; |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
Not supported in Mass Storage file system. |
|
351 |
||
352 |
@return KErrNotSupported |
|
353 |
*/ |
|
354 |
TInt CMassStorageFileSystem::DefaultPath(TDes& /*aPath*/) const |
|
355 |
{ |
|
356 |
return KErrNotSupported; |
|
357 |
} |
|
358 |
||
359 |
/** |
|
360 |
Not supported in Mass Storage file system. |
|
361 |
||
362 |
@return KErrNotSupported |
|
363 |
*/ |
|
364 |
TInt CMassStorageFileSystem::DriveList(TDriveList& /*aList*/) const |
|
365 |
{ |
|
366 |
return KErrNotSupported; |
|
367 |
} |
|
368 |
||
369 |
/** |
|
370 |
Thread entry point. |
|
371 |
*/ |
|
372 |
LOCAL_C TInt MsInitThreadFn(TAny* aPtr) |
|
373 |
{ |
|
374 |
User::SetCritical(User::ESystemCritical); |
|
375 |
((CMassStorageFileSystem*)aPtr)->InitThread(); |
|
376 |
//Rename the thread so we can create a new one with the same original name later |
|
377 |
User::RenameThread(KMsDeadThreadName); |
|
378 |
return KErrNone; |
|
379 |
} |
|
380 |
||
381 |
/** |
|
382 |
Standard entry point for file systems. |
|
383 |
Creates a new file system object and starts a new thread for the Mass Storage controller. |
|
384 |
*/ |
|
385 |
extern "C" EXPORT_C CFileSystem* CreateFileSystem() |
|
386 |
{ |
|
387 |
__PRINT(_L("CMassStorageFileSystem::CreateFileSystem In\n")); |
|
388 |
RSemaphore gSemThreadReady; |
|
389 |
TInt err = gSemThreadReady.CreateGlobal(KMsFsysSemName, 0); |
|
390 |
if (err != KErrNone) |
|
391 |
{ |
|
392 |
__PRINT1(_L("CMassStorageFileSystem::CreateFileSystem Out Semaphore Error %d\n"),err); |
|
393 |
return NULL; |
|
394 |
} |
|
395 |
||
396 |
CFileSystem* msFsys = NULL; |
|
397 |
TRAP(err, msFsys = CMassStorageFileSystem::NewL()); |
|
398 |
if (err != KErrNone) |
|
399 |
{ |
|
400 |
__PRINT1(_L("CMassStorageFileSystem::CreateFileSystem Out MSFS Error %d\n"),err); |
|
401 |
gSemThreadReady.Close(); |
|
402 |
return NULL; |
|
403 |
} |
|
404 |
||
405 |
RThread msThread; |
|
406 |
__PRINT(_L("CMassStorageFileSystem::CreateFileSystem: Creating Mass Storage thread\n")); |
|
407 |
err = msThread.Create(KMsThreadName, MsInitThreadFn, KDefaultStackSize, NULL, msFsys); |
|
408 |
if (err != KErrNone) |
|
409 |
{ |
|
410 |
__PRINT1(_L("CMassStorageFileSystem::CreateFileSystem Out Thread Error %d\n"),err); |
|
411 |
gSemThreadReady.Close(); |
|
412 |
return msFsys; |
|
413 |
} |
|
414 |
((CMassStorageFileSystem*)msFsys)->iInstalled=ETrue; |
|
415 |
||
416 |
||
417 |
msThread.Logon(((CMassStorageFileSystem*)msFsys)->iThreadStat); |
|
418 |
msThread.Resume(); |
|
419 |
gSemThreadReady.Wait(); |
|
420 |
gSemThreadReady.Close(); |
|
421 |
msThread.Close(); |
|
422 |
||
423 |
__PRINT(_L("CMassStorageFileSystem::CreateFileSystem Out Clean\n")); |
|
424 |
||
425 |
return msFsys; |
|
426 |
} |
|
427 |