19 @internalTechnology |
19 @internalTechnology |
20 */ |
20 */ |
21 |
21 |
22 #include <f32fsys.h> |
22 #include <f32fsys.h> |
23 |
23 |
|
24 #include "OstTraceDefinitions.h" |
|
25 #ifdef OST_TRACE_COMPILER_IN_USE |
|
26 static const TUint KBlockSize = 0x200; |
|
27 #include "hostusbmsproxyTraces.h" |
|
28 #endif |
|
29 |
24 #include "hostusbmsproxy.h" |
30 #include "hostusbmsproxy.h" |
25 #include "debug.h" |
31 |
|
32 |
|
33 |
26 |
34 |
27 |
35 |
28 CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice) |
36 CUsbHostMsProxyDrive::CUsbHostMsProxyDrive(CMountCB* aMount, CExtProxyDriveFactory* aDevice) |
29 : CExtProxyDrive(aMount,aDevice) |
37 : CExtProxyDrive(aMount,aDevice) |
30 { |
38 { |
31 __MSFNSLOG |
39 } |
32 } |
|
33 |
40 |
34 CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive() |
41 CUsbHostMsProxyDrive::~CUsbHostMsProxyDrive() |
35 { |
42 { |
36 __MSFNSLOG |
43 iUsbHostMsLun.UnInitialise(); |
37 iUsbHostMsLun.UnInitialise(); |
44 } |
38 } |
|
39 |
45 |
40 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) |
46 TInt CUsbHostMsProxyDrive::InitialiseOffset(TCapsInfo& aCapsInfo) |
41 { |
47 { |
42 __MSFNSLOG |
|
43 RBuf8 partitionInfo; |
48 RBuf8 partitionInfo; |
44 TInt r; |
49 TInt r; |
45 TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength)); |
50 TRAP(r, partitionInfo.CreateL(aCapsInfo.iBlockLength)); |
46 if (r != KErrNone) |
51 if (r != KErrNone) |
47 { |
52 { |
48 return r; |
53 return r; |
49 } |
54 } |
50 |
55 |
51 r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo); |
56 r = iUsbHostMsLun.Read(0, aCapsInfo.iBlockLength, partitionInfo); |
52 if (r != KErrNone) |
57 if (r != KErrNone) |
53 { |
58 { |
54 __PXYPRINT1(_L("!! Reading medium failed with %d !!"), r); |
59 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_10, |
|
60 "!! Reading medium failed with %d !!", r); |
55 partitionInfo.Close(); |
61 partitionInfo.Close(); |
56 return r; |
62 return r; |
57 } |
63 } |
58 TUint8* buffer = const_cast<TUint8*>(partitionInfo.Ptr()); |
64 TUint8* buffer = const_cast<TUint8*>(partitionInfo.Ptr()); |
59 |
65 |
60 // Read of the first sector successful so check for a Master Boot Record |
66 // Read of the first sector successful so check for a Master Boot Record |
61 if (*(reinterpret_cast<TUint16*>(&buffer[KMBRSignatureOffset]))!= KMBRSignature) |
67 if (*(reinterpret_cast<TUint16*>(&buffer[KMBRSignatureOffset]))!= KMBRSignature) |
62 { |
68 { |
63 __PXYPRINT(_L("MBR not present")); |
69 OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_11, |
|
70 "MBR not present"); |
64 iMsDataMemMap.Reset(); |
71 iMsDataMemMap.Reset(); |
65 } |
72 } |
66 else |
73 else |
67 { |
74 { |
68 // Move the partition entries to a 4 byte boundary |
75 // Move the partition entries to a 4 byte boundary |
69 memcpy(&buffer[0],&buffer[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2)); |
76 memcpy(&buffer[0],&buffer[KMBRFirstPartitionOffset],(sizeof(TMBRPartitionEntry)<<2)); |
70 // Search for a x86 default boot partition - let this be the first |
77 // Search for a x86 default boot partition - let this be the first |
71 TMBRPartitionEntry* pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
78 TMBRPartitionEntry* pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
72 |
79 |
73 TInt firstValidPartitionCount = -1; |
80 TInt firstValidPartitionCount = -1; |
74 TInt defaultPartitionNumber = -1; |
81 TInt defaultPartitionNumber = -1; |
75 TInt partitionCount = 0; |
82 TInt partitionCount = 0; |
76 for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++) |
83 for (TInt i = 0; i < KMBRMaxPrimaryPartitions; i++, pe++) |
77 { |
84 { |
78 if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition() || pe->IsValidExFATPartition()) |
85 if (pe->IsValidDosPartition() || pe->IsValidFAT32Partition() || pe->IsValidExFATPartition()) |
79 { |
86 { |
80 __PXYPRINT(_L("Found a Valid Partition")); |
87 OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_12, |
81 partitionCount++; |
88 "Found a Valid Partition"); |
82 |
89 partitionCount++; |
83 if (firstValidPartitionCount < 0) |
90 |
84 firstValidPartitionCount = i; |
91 if (firstValidPartitionCount < 0) |
85 |
92 firstValidPartitionCount = i; |
86 if (pe->iX86BootIndicator == KBootIndicatorBootable) |
93 |
|
94 if (pe->iX86BootIndicator == KBootIndicatorBootable) |
87 { |
95 { |
88 defaultPartitionNumber = i; |
96 defaultPartitionNumber = i; |
89 break; |
97 break; |
90 } |
98 } |
91 } |
99 } |
92 else |
100 else |
93 { |
101 { |
94 __PXYPRINT(_L("!! Invalid Partition !!")); |
102 OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_13, |
95 } |
103 "!! Invalid Partition !!"); |
96 } |
104 } |
97 |
105 } |
98 // Check the validity of the partition address boundaries |
106 |
99 if (partitionCount > 0) |
107 // Check the validity of the partition address boundaries |
100 { |
108 if (partitionCount > 0) |
101 __PXYPRINT1(_L("Using Partition %d"), partitionCount); |
109 { |
102 pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
110 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_14, |
|
111 "Using Partition %d", partitionCount); |
|
112 pe = reinterpret_cast<TMBRPartitionEntry*>(&buffer[0]); |
103 TInt partitionIndex = firstValidPartitionCount; |
113 TInt partitionIndex = firstValidPartitionCount; |
104 if (defaultPartitionNumber > 0) |
114 if (defaultPartitionNumber > 0) |
105 { |
115 { |
106 partitionIndex = defaultPartitionNumber; |
116 partitionIndex = defaultPartitionNumber; |
107 } |
117 } |
108 |
118 |
109 TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; |
119 TMBRPartitionEntry& partitionEntry = pe[partitionIndex]; |
110 |
120 |
111 iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, |
121 iMsDataMemMap.InitDataArea(partitionEntry.iFirstSector, |
112 partitionEntry.iNumSectors, |
122 partitionEntry.iNumSectors, |
113 aCapsInfo.iBlockLength); |
123 aCapsInfo.iBlockLength); |
114 __PXYPRINT2(_L("paritioncount = %d defaultpartition = %d"), |
124 OstTraceExt2(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_15, |
115 partitionCount, partitionIndex); |
125 "paritioncount = %d defaultpartition = %d", |
116 __PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"), |
126 partitionCount, partitionIndex); |
117 partitionEntry.iFirstSector, |
127 OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_16, |
118 partitionEntry.iNumSectors, |
128 "iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x", |
119 aCapsInfo.iBlockLength); |
129 partitionEntry.iFirstSector, |
120 } |
130 partitionEntry.iNumSectors, |
121 else |
131 aCapsInfo.iBlockLength); |
122 { |
132 } |
123 __PXYPRINT(_L("No partition found")); |
133 else |
124 iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength); |
134 { |
125 __PXYPRINT3(_L("iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x"), |
135 OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_17, |
126 0, |
136 "No partition found"); |
127 aCapsInfo.iNumberOfBlocks, |
137 iMsDataMemMap.InitDataArea(0, aCapsInfo.iNumberOfBlocks, aCapsInfo.iBlockLength); |
128 aCapsInfo.iBlockLength); |
138 OstTraceExt3(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_18, |
129 } |
139 "iFirstSector = x%x iNumSectors = x%x iSectorSize = x%x", |
130 } |
140 0, |
|
141 aCapsInfo.iNumberOfBlocks, |
|
142 aCapsInfo.iBlockLength); |
|
143 } |
|
144 } |
131 |
145 |
132 partitionInfo.Close(); |
146 partitionInfo.Close(); |
133 return KErrNone; |
147 return KErrNone; |
134 } |
148 } |
135 |
149 |
136 /** |
150 /** |
137 Initialise the proxy drive. |
151 Initialise the proxy drive. |
138 @return system wide error code. |
152 @return system wide error code. |
139 */ |
153 */ |
140 TInt CUsbHostMsProxyDrive::Initialise() |
154 TInt CUsbHostMsProxyDrive::Initialise() |
141 { |
155 { |
142 __MSFNSLOG |
156 OstTrace0(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_20, |
143 __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::Initialise()")); |
157 ">>> CUsbHostMsProxyDrive::Initialise()"); |
144 |
158 |
145 if(Mount()) |
159 if(Mount()) |
146 { |
160 { |
147 // as we can't currently handle remounting devices that have |
161 // as we can't currently handle remounting devices that have |
148 // been removed by unplugging the USB cable, disable critical notifiers |
162 // been removed by unplugging the USB cable, disable critical notifiers |
149 // as there's no point in asking the user to re-insert the disk. |
163 // as there's no point in asking the user to re-insert the disk. |
150 Mount()->SetNotifyOff(); |
164 Mount()->SetNotifyOff(); |
151 } |
165 } |
152 |
166 |
153 // Check for media presence |
167 // Check for media presence |
154 TCapsInfo capsInfo; |
168 TCapsInfo capsInfo; |
155 TInt err = iUsbHostMsLun.Caps(capsInfo); |
169 TInt err = iUsbHostMsLun.Caps(capsInfo); |
156 |
170 |
157 if (err == KErrNone && capsInfo.iMediaType == EMediaHardDisk) |
171 if (err == KErrNone && capsInfo.iMediaType == EMediaHardDisk) |
158 { |
172 { |
159 err = InitialiseOffset(capsInfo); |
173 err = InitialiseOffset(capsInfo); |
160 } |
174 } |
161 |
175 |
162 __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::Initialise() err = %d"), err); |
176 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_21, |
|
177 "<<< CUsbHostMsProxyDrive::Initialise() err = %d", err); |
163 return err; |
178 return err; |
164 } |
179 } |
165 |
180 |
166 TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3) |
181 TInt CUsbHostMsProxyDrive::SetInfo(const RMessage2 &msg, TAny* aMessageParam2, TAny* aMessageParam3) |
167 { |
182 { |
168 __MSFNSLOG |
183 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_22, |
169 __HOSTPRINT(_L(">>> CUsbHostMsProxyDrive::SetInfo()")); |
184 ">>> CUsbHostMsProxyDrive::SetInfo()"); |
170 TMassStorageUnitInfo iUnitInfo; |
185 TMassStorageUnitInfo iUnitInfo; |
171 TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo); |
186 TPckg<TMassStorageUnitInfo> infoPckg(iUnitInfo); |
172 TRAPD(err, msg.ReadL(2, infoPckg)); |
187 TRAPD(err, msg.ReadL(2, infoPckg)); |
173 |
188 |
174 if(err != KErrNone) |
189 if(err != KErrNone) |
175 { |
190 { |
176 __PXYPRINT1(_L("Cant read from the RMessage %d"), err); |
191 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_23, |
177 __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); |
192 "Cant read from the RMessage %d", err); |
178 return err; |
193 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_24, |
179 } |
194 "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
180 |
195 return err; |
181 err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID); |
196 } |
182 if(err != KErrNone) |
197 |
183 { |
198 err = iUsbHostMsLun.Initialise(msg, 3, iUnitInfo.iLunID); |
184 __PXYPRINT1(_L("Initialising logical unit failed %d"), err); |
199 if(err != KErrNone) |
185 __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); |
200 { |
186 return err; |
201 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_25, |
187 } |
202 "Initialising logical unit failed %d", err); |
188 |
203 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_26, |
189 __HOSTPRINT1(_L("<<< CUsbHostMsProxyDrive::SetInfo() err = %d"), err); |
204 "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
190 return err; |
205 return err; |
|
206 } |
|
207 |
|
208 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_27, |
|
209 "<<< CUsbHostMsProxyDrive::SetInfo() err = %d", err); |
|
210 return err; |
191 } |
211 } |
192 |
212 |
193 TInt CUsbHostMsProxyDrive::Dismounted() |
213 TInt CUsbHostMsProxyDrive::Dismounted() |
194 { |
214 { |
195 __MSFNSLOG |
215 return KErrNone; |
196 return KErrNone; |
216 } |
197 } |
|
198 |
217 |
199 TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/) |
218 TInt CUsbHostMsProxyDrive::Enlarge(TInt /*aLength*/) |
200 { |
219 { |
201 __MSFNSLOG |
220 return KErrNotSupported; |
202 return KErrNotSupported; |
221 } |
203 } |
|
204 |
222 |
205 |
223 |
206 TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/) |
224 TInt CUsbHostMsProxyDrive::ReduceSize(TInt /*aPos*/, TInt /*aLength*/) |
207 { |
225 { |
208 __MSFNSLOG |
226 return KErrNotSupported; |
209 return KErrNotSupported; |
227 } |
210 } |
228 |
211 |
229 #define GetIndex(msg, aAddress, aIndex) \ |
212 #define GetIndex(msg, aAddress, aIndex) \ |
230 aIndex = msg.Ptr0() == aAddress ? 0 : \ |
213 aIndex = msg.Ptr0() == aAddress ? 0 : \ |
231 msg.Ptr1() == aAddress ? 1 : \ |
214 msg.Ptr1() == aAddress ? 1 : \ |
232 msg.Ptr1() == aAddress ? 2 : \ |
215 msg.Ptr1() == aAddress ? 2 : \ |
233 msg.Ptr1() == aAddress ? 3 : -1; |
216 msg.Ptr1() == aAddress ? 3 : -1; |
|
217 |
234 |
218 /** |
235 /** |
219 Read from the proxy drive. |
236 Read from the proxy drive. |
220 |
237 |
221 @param aPos The address from where the read begins. |
238 @param aPos The address from where the read begins. |
226 |
243 |
227 @return system wide error code. |
244 @return system wide error code. |
228 */ |
245 */ |
229 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, |
246 TInt CUsbHostMsProxyDrive::Read(TInt64 aPos, TInt aLength, |
230 const TAny* aTrg, TInt aThreadHandle, TInt aOffset) |
247 const TAny* aTrg, TInt aThreadHandle, TInt aOffset) |
231 { |
248 { |
232 __MSFNSLOG |
249 OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_300, |
233 __HOSTPRINT4(_L("\n>>> HOST Read Pos=0x%lx LBA=0x%lx 0x%x 0x%x"), |
250 ">>> HOST Read Pos=0x%x %x LBA=0x%x %x", |
234 aPos, aPos/KBlockSize, aLength, aOffset); |
251 I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize)); |
235 |
252 OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_301, |
236 TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
253 ">>> Len 0x%x Offset 0x%x", |
237 |
254 aLength, aOffset); |
238 // |
255 |
239 // Set file position to where we want to read... |
256 TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
240 // |
257 |
241 if(!localMessage) |
258 // |
242 { |
259 // Set file position to where we want to read... |
243 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
260 // |
244 localMessage = (msg.Handle() == KLocalMessageHandle); |
261 if(!localMessage) |
245 } |
262 { |
246 |
263 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
247 TInt index = 0; |
264 localMessage = (msg.Handle() == KLocalMessageHandle); |
248 if (!localMessage) |
265 } |
249 { |
266 |
250 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
267 TInt index = 0; |
251 GetIndex(msg, aTrg, index); |
268 if (!localMessage) |
252 |
269 { |
253 if (index < 0) |
270 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
254 { |
271 GetIndex(msg, aTrg, index); |
255 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrArgument); |
272 |
|
273 if (index < 0) |
|
274 { |
|
275 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_302, |
|
276 "<<< HOST Read ret=%d", KErrArgument); |
256 return KErrArgument; |
277 return KErrArgument; |
257 } |
278 } |
258 } |
279 } |
259 |
280 |
260 /* Calculate the end position */ |
281 /* Calculate the end position */ |
261 TInt64 end = aPos + static_cast<TInt64>(aLength); |
282 TInt64 end = aPos + static_cast<TInt64>(aLength); |
262 |
283 |
263 /* check whether there is enough source data to write to the destination descriptor */ |
284 /* check whether there is enough source data to write to the destination descriptor */ |
264 TInt64 truncate; |
285 TInt64 truncate; |
265 if(localMessage) |
286 if(localMessage) |
266 { |
287 { |
267 truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset); |
288 truncate = aLength - (((TPtr8* )aTrg)->MaxLength() - aOffset); |
268 __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aTrg)->MaxLength()); |
289 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_303, |
269 } |
290 "Descriptor length: %08x", ((TPtr8* )aTrg)->MaxLength()); |
270 else |
291 } |
271 { |
292 else |
272 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
293 { |
273 truncate = aLength - (msg.GetDesMaxLength(index) - aOffset); |
294 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
274 __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesMaxLength(index)); |
295 truncate = aLength - (msg.GetDesMaxLength(index) - aOffset); |
275 } |
296 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_304, |
276 |
297 "Descriptor length: %08x", msg.GetDesMaxLength(index)); |
277 __PXYPRINT1(_L("Offset: %08x"), aOffset); |
298 } |
278 __PXYPRINT1(_L("Truncate: 0x%lx"), truncate); |
299 |
279 |
300 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_305, |
280 if (truncate > 0) |
301 "Offset: %08x", aOffset); |
281 { |
302 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_306, |
282 end -= truncate; |
303 "Truncate: 0x%lx", truncate); |
283 } |
304 |
284 |
305 if (truncate > 0) |
285 iBuf.SetMax(); |
306 { |
|
307 end -= truncate; |
|
308 } |
|
309 |
|
310 iBuf.SetMax(); |
286 TInt r; |
311 TInt r; |
287 TInt64 mediaPos; |
312 TInt64 mediaPos; |
288 while (aPos < end) |
313 while (aPos < end) |
289 { |
314 { |
290 TInt len = end - aPos; |
315 TInt len = end - aPos; |
291 mediaPos = aPos; |
316 mediaPos = aPos; |
292 r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
317 r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
293 if (r != KErrNone) |
318 if (r != KErrNone) |
294 { |
319 { |
295 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); |
320 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_307, |
|
321 "<<< HOST Read ret=%d", r); |
296 return r; |
322 return r; |
297 } |
323 } |
298 |
324 |
299 if (localMessage) |
325 if (localMessage) |
300 { |
326 { |
301 TPtr8* pTrgPtr = (TPtr8*)aTrg; |
327 TPtr8* pTrgPtr = (TPtr8*)aTrg; |
302 TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset); |
328 TPtr8 trgDes((TUint8*)(pTrgPtr->MidTPtr(aOffset).Ptr()), pTrgPtr->MaxLength() - aOffset); |
303 r = iUsbHostMsLun.Read(mediaPos, len, trgDes); |
329 r = iUsbHostMsLun.Read(mediaPos, len, trgDes); |
304 if (r != KErrNone) |
330 if (r != KErrNone) |
305 return r; |
331 return r; |
306 pTrgPtr->SetLength(aOffset + trgDes.Length()); |
332 pTrgPtr->SetLength(aOffset + trgDes.Length()); |
307 } |
333 } |
308 else |
334 else |
309 { |
335 { |
310 if (len > iBuf.MaxLength()) |
336 if (len > iBuf.MaxLength()) |
311 len = iBuf.MaxLength(); |
337 len = iBuf.MaxLength(); |
312 |
338 |
313 r = iUsbHostMsLun.Read(mediaPos, len, iBuf); |
339 r = iUsbHostMsLun.Read(mediaPos, len, iBuf); |
314 if (r != KErrNone) |
340 if (r != KErrNone) |
315 { |
341 { |
316 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); |
342 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_308, |
|
343 "<<< HOST Read ret=%d", r); |
317 return r; |
344 return r; |
318 } |
345 } |
319 |
346 |
320 iBuf.SetLength(len); |
347 iBuf.SetLength(len); |
321 |
348 |
322 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
349 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
323 r = msg.Write(index, iBuf, aOffset); |
350 r = msg.Write(index, iBuf, aOffset); |
324 if (r != KErrNone) |
351 if (r != KErrNone) |
325 { |
352 { |
326 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), r); |
353 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_309, |
|
354 "<<< HOST Read ret=%d", r); |
327 return r; |
355 return r; |
328 } |
356 } |
329 } |
357 } |
330 |
358 |
331 aPos += len; |
359 aPos += len; |
332 aOffset += len; |
360 aOffset += len; |
333 } |
361 } |
334 |
362 |
335 __HOSTPRINT1(_L("<<< HOST Read ret=%d"), KErrNone); |
363 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_310, |
336 return KErrNone; |
364 "<<< HOST Read ret=%d", KErrNone); |
337 } |
365 return KErrNone; |
|
366 } |
338 |
367 |
339 |
368 |
340 /** |
369 /** |
341 Read from the proxy drive, and pass flags to driver. |
370 Read from the proxy drive, and pass flags to driver. |
342 |
371 |
384 |
412 |
385 @return system wide error code. |
413 @return system wide error code. |
386 */ |
414 */ |
387 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
415 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
388 const TAny* aSrc, TInt aThreadHandle, TInt aOffset) |
416 const TAny* aSrc, TInt aThreadHandle, TInt aOffset) |
389 { |
417 { |
390 // |
418 // |
391 // Set file position to where we want to write... |
419 // Set file position to where we want to write... |
392 // |
420 // |
393 __MSFNSLOG |
421 OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_50, |
394 __HOSTPRINT4(_L("\n>>> HOST Write Pos=0x%lx LBA=0%lx 0x%x 0x%x"), |
422 ">>> HOST Write Pos=0x%x %x LBA=0%x %x", |
395 aPos, aPos/KBlockSize, aLength, aOffset); |
423 I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize)); |
396 |
424 OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_501, |
397 TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
425 "Len=0x%x Offset=0x%x", aLength, aOffset); |
398 |
426 |
399 if(!localMessage) |
427 TBool localMessage = (aThreadHandle == KLocalMessageHandle); |
400 { |
428 |
401 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
429 if(!localMessage) |
402 localMessage = (msg.Handle() == KLocalMessageHandle); |
430 { |
403 } |
431 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
404 |
432 localMessage = (msg.Handle() == KLocalMessageHandle); |
405 TInt index = 0; |
433 } |
406 if(!localMessage) |
434 |
407 { |
435 TInt index = 0; |
408 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
436 if(!localMessage) |
409 GetIndex(msg, aSrc, index); |
437 { |
410 |
438 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
411 if (index < 0) |
439 GetIndex(msg, aSrc, index); |
412 return KErrArgument; |
440 |
413 } |
441 if (index < 0) |
414 |
442 return KErrArgument; |
415 /* Calculate the end position */ |
443 } |
416 TInt64 end = aPos + static_cast<TInt64>(aLength); |
444 |
417 /* check whether there is enough source data to read */ |
445 /* Calculate the end position */ |
418 TInt64 truncate; |
446 TInt64 end = aPos + static_cast<TInt64>(aLength); |
419 if (localMessage) |
447 /* check whether there is enough source data to read */ |
420 { |
448 TInt64 truncate; |
421 truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset); |
449 if (localMessage) |
422 __PXYPRINT1(_L("Descriptor length: %08x"), ((TPtr8* )aSrc)->Length()); |
450 { |
423 } |
451 truncate = aLength - (((TPtr8* )aSrc)->Length() - aOffset); |
424 else |
452 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_51, |
425 { |
453 "Descriptor length: %08x", ((TPtr8* )aSrc)->Length()); |
426 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
454 } |
427 truncate = aLength - (msg.GetDesLength(index) - aOffset); |
455 else |
428 __PXYPRINT1(_L("Descriptor length: %08x"), msg.GetDesLength(index)); |
456 { |
429 } |
457 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
430 |
458 truncate = aLength - (msg.GetDesLength(index) - aOffset); |
431 __PXYPRINT1(_L("Offset: %08x"), aOffset); |
459 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_52, |
432 __PXYPRINT1(_L("Truncate: 0x%lx"), truncate); |
460 "Descriptor length: %08x", msg.GetDesLength(index)); |
433 |
461 } |
434 /* if truncate is > 0 we are short of source data as claimed by the aLength. Hence adjust the 'end' */ |
462 |
435 if (truncate > 0) |
463 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_53, |
436 { |
464 "Offset: %08x", aOffset); |
437 end -= truncate; |
465 OstTrace1(TRACE_SHOSTMASSSTORAGE_PROXY, HOSTUSBMSPROXY_54, |
438 } |
466 "Truncate: 0x%lx", truncate); |
439 |
467 |
440 iBuf.SetMax(); |
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 } |
|
473 |
|
474 iBuf.SetMax(); |
441 |
475 |
442 TInt r; |
476 TInt r; |
443 TInt64 mediaPos; |
477 TInt64 mediaPos; |
444 while (aPos < end) |
478 while (aPos < end) |
445 { |
479 { |
446 TInt len = end - aPos; |
480 TInt len = end - aPos; |
447 mediaPos = aPos; |
481 mediaPos = aPos; |
448 r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
482 r = iMsDataMemMap.CheckBlockInRange(mediaPos, len); |
449 if (r != KErrNone) |
483 if (r != KErrNone) |
450 { |
484 { |
451 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); |
485 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_55, |
|
486 "<<< HOST Write ret=%d", r); |
452 return r; |
487 return r; |
453 } |
488 } |
454 |
489 |
455 if (localMessage) |
490 if (localMessage) |
456 { |
491 { |
457 r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset)); |
492 r = iUsbHostMsLun.Write(mediaPos, len, ((TPtr8*)aSrc)->MidTPtr(aOffset)); |
458 |
493 |
459 if (r != KErrNone) |
494 if (r != KErrNone) |
460 { |
495 { |
461 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); |
496 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_56, |
|
497 "<<< HOST Write ret=%d", r); |
462 return r; |
498 return r; |
463 } |
499 } |
464 } |
500 } |
465 else |
501 else |
466 { |
502 { |
467 if (len > iBuf.Length()) |
503 if (len > iBuf.Length()) |
468 len = iBuf.Length(); |
504 len = iBuf.Length(); |
469 |
505 |
470 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
506 RMessage2 msg(*(RMessagePtr2 *) &aThreadHandle); |
471 r = msg.Read(index, iBuf, aOffset); |
507 r = msg.Read(index, iBuf, aOffset); |
472 if (r != KErrNone) |
508 if (r != KErrNone) |
473 { |
509 { |
474 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); |
510 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_57, |
|
511 "<<< HOST Write ret=%d", r); |
475 return r; |
512 return r; |
476 } |
513 } |
477 |
514 |
478 r = iUsbHostMsLun.Write(mediaPos, len, iBuf); |
515 r = iUsbHostMsLun.Write(mediaPos, len, iBuf); |
479 if (r != KErrNone) |
516 if (r != KErrNone) |
480 { |
517 { |
481 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), r); |
518 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_58, |
|
519 "<<< HOST Write ret=%d", r); |
482 return r; |
520 return r; |
483 } |
521 } |
484 } |
522 } |
485 |
523 |
486 aPos += len; |
524 aPos += len; |
487 aOffset += len; |
525 aOffset += len; |
488 } |
526 } |
489 |
527 |
490 __HOSTPRINT1(_L("<<< HOST Write ret=%d"), KErrNone); |
528 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_59, |
491 return KErrNone; |
529 "<<< HOST Write ret=%d", KErrNone); |
492 } |
530 return KErrNone; |
|
531 } |
493 |
532 |
494 |
533 |
495 /** |
534 /** |
496 Write to the proxy drive and pass flags to driver |
535 Write to the proxy drive and pass flags to driver |
497 |
536 |
504 |
543 |
505 @return system wide error code. |
544 @return system wide error code. |
506 */ |
545 */ |
507 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
546 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos, TInt aLength, |
508 const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) |
547 const TAny* aSrc, TInt aThreadHandle, TInt aOffset, TInt /* aFlags */) |
509 { |
548 { |
510 __MSFNSLOG |
549 return Write(aPos, aLength, aSrc, aThreadHandle, aOffset); |
511 return Write(aPos, aLength, aSrc, aThreadHandle, aOffset); |
550 } |
512 } |
|
513 |
551 |
514 /** |
552 /** |
515 Write to the proxy drive. |
553 Write to the proxy drive. |
516 |
554 |
517 @param aPos The address from where the write begins. |
555 @param aPos The address from where the write begins. |
518 @param aSrc A descriptor of the memory buffer from which to write. |
556 @param aSrc A descriptor of the memory buffer from which to write. |
519 |
557 |
520 @return system wide error code. |
558 @return system wide error code. |
521 */ |
559 */ |
522 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc) |
560 TInt CUsbHostMsProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc) |
523 { |
561 { |
524 __MSFNSLOG |
562 OstTraceExt5(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_60, |
525 __HOSTPRINT3(_L("\n>>> HOST Write Pos=0x%lx LBA=0x%lx 0x%x"), |
563 ">>> HOST Write Pos=0x%x %x LBA=0x%x %x Len=0x%x", |
526 aPos, aPos/KBlockSize, aSrc.Length()); |
564 I64HIGH(aPos), I64LOW(aPos), I64HIGH(aPos/KBlockSize), I64LOW(aPos/KBlockSize), aSrc.Length()); |
527 return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc); |
565 return iUsbHostMsLun.Write(iMsDataMemMap.GetDataPos(aPos), aSrc.Length(), aSrc); |
528 } |
566 } |
529 |
567 |
530 |
568 |
531 /** |
569 /** |
532 Get the proxy drive's capabilities information. |
570 Get the proxy drive's capabilities information. |
533 |
571 |
534 @param anInfo A descriptor of the connected drives capabilities. |
572 @param anInfo A descriptor of the connected drives capabilities. |
535 |
573 |
536 @return system wide error code |
574 @return system wide error code |
537 */ |
575 */ |
538 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) |
576 TInt CUsbHostMsProxyDrive::Caps(TDes8& anInfo) |
539 { |
577 { |
540 __MSFNSLOG |
578 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_70, |
541 __HOSTPRINT(_L(">>> HOST Caps")); |
579 ">>> HOST Caps"); |
542 TLocalDriveCapsV6Buf caps; |
580 TLocalDriveCapsV6Buf caps; |
543 caps.FillZ(); |
581 caps.FillZ(); |
544 |
582 |
545 TLocalDriveCapsV6& c = caps(); |
583 TLocalDriveCapsV6& c = caps(); |
546 |
584 |
547 c.iConnectionBusType = EConnectionBusUsb; |
585 c.iConnectionBusType = EConnectionBusUsb; |
548 c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; |
586 c.iDriveAtt = KDriveAttLocal | KDriveAttRemovable | KDriveAttExternal; |
549 c.iMediaAtt = KMediaAttFormattable; |
587 c.iMediaAtt = KMediaAttFormattable; |
550 c.iFileSystemId = KDriveFileSysFAT; |
588 c.iFileSystemId = KDriveFileSysFAT; |
551 |
589 |
552 TCapsInfo capsInfo; |
590 TCapsInfo capsInfo; |
553 TInt r = iUsbHostMsLun.Caps(capsInfo); |
591 TInt r = iUsbHostMsLun.Caps(capsInfo); |
554 |
592 |
555 if (KErrNone == r) |
593 if (KErrNone == r) |
556 { |
594 { |
557 c.iType = capsInfo.iMediaType; |
595 c.iType = capsInfo.iMediaType; |
558 |
596 |
559 if (capsInfo.iMediaType == EMediaHardDisk) |
597 if (capsInfo.iMediaType == EMediaHardDisk) |
560 { |
598 { |
561 c.iBlockSize = capsInfo.iBlockLength; |
599 c.iBlockSize = capsInfo.iBlockLength; |
562 TUint64 size = iMsDataMemMap.DataSize(); |
600 TUint64 size = iMsDataMemMap.DataSize(); |
563 |
601 |
564 if (size == 0) |
602 if (size == 0) |
565 { |
603 { |
566 // No valid partitions so specify the size of the disk |
604 // No valid partitions so specify the size of the disk |
567 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; |
605 size = static_cast<TUint64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength; |
568 } |
606 } |
569 c.iSize = size; |
607 c.iSize = size; |
570 |
608 |
571 c.iEraseBlockSize = 0; |
609 c.iEraseBlockSize = 0; |
572 |
610 |
573 if (capsInfo.iWriteProtect) |
611 if (capsInfo.iWriteProtect) |
574 { |
612 { |
575 c.iMediaAtt |= KMediaAttWriteProtected; |
613 c.iMediaAtt |= KMediaAttWriteProtected; |
576 } |
614 } |
577 |
615 |
578 static const TInt K512ByteSectorSize = 0x200; // 512 |
616 static const TInt K512ByteSectorSize = 0x200; // 512 |
579 if(K512ByteSectorSize != capsInfo.iBlockLength) |
617 if(K512ByteSectorSize != capsInfo.iBlockLength) |
580 { |
618 { |
581 // not formattable if sector size is not 512 |
619 // not formattable if sector size is not 512 |
582 c.iMediaAtt &= ~KMediaAttFormattable; |
620 c.iMediaAtt &= ~KMediaAttFormattable; |
583 } |
621 } |
584 __HOSTPRINT4(_L("<<< HOST Caps Block[num=0x%x size=0x%x] Media[size=0x%lx WP=0x%x]"), |
622 OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_710, |
585 capsInfo.iNumberOfBlocks, capsInfo.iBlockLength, |
623 "<<< HOST Caps Block[num=0x%x size=0x%x]", |
586 caps().iSize, caps().iMediaAtt); |
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); |
587 } |
629 } |
588 else if (capsInfo.iMediaType == EMediaCdRom) |
630 else if (capsInfo.iMediaType == EMediaCdRom) |
589 { |
631 { |
590 // not formattable |
632 // not formattable |
591 c.iMediaAtt &= ~KMediaAttFormattable; |
633 c.iMediaAtt &= ~KMediaAttFormattable; |
592 __HOSTPRINT(_L(">>> HOST Caps MediaType = EMediaCdRom")); |
634 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_72, |
|
635 ">>> HOST Caps MediaType = EMediaCdRom"); |
593 } |
636 } |
594 else |
637 else |
595 { |
638 { |
596 // do nothing |
639 // do nothing |
597 } |
640 } |
598 } |
641 } |
599 else if (KErrNotReady == r) |
642 else if (KErrNotReady == r) |
600 { |
643 { |
601 __HOSTPRINT(_L("<<< HOST Caps Media Not Present")); |
644 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_73, |
602 c.iType = EMediaNotPresent; |
645 "<<< HOST Caps Media Not Present"); |
603 r = KErrNone; |
646 c.iType = EMediaNotPresent; |
604 } |
647 r = KErrNone; |
605 else if (KErrGeneral == r) |
648 } |
606 { |
649 else if (KErrGeneral == r) |
607 __HOSTPRINT(_L("<<< HOST Caps Unable to communicate with media")); |
650 { |
608 c.iType = EMediaUnknown; |
651 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_74, |
|
652 "<<< HOST Caps Unable to communicate with media"); |
|
653 c.iType = EMediaUnknown; |
609 } |
654 } |
610 |
655 |
611 else |
656 else |
612 { |
657 { |
613 __HOSTPRINT(_L("<<< HOST Caps Unknown Error")); |
658 OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, HOSTUSBMSPROXY_75, |
|
659 "<<< HOST Caps Unknown Error"); |
614 c.iType = EMediaUnknown; |
660 c.iType = EMediaUnknown; |
615 r = KErrUnknown; |
661 r = KErrUnknown; |
616 } |
662 } |
617 anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); |
663 anInfo = caps.Left(Min(caps.Length(),anInfo.MaxLength())); |
618 return r; |
664 return r; |
619 } |
665 } |
620 |
666 |
621 |
667 |
622 /** |
668 /** |
623 Format the proxy drive. The drive is assumed to be a single partition. The |
669 Format the proxy drive. The drive is assumed to be a single partition. The |
624 partition size is equivalent to the size of the media. |
670 partition size is equivalent to the size of the media. |