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