author | hgs |
Tue, 26 Oct 2010 12:49:20 +0100 | |
changeset 297 | b2826f67641f |
parent 245 | 647ab20fee2e |
permissions | -rw-r--r-- |
119 | 1 |
// Copyright (c) 2008-2010 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". |
|
0 | 7 |
// |
119 | 8 |
// Initial Contributors: |
9 |
// Nokia Corporation - initial contribution. |
|
0 | 10 |
// |
119 | 11 |
// Contributors: |
12 |
// |
|
13 |
// Description: |
|
14 |
// This file system extension provides a way to access a drive on the MS system |
|
15 |
// in "raw format". It can be used to test large files / drives |
|
0 | 16 |
// |
17 |
||
18 |
/** @file |
|
19 |
@internalTechnology |
|
20 |
*/ |
|
21 |
||
22 |
#include <f32fsys.h> |
|
23 |
||
297 | 24 |
#include "OstTraceDefinitions.h" |
25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
26 |
static const TUint KBlockSize = 0x200; |
|
27 |
#include "hostusbmsproxyTraces.h" |
|
28 |
#endif |
|
29 |
||
0 | 30 |
#include "hostusbmsproxy.h" |
297 | 31 |
|
32 |
||
33 |
||
0 | 34 |
|
35 |
||
36 |
CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice) |
|
37 |
: CExtProxyDrive(aMount,aDevice) |
|
297 | 38 |
{ |
39 |
} |
|
0 | 40 |
|
41 |
CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive() |
|
297 | 42 |
{ |
43 |
iUsbHostMsLun.UnInitialise(); |
|
44 |
} |
|
0 | 45 |
|
46 |
TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) |
|
297 | 47 |
{ |
119 | 48 |
RBuf8 partitionInfo; |
49 |
TInt r; |
|
50 |
TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength)); |
|
51 |
if (r != KErrNone) |
|
52 |
{ |
|
53 |
return r; |
|
54 |
} |
|
0 | 55 |
|
297 | 56 |
r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo); |
57 |
if (r != KErrNone) |
|
0 | 58 |
{ |
297 | 59 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_10, |
60 |
"!! Reading medium failed with %d !!", r); |
|
119 | 61 |
partitionInfo.Close(); |
297 | 62 |
return r; |
0 | 63 |
} |
297 | 64 |
TUint8* buffer = const_cast<TUint8*>(partitionInfo.Ptr()); |
0 | 65 |
|
297 | 66 |
// Read of the first sector successful so check for a Master Boot Record |
67 |
if (*(reinterpret_cast<TUint16*>(&buffer[KMBRSignatureOffset]))!= KMBRSignature) |
|
68 |
{ |
|
69 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_11, |
|
70 |
"MBR not present"); |
|
0 | 71 |
iMsDataMemMap.Reset(); |
72 |
} |
|
297 | 73 |
else |
74 |
{ |
|
75 |
// Move the partition entries to a 4 byte boundary |
|
76 |
memcpy(&buffer[0],&buffer[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2)); |
|
77 |
// Search for a x86 default boot partition - let this be the first |
|
78 |
TMBRPartitionEntry* pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
|
0 | 79 |
|
297 | 80 |
TInt firstValidPartitionCount = -1; |
81 |
TInt defaultPartitionNumber = -1; |
|
82 |
TInt partitionCount = 0; |
|
83 |
for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++) |
|
84 |
{ |
|
85 |
if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition() || pe->IsValidExFATPartition()) |
|
86 |
{ |
|
87 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_12, |
|
88 |
"Found a Valid Partition"); |
|
89 |
partitionCount++; |
|
0 | 90 |
|
297 | 91 |
if (firstValidPartitionCount < 0) |
92 |
firstValidPartitionCount = i; |
|
0 | 93 |
|
297 | 94 |
if (pe->iX86BootIndicator == KBootIndicatorBootable) |
0 | 95 |
{ |
297 | 96 |
defaultPartitionNumber = i; |
97 |
break; |
|
0 | 98 |
} |
297 | 99 |
} |
100 |
else |
|
101 |
{ |
|
102 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_13, |
|
103 |
"!! Invalid Partition !!"); |
|
104 |
} |
|
105 |
} |
|
0 | 106 |
|
297 | 107 |
// Check the validity of the partition address boundaries |
108 |
if (partitionCount > 0) |
|
109 |
{ |
|
110 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_14, |
|
111 |
"Using Partition %d", partitionCount); |
|
112 |
pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
|
0 | 113 |
TInt partitionIndex = firstValidPartitionCount; |
114 |
if (defaultPartitionNumber > 0) |
|
115 |
{ |
|
116 |
partitionIndex = defaultPartitionNumber; |
|
117 |
} |
|
118 |
||
119 |
TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; |
|
120 |
||
297 | 121 |
iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, |
119 | 122 |
partitionEntry.iNumSectors, |
123 |
aCapsInfo.iBlockLength); |
|
297 | 124 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_15, |
125 |
"paritioncount = %d defaultpartition = %d", |
|
126 |
partitionCount, partitionIndex); |
|
127 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_16, |
|
128 |
"iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x", |
|
129 |
partitionEntry.iFirstSector, |
|
130 |
partitionEntry.iNumSectors, |
|
131 |
aCapsInfo.iBlockLength); |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_17, |
|
136 |
"No partition found"); |
|
137 |
iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength); |
|
138 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_18, |
|
139 |
"iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x", |
|
140 |
0, |
|
141 |
aCapsInfo.iNumberOfBlocks, |
|
142 |
aCapsInfo.iBlockLength); |
|
143 |
} |
|
144 |
} |
|
119 | 145 |
|
146 |
partitionInfo.Close(); |
|
297 | 147 |
return KErrNone; |
148 |
} |
|
0 | 149 |
|
150 |
/** |
|
151 |
Initialise the proxy drive. |
|
152 |
@return system wide error code. |
|
153 |
*/ |
|
154 |
TInt CUsbHostMsProxyDrive::Initialise() |
|
297 | 155 |
{ |
156 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_20, |
|
157 |
">>> CUsbHostMsProxyDrive::Initialise()"); |
|
0 | 158 |
|
297 | 159 |
if(Mount()) |
160 |
{ |
|
161 |
// as we can't currently handle remounting devices that have |
|
162 |
// been removed by unplugging the USB cable, disable critical notifiers |
|
163 |
// as there's no point in asking the user to re-insert the disk. |
|
164 |
Mount()->SetNotifyOff(); |
|
165 |
} |
|
0 | 166 |
|
167 |
// Check for media presence |
|
297 | 168 |
TCapsInfo capsInfo; |
169 |
TInt err = iUsbHostMsLun.Caps(capsInfo); |
|
0 | 170 |
|
124 | 171 |
if (err == KErrNone && capsInfo.iMediaType == EMediaHardDisk) |
0 | 172 |
{ |
173 |
err = InitialiseOffset(capsInfo); |
|
174 |
} |
|
175 |
||
297 | 176 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_21, |
177 |
"<<< CUsbHostMsProxyDrive::Initialise() err = %d", err); |
|
0 | 178 |
return err; |
297 | 179 |
} |
0 | 180 |
|
181 |
TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3) |
|
182 |
{ |
|
297 | 183 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_22, |
184 |
">>> CUsbHostMsProxyDrive::SetInfo()"); |
|
185 |
TMassStorageUnitInfo iUnitInfo; |
|
0 | 186 |
TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo); |
297 | 187 |
TRAPD(err, msg.ReadL(2, infoPckg)); |
0 | 188 |
|
297 | 189 |
if(err != KErrNone) |
190 |
{ |
|
191 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_23, |
|
192 |
"Cant read from the RMessage %d", err); |
|
193 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_24, |
|
194 |
"<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
|
195 |
return err; |
|
196 |
} |
|
0 | 197 |
|
297 | 198 |
err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID); |
199 |
if(err != KErrNone) |
|
200 |
{ |
|
201 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_25, |
|
202 |
"Initialising logical unit failed %d", err); |
|
203 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_26, |
|
204 |
"<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
|
205 |
return err; |
|
206 |
} |
|
0 | 207 |
|
297 | 208 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_27, |
209 |
"<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
|
210 |
return err; |
|
0 | 211 |
} |
212 |
||
213 |
TInt CUsbHostMsProxyDrive::Dismounted() |
|
297 | 214 |
{ |
215 |
return KErrNone; |
|
216 |
} |
|
0 | 217 |
|
218 |
TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/) |
|
297 | 219 |
{ |
220 |
return KErrNotSupported; |
|
221 |
} |
|
0 | 222 |
|
223 |
||
224 |
TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/) |
|
297 | 225 |
{ |
226 |
return KErrNotSupported; |
|
227 |
} |
|
0 | 228 |
|
297 | 229 |
#define GetIndex(msg, aAddress, aIndex) \ |
230 |
aIndex = msg.Ptr0() == aAddress ? 0 : \ |
|
231 |
msg.Ptr1() == aAddress ? 1 : \ |
|
232 |
msg.Ptr1() == aAddress ? 2 : \ |
|
233 |
msg.Ptr1() == aAddress ? 3 : -1; |
|
0 | 234 |
|
235 |
/** |
|
236 |
Read from the proxy drive. |
|
237 |
||
238 |
@param aPos The address from where the read begins. |
|
239 |
@param aLength The length of the read. |
|
240 |
@param aTrg A descriptor of the memory buffer from which to read. |
|
241 |
@param aThreadHandle The handle-number representing the drive thread. |
|
242 |
@param aOffset Offset into aTrg to read the data from. |
|
243 |
||
244 |
@return system wide error code. |
|
245 |
*/ |
|
246 |
TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, |
|
247 |
const TAny* aTrg, TInt aThreadHandle, TInt aOffset) |
|
297 | 248 |
{ |
249 |
OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_300, |
|
250 |
">>> HOST Read Pos=0x%x %x LBA=0x%x %x", |
|
251 |
I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize)); |
|
252 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_301, |
|
253 |
">>> Len 0x%x Offset 0x%x", |
|
254 |
aLength, aOffset); |
|
0 | 255 |
|
297 | 256 |
TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
0 | 257 |
|
297 | 258 |
// |
259 |
// Set file position to where we want to read... |
|
260 |
// |
|
261 |
if(!localMessage) |
|
262 |
{ |
|
263 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
264 |
localMessage = (msg.Handle() == KLocalMessageHandle); |
|
265 |
} |
|
0 | 266 |
|
297 | 267 |
TInt index = 0; |
268 |
if (!localMessage) |
|
269 |
{ |
|
270 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
271 |
GetIndex(msg, aTrg, index); |
|
0 | 272 |
|
297 | 273 |
if (index < 0) |
0 | 274 |
{ |
297 | 275 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_302, |
276 |
"<<< HOST Read ret=%d", KErrArgument); |
|
0 | 277 |
return KErrArgument; |
278 |
} |
|
297 | 279 |
} |
0 | 280 |
|
297 | 281 |
/* Calculate the end position */ |
282 |
TInt64 end = aPos + static_cast<TInt64>(aLength); |
|
0 | 283 |
|
297 | 284 |
/* check whether there is enough source data to write to the destination descriptor */ |
285 |
TInt64 truncate; |
|
286 |
if(localMessage) |
|
287 |
{ |
|
288 |
truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset); |
|
289 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_303, |
|
290 |
"Descriptor length: %08x", ((TPtr8* )aTrg)->MaxLength()); |
|
291 |
} |
|
292 |
else |
|
293 |
{ |
|
294 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
295 |
truncate = aLength - (msg.GetDesMaxLength(index) - aOffset); |
|
296 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_304, |
|
297 |
"Descriptor length: %08x", msg.GetDesMaxLength(index)); |
|
298 |
} |
|
0 | 299 |
|
297 | 300 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_305, |
301 |
"Offset: %08x", aOffset); |
|
302 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_306, |
|
303 |
"Truncate: 0x%lx", truncate); |
|
0 | 304 |
|
297 | 305 |
if (truncate > 0) |
306 |
{ |
|
307 |
end -= truncate; |
|
308 |
} |
|
0 | 309 |
|
297 | 310 |
iBuf.SetMax(); |
0 | 311 |
TInt r; |
312 |
TInt64 mediaPos; |
|
297 | 313 |
while (aPos < end) |
0 | 314 |
{ |
297 | 315 |
TInt len = end - aPos; |
0 | 316 |
mediaPos = aPos; |
317 |
r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
|
318 |
if (r != KErrNone) |
|
319 |
{ |
|
297 | 320 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_307, |
321 |
"<<< HOST Read ret=%d", r); |
|
0 | 322 |
return r; |
323 |
} |
|
324 |
||
297 | 325 |
if (localMessage) |
326 |
{ |
|
327 |
TPtr8* pTrgPtr = (TPtr8*)aTrg; |
|
328 |
TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset); |
|
329 |
r = iUsbHostMsLun.Read(mediaPos, len, trgDes); |
|
330 |
if (r != KErrNone) |
|
331 |
return r; |
|
332 |
pTrgPtr->SetLength(aOffset + trgDes.Length()); |
|
333 |
} |
|
334 |
else |
|
335 |
{ |
|
336 |
if (len > iBuf.MaxLength()) |
|
337 |
len = iBuf.MaxLength(); |
|
0 | 338 |
|
339 |
r = iUsbHostMsLun.Read(mediaPos, len, iBuf); |
|
297 | 340 |
if (r != KErrNone) |
0 | 341 |
{ |
297 | 342 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_308, |
343 |
"<<< HOST Read ret=%d", r); |
|
0 | 344 |
return r; |
345 |
} |
|
346 |
||
297 | 347 |
iBuf.SetLength(len); |
0 | 348 |
|
297 | 349 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
350 |
r = msg.Write(index, iBuf, aOffset); |
|
351 |
if (r != KErrNone) |
|
0 | 352 |
{ |
297 | 353 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_309, |
354 |
"<<< HOST Read ret=%d", r); |
|
0 | 355 |
return r; |
356 |
} |
|
297 | 357 |
} |
0 | 358 |
|
359 |
aPos += len; |
|
360 |
aOffset += len; |
|
361 |
} |
|
362 |
||
297 | 363 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_310, |
364 |
"<<< HOST Read ret=%d", KErrNone); |
|
365 |
return KErrNone; |
|
366 |
} |
|
0 | 367 |
|
368 |
||
369 |
/** |
|
370 |
Read from the proxy drive, and pass flags to driver. |
|
371 |
||
372 |
@param aPos The address from where the read begins. |
|
373 |
@param aLength The length of the read. |
|
374 |
@param aTrg A descriptor of the memory buffer from which to read. |
|
375 |
@param aThreadHandle The handle-number representing the drive thread. |
|
376 |
@param aOffset Offset into aTrg to read the data from. |
|
377 |
@param aFlags Flags to be passed into the driver. |
|
378 |
||
379 |
@return system wide error code. |
|
380 |
*/ |
|
381 |
TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, |
|
382 |
const TAny* aTrg, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) |
|
297 | 383 |
{ |
384 |
return Read(aPos, aLength, aTrg, aThreadHandle, aOffset); |
|
385 |
} |
|
0 | 386 |
|
387 |
/** |
|
388 |
Read from the proxy drive. |
|
389 |
||
390 |
@param aPos The address from where the read begins. |
|
391 |
@param aLength The length of the read. |
|
392 |
@param aTrg A descriptor of the memory buffer from which to read. |
|
393 |
||
394 |
@return system wide error code. |
|
395 |
*/ |
|
396 |
TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, TDes8& aTrg) |
|
297 | 397 |
{ |
398 |
OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_40, |
|
399 |
">>> HOST Read Pos=0x%x %x LBA=0x%x %x 0x%x", |
|
400 |
I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aLength); |
|
401 |
return iUsbHostMsLun.Read(iMsDataMemMap.GetDataPos(aPos), aLength, aTrg); |
|
402 |
} |
|
0 | 403 |
|
404 |
/** |
|
405 |
Write to the proxy drive. |
|
406 |
||
407 |
@param aPos The address from where the write begins. |
|
408 |
@param aLength The length of the write. |
|
409 |
@param aSrc A descriptor of the memory buffer from which to write. |
|
410 |
@param aThreadHandle The handle-number representing the drive thread. |
|
411 |
@param aOffset Offset into aSrc to write the data to. |
|
412 |
||
413 |
@return system wide error code. |
|
414 |
*/ |
|
415 |
TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
|
416 |
const TAny* aSrc, TInt aThreadHandle, TInt aOffset) |
|
297 | 417 |
{ |
418 |
// |
|
419 |
// Set file position to where we want to write... |
|
420 |
// |
|
421 |
OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_50, |
|
422 |
">>> HOST Write Pos=0x%x %x LBA=0%x %x", |
|
423 |
I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize)); |
|
424 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_501, |
|
425 |
"Len=0x%x Offset=0x%x", aLength, aOffset); |
|
0 | 426 |
|
297 | 427 |
TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
0 | 428 |
|
297 | 429 |
if(!localMessage) |
430 |
{ |
|
431 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
432 |
localMessage = (msg.Handle() == KLocalMessageHandle); |
|
433 |
} |
|
0 | 434 |
|
297 | 435 |
TInt index = 0; |
436 |
if(!localMessage) |
|
437 |
{ |
|
438 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
439 |
GetIndex(msg, aSrc, index); |
|
0 | 440 |
|
297 | 441 |
if (index < 0) |
442 |
return KErrArgument; |
|
443 |
} |
|
0 | 444 |
|
297 | 445 |
/* Calculate the end position */ |
446 |
TInt64 end = aPos + static_cast<TInt64>(aLength); |
|
447 |
/* check whether there is enough source data to read */ |
|
448 |
TInt64 truncate; |
|
449 |
if (localMessage) |
|
450 |
{ |
|
451 |
truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset); |
|
452 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_51, |
|
453 |
"Descriptor length: %08x", ((TPtr8* )aSrc)->Length()); |
|
454 |
} |
|
455 |
else |
|
456 |
{ |
|
457 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
|
458 |
truncate = aLength - (msg.GetDesLength(index) - aOffset); |
|
459 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_52, |
|
460 |
"Descriptor length: %08x", msg.GetDesLength(index)); |
|
461 |
} |
|
0 | 462 |
|
297 | 463 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_53, |
464 |
"Offset: %08x", aOffset); |
|
465 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_54, |
|
466 |
"Truncate: 0x%lx", truncate); |
|
0 | 467 |
|
297 | 468 |
/* if truncate is > 0 we are short of source data as claimed by the aLength. Hence adjust the 'end' */ |
469 |
if (truncate > 0) |
|
470 |
{ |
|
471 |
end -= truncate; |
|
472 |
} |
|
0 | 473 |
|
297 | 474 |
iBuf.SetMax(); |
0 | 475 |
|
476 |
TInt r; |
|
477 |
TInt64 mediaPos; |
|
297 | 478 |
while (aPos < end) |
0 | 479 |
{ |
297 | 480 |
TInt len = end - aPos; |
0 | 481 |
mediaPos = aPos; |
482 |
r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
|
483 |
if (r != KErrNone) |
|
484 |
{ |
|
297 | 485 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_55, |
486 |
"<<< HOST Write ret=%d", r); |
|
0 | 487 |
return r; |
488 |
} |
|
489 |
||
297 | 490 |
if (localMessage) |
491 |
{ |
|
492 |
r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset)); |
|
0 | 493 |
|
297 | 494 |
if (r != KErrNone) |
0 | 495 |
{ |
297 | 496 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_56, |
497 |
"<<< HOST Write ret=%d", r); |
|
0 | 498 |
return r; |
499 |
} |
|
297 | 500 |
} |
501 |
else |
|
502 |
{ |
|
503 |
if (len > iBuf.Length()) |
|
504 |
len = iBuf.Length(); |
|
0 | 505 |
|
297 | 506 |
RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
507 |
r = msg.Read(index, iBuf, aOffset); |
|
508 |
if (r != KErrNone) |
|
0 | 509 |
{ |
297 | 510 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_57, |
511 |
"<<< HOST Write ret=%d", r); |
|
0 | 512 |
return r; |
513 |
} |
|
514 |
||
297 | 515 |
r = iUsbHostMsLun.Write(mediaPos, len, iBuf); |
516 |
if (r != KErrNone) |
|
0 | 517 |
{ |
297 | 518 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_58, |
519 |
"<<< HOST Write ret=%d", r); |
|
0 | 520 |
return r; |
521 |
} |
|
297 | 522 |
} |
0 | 523 |
|
524 |
aPos += len; |
|
525 |
aOffset += len; |
|
526 |
} |
|
527 |
||
297 | 528 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_59, |
529 |
"<<< HOST Write ret=%d", KErrNone); |
|
530 |
return KErrNone; |
|
531 |
} |
|
0 | 532 |
|
119 | 533 |
|
0 | 534 |
/** |
535 |
Write to the proxy drive and pass flags to driver |
|
536 |
||
537 |
@param aPos The address from where the write begins. |
|
538 |
@param aLength The length of the write. |
|
539 |
@param aSrc A descriptor of the memory buffer from which to write. |
|
540 |
@param aThreadHandle The handle-number representing the drive thread. |
|
541 |
@param aOffset Offset into aSrc to write the data to. |
|
542 |
@param aFlags Flags to be passed into the driver. |
|
543 |
||
544 |
@return system wide error code. |
|
545 |
*/ |
|
546 |
TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
|
547 |
const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) |
|
297 | 548 |
{ |
549 |
return Write(aPos, aLength, aSrc, aThreadHandle, aOffset); |
|
550 |
} |
|
0 | 551 |
|
552 |
/** |
|
553 |
Write to the proxy drive. |
|
554 |
||
555 |
@param aPos The address from where the write begins. |
|
556 |
@param aSrc A descriptor of the memory buffer from which to write. |
|
557 |
||
558 |
@return system wide error code. |
|
559 |
*/ |
|
560 |
TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc) |
|
297 | 561 |
{ |
562 |
OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_60, |
|
563 |
">>> HOST Write Pos=0x%x %x LBA=0x%x %x Len=0x%x", |
|
564 |
I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aSrc.Length()); |
|
565 |
return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc); |
|
566 |
} |
|
0 | 567 |
|
119 | 568 |
|
0 | 569 |
/** |
570 |
Get the proxy drive's capabilities information. |
|
571 |
||
572 |
@param anInfo A descriptor of the connected drives capabilities. |
|
573 |
||
574 |
@return system wide error code |
|
575 |
*/ |
|
576 |
TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) |
|
297 | 577 |
{ |
578 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_70, |
|
579 |
">>> HOST Caps"); |
|
580 |
TLocalDriveCapsV6Buf caps; |
|
0 | 581 |
caps.FillZ(); |
582 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
TLocalDriveCapsV6& c = caps(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
c.iConnectionBusType = EConnectionBusUsb; |
297 | 586 |
c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; |
587 |
c.iMediaAtt = KMediaAttFormattable; |
|
588 |
c.iFileSystemId = KDriveFileSysFAT; |
|
0 | 589 |
|
297 | 590 |
TCapsInfo capsInfo; |
591 |
TInt r = iUsbHostMsLun.Caps(capsInfo); |
|
124 | 592 |
|
297 | 593 |
if (KErrNone == r) |
594 |
{ |
|
124 | 595 |
c.iType = capsInfo.iMediaType; |
0 | 596 |
|
124 | 597 |
if (capsInfo.iMediaType == EMediaHardDisk) |
0 | 598 |
{ |
124 | 599 |
c.iBlockSize = capsInfo.iBlockLength; |
600 |
TUint64 size = iMsDataMemMap.DataSize(); |
|
297 | 601 |
|
124 | 602 |
if (size == 0) |
603 |
{ |
|
604 |
// No valid partitions so specify the size of the disk |
|
605 |
size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; |
|
606 |
} |
|
607 |
c.iSize = size; |
|
297 | 608 |
|
124 | 609 |
c.iEraseBlockSize = 0; |
297 | 610 |
|
124 | 611 |
if (capsInfo.iWriteProtect) |
612 |
{ |
|
613 |
c.iMediaAtt |= KMediaAttWriteProtected; |
|
614 |
} |
|
297 | 615 |
|
124 | 616 |
static const TInt K512ByteSectorSize = 0x200; // 512 |
617 |
if(K512ByteSectorSize != capsInfo.iBlockLength) |
|
618 |
{ |
|
619 |
// not formattable if sector size is not 512 |
|
620 |
c.iMediaAtt &= ~KMediaAttFormattable; |
|
621 |
} |
|
297 | 622 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_710, |
623 |
"<<< HOST Caps Block[num=0x%x size=0x%x]", |
|
624 |
capsInfo.iNumberOfBlocks, capsInfo.iBlockLength); |
|
625 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_711, |
|
626 |
"Media size=0x%x %x", I64HIGH(caps().iSize), I64LOW(caps().iSize)); |
|
627 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_712, |
|
628 |
"WP=0x%x", caps().iMediaAtt); |
|
0 | 629 |
} |
124 | 630 |
else if (capsInfo.iMediaType == EMediaCdRom) |
631 |
{ |
|
632 |
// not formattable |
|
633 |
c.iMediaAtt &= ~KMediaAttFormattable; |
|
297 | 634 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_72, |
635 |
">>> HOST Caps MediaType = EMediaCdRom"); |
|
124 | 636 |
} |
637 |
else |
|
638 |
{ |
|
639 |
// do nothing |
|
640 |
} |
|
297 | 641 |
} |
642 |
else if (KErrNotReady == r) |
|
0 | 643 |
{ |
297 | 644 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_73, |
645 |
"<<< HOST Caps Media Not Present"); |
|
646 |
c.iType = EMediaNotPresent; |
|
647 |
r = KErrNone; |
|
119 | 648 |
} |
297 | 649 |
else if (KErrGeneral == r) |
127 | 650 |
{ |
297 | 651 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_74, |
652 |
"<<< HOST Caps Unable to communicate with media"); |
|
653 |
c.iType = EMediaUnknown; |
|
127 | 654 |
} |
655 |
||
119 | 656 |
else |
657 |
{ |
|
297 | 658 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_75, |
659 |
"<<< HOST Caps Unknown Error"); |
|
119 | 660 |
c.iType = EMediaUnknown; |
297 | 661 |
r = KErrUnknown; |
0 | 662 |
} |
297 | 663 |
anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); |
664 |
return r; |
|
665 |
} |
|
0 | 666 |
|
667 |
||
668 |
/** |
|
669 |
Format the proxy drive. The drive is assumed to be a single partition. The |
|
670 |
partition size is equivalent to the size of the media. |
|
671 |
||
672 |
@param aPos The position of the data which is being formatted. |
|
673 |
@param aLength [IN] The length of the data which is being formatted. [OUT] The |
|
674 |
length of data formatted, truncated when end of drive is reached. |
|
675 |
||
676 |
@return system wide error code. |
|
677 |
*/ |
|
678 |
TInt CUsbHostMsProxyDrive::Erase(TInt64 aPos, TInt& aLength) |
|
297 | 679 |
{ |
680 |
OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_80, |
|
681 |
"HOST Erase Pos=0x%x %x LBA=0x%x %x 0x%x", |
|
682 |
I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aLength); |
|
0 | 683 |
TInt err = iMsDataMemMap.TranslateDataPos(aPos, aLength); |
684 |
||
685 |
if (err) |
|
686 |
return err; |
|
687 |
||
688 |
err = iUsbHostMsLun.Erase(aPos, aLength); |
|
689 |
return err; |
|
297 | 690 |
} |
0 | 691 |
|
692 |
||
693 |
/** |
|
694 |
Format the proxy drive. |
|
695 |
||
696 |
@param aPos The position of the data which is being formatted. |
|
697 |
@param aLength The length of the data which is being formatted. |
|
698 |
||
699 |
@return system wide error code. |
|
700 |
*/ |
|
701 |
TInt CUsbHostMsProxyDrive::Format(TInt64 aPos, TInt aLength) |
|
297 | 702 |
{ |
0 | 703 |
return Erase(aPos, aLength); |
297 | 704 |
} |
0 | 705 |
|
706 |
||
707 |
/** |
|
708 |
Format the connected drive. |
|
709 |
||
710 |
@param anInfo Device specific format information. |
|
711 |
||
712 |
@return system wide error code. |
|
713 |
*/ |
|
714 |
TInt CUsbHostMsProxyDrive::Format(TFormatInfo& aInfo) |
|
297 | 715 |
{ |
119 | 716 |
const TInt KDefaultMaxBytesPerFormat = 0x100 * iMsDataMemMap.BlockLength(); // 128K |
0 | 717 |
|
718 |
if (aInfo.i512ByteSectorsFormatted < 0) |
|
719 |
return KErrArgument; |
|
720 |
||
721 |
if (!aInfo.iFormatIsCurrent) |
|
722 |
{ |
|
723 |
aInfo.iFormatIsCurrent = ETrue; |
|
724 |
aInfo.i512ByteSectorsFormatted = 0; |
|
725 |
aInfo.iMaxBytesPerFormat = KDefaultMaxBytesPerFormat; |
|
726 |
||
297 | 727 |
TLocalDriveCapsV6Buf caps; |
728 |
TInt r = Caps(caps); |
|
729 |
if (r != KErrNone) |
|
730 |
return r; |
|
0 | 731 |
|
732 |
iMsDataMemMap.InitDataArea(caps().iSize); |
|
733 |
} |
|
734 |
||
119 | 735 |
TInt64 pos = static_cast<TInt64>(aInfo.i512ByteSectorsFormatted) << iMsDataMemMap.FormatSectorShift(); |
0 | 736 |
TInt length = aInfo.iMaxBytesPerFormat; |
737 |
TInt r = Erase(pos, length); |
|
738 |
||
739 |
if (r == KErrNone) |
|
740 |
{ |
|
119 | 741 |
length += iMsDataMemMap.BlockLength() - 1; |
742 |
length >>= iMsDataMemMap.FormatSectorShift(); |
|
0 | 743 |
aInfo.i512ByteSectorsFormatted += length; |
744 |
} |
|
745 |
||
746 |
return r; |
|
747 |
} |
|
748 |
||
749 |
||
750 |
TInt CUsbHostMsProxyDrive::NotifyChange(TDes8 &aChanged,TRequestStatus* aStatus) |
|
297 | 751 |
{ |
752 |
iUsbHostMsLun.NotifyChange(aChanged, *aStatus); |
|
0 | 753 |
|
297 | 754 |
if(*aStatus != KRequestPending) |
755 |
return KErrUnknown; |
|
0 | 756 |
|
297 | 757 |
return KErrNone; |
758 |
} |
|
0 | 759 |
|
760 |
void CUsbHostMsProxyDrive::NotifyChangeCancel() |
|
297 | 761 |
{ |
762 |
iUsbHostMsLun.NotifyChangeCancel(); |
|
763 |
} |
|
0 | 764 |
|
765 |
TInt CUsbHostMsProxyDrive::SetMountInfo(const TDesC8* /*aMountInfo*/,TInt /*aMountInfoThreadHandle=KCurrentThreadHandle*/) |
|
766 |
{ |
|
767 |
return KErrNone; |
|
768 |
} |
|
769 |
||
770 |
TInt CUsbHostMsProxyDrive::ForceRemount(TUint aFlags) |
|
771 |
{ |
|
772 |
iUsbHostMsLun.ForceRemount(aFlags); |
|
773 |
return KErrNone; |
|
774 |
} |
|
775 |
||
776 |
TInt CUsbHostMsProxyDrive::Unlock(TMediaPassword& /*aPassword*/, TBool /*aStorePassword*/) |
|
777 |
{ |
|
778 |
return KErrNotSupported; |
|
779 |
} |
|
780 |
||
781 |
TInt CUsbHostMsProxyDrive::Lock(TMediaPassword& /*aOldPassword*/, TMediaPassword& /*aNewPassword*/, TBool /*aStorePassword*/) |
|
782 |
{ |
|
783 |
return KErrNotSupported; |
|
784 |
} |
|
785 |
||
786 |
TInt CUsbHostMsProxyDrive::Clear(TMediaPassword& /*aPassword*/) |
|
787 |
{ |
|
788 |
return KErrNotSupported; |
|
789 |
} |
|
790 |
||
791 |
TInt CUsbHostMsProxyDrive::ErasePassword() |
|
792 |
{ |
|
793 |
return KErrNotSupported; |
|
794 |
} |
|
795 |
||
796 |
TInt CUsbHostMsProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput) |
|
297 | 797 |
{ |
798 |
switch(aInterfaceId) |
|
799 |
{ |
|
800 |
case ELocalBufferSupport: |
|
801 |
return KErrNone; |
|
802 |
case EFinalised: |
|
803 |
{ |
|
804 |
TBool isFinalised = (TBool)aInput; |
|
805 |
if(isFinalised) |
|
806 |
{ |
|
807 |
iUsbHostMsLun.SuspendLun(); |
|
808 |
} |
|
809 |
} |
|
810 |
return KErrNone; |
|
811 |
default: |
|
812 |
return KErrNotSupported; |
|
813 |
} |
|
814 |
} |