os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/msproxy/tmsmemmap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 <e32err.h>
    29 
    30 #include "tmsmemmap.h"
    31 #include "debug.h"
    32 
    33 
    34 TMsDataMemMap::TMsDataMemMap()
    35 	{
    36 	__MSFNSLOG
    37     Reset();
    38 	}
    39 
    40 
    41 /**
    42     Checks that the block is within the limits of the media memory address space
    43     and truncates the length if block extends beyond media size.
    44 
    45    @param aPos [IN] Position of start address [OUT] Adjusted position to real
    46    address on media.
    47    @param aLength [IN] Number of bytes [OUT] Number of bytes truncated in case
    48    of block overflow.
    49 
    50    @return TInt KErrNone if block fits. KErrArgument if start position is
    51    greater than the media size. KErrEof if block extends beyond media size.
    52  */
    53 TInt TMsDataMemMap::TranslateDataPos(TInt64& aPos, TInt& aLength) const
    54     {
    55 	__MSFNSLOG
    56     // Map to the actual position on the media
    57     aPos += iDataOffset;
    58 
    59     if (aPos > iSize)
    60         {
    61         return KErrArgument;
    62         }
    63 
    64     TInt64 endPos = aPos + aLength;
    65     if (endPos > iSize)
    66         {
    67         aLength = iSize - aPos;
    68         return KErrEof;
    69         }
    70     return KErrNone;
    71     }
    72 
    73 /**
    74    Checks that the block is within the limits of the media memory address space
    75 
    76    @param aPos [IN] Position of start address [OUT] Adjusted position to real
    77    address on media.
    78    @param aLength Number of bytes.
    79 
    80    @return TInt KErrNone if block fits. KErrArgument if start position is
    81    greater than the media size. KErrEof if block extends beyond media size.
    82  */
    83 TInt TMsDataMemMap::CheckBlockInRange(TInt64& aPos, TInt aLength) const
    84     {
    85 	__MSFNSLOG
    86     // Map to the actual position on the media
    87     aPos += iDataOffset;
    88 
    89     if (aPos > iSize)
    90         {
    91         return KErrArgument;
    92         }
    93 
    94     TInt64 endPos = aPos + aLength;
    95     if (endPos > iSize)
    96         {
    97         __PXYPRINT2(_L("EOF found 0x%lx x%x"), aPos, aLength);
    98         return KErrEof;
    99         }
   100 
   101     return KErrNone;
   102     }