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