⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dir.lst

📁 Philips LPC2138 Demo Application with Keil C
💻 LST
📖 第 1 页 / 共 5 页
字号:
ARM COMPILER V2.42,  dir                                                                   27/03/06  10:45:48  PAGE 1   


ARM COMPILER V2.42, COMPILATION OF MODULE dir
OBJECT MODULE PLACED IN .\obj\dir.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe src\dir.c THUMB DEBUG PRINT(.\LST\DIR.LST) TABS(4) OBJECT(.\obj\dir.obj) 

stmt  level    source

    1          /*****************************************************************************\
    2          *              efs - General purpose Embedded Filesystem library              *
    3          *          --------------------- -----------------------------------          *
    4          *                                                                             *
    5          * Filename : dir.c                                                            *
    6          * Description : The functions of dir.c are part of fs.c, they deal with all   *
    7          *               the directory specific stuff.                                 *
    8          *                                                                             *
    9          * This library is free software; you can redistribute it and/or               *
   10          * modify it under the terms of the GNU Lesser General Public                  *
   11          * License as published by the Free Software Foundation; either                *
   12          * version 2.1 of the License, or (at your option) any later version.          *
   13          *                                                                             *
   14          * This library is distributed in the hope that it will be useful,             *
   15          * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
   16          * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           *
   17          * Lesser General Public License for more details.                             *
   18          *                                                                             *
   19          *                                                    (c)2004 Lennart Yseboodt *
   20          *                                                    (c)2004 Michael De Nil   *
   21          \*****************************************************************************/
   22          
   23          /*****************************************************************************/
   24          #include "dir.h"
   25          /*****************************************************************************/
   26          
   27          /* ****************************************************************************  
   28           * void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
   29           * Description: This function stores the filerecord located at loc in filerec.
   30           * It fetches the required sector for this.
   31           * Return value: void
   32          */
   33          void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
   34          {
   35   1          euint8 *buf;
   36   1      
   37   1          buf=part_getSect(fs->part,loc->Sector,IOM_MODE_READONLY);
   38   1          *filerec=*(((FileRecord*)buf)+loc->Offset);
   39   1          part_relSect(fs->part,buf);
   40   1      }   
   41          
   42          /*****************************************************************************/
   43          
   44          /* ****************************************************************************  
   45           * void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
   46           * Description: This function writes the filerecord stored in filerec to disc at
   47           * location loc. 
   48           * Return value: void
   49          */
   50          void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
   51          {
   52   1          euint8 *buf;
   53   1          
   54   1          buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
   55   1          memCpy(filerec,buf+(loc->Offset*sizeof(*filerec)),sizeof(*filerec));
   56   1          part_relSect(fs->part,buf);
   57   1      }
   58          /*****************************************************************************/
   59          
ARM COMPILER V2.42,  dir                                                                   27/03/06  10:45:48  PAGE 2   

   60          /* ****************************************************************************  
   61           * void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename)
   62           * Description: This function fills in a filerecord with safe default values, and
   63           * a given fatfilename. If your system has a means of knowing time, here is an 
   64           * excellent place to apply it to the filerecord.  
   65           * Return value: void
   66          */
   67          void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename)
   68          {
   69   1          memCpy(fatfilename,filerec->FileName,11);
   70   1          filerec->Attribute=0x00;
   71   1          filerec->NTReserved=0x00;
   72   1          filerec->MilliSecTimeStamp=0x00;
   73   1          filerec->CreatedTime=time_getTime();
   74   1          filerec->CreatedDate=time_getDate(); 
   75   1          filerec->AccessDate=filerec->CreatedDate;
   76   1          filerec->FirstClusterHigh=0x0000;
   77   1          filerec->WriteTime=filerec->CreatedTime;
   78   1          filerec->WriteDate=filerec->CreatedDate;
   79   1          filerec->FirstClusterLow=0x0000;
   80   1          filerec->FileSize=0x00000000;
   81   1      }
