userlibandfileserver/fileserver/sfat32/sl_dir.cpp
changeset 2 4122176ea935
equal deleted inserted replaced
0:a41df078684a 2:4122176ea935
       
     1 // Copyright (c) 1996-2009 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 // f32\sfat\sl_dir.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "sl_std.h"
       
    19 
       
    20 CFatDirCB* CFatDirCB::NewL()
       
    21 //
       
    22 // Static constructor
       
    23 //
       
    24 	{
       
    25 
       
    26 	CFatDirCB* fatDirCB=new(ELeave) CFatDirCB;
       
    27 	return fatDirCB;
       
    28 	}
       
    29 
       
    30 CFatDirCB::CFatDirCB()
       
    31 //
       
    32 // Constructor
       
    33 //
       
    34 	{
       
    35 	}
       
    36 
       
    37 CFatDirCB::~CFatDirCB()
       
    38 //
       
    39 // Destructor
       
    40 //
       
    41 	{
       
    42 	
       
    43 	delete iMatch;
       
    44 	delete iLongNameBuf;
       
    45 	}
       
    46 
       
    47 void CFatDirCB::SetDirL(const TFatDirEntry& anEntry,const TDesC& aName)
       
    48 //
       
    49 // Set the current entry to anEntryAddr
       
    50 //
       
    51 	{
       
    52 
       
    53 	__PRINT(_L("CFatDirCB::SetDirL"));	
       
    54 //	iEntryAddr=0;
       
    55 //	iPending=EFalse;
       
    56 	iEntry=anEntry;
       
    57 	iCurrentPos.iCluster= FatMount().StartCluster(iEntry);
       
    58 	iMatch=aName.AllocL();
       
    59 	if (iUidType[0]!=TUid::Null() || iUidType[1]!=TUid::Null() || iUidType[2]!=TUid::Null())
       
    60 		iMatchUid=ETrue;
       
    61 	}
       
    62 
       
    63 LOCAL_C TBool CompareUid(const TUidType& aUidTrg, const TUidType& aUidSuitor)
       
    64 //
       
    65 // Compare the suitor to the target pattern
       
    66 //
       
    67 	{
       
    68 	
       
    69 	if (aUidTrg[0]!=TUid::Null() && aUidTrg[0]!=aUidSuitor[0])
       
    70 		return(EFalse);
       
    71 	if (aUidTrg[1]!=TUid::Null() && aUidTrg[1]!=aUidSuitor[1])
       
    72 		return(EFalse);
       
    73 	if (aUidTrg[2]!=TUid::Null() && aUidTrg[2]!=aUidSuitor[2])
       
    74 		return(EFalse);
       
    75 	return(ETrue);
       
    76 	}
       
    77 
       
    78 void CFatDirCB::ReadL(TEntry &anEntry)
       
    79 //
       
    80 // Read the next entry from the directory.
       
    81 //
       
    82 	{
       
    83 
       
    84 	__PRINT(_L("CFatDirCB::ReadL"));
       
    85     
       
    86     FatMount().CheckStateConsistentL();
       
    87     
       
    88 
       
    89 	Mem::FillZ(&anEntry.iType,sizeof(TUidType));
       
    90 
       
    91 	TPtr entryName(anEntry.iName.Des());
       
    92 	FOREVER
       
    93 		{
       
    94 		if (iPending)
       
    95 			entryName=(*iLongNameBuf);
       
    96 		else
       
    97 			{
       
    98             FatMount().FindDosNameL(*iMatch,iAtt,iCurrentPos,iEntry,entryName,KErrEof);
       
    99 			FatMount().MoveToNextEntryL(iCurrentPos);
       
   100 			}
       
   101 		iPending=EFalse;
       
   102 		if (iEntry.Attributes()&~KEntryAttMaskSupported)
       
   103 			continue; // Ignore illegal entries
       
   104 		anEntry.iAtt=iEntry.Attributes();
       
   105 		anEntry.iSize=iEntry.Size();
       
   106 		anEntry.iModified=iEntry.Time(FatMount().TimeOffset() );
       
   107 	
       
   108 		if (entryName.Length()==0)
       
   109 			{
       
   110 			//	VFAT entry names are always created for UNICODE at an earlier stage
       
   111 			//	However, UNICODE builds may still encounter genuine FAT filenames through
       
   112 			//	the introduction of files created using a narrow (ASCII) build
       
   113 			TBuf8<0x20> dosName(DosNameFromStdFormat(iEntry.Name()));
       
   114 			LocaleUtils::ConvertToUnicodeL(entryName, dosName);
       
   115 			}
       
   116 		TBool matchedUid=ETrue;
       
   117 		if (iMatchUid && (anEntry.iAtt&KEntryAttDir)==EFalse)
       
   118 			{
       
   119 			if ((TUint)anEntry.iSize>=sizeof(TCheckedUid))
       
   120 				FatMount().ReadUidL(FatMount().StartCluster(iEntry),anEntry);
       
   121 			if (CompareUid(iUidType,anEntry.iType)==EFalse)
       
   122 				matchedUid=EFalse;
       
   123 			}
       
   124 					
       
   125 		if (matchedUid)
       
   126 			break;
       
   127 		}
       
   128 	if ((iAtt&KEntryAttAllowUid)==0 || (anEntry.iAtt&KEntryAttDir) || (TUint)anEntry.iSize<sizeof(TCheckedUid))
       
   129 		return;
       
   130 	if (iMatchUid==EFalse)
       
   131 		{
       
   132 		TInt r;
       
   133 		TRAP(r,FatMount().ReadUidL(FatMount().StartCluster(iEntry),anEntry));
       
   134 		if(r!=KErrNone && r!=KErrCorrupt)
       
   135 			User::Leave(r);
       
   136 		}
       
   137 	}
       
   138 
       
   139 void CFatDirCB::StoreLongEntryNameL(const TDesC& aName)
       
   140 //
       
   141 // Store aName while next read is pending
       
   142 //
       
   143 	{
       
   144 
       
   145 	AllocBufferL(iLongNameBuf,aName);
       
   146 	}