0
|
1 |
// Copyright (c) 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 |
// CMassStorageMountCB implementation.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file
|
|
22 |
@internalTechnology
|
|
23 |
*/
|
|
24 |
|
|
25 |
#include <f32fsys.h>
|
|
26 |
|
|
27 |
#include "mstypes.h"
|
|
28 |
#include "msctypes.h"
|
|
29 |
|
|
30 |
#include "cmassstoragefilesystem.h"
|
|
31 |
#include "drivemanager.h"
|
|
32 |
|
|
33 |
|
|
34 |
#include "cusbmassstoragecontroller.h"
|
|
35 |
#include "cmassstoragemountcb.h"
|
|
36 |
#include "debug.h"
|
|
37 |
|
|
38 |
CMassStorageMountCB::CMassStorageMountCB(const TLunToDriveMap& aDriveMapping)
|
|
39 |
: iDriveMapping(aDriveMapping)
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
CMassStorageMountCB* CMassStorageMountCB::NewL(const TLunToDriveMap& aDriveMapping)
|
|
44 |
{
|
|
45 |
return new (ELeave) CMassStorageMountCB(aDriveMapping);
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
Checks that the drive number is supported.
|
|
50 |
|
|
51 |
@leave KErrNotReady The drive number is not supported.
|
|
52 |
*/
|
|
53 |
TInt CMassStorageMountCB::CheckDriveNumberL()
|
|
54 |
{
|
|
55 |
__FNLOG("CMassStorageMountCB::CheckDriveNumberL");
|
|
56 |
TInt driveNumber;
|
|
57 |
driveNumber = Drive().DriveNumber();
|
|
58 |
if (!IsValidLocalDriveMapping(driveNumber))
|
|
59 |
{
|
|
60 |
__PRINT1(_L("CMassStorageMountCB::CheckDriveNumberL: Drive number %d not supported"), driveNumber);
|
|
61 |
User::Leave(KErrNotReady);
|
|
62 |
}
|
|
63 |
__PRINT1(_L("CMassStorageMountCB::CheckDriveNumberL: Drive number = %d"), driveNumber);
|
|
64 |
return driveNumber;
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
Registers the drive with the Mass Storage drive manager.
|
|
69 |
|
|
70 |
@leave KErrNotSupported The drive is not compatible with Mass Storage.
|
|
71 |
*/
|
|
72 |
void CMassStorageMountCB::MountL(TBool /*aForceMount*/)
|
|
73 |
{
|
|
74 |
__FNLOG("CMassStorageMountCB::MountL");
|
|
75 |
|
|
76 |
CheckDriveNumberL();
|
|
77 |
CMassStorageFileSystem& msFsys = *reinterpret_cast<CMassStorageFileSystem*>(Drive().GetFSys());
|
|
78 |
|
|
79 |
TInt lun = DriveNumberToLun(Drive().DriveNumber());
|
|
80 |
|
|
81 |
if(lun < 0)
|
|
82 |
{
|
|
83 |
// This is not a supported Mass Storage drive
|
|
84 |
User::Leave(KErrNotSupported);
|
|
85 |
}
|
|
86 |
|
|
87 |
TBusLocalDrive& localDrive = msFsys.iMediaChangedStatusList[lun].iLocalDrive;
|
|
88 |
|
|
89 |
TInt err = CreateLocalDrive(localDrive);
|
|
90 |
User::LeaveIfError(err);
|
|
91 |
|
|
92 |
CProxyDrive* proxyDrive = LocalDrive();
|
|
93 |
|
|
94 |
TLocalDriveCapsV2Buf caps;
|
|
95 |
err = localDrive.Caps(caps);
|
|
96 |
|
|
97 |
//Make sure file system is FAT and removable
|
|
98 |
if (err == KErrNone)
|
|
99 |
{
|
|
100 |
err = KErrNotSupported;
|
|
101 |
if ((caps().iDriveAtt & KDriveAttRemovable) == KDriveAttRemovable)
|
|
102 |
{
|
|
103 |
if (caps().iType != EMediaNotPresent)
|
|
104 |
{
|
|
105 |
err = KErrNone;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
if (err != KErrNone && err != KErrNotReady)
|
|
111 |
{
|
|
112 |
__PRINT1(_L("CMassStorageMountCB::MountL: Drive is not compatible with Mass Storage, err=%d"), err);
|
|
113 |
User::Leave(err);
|
|
114 |
}
|
|
115 |
|
|
116 |
__PRINT(_L("CMassStorageMountCB::MountL: Registering drive"));
|
|
117 |
// Set media changed to true so that Win2K doesn't used cached drive data
|
|
118 |
TBool& mediaChanged = msFsys.iMediaChangedStatusList[lun].iMediaChanged;
|
|
119 |
mediaChanged = ETrue;
|
|
120 |
msFsys.Controller().DriveManager().RegisterDriveL(*proxyDrive, mediaChanged, lun);
|
|
121 |
SetVolumeName(_L("MassStorage").AllocL());
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
Returns the LUN that corresponds to the specified drive number.
|
|
126 |
|
|
127 |
@param aDriveNumber The drive number.
|
|
128 |
*/
|
|
129 |
TInt CMassStorageMountCB::DriveNumberToLun(TInt aDriveNumber)
|
|
130 |
{
|
|
131 |
__FNLOG("CMassStorageMountCB::DriveNumberToLun");
|
|
132 |
TInt lun = -1;
|
|
133 |
for (TInt i = 0; i < iDriveMapping.Count(); i++)
|
|
134 |
{
|
|
135 |
if (iDriveMapping[i] == aDriveNumber)
|
|
136 |
{
|
|
137 |
lun = i;
|
|
138 |
break;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
__PRINT2(_L("CMassStorageMountCB::DriveNumberToLun: Drive %d maps to LUN %d"), aDriveNumber, lun);
|
|
142 |
return lun;
|
|
143 |
}
|
|
144 |
|
|
145 |
/**
|
|
146 |
Deregisters the drive from the Drive Manager.
|
|
147 |
*/
|
|
148 |
void CMassStorageMountCB::Dismounted()
|
|
149 |
{
|
|
150 |
__FNLOG("CMassStorageMountCB::Dismounted");
|
|
151 |
TInt driveNumber = -1;
|
|
152 |
TRAPD(err, driveNumber = CheckDriveNumberL());
|
|
153 |
if (err != KErrNone)
|
|
154 |
{
|
|
155 |
return;
|
|
156 |
}
|
|
157 |
__PRINT(_L("CMassStorageMountCB::Dismounted: Deregistering drive"));
|
|
158 |
CMassStorageFileSystem& msFsys = *reinterpret_cast<CMassStorageFileSystem*>(Drive().GetFSys());
|
|
159 |
msFsys.Controller().DriveManager().DeregisterDrive(DriveNumberToLun(driveNumber));
|
|
160 |
|
|
161 |
DismountedLocalDrive();
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
165 |
Unlocks the drive with the specified password, optionally storing the password for later use.
|
|
166 |
|
|
167 |
@param aPassword The password to use for unlocking the drive.
|
|
168 |
@param aStore True if the password is to be stored.
|
|
169 |
*/
|
|
170 |
TInt CMassStorageMountCB::Unlock(TMediaPassword& aPassword, TBool aStore)
|
|
171 |
{
|
|
172 |
__FNLOG("CMassStorageMountCB::Unlock");
|
|
173 |
TInt driveNumber = -1;
|
|
174 |
TRAPD(err, driveNumber = CheckDriveNumberL());
|
|
175 |
if (err != KErrNone)
|
|
176 |
{
|
|
177 |
return err;
|
|
178 |
}
|
|
179 |
TBusLocalDrive& localDrive=GetLocalDrive(driveNumber);
|
|
180 |
if(localDrive.Status() == KErrLocked)
|
|
181 |
{
|
|
182 |
localDrive.Status() = KErrNotReady;
|
|
183 |
}
|
|
184 |
TInt r = localDrive.Unlock(aPassword, aStore);
|
|
185 |
if(r == KErrNone && aStore)
|
|
186 |
{
|
|
187 |
WritePasswordData();
|
|
188 |
}
|
|
189 |
return(r);
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
Stores the password for the drive to the password file.
|
|
194 |
*/
|
|
195 |
void CMassStorageMountCB::WritePasswordData()
|
|
196 |
{
|
|
197 |
__FNLOG("CMassStorageMountCB::WritePasswordData");
|
|
198 |
TBusLocalDrive& local=GetLocalDrive(Drive().DriveNumber());
|
|
199 |
TInt length = local.PasswordStoreLengthInBytes();
|
|
200 |
if(length==0)
|
|
201 |
{
|
|
202 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
|
|
203 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
204 |
WriteToDisk(mediaPWrdFile,_L8(""));
|
|
205 |
return;
|
|
206 |
}
|
|
207 |
HBufC8* hDes=HBufC8::New(length);
|
|
208 |
if(hDes==NULL)
|
|
209 |
{
|
|
210 |
return;
|
|
211 |
}
|
|
212 |
TPtr8 pDes=hDes->Des();
|
|
213 |
TInt r=local.ReadPasswordData(pDes);
|
|
214 |
if(r==KErrNone)
|
|
215 |
{
|
|
216 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
|
|
217 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
218 |
WriteToDisk(mediaPWrdFile,pDes);
|
|
219 |
}
|
|
220 |
delete hDes;
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
TInt CMassStorageMountCB::ReMount()
|
|
225 |
{
|
|
226 |
RDebug::Printf("CMassStorageMountCB::ReMount()");
|
|
227 |
return KErrNotReady;
|
|
228 |
}
|
|
229 |
|
|
230 |
void CMassStorageMountCB::VolumeL(TVolumeInfo& /*aVolume*/) const
|
|
231 |
{
|
|
232 |
User::Leave(KErrNotReady);
|
|
233 |
}
|
|
234 |
|
|
235 |
void CMassStorageMountCB::SetVolumeL(TDes& /*aName*/)
|
|
236 |
{
|
|
237 |
User::Leave(KErrNotReady);
|
|
238 |
}
|
|
239 |
|
|
240 |
void CMassStorageMountCB::MkDirL(const TDesC& /*aName*/)
|
|
241 |
{
|
|
242 |
User::Leave(KErrNotReady);
|
|
243 |
}
|
|
244 |
|
|
245 |
void CMassStorageMountCB::RmDirL(const TDesC& /*aName*/)
|
|
246 |
{
|
|
247 |
User::Leave(KErrNotReady);
|
|
248 |
}
|
|
249 |
|
|
250 |
void CMassStorageMountCB::DeleteL(const TDesC& /*aName*/)
|
|
251 |
{
|
|
252 |
User::Leave(KErrNotReady);
|
|
253 |
}
|
|
254 |
|
|
255 |
void CMassStorageMountCB::RenameL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
|
|
256 |
{
|
|
257 |
User::Leave(KErrNotReady);
|
|
258 |
}
|
|
259 |
|
|
260 |
void CMassStorageMountCB::ReplaceL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
|
|
261 |
{
|
|
262 |
User::Leave(KErrNotReady);
|
|
263 |
}
|
|
264 |
|
|
265 |
void CMassStorageMountCB::EntryL(const TDesC& /*aName*/,TEntry& /*anEntry*/) const
|
|
266 |
{
|
|
267 |
User::Leave(KErrNotReady);
|
|
268 |
}
|
|
269 |
|
|
270 |
void CMassStorageMountCB::SetEntryL(const TDesC& /*aName*/,const TTime& /*aTime*/,TUint /*aSetAttMask*/,TUint /*aClearAttMask*/)
|
|
271 |
{
|
|
272 |
User::Leave(KErrNotReady);
|
|
273 |
}
|
|
274 |
|
|
275 |
void CMassStorageMountCB::FileOpenL(const TDesC& /*aName*/,TUint /*aMode*/,TFileOpen /*anOpen*/,CFileCB* /*aFile*/)
|
|
276 |
{
|
|
277 |
User::Leave(KErrNotReady);
|
|
278 |
}
|
|
279 |
|
|
280 |
void CMassStorageMountCB::DirOpenL(const TDesC& /*aName*/,CDirCB* /*aDir*/)
|
|
281 |
{
|
|
282 |
User::Leave(KErrNotReady);
|
|
283 |
}
|
|
284 |
|
|
285 |
|
|
286 |
void CMassStorageMountCB::RawReadL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aTrg*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) const
|
|
287 |
{
|
|
288 |
User::Leave(KErrNotReady);
|
|
289 |
}
|
|
290 |
|
|
291 |
void CMassStorageMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aSrc*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/)
|
|
292 |
{
|
|
293 |
User::Leave(KErrNotReady);
|
|
294 |
}
|
|
295 |
|
|
296 |
|
|
297 |
void CMassStorageMountCB::GetShortNameL(const TDesC& /*aLongName*/,TDes& /*aShortName*/)
|
|
298 |
{
|
|
299 |
User::Leave(KErrNotReady);
|
|
300 |
}
|
|
301 |
|
|
302 |
void CMassStorageMountCB::GetLongNameL(const TDesC& /*aShorName*/,TDes& /*aLongName*/)
|
|
303 |
{
|
|
304 |
User::Leave(KErrNotReady);
|
|
305 |
}
|
|
306 |
|
|
307 |
#if defined(_DEBUG)
|
|
308 |
TInt CMassStorageMountCB::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
|
|
309 |
//
|
|
310 |
// Debug function
|
|
311 |
//
|
|
312 |
{
|
|
313 |
if(aCommand>=(KMaxTInt/2))
|
|
314 |
return LocalDrive()->ControlIO(aMessage,aCommand-(KMaxTInt/2),aParam1,aParam2);
|
|
315 |
else
|
|
316 |
return KErrNotSupported;
|
|
317 |
}
|
|
318 |
#else
|
|
319 |
TInt CMassStorageMountCB::ControlIO(const RMessagePtr2& /*aMessage*/,TInt /*aCommand*/,TAny* /*aParam1*/,TAny* /*aParam2*/)
|
|
320 |
{return(KErrNotSupported);}
|
|
321 |
#endif
|
|
322 |
|
|
323 |
void CMassStorageMountCB::ReadSectionL(const TDesC& /*aName*/,TInt /*aPos*/,TAny* /*aTrg*/,TInt /*aLength*/,const RMessagePtr2& /*aMessage*/)
|
|
324 |
{
|
|
325 |
User::Leave(KErrNotReady);
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
Returns ETrue if aNum is a power of two
|
|
330 |
*/
|
|
331 |
TBool CMassStorageMountCB::IsPowerOfTwo(TInt aNum)
|
|
332 |
{
|
|
333 |
|
|
334 |
if (aNum==0)
|
|
335 |
return(EFalse);
|
|
336 |
|
|
337 |
while(aNum)
|
|
338 |
{
|
|
339 |
if (aNum & 0x01)
|
|
340 |
{
|
|
341 |
if (aNum>>1)
|
|
342 |
return EFalse;
|
|
343 |
break;
|
|
344 |
}
|
|
345 |
aNum>>=1;
|
|
346 |
}
|
|
347 |
return ETrue;
|
|
348 |
}
|
|
349 |
|
|
350 |
/**
|
|
351 |
Returns the position of the highest bit in aNum or -1 if aNum == 0
|
|
352 |
*/
|
|
353 |
TInt CMassStorageMountCB::Log2(TInt aNum)
|
|
354 |
{
|
|
355 |
|
|
356 |
TInt res=-1;
|
|
357 |
while(aNum)
|
|
358 |
{
|
|
359 |
res++;
|
|
360 |
aNum>>=1;
|
|
361 |
}
|
|
362 |
return(res);
|
|
363 |
}
|