*** WARNING C47 IN LINE 67 OF SRC\DIR.C: 'fs': unreferenced parameter
   82          /*****************************************************************************/
   83          
   84          /* ****************************************************************************  
   85           * void dir_setFirstCluster(File *file,euint32 cluster_addr)
   86           * Description: This function requires modification to release it from
   87           * depending on the file object.
   88           * Return value:
   89          */
   90          void dir_setFirstCluster(FileSystem *fs,FileLocation *loc,euint32 cluster_addr)
   91          {
   92   1          euint8 *buf;
   93   1          
   94   1          buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
   95   1          (((FileRecord*)buf)+loc->Offset)->FirstClusterHigh=cluster_addr>>16;
   96   1          (((FileRecord*)buf)+loc->Offset)->FirstClusterLow=cluster_addr&0xFFFF;  
   97   1          part_relSect(fs->part,buf);
   98   1      }
   99          /*****************************************************************************/
  100          
  101          /* ****************************************************************************  
  102           * void dir_setFileSize(FileSystem *fs, FileLocation *loc,euint32 numbytes)
  103           * Description: This function changes the filesize recorded at loc->Sector
  104           * to 'numbytes'.
  105           * Return value: void
  106          */
  107          void dir_setFileSize(FileSystem *fs, FileLocation *loc,euint32 numbytes)
  108          {
  109   1          euint8 *buf;
  110   1          
  111   1          buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
  112   1          (((FileRecord*)buf)+loc->Offset)->FileSize=numbytes;
  113   1          part_relSect(fs->part,buf);
  114   1      }
  115          /*****************************************************************************/
  116          
  117          /* ****************************************************************************  
  118           * esint8 dir_updateDirectoryEntry(FileSystem *fs,FileRecord *entry,FileLocation *loc))
  119           * This function changes the entire entity stores at loc to the data recorded
  120           * in entry. This is for custom updates to the directoryentry.
  121           * Return value: 0 on success, -1 on failure
  122          */
  123          esint8 dir_updateDirectoryEntry(FileSystem *fs,FileRecord *entry,FileLocation *loc)
  124          {
ARM COMPILER V2.42,  dir                                                                   27/03/06  10:45:48  PAGE 3   

  125   1          euint8 *buf;
  126   1          
  127   1          buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
  128   1          memCpy(entry,buf+(loc->Offset*sizeof(*entry)),sizeof(*entry));
  129   1          part_relSect(fs->part,buf);
  130   1          return(0);
  131   1      }
  132          
  133          /* ****************************************************************************  
  134           * euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
  135           * This function searches for a given fatfilename in the buffer provided.
  136           * It will iterate through the 16 direntry's in the buffer and searches
  137           * for the fatfilename. If found, it will store the offset and attribute
  138           * entry of the directoryrecord in the loc structure.
  139           * If loc is 0, then it's members are not touched.
  140           * Return value: This function returns 0 when it cannot find the file,
  141           * if it can find the file it will return the first cluster number.
  142          */
  143          euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
  144          {
  145   1          FileRecord fileEntry;
  146   1          euint8 c;
  147   1          
  148   1          for(c=0; c<16; c++)
  149   1          {
  150   2              fileEntry = *(((FileRecord*)buf) + c);
  151   2              /* Check if the entry is for short filenames */
  152   2              if( !( (fileEntry.Attribute & 0x0F) == 0x0F ) )
  153   2              {
  154   3                  if( strMatch((eint8*)fileEntry.FileName,fatname,11) == 0 )
  155   3                  {
  156   4                      /* The entry has been found, return the location in the dir */
  157   4                      if(loc)loc->Offset = c;
  158   4                      if(loc)loc->attrib = fileEntry.Attribute;
  159   4                      if((((euint32 )fileEntry.FirstClusterHigh)<<16)+ fileEntry.FirstClusterLow==0){
  160   5                          return(1); /* Lie about cluster, 0 means not found! */
  161   5                      }else{
  162   5                          return
  163   5                                  (
  164   5                                  (((euint32 )fileEntry.FirstClusterHigh)<<16)
  165   5                                  + fileEntry.FirstClusterLow
  166   5                                  );
  167   5                      }
  168   4                  }
  169   3              }
  170   2          }
  171   1          return(0);
  172   1      }
  173          
  174          /* ****************************************************************************  
  175           * euint32 dir_findFreeEntryinBuf(euint8* buf, FileLocation *loc)
  176           * This function searches for a free entry in a given sector 'buf'.
  177           * It will put the offset into the loc->Offset field, given that loc is not 0.
  178           * Return value: 1 when it found a free spot, 0 if it hasn't.
  179          */
  180          euint32 dir_findFreeEntryinBuf(euint8* buf, FileLocation *loc)
  181          {
  182   1          FileRecord fileEntry;
  183   1          euint8 c;
  184   1          
  185   1          for(c=0;c<16;c++){
  186   2              fileEntry = *(((FileRecord*)buf) + c);
  187   2              if( !( (fileEntry.Attribute & 0x0F) == 0x0F ) ){
  188   3                  if(fileEntry.FileName[0] == 0x00 ||
  189   3                     fileEntry.FileName[0] == 0xE5 ){
  190   4                      if(loc)loc->Offset=c;
ARM COMPILER V2.42,  dir                                                                   27/03/06  10:45:48  PAGE 4   

  191   4                      return(1);
  192   4                  }
  193   3              }
  194   2          }
  195   1          return(0);
  196   1      }
  197          
  198          /* ****************************************************************************  
  199           * euint32  dir_findinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
  200           * Description: This function searches for a given fatfilename in a buffer.
  201           * Return value: Returns 0 on not found, and the firstcluster when the name is found.
  202          */
  203          euint32  dir_findinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc, euint8 mode)
  204          {
  205   1          switch(mode){
  206   2              case DIRFIND_FILE:
  207   2                  return(dir_findFileinBuf(buf,fatname,loc));
  208   2                  break;
  209   2              case DIRFIND_FREE:
  210   2                  return(dir_findFreeEntryinBuf(buf,loc));
  211   2                  break;
  212   2              default:
  213   2                  return(0);
  214   2                  break;
  215   2          }
  216   1          return(0);
  217   1      }
  218          /*****************************************************************************/
  219          
  220          /* ****************************************************************************  
  221           * euint32 dir_findinCluster(FileSystem *fs,euint32 cluster,eint8 *fatname, FileLocation *loc, euint8 mod
             -e)
  222           * This function will search for an existing (fatname) or free directory entry
  223           * in a full cluster.
  224           * Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.
  225          */
  226          euint32 dir_findinCluster(FileSystem *fs,euint32 cluster,eint8 *fatname, FileLocation *loc, euint8 mode)
  227          {
  228   1          euint8 c,*buf=0;
  229   1          euint32 fclus;
  230   1          
  231   1          for(c=0;c<fs->volumeId.SectorsPerCluster;c++){
  232   2              buf = part_getSect(fs->part,fs_clusterToSector(fs,cluster)+c,IOM_MODE_READONLY);
  233   2              if((fclus=dir_findinBuf(buf,fatname,loc,mode))){
  234   3                  if(loc)loc->Sector=fs_clusterToSector(fs,cluster)+c;
  235   3                  part_relSect(fs->part,buf);
  236   3                  return(fclus);
  237   3              }
  238   2          }
  239   1          part_relSect(fs->part,buf);
  240   1          return(0);
  241   1      }
  242          
  243          /* ****************************************************************************  
  244           * euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 m
             -ode)
  245           * This function will search for an existing (fatname) or free directory entry
  246           * in a directory, following the clusterchains.
  247           * Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -