userlibandfileserver/fileserver/sfat32/fat_dir_entry.inl
changeset 15 4122176ea935
child 62 4a8fed1c0ef6
child 90 947f0dc9f7a8
equal deleted inserted replaced
0:a41df078684a 15:4122176ea935
       
     1 // Copyright (c) 1998-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\inc\fat_dir_entry.inl
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #if !defined(FAT_DIR_ENTRY_INL)
       
    24 #define FAT_DIR_ENTRY_INL
       
    25 
       
    26 //-------------------------------------------------------------------------------------------------------------------
       
    27 
       
    28 
       
    29 /**
       
    30 Defined cast of Fat directory entry data read to structure allowing access to data
       
    31 */
       
    32 #define pDir ((SFatDirEntry*)&iData[0])
       
    33 
       
    34 
       
    35 inline TFatDirEntry::TFatDirEntry() 
       
    36     {
       
    37     InitZ();
       
    38     }       
       
    39 
       
    40 /** zero-fill the entry contents  */
       
    41 inline void TFatDirEntry::InitZ() 
       
    42     {
       
    43     Mem::FillZ(iData, KSizeOfFatDirEntry);
       
    44     }
       
    45 
       
    46 /**
       
    47 Return the Dos name of a directory entry
       
    48 
       
    49 @return A descriptor containing the Dos name of a directory entry
       
    50 */
       
    51 inline const TPtrC8 TFatDirEntry::Name() const
       
    52     {return TPtrC8((TUint8*)&(pDir->iName),KFatDirNameSize);}
       
    53 /**
       
    54 @return The attributes for the Directory entry
       
    55 */
       
    56 inline TInt TFatDirEntry::Attributes() const
       
    57     {return pDir->iAttributes;}
       
    58 /**
       
    59 @param aOffset This offset will be subtracted from the returned time.
       
    60 @return Time of file modification
       
    61 */
       
    62 inline TTime TFatDirEntry::Time(TTimeIntervalSeconds aOffset) const
       
    63     {
       
    64     TTime time=DosTimeToTTime(pDir->iTime,pDir->iDate);
       
    65     return time-=aOffset;
       
    66     }
       
    67 /**
       
    68 @return The Start cluster for the file or directory for this entry 
       
    69 */
       
    70 inline TInt TFatDirEntry::StartCluster() const      
       
    71     {
       
    72     const TUint16 KStClustMaskHi = 0x0FFF;  
       
    73     return ((pDir->iStartClusterHi & KStClustMaskHi) << 16) | pDir->iStartClusterLo;
       
    74     }
       
    75 
       
    76 /**
       
    77 @return The size of file or directory for this entry 
       
    78 */
       
    79 inline TUint32 TFatDirEntry::Size() const
       
    80     {return pDir->iSize;}
       
    81 /**
       
    82 @return True if the entry is erased
       
    83 */
       
    84 inline TBool TFatDirEntry::IsErased() const
       
    85     {return (TBool)(iData[0]==KEntryErasedMarker);}
       
    86 /**
       
    87 @return True if the entry refers to the current directory
       
    88 */
       
    89 inline TBool TFatDirEntry::IsCurrentDirectory() const
       
    90     {return (TBool)(iData[0]==KDotEntryByte && iData[1]==KBlankSpace);}
       
    91 /**
       
    92 @return True if the Entry refers to the parent directory
       
    93 */
       
    94 inline TBool TFatDirEntry::IsParentDirectory() const
       
    95     {return (TBool)(iData[0]==KDotEntryByte && iData[1]==KDotEntryByte);}
       
    96 /**
       
    97 @return True if end of directory
       
    98 */
       
    99 inline TBool TFatDirEntry::IsEndOfDirectory() const
       
   100     {return (TBool)(iData[0]==0x00);}
       
   101 /**
       
   102 Set the Dos name of a directory entry
       
   103 
       
   104 @param aDes A descriptor containg the name
       
   105 */
       
   106 inline void TFatDirEntry::SetName(const TDesC8& aDes)
       
   107     {
       
   108     __ASSERT_DEBUG(aDes.Length()<=KFatDirNameSize,Fault(EFatBadDirEntryParameter));
       
   109     TPtr8 name(pDir->iName,KFatDirNameSize);
       
   110     name=aDes;
       
   111     }
       
   112 /**
       
   113 Set the file or directory attributes for this entry
       
   114 
       
   115 @param anAtts The file or directory attributes
       
   116 */
       
   117 inline void TFatDirEntry::SetAttributes(TInt anAtts)
       
   118     {
       
   119     __ASSERT_DEBUG(!(anAtts&~KMaxTUint8),Fault(EFatBadDirEntryParameter));
       
   120     pDir->iAttributes=(TUint8)anAtts;
       
   121     }
       
   122 /**
       
   123 Set the modification time and date of the directory entry
       
   124 
       
   125 @param aTime Modification time of the file or directory
       
   126 @aOffset aOffset This offset will be added to the time. 
       
   127 */
       
   128 inline void TFatDirEntry::SetTime(TTime aTime, TTimeIntervalSeconds aOffset)
       
   129     {
       
   130     aTime+=aOffset;
       
   131     pDir->iTime=(TUint16)DosTimeFromTTime(aTime);
       
   132     pDir->iDate=(TUint16)DosDateFromTTime(aTime);
       
   133     }
       
   134 
       
   135 inline void TFatDirEntry::SetCreateTime(TTime aTime, TTimeIntervalSeconds aOffset)
       
   136     {
       
   137     aTime+=aOffset;
       
   138     pDir->iTimeC=(TUint16)DosTimeFromTTime(aTime);
       
   139     pDir->iDateC=(TUint16)DosDateFromTTime(aTime);
       
   140     }
       
   141 
       
   142 /**
       
   143 Set the start cluster number of the file or directory refered to by the entry
       
   144 
       
   145 @param aStartCluster The start cluster number
       
   146 */
       
   147 inline void TFatDirEntry::SetStartCluster(TInt aStartCluster)
       
   148     {
       
   149     pDir->iStartClusterLo=(TUint16)(aStartCluster);
       
   150     pDir->iStartClusterHi=(TUint16)(aStartCluster >> 16);
       
   151     }
       
   152 /**
       
   153 Set the size of the file or directory refered to by the entry
       
   154 
       
   155 @param aFileSize Size of the file
       
   156 */
       
   157 inline void TFatDirEntry::SetSize(TUint32 aFileSize)
       
   158     {pDir->iSize=aFileSize;}
       
   159 /**
       
   160 Set the directory entry as erased
       
   161 */
       
   162 inline void TFatDirEntry::SetErased()
       
   163     {iData[0]=KEntryErasedMarker;}
       
   164 /**
       
   165 Set the current entry to refer to the current directory
       
   166 */
       
   167 inline void TFatDirEntry::SetCurrentDirectory()
       
   168     {
       
   169     iData[0]='.';
       
   170     Mem::Fill(&iData[1],KFatDirNameSize-1,' ');
       
   171     }
       
   172 /**
       
   173 Set the current entry to refer to the parent directory
       
   174 */
       
   175 inline void TFatDirEntry::SetParentDirectory()
       
   176     {
       
   177     iData[0]='.';iData[1]='.';
       
   178     Mem::Fill(&iData[2],KFatDirNameSize-2,' ');
       
   179     }
       
   180 /**
       
   181 Set the current entry to be the end of directory marker
       
   182 */
       
   183 inline void TFatDirEntry::SetEndOfDirectory()
       
   184     {Mem::FillZ(&iData[0],KFatDirNameSize);}
       
   185 
       
   186 /**
       
   187     Get VFAT entry ID. Uset by Rugged FAT and Scan Drive to fix broken entries
       
   188     Uses 1 byte from "Last Access Date" field, offset 19. Hack.
       
   189 */
       
   190 TUint TFatDirEntry::RuggedFatEntryId() const
       
   191     {
       
   192     return pDir->iReserved2;
       
   193     }
       
   194 
       
   195 /**
       
   196     Set VFAT entry ID. Uset by Rugged FAT and Scan Drive to fix broken entries
       
   197     Uses 1 byte from "Last Access Date" field, offset 19. Hack.
       
   198 */
       
   199 void  TFatDirEntry::SetRuggedFatEntryId(TUint16 aId) 
       
   200     {
       
   201     pDir->iReserved2 = aId;
       
   202     }
       
   203 
       
   204 
       
   205 /**
       
   206 @return True if the entry is the start of a long name set of entries
       
   207 */
       
   208 inline TBool TFatDirEntry::IsLongNameStart() const
       
   209     {return (TBool)((iData[0]&0x40) != 0);}
       
   210 /**
       
   211 @return True is the Entry is a VFat entry
       
   212 */
       
   213 inline TBool TFatDirEntry::IsVFatEntry() const
       
   214     {return (TBool)(Attributes()==KVFatEntryAttribute && IsEndOfDirectory()==EFalse);}
       
   215 /**
       
   216 @return The number of following VFat entries
       
   217 */
       
   218 inline TInt TFatDirEntry::NumFollowing() const
       
   219     {return (iData[0]&0x3F);}
       
   220 
       
   221 
       
   222 inline TUint8 TFatDirEntry::CheckSum() const
       
   223     {
       
   224         ASSERT(IsVFatEntry());
       
   225         return iData[13];
       
   226     }
       
   227 
       
   228 
       
   229 
       
   230 /**
       
   231 @return  ETrue if the Directory entry contains garbage data
       
   232 */
       
   233 inline TBool TFatDirEntry::IsGarbage() const
       
   234     {
       
   235     return (iData[0]==0xFF);
       
   236     }
       
   237 
       
   238 
       
   239 
       
   240 #endif //FAT_DIR_ENTRY_INL
       
   241 
       
   242 
       
   243 
       
   244 
       
   245 
       
   246 
       
   247 
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 
       
   254