userlibandfileserver/fileserver/shostmassstorage/msproxy/tmsmemmap.cpp
changeset 0 a41df078684a
child 6 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 //
       
    18 // tmsmemmap.cpp
       
    19 //
       
    20 // Maps a position to mass storage address space
       
    21 //
       
    22 
       
    23 /** @file
       
    24 @internalTechnology
       
    25 */
       
    26 
       
    27 #include <e32def.h>
       
    28 #include <e32def_private.h>
       
    29 #include <e32err.h>
       
    30 #include <e32debug.h>
       
    31 
       
    32 #include "tmsmemmap.h"
       
    33 #include "debug.h"
       
    34 
       
    35 
       
    36 TMsDataMemMap::TMsDataMemMap()
       
    37 	{
       
    38 	__MSFNSLOG
       
    39     Reset();
       
    40 	}
       
    41 
       
    42 
       
    43 /**
       
    44     Checks that the block is within the limits of the media memory address space
       
    45     and truncates the length if block extends beyond media size.
       
    46 
       
    47    @param aPos [IN] Position of start address [OUT] Adjusted position to real
       
    48    address on media.
       
    49    @param aLength [IN] Number of bytes [OUT] Number of bytes truncated in case
       
    50    of block overflow.
       
    51 
       
    52    @return TInt KErrNone if block fits. KErrArgument if start position is
       
    53    greater than the media size. KErrEof if block extends beyond media size.
       
    54  */
       
    55 TInt TMsDataMemMap::TranslateDataPos(TInt64& aPos, TInt& aLength) const
       
    56     {
       
    57 	__MSFNSLOG
       
    58     // Map to the actual position on the media
       
    59     aPos += iDataOffset;
       
    60 
       
    61     if (aPos > iSize)
       
    62         {
       
    63         return KErrArgument;
       
    64         }
       
    65 
       
    66     TInt64 endPos = aPos + aLength;
       
    67     if (endPos > iSize)
       
    68         {
       
    69         aLength = iSize - aPos;
       
    70         return KErrEof;
       
    71         }
       
    72     return KErrNone;
       
    73     }
       
    74 
       
    75 /**
       
    76    Checks that the block is within the limits of the media memory address space
       
    77 
       
    78    @param aPos [IN] Position of start address [OUT] Adjusted position to real
       
    79    address on media.
       
    80    @param aLength Number of bytes.
       
    81 
       
    82    @return TInt KErrNone if block fits. KErrArgument if start position is
       
    83    greater than the media size. KErrEof if block extends beyond media size.
       
    84  */
       
    85 TInt TMsDataMemMap::CheckBlockInRange(TInt64& aPos, TInt aLength) const
       
    86     {
       
    87 	__MSFNSLOG
       
    88     // Map to the actual position on the media
       
    89     aPos += iDataOffset;
       
    90 
       
    91     if (aPos > iSize)
       
    92         {
       
    93         return KErrArgument;
       
    94         }
       
    95 
       
    96     TInt64 endPos = aPos + aLength;
       
    97     if (endPos > iSize)
       
    98         {
       
    99         __PXYPRINT2(_L("EOF found 0x%lx x%x"), aPos, aLength);
       
   100         return KErrEof;
       
   101         }
       
   102 
       
   103     return KErrNone;
       
   104     }