author | hgs |
Tue, 02 Nov 2010 15:29:23 +0000 | |
changeset 300 | 1d28c8722707 |
parent 31 | 56f325a607ea |
permissions | -rw-r--r-- |
300 | 1 |
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
// |
|
15 |
||
16 |
/** |
|
17 |
@file |
|
18 |
@internalTechnology |
|
19 |
*/ |
|
20 |
||
21 |
#include <e32def.h> |
|
22 |
#include <e32std.h> |
|
23 |
#include <e32base.h> |
|
24 |
#include "msctypes.h" |
|
25 |
||
26 |
#include "mblocktransferprotocol.h" |
|
27 |
#include "tblocktransfer.h" |
|
300 | 28 |
|
29 |
#include "OstTraceDefinitions.h" |
|
30 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
31 |
#include "tblocktransferTraces.h" |
|
32 |
#endif |
|
0 | 33 |
|
34 |
||
35 |
/** |
|
36 |
Manage a read from a block device. |
|
37 |
||
38 |
@param aProtocol A reference to object providing protocol read method |
|
39 |
@param aPosition The position to start reading from |
|
40 |
@param aLength The length of data to read |
|
41 |
@param aBuf Buffer to copy the data to |
|
42 |
*/ |
|
43 |
void TBlockTransfer::ReadL(MBlockTransferProtocol& aProtocol, |
|
44 |
TPos aPosition, |
|
45 |
TInt aLength, |
|
46 |
TDes8& aBuf) |
|
47 |
{ |
|
300 | 48 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_1, |
49 |
"blocklen = 0%lx", iBlockLength); |
|
0 | 50 |
|
300 | 51 |
TInt copylen = 0; |
0 | 52 |
TInt headlen = 0; |
53 |
||
300 | 54 |
aBuf.SetLength(0); |
0 | 55 |
TPos headOffset = GetHeadBlockOffset(aPosition); |
300 | 56 |
/**** READ10 HEAD ****/ |
57 |
if (headOffset) |
|
0 | 58 |
{ |
300 | 59 |
TPos headpos = aPosition - headOffset; |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
iHeadbuf->Zero(); |
300 | 61 |
headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset); |
0 | 62 |
|
300 | 63 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_10, |
64 |
"Read head pos = 0%x %x length = 0%lx", |
|
65 |
I64HIGH(headpos), I64LOW(headpos), iBlockLength); |
|
66 |
aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength); |
|
67 |
aBuf.Append(iHeadbuf->Ptr() + headOffset, headlen); |
|
0 | 68 |
} |
69 |
||
300 | 70 |
/**** READ10 BODY ****/ |
0 | 71 |
TInt blocksInMain = (aLength - headlen)/iBlockLength; |
300 | 72 |
if (blocksInMain) |
0 | 73 |
{ |
300 | 74 |
copylen = blocksInMain * iBlockLength; |
75 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_11, |
|
76 |
"Read main pos = 0%x %x length = 0x%x", |
|
77 |
I64HIGH(aPosition+headlen), I64LOW(aPosition+headlen), copylen); |
|
78 |
aProtocol.BlockReadL(aPosition+headlen, (TDes8 &)aBuf, copylen); |
|
0 | 79 |
} |
80 |
||
300 | 81 |
copylen += headlen; |
0 | 82 |
|
300 | 83 |
/**** READ10 TAIL ****/ |
0 | 84 |
TInt tailLen = aLength - copylen; |
300 | 85 |
if ((tailLen) != 0) |
0 | 86 |
{ |
300 | 87 |
OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_12, |
88 |
"Read tail pos = 0%x %x length = 0%x %x", |
|
89 |
I64HIGH(aPosition+copylen), I64LOW(aPosition+copylen), I64HIGH(iBlockLength), I64LOW(iBlockLength)); |
|
90 |
iTailbuf->Zero(); |
|
91 |
aProtocol.BlockReadL(aPosition+copylen, *iTailbuf, iBlockLength); |
|
92 |
aBuf.Append(iTailbuf->Ptr(), tailLen); |
|
0 | 93 |
} |
94 |
} |
|
95 |
||
96 |
||
97 |
/** |
|
98 |
Manage a write to a block device |
|
99 |
||
100 |
@param aProtocol A reference to object providing protocol read method |
|
101 |
@param aPosition The position to start reading from |
|
102 |
@param aLength The length of data to read |
|
103 |
@param aBuf Buffer containing the data to write |
|
104 |
*/ |
|
105 |
void TBlockTransfer::WriteL(MBlockTransferProtocol& aProtocol, |
|
106 |
TPos aPosition, |
|
107 |
TInt aLength, |
|
108 |
TDesC8& aBuf) |
|
109 |
{ |
|
300 | 110 |
TInt copylen = 0; |
0 | 111 |
TInt headlen = 0; |
112 |
||
113 |
TPos headOffset = GetHeadBlockOffset(aPosition); |
|
300 | 114 |
/**** WRITE10 HEAD ****/ |
115 |
if (headOffset) |
|
0 | 116 |
{ |
300 | 117 |
TPos headpos = aPosition - headOffset; |
0 | 118 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
iHeadbuf->Zero(); |
0 | 120 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
RBuf8& buf = *iTailbuf; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
buf.Zero(); |
0 | 123 |
|
300 | 124 |
headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset); |
0 | 125 |
|
300 | 126 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_20, |
127 |
"Write-Read head pos = 0%x %x length = 0%lx", |
|
128 |
I64HIGH(headpos), I64LOW(headpos), iBlockLength); |
|
0 | 129 |
|
300 | 130 |
aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength); |
131 |
/* get head */ |
|
132 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_21, |
|
133 |
"tcopying read data pos = 0%x %x offset = 0%lx", |
|
134 |
I64HIGH(headpos), I64LOW(headpos), headOffset); |
|
135 |
buf.Append(iHeadbuf->Ptr(), headOffset); |
|
0 | 136 |
|
300 | 137 |
/* get body */ |
138 |
buf.Append(aBuf.Ptr(), headlen); |
|
0 | 139 |
|
300 | 140 |
/* Is it a short write and tail exist? */ |
0 | 141 |
TInt headEndOffset = headOffset + headlen; |
300 | 142 |
if (headEndOffset != iBlockLength) |
0 | 143 |
{ |
144 |
TInt len = iBlockLength - headEndOffset; |
|
145 |
||
300 | 146 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_22, |
147 |
"(short write) copying read data pos = 0%x %x length = %08x", |
|
148 |
I64HIGH(headpos + headEndOffset), I64LOW(headpos + headEndOffset), len); |
|
149 |
buf.Append(iHeadbuf->Ptr() + headEndOffset, len); |
|
0 | 150 |
} |
151 |
||
300 | 152 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_23, |
153 |
"Write head pos = 0%x %x length = %08x", |
|
154 |
I64HIGH(headpos), I64LOW(headpos), headlen); |
|
0 | 155 |
|
300 | 156 |
aProtocol.BlockWriteL(headpos, (TDes8 &)buf, 0, iBlockLength); |
0 | 157 |
} |
158 |
||
300 | 159 |
/**** WRITE10 BODY ****/ |
0 | 160 |
TPos blocksInMain = (aLength - headlen)/iBlockLength; |
300 | 161 |
if (blocksInMain) |
0 | 162 |
{ |
300 | 163 |
copylen = blocksInMain * iBlockLength; |
0 | 164 |
|
165 |
const TUint64 pos = aPosition + headlen; |
|
300 | 166 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_24, |
167 |
"Write main pos = 0%x %x length = %08x", |
|
168 |
I64HIGH(pos), I64LOW(pos), copylen); |
|
0 | 169 |
|
300 | 170 |
/* form the body */ |
171 |
aProtocol.BlockWriteL(pos, (TDes8 &)aBuf, headlen, copylen); |
|
0 | 172 |
} |
173 |
||
300 | 174 |
copylen += headlen; |
0 | 175 |
|
300 | 176 |
/**** WRITE10 TAIL ****/ |
0 | 177 |
TInt tailLen = aLength - copylen;; |
300 | 178 |
if (tailLen != 0) |
0 | 179 |
{ |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
RBuf8& buf = *iHeadbuf; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
buf.Zero(); |
0 | 182 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
iTailbuf->Zero(); |
0 | 184 |
|
185 |
const TUint64 pos = aPosition + copylen; |
|
186 |
||
300 | 187 |
OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_25, |
188 |
"Write-Read tail pos = 0%x %x length = %08x", |
|
189 |
I64HIGH(pos), I64LOW(pos), iBlockLength); |
|
0 | 190 |
|
300 | 191 |
aProtocol.BlockReadL(pos, *iTailbuf, iBlockLength); |
192 |
/* get head */ |
|
193 |
buf.Append(aBuf.Ptr() + copylen, tailLen); |
|
194 |
/* get tail */ |
|
195 |
buf.Append(iTailbuf->Ptr() + tailLen, iBlockLength - tailLen); |
|
0 | 196 |
|
300 | 197 |
aProtocol.BlockWriteL(pos, (TDes8 &)buf, 0, iBlockLength); |
0 | 198 |
} |
199 |
} |
|
200 |
||
201 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
void TBlockTransfer::SetCapacityL(TUint32 aBlockLength, TLba aLastLba) |
0 | 203 |
{ |
204 |
iBlockLength = static_cast<TInt64>(aBlockLength); |
|
205 |
iLastLba = aLastLba; |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
__ASSERT_DEBUG(iHeadbuf, User::Invariant()); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
__ASSERT_DEBUG(iTailbuf, User::Invariant()); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
if (iHeadbuf->Length() < iBlockLength) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
iHeadbuf->ReAllocL(aBlockLength); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
iTailbuf->ReAllocL(aBlockLength); |
300 | 214 |
} |
0 | 215 |
} |
216 |
||
217 |
||
218 |
TPos TBlockTransfer::GetHeadBlockOffset(TPos aPos) |
|
219 |
{ |
|
300 | 220 |
return (aPos % iBlockLength); |
0 | 221 |
} |
222 |
||
223 |
TLba TBlockTransfer::GetHeadBlockLbaL(TPos aPos) |
|
224 |
{ |
|
225 |
TLba lba = I64LOW(aPos / iBlockLength); |
|
226 |
if (lba > iLastLba) |
|
227 |
User::Leave(KErrArgument); |
|
228 |
return lba; |
|
229 |
} |
|
230 |
||
231 |
TPos TBlockTransfer::GetTailBlockOffset(TPos aPos, TInt aLen) |
|
232 |
{ |
|
233 |
return ((aPos + aLen) % iBlockLength); |
|
234 |
} |
|
235 |
||
236 |
TLba TBlockTransfer::GetTailBlockLbaL(TPos aPos, TInt aLen) |
|
237 |
{ |
|
238 |
TLba lba = I64LOW((aPos + aLen) / iBlockLength); |
|
239 |
if (lba > iLastLba) |
|
240 |
User::Leave(KErrArgument); |
|
241 |
return lba; |
|
242 |
} |
|
243 |
||
244 |
||
245 |