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