sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: // sl@0: // tmsmemmap.cpp sl@0: // sl@0: // Maps a position to mass storage address space sl@0: // sl@0: sl@0: /** @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "tmsmemmap.h" sl@0: #include "debug.h" sl@0: sl@0: sl@0: TMsDataMemMap::TMsDataMemMap() sl@0: { sl@0: __MSFNSLOG sl@0: Reset(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Checks that the block is within the limits of the media memory address space sl@0: and truncates the length if block extends beyond media size. sl@0: sl@0: @param aPos [IN] Position of start address [OUT] Adjusted position to real sl@0: address on media. sl@0: @param aLength [IN] Number of bytes [OUT] Number of bytes truncated in case sl@0: of block overflow. sl@0: sl@0: @return TInt KErrNone if block fits. KErrArgument if start position is sl@0: greater than the media size. KErrEof if block extends beyond media size. sl@0: */ sl@0: TInt TMsDataMemMap::TranslateDataPos(TInt64& aPos, TInt& aLength) const sl@0: { sl@0: __MSFNSLOG sl@0: // Map to the actual position on the media sl@0: aPos += iDataOffset; sl@0: sl@0: if (aPos > iSize) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: TInt64 endPos = aPos + aLength; sl@0: if (endPos > iSize) sl@0: { sl@0: aLength = iSize - aPos; sl@0: return KErrEof; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Checks that the block is within the limits of the media memory address space sl@0: sl@0: @param aPos [IN] Position of start address [OUT] Adjusted position to real sl@0: address on media. sl@0: @param aLength Number of bytes. sl@0: sl@0: @return TInt KErrNone if block fits. KErrArgument if start position is sl@0: greater than the media size. KErrEof if block extends beyond media size. sl@0: */ sl@0: TInt TMsDataMemMap::CheckBlockInRange(TInt64& aPos, TInt aLength) const sl@0: { sl@0: __MSFNSLOG sl@0: // Map to the actual position on the media sl@0: aPos += iDataOffset; sl@0: sl@0: if (aPos > iSize) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: TInt64 endPos = aPos + aLength; sl@0: if (endPos > iSize) sl@0: { sl@0: __PXYPRINT2(_L("EOF found 0x%lx x%x"), aPos, aLength); sl@0: return KErrEof; sl@0: } sl@0: sl@0: return KErrNone; sl@0: }