kernel/eka/drivers/medmmc/toc.cpp
changeset 247 d8d70de2bd36
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // TOC Partition Management for Embedded MMC devices
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "toc.h"
       
    19 
       
    20 
       
    21 /*
       
    22  * Search entry in TOC with aName as part of ItemName.
       
    23  */
       
    24 TInt Toc::GetItemByName(const TText8* aName, STocItem& aItem)
       
    25     {
       
    26     if ( aName == NULL )
       
    27         {
       
    28         return KErrNotFound;
       
    29         }
       
    30     
       
    31 	// calculate length for name to be searched
       
    32     TUint nameLen = 0;
       
    33     for (; nameLen < KMaxItemNameLen && aName[nameLen] != 0; nameLen++) {};
       
    34         
       
    35 	if ( !nameLen ) 
       
    36 	    return KErrGeneral; // zero length or Blank Name
       
    37 
       
    38 	// check all items in TOC	 
       
    39 	for (TUint i=0; i < KMaxNbrOfTocItems && iTOC[i].iStart != KEndOfToc; i++)
       
    40 		{	
       
    41 		// calculate length of current item 
       
    42         TUint fileNameLen = 0;
       
    43 		for (; fileNameLen < KMaxItemNameLen && iTOC[i].iFileName[fileNameLen] != 0; fileNameLen++) {};
       
    44 		    
       
    45 		if ( fileNameLen < nameLen ) 
       
    46 		    continue;  // file name too short
       
    47 	
       
    48 		// compare Item with aName
       
    49 		for (TUint k = 0; k <= (fileNameLen - nameLen); k++ )				
       
    50 			{
       
    51             TUint l=0;
       
    52             for (; l < nameLen; l++ )
       
    53                 {
       
    54                 if ( aName[l] != iTOC[i].iFileName[k+l] ) 
       
    55                     break;
       
    56                 }
       
    57 
       
    58             if ( l == nameLen )
       
    59                 {
       
    60                 // item found
       
    61                 aItem = iTOC[i];
       
    62                 aItem.iStart += (iTocStartSector << KSectorShift);
       
    63                 return KErrNone;
       
    64                 }
       
    65 			}		
       
    66 		}
       
    67 	
       
    68 	return KErrNotFound;
       
    69     }
       
    70 
       
    71 //  End of File