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