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