userlibandfileserver/fileserver/shostmassstorage/server/protocol/tblocktransfer.cpp
changeset 300 1d28c8722707
parent 31 56f325a607ea
equal deleted inserted replaced
293:0659d0e1a03c 300:1d28c8722707
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include <e32base.h>
    23 #include <e32base.h>
    24 #include "msctypes.h"
    24 #include "msctypes.h"
    25 
    25 
    26 #include "mblocktransferprotocol.h"
    26 #include "mblocktransferprotocol.h"
    27 #include "tblocktransfer.h"
    27 #include "tblocktransfer.h"
    28 #include "debug.h"
    28 
    29 #include "msdebug.h"
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "tblocktransferTraces.h"
       
    32 #endif
    30 
    33 
    31 
    34 
    32 /**
    35 /**
    33 Manage a read from a block device.
    36 Manage a read from a block device.
    34 
    37 
    40 void TBlockTransfer::ReadL(MBlockTransferProtocol& aProtocol,
    43 void TBlockTransfer::ReadL(MBlockTransferProtocol& aProtocol,
    41                            TPos aPosition,
    44                            TPos aPosition,
    42                            TInt aLength,
    45                            TInt aLength,
    43                            TDes8& aBuf)
    46                            TDes8& aBuf)
    44     {
    47     {
    45     __MSFNLOG
    48     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_1,
    46 	__HOSTPRINT1(_L("blocklen = 0%lx"), iBlockLength);
    49               "blocklen = 0%lx", iBlockLength);
    47 
    50 
    48 	TInt copylen = 0;
    51     TInt copylen = 0;
    49     TInt headlen = 0;
    52     TInt headlen = 0;
    50 
    53 
    51 	aBuf.SetLength(0);
    54     aBuf.SetLength(0);
    52     TPos headOffset = GetHeadBlockOffset(aPosition);
    55     TPos headOffset = GetHeadBlockOffset(aPosition);
    53 	/**** READ10 HEAD ****/
    56     /**** READ10 HEAD ****/
    54 	if (headOffset)
    57     if (headOffset)
    55         {
    58         {
    56 		TPos headpos = aPosition - headOffset;
    59         TPos headpos = aPosition - headOffset;
    57         iHeadbuf->Zero();
    60         iHeadbuf->Zero();
    58 		headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset);
    61         headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset);
    59 
    62 
    60 		__HOSTPRINT2(_L("\tRead head pos = 0%lx length = 0%lx"),
    63         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_10,
    61                      headpos, iBlockLength);
    64                      "Read head pos = 0%x %x length = 0%lx",
    62 		aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength);
    65                     I64HIGH(headpos), I64LOW(headpos), iBlockLength);
    63 		aBuf.Append(iHeadbuf->Ptr() + headOffset, headlen);		
    66         aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength);
    64         }
    67         aBuf.Append(iHeadbuf->Ptr() + headOffset, headlen);
    65 
    68         }
    66 	/**** READ10 BODY ****/
    69 
       
    70     /**** READ10 BODY ****/
    67     TInt blocksInMain = (aLength - headlen)/iBlockLength;
    71     TInt blocksInMain = (aLength - headlen)/iBlockLength;
    68 	if (blocksInMain)
    72     if (blocksInMain)
    69         {
    73         {
    70 		copylen = blocksInMain * iBlockLength;
    74         copylen = blocksInMain * iBlockLength;
    71 		__HOSTPRINT2(_L("\tRead main pos = 0%lx length = 0x%x"),
    75         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_11,
    72                      aPosition+headlen, copylen);
    76                      "Read main pos = 0%x %x length = 0x%x",
    73 		aProtocol.BlockReadL(aPosition+headlen, (TDes8 &)aBuf, copylen);
    77                      I64HIGH(aPosition+headlen), I64LOW(aPosition+headlen), copylen);
    74         }
    78         aProtocol.BlockReadL(aPosition+headlen, (TDes8 &)aBuf, copylen);
    75 
    79         }
    76 	copylen += headlen;
    80 
    77 
    81     copylen += headlen;
    78 	/**** READ10 TAIL ****/
    82 
       
    83     /**** READ10 TAIL ****/
    79     TInt tailLen = aLength - copylen;
    84     TInt tailLen = aLength - copylen;
    80 	if ((tailLen) != 0)
    85     if ((tailLen) != 0)
    81         {
    86         {
    82 		__HOSTPRINT2(_L("\tRead tail pos = 0%lx length = 0%lx"),
    87         OstTraceExt4(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_12,
    83                      aPosition+copylen, iBlockLength);
    88                      "Read tail pos = 0%x %x length = 0%x %x",
    84         iTailbuf->Zero();    
    89                      I64HIGH(aPosition+copylen), I64LOW(aPosition+copylen), I64HIGH(iBlockLength), I64LOW(iBlockLength));
    85 		aProtocol.BlockReadL(aPosition+copylen, *iTailbuf, iBlockLength);
    90         iTailbuf->Zero();
    86 		aBuf.Append(iTailbuf->Ptr(), tailLen);
    91         aProtocol.BlockReadL(aPosition+copylen, *iTailbuf, iBlockLength);
       
    92         aBuf.Append(iTailbuf->Ptr(), tailLen);
    87         }
    93         }
    88     }
    94     }
    89 
    95 
    90 
    96 
    91 /**
    97 /**
    99 void TBlockTransfer::WriteL(MBlockTransferProtocol& aProtocol,
   105 void TBlockTransfer::WriteL(MBlockTransferProtocol& aProtocol,
   100                             TPos aPosition,
   106                             TPos aPosition,
   101                             TInt aLength,
   107                             TInt aLength,
   102                             TDesC8& aBuf)
   108                             TDesC8& aBuf)
   103     {
   109     {
   104     __MSFNLOG
   110     TInt copylen = 0;
   105 	TInt copylen = 0;
       
   106     TInt headlen = 0;
   111     TInt headlen = 0;
   107 
   112 
   108     TPos headOffset = GetHeadBlockOffset(aPosition);
   113     TPos headOffset = GetHeadBlockOffset(aPosition);
   109 	/**** WRITE10 HEAD ****/
   114     /**** WRITE10 HEAD ****/
   110 	if (headOffset)
   115     if (headOffset)
   111         {
   116         {
   112 		TPos headpos = aPosition - headOffset;
   117         TPos headpos = aPosition - headOffset;
   113 
   118 
   114         iHeadbuf->Zero();
   119         iHeadbuf->Zero();
   115 
   120 
   116         RBuf8& buf = *iTailbuf;
   121         RBuf8& buf = *iTailbuf;
   117         buf.Zero();
   122         buf.Zero();
   118 
   123 
   119 		headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset);
   124         headlen = ((headOffset + aLength - 1) / iBlockLength) == 0 ? aLength : (iBlockLength - headOffset);
   120 
   125 
   121 		__HOSTPRINT2(_L("\tWrite-Read head pos = 0%lx length = 0%lx"),
   126         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_20,
   122                      headpos, iBlockLength);
   127                      "Write-Read head pos = 0%x %x length = 0%lx",
   123 
   128                      I64HIGH(headpos), I64LOW(headpos), iBlockLength);
   124 		aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength);
   129 
   125 		/* get head */
   130         aProtocol.BlockReadL(headpos, *iHeadbuf, iBlockLength);
   126 		__HOSTPRINT2(_L("\tcopying read data pos = 0%lx offset = 0%lx"),
   131         /* get head */
   127                      headpos, headOffset);
   132         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_21,
   128 		buf.Append(iHeadbuf->Ptr(), headOffset);
   133                      "tcopying read data pos = 0%x %x offset = 0%lx",
   129 
   134                      I64HIGH(headpos), I64LOW(headpos), headOffset);
   130 		/* get body */
   135         buf.Append(iHeadbuf->Ptr(), headOffset);
   131 		buf.Append(aBuf.Ptr(), headlen);
   136 
   132 
   137         /* get body */
   133 		/* Is it a short write and tail exist? */
   138         buf.Append(aBuf.Ptr(), headlen);
       
   139 
       
   140         /* Is it a short write and tail exist? */
   134         TInt headEndOffset = headOffset + headlen;
   141         TInt headEndOffset = headOffset + headlen;
   135 		if (headEndOffset != iBlockLength)
   142         if (headEndOffset != iBlockLength)
   136             {
   143             {
   137             TInt len = iBlockLength - headEndOffset;
   144             TInt len = iBlockLength - headEndOffset;
   138 
   145 
   139 			__HOSTPRINT2(_L("\t(short write) copying read data pos = 0%lx length = %08x"),
   146             OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_22,
   140                          (headpos + headEndOffset), len);
   147                          "(short write) copying read data pos = 0%x %x length = %08x",
   141 			buf.Append(iHeadbuf->Ptr() + headEndOffset, len);
   148                          I64HIGH(headpos + headEndOffset), I64LOW(headpos + headEndOffset), len);
       
   149             buf.Append(iHeadbuf->Ptr() + headEndOffset, len);
   142             }
   150             }
   143 
   151 
   144 		__HOSTPRINT2(_L("\tWrite head pos = 0%lx length = %08x"),
   152         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_23,
   145                      headpos, headlen);
   153                      "Write head pos = 0%x %x length = %08x",
   146 
   154                      I64HIGH(headpos), I64LOW(headpos), headlen);
   147 		aProtocol.BlockWriteL(headpos, (TDes8 &)buf, 0, iBlockLength);
   155 
   148         }
   156         aProtocol.BlockWriteL(headpos, (TDes8 &)buf, 0, iBlockLength);
   149 
   157         }
   150 	/**** WRITE10 BODY ****/
   158 
       
   159     /**** WRITE10 BODY ****/
   151     TPos blocksInMain = (aLength - headlen)/iBlockLength;
   160     TPos blocksInMain = (aLength - headlen)/iBlockLength;
   152 	if (blocksInMain)
   161     if (blocksInMain)
   153         {
   162         {
   154 		copylen = blocksInMain * iBlockLength;
   163         copylen = blocksInMain * iBlockLength;
   155 
   164 
   156         const TUint64 pos = aPosition + headlen;
   165         const TUint64 pos = aPosition + headlen;
   157 		__HOSTPRINT2(_L("\tWrite main pos = 0%lx length = %08x"),
   166         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_24,
   158                      pos, copylen);
   167                      "Write main pos = 0%x %x length = %08x",
   159 
   168                      I64HIGH(pos), I64LOW(pos), copylen);
   160 		/* form the body */
   169 
   161 		aProtocol.BlockWriteL(pos, (TDes8 &)aBuf, headlen, copylen);
   170         /* form the body */
   162         }
   171         aProtocol.BlockWriteL(pos, (TDes8 &)aBuf, headlen, copylen);
   163 
   172         }
   164 	copylen += headlen;
   173 
   165 
   174     copylen += headlen;
   166 	/**** WRITE10 TAIL ****/
   175 
       
   176     /**** WRITE10 TAIL ****/
   167     TInt tailLen = aLength - copylen;;
   177     TInt tailLen = aLength - copylen;;
   168 	if (tailLen != 0)
   178     if (tailLen != 0)
   169         {
   179         {
   170         RBuf8& buf = *iHeadbuf;
   180         RBuf8& buf = *iHeadbuf;
   171         buf.Zero();
   181         buf.Zero();
   172 
   182 
   173         iTailbuf->Zero();
   183         iTailbuf->Zero();
   174 
   184 
   175         const TUint64 pos = aPosition + copylen;
   185         const TUint64 pos = aPosition + copylen;
   176 
   186 
   177 		__HOSTPRINT2(_L("\tWrite-Read tail pos = 0%lx length = %08x"),
   187         OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, TBLOCKTRANSFER_25,
   178                      pos, iBlockLength);
   188                   "Write-Read tail pos = 0%x %x length = %08x",
   179 
   189                   I64HIGH(pos), I64LOW(pos), iBlockLength);
   180 		aProtocol.BlockReadL(pos, *iTailbuf, iBlockLength);
   190 
   181 		/* get head */
   191         aProtocol.BlockReadL(pos, *iTailbuf, iBlockLength);
   182 		buf.Append(aBuf.Ptr() + copylen, tailLen);
   192         /* get head */
   183 		/* get tail */
   193         buf.Append(aBuf.Ptr() + copylen, tailLen);
   184 		buf.Append(iTailbuf->Ptr() + tailLen, iBlockLength - tailLen);
   194         /* get tail */
   185 
   195         buf.Append(iTailbuf->Ptr() + tailLen, iBlockLength - tailLen);
   186 		aProtocol.BlockWriteL(pos, (TDes8 &)buf, 0, iBlockLength);
   196 
       
   197         aProtocol.BlockWriteL(pos, (TDes8 &)buf, 0, iBlockLength);
   187         }
   198         }
   188     }
   199     }
   189 
   200 
   190 
   201 
   191 void TBlockTransfer::SetCapacityL(TUint32 aBlockLength, TLba aLastLba)
   202 void TBlockTransfer::SetCapacityL(TUint32 aBlockLength, TLba aLastLba)
   192     {
   203     {
   193     __MSFNLOG
       
   194     iBlockLength = static_cast<TInt64>(aBlockLength);
   204     iBlockLength = static_cast<TInt64>(aBlockLength);
   195     iLastLba = aLastLba;
   205     iLastLba = aLastLba;
   196 
   206 
   197     __ASSERT_DEBUG(iHeadbuf, User::Invariant());
   207     __ASSERT_DEBUG(iHeadbuf, User::Invariant());
   198     __ASSERT_DEBUG(iTailbuf, User::Invariant());
   208     __ASSERT_DEBUG(iTailbuf, User::Invariant());
   199 
   209 
   200     if (iHeadbuf->Length() < iBlockLength)
   210     if (iHeadbuf->Length() < iBlockLength)
   201         {
   211         {
   202         iHeadbuf->ReAllocL(aBlockLength);
   212         iHeadbuf->ReAllocL(aBlockLength);
   203         iTailbuf->ReAllocL(aBlockLength);
   213         iTailbuf->ReAllocL(aBlockLength);
   204         }    
   214         }
   205     }
   215     }
   206 
   216 
   207 
   217 
   208 TPos TBlockTransfer::GetHeadBlockOffset(TPos aPos)
   218 TPos TBlockTransfer::GetHeadBlockOffset(TPos aPos)
   209     {
   219     {
   210     __MSFNLOG
   220     return (aPos % iBlockLength);
   211 	return (aPos % iBlockLength);
       
   212     }
   221     }
   213 
   222 
   214 TLba TBlockTransfer::GetHeadBlockLbaL(TPos aPos)
   223 TLba TBlockTransfer::GetHeadBlockLbaL(TPos aPos)
   215     {
   224     {
   216     __MSFNLOG
       
   217     TLba lba = I64LOW(aPos / iBlockLength);
   225     TLba lba = I64LOW(aPos / iBlockLength);
   218     if (lba > iLastLba)
   226     if (lba > iLastLba)
   219         User::Leave(KErrArgument);
   227         User::Leave(KErrArgument);
   220     return lba;
   228     return lba;
   221     }
   229     }
   222 
   230 
   223 TPos TBlockTransfer::GetTailBlockOffset(TPos aPos, TInt aLen)
   231 TPos TBlockTransfer::GetTailBlockOffset(TPos aPos, TInt aLen)
   224     {
   232     {
   225     __MSFNLOG
       
   226     return ((aPos + aLen) % iBlockLength);
   233     return ((aPos + aLen) % iBlockLength);
   227     }
   234     }
   228 
   235 
   229 TLba TBlockTransfer::GetTailBlockLbaL(TPos aPos, TInt aLen)
   236 TLba TBlockTransfer::GetTailBlockLbaL(TPos aPos, TInt aLen)
   230     {
   237     {
   231     __MSFNLOG
       
   232     TLba lba = I64LOW((aPos + aLen) / iBlockLength);
   238     TLba lba = I64LOW((aPos + aLen) / iBlockLength);
   233     if (lba > iLastLba)
   239     if (lba > iLastLba)
   234         User::Leave(KErrArgument);
   240         User::Leave(KErrArgument);
   235     return lba;
   241     return lba;
   236     }
   242     }