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