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