os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/msproxy/tmsmemmap.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/msproxy/tmsmemmap.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,102 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +//
    1.21 +// tmsmemmap.cpp
    1.22 +//
    1.23 +// Maps a position to mass storage address space
    1.24 +//
    1.25 +
    1.26 +/** @file
    1.27 +@internalTechnology
    1.28 +*/
    1.29 +
    1.30 +#include <e32def.h>
    1.31 +#include <e32err.h>
    1.32 +
    1.33 +#include "tmsmemmap.h"
    1.34 +#include "debug.h"
    1.35 +
    1.36 +
    1.37 +TMsDataMemMap::TMsDataMemMap()
    1.38 +	{
    1.39 +	__MSFNSLOG
    1.40 +    Reset();
    1.41 +	}
    1.42 +
    1.43 +
    1.44 +/**
    1.45 +    Checks that the block is within the limits of the media memory address space
    1.46 +    and truncates the length if block extends beyond media size.
    1.47 +
    1.48 +   @param aPos [IN] Position of start address [OUT] Adjusted position to real
    1.49 +   address on media.
    1.50 +   @param aLength [IN] Number of bytes [OUT] Number of bytes truncated in case
    1.51 +   of block overflow.
    1.52 +
    1.53 +   @return TInt KErrNone if block fits. KErrArgument if start position is
    1.54 +   greater than the media size. KErrEof if block extends beyond media size.
    1.55 + */
    1.56 +TInt TMsDataMemMap::TranslateDataPos(TInt64& aPos, TInt& aLength) const
    1.57 +    {
    1.58 +	__MSFNSLOG
    1.59 +    // Map to the actual position on the media
    1.60 +    aPos += iDataOffset;
    1.61 +
    1.62 +    if (aPos > iSize)
    1.63 +        {
    1.64 +        return KErrArgument;
    1.65 +        }
    1.66 +
    1.67 +    TInt64 endPos = aPos + aLength;
    1.68 +    if (endPos > iSize)
    1.69 +        {
    1.70 +        aLength = iSize - aPos;
    1.71 +        return KErrEof;
    1.72 +        }
    1.73 +    return KErrNone;
    1.74 +    }
    1.75 +
    1.76 +/**
    1.77 +   Checks that the block is within the limits of the media memory address space
    1.78 +
    1.79 +   @param aPos [IN] Position of start address [OUT] Adjusted position to real
    1.80 +   address on media.
    1.81 +   @param aLength Number of bytes.
    1.82 +
    1.83 +   @return TInt KErrNone if block fits. KErrArgument if start position is
    1.84 +   greater than the media size. KErrEof if block extends beyond media size.
    1.85 + */
    1.86 +TInt TMsDataMemMap::CheckBlockInRange(TInt64& aPos, TInt aLength) const
    1.87 +    {
    1.88 +	__MSFNSLOG
    1.89 +    // Map to the actual position on the media
    1.90 +    aPos += iDataOffset;
    1.91 +
    1.92 +    if (aPos > iSize)
    1.93 +        {
    1.94 +        return KErrArgument;
    1.95 +        }
    1.96 +
    1.97 +    TInt64 endPos = aPos + aLength;
    1.98 +    if (endPos > iSize)
    1.99 +        {
   1.100 +        __PXYPRINT2(_L("EOF found 0x%lx x%x"), aPos, aLength);
   1.101 +        return KErrEof;
   1.102 +        }
   1.103 +
   1.104 +    return KErrNone;
   1.105 +    }