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

📄 tff.lst

📁 文件系统 :FatFs/Tiny-FatFs Module Source Files R0.06
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V8.08   TFF                                                                   10/31/2008 14:44:16 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE TFF
OBJECT MODULE PLACED IN .\tff.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\src\tff.c BROWSE DEBUG OBJECTEXTEND PRINT(.\tff.lst) OBJECT(.\tff.obj)

line level    source

   1          /*----------------------------------------------------------------------------/
   2          /  FatFs - Tiny FAT file system module  R0.06                 (C)ChaN, 2008
   3          /-----------------------------------------------------------------------------/
   4          / The FatFs module is an experimenal project to implement FAT file system to
   5          / cheap microcontrollers. This is a free software and is opened for education,
   6          / research and development under license policy of following trems.
   7          /
   8          /  Copyright (C) 2008, ChaN, all right reserved.
   9          /
  10          / * The FatFs module is a free software and there is no warranty.
  11          / * You can use, modify and/or redistribute it for personal, non-profit or
  12          /   commercial use without any restriction under your responsibility.
  13          / * Redistributions of source code must retain the above copyright notice.
  14          /
  15          /-----------------------------------------------------------------------------/
  16          / Feb 26,'06 R0.00  Prototype.
  17          /
  18          / Apr 29,'06 R0.01  First stable version.
  19          /
  20          / Jun 01,'06 R0.02  Added FAT12 support.
  21          /                   Removed unbuffered mode.
  22          /                   Fixed a problem on small (<32M) patition.
  23          / Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).
  24          /
  25          / Sep 22,'06 R0.03  Added f_rename().
  26          /                   Changed option _FS_MINIMUM to _FS_MINIMIZE.
  27          / Dec 09,'06 R0.03a Improved cluster scan algolithm to write files fast.
  28          /
  29          / Feb 04,'07 R0.04  Added FAT32 supprt.
  30          /                   Changed some interfaces incidental to FatFs.
  31          /                   Changed f_mountdrv() to f_mount().
  32          / Apr 01,'07 R0.04a Added a capability of extending file size to f_lseek().
  33          /                   Added minimization level 3.
  34          /                   Fixed a problem in FAT32 support.
  35          / May 05,'07 R0.04b Added a configuration option _USE_NTFLAG.
  36          /                   Added FSInfo support.
  37          /                   Fixed some problems corresponds to FAT32 support.
  38          /                   Fixed DBCS name can result FR_INVALID_NAME.
  39          /                   Fixed short seek (<= csize) collapses the file object.
  40          /
  41          / Aug 25,'07 R0.05  Changed arguments of f_read() and f_write().
  42          / Feb 03,'08 R0.05a Added f_truncate() and f_utime().
  43          /                   Fixed off by one error at FAT sub-type determination.
  44          /                   Fixed btr in f_read() can be mistruncated.
  45          /                   Fixed cached sector is not flushed when create and close
  46          /                   without write.
  47          /
  48          / Apr 01,'08 R0.06  Added f_forward(), fputc(), fputs(), fprintf() and fgets().
  49          /                   Improved performance of f_lseek() on moving to the same
  50          /                   or following cluster.
  51          /----------------------------------------------------------------------------*/
  52          
  53          #include <string.h>
  54          #include "tff.h"                /* Tiny-FatFs declarations */
  55          #include "diskio.h"             /* Include file for user provided disk functions */
C51 COMPILER V8.08   TFF                                                                   10/31/2008 14:44:16 PAGE 2   

  56          
  57          
  58          static
  59          FATFS *FatFs;                   /* Pointer to the file system objects (logical drive) */
  60          static
  61          WORD fsid;                              /* File system mount ID */
  62          
  63          
  64          /*-------------------------------------------------------------------------
  65          
  66            Module Private Functions
  67          
  68          -------------------------------------------------------------------------*/
  69          
  70          
  71          /*-----------------------------------------------------------------------*/
  72          /* Change window offset                                                  */
  73          /*-----------------------------------------------------------------------*/
  74          
  75          static
  76          BOOL move_window (      /* TRUE: successful, FALSE: failed */
  77                  DWORD sector    /* Sector number to make apperance in the FatFs->win */
  78          )                                       /* Move to zero only writes back dirty window */
  79          {
  80   1              DWORD wsect;
  81   1              FATFS *fs = FatFs;
  82   1      
  83   1      
  84   1              wsect = fs->winsect;
  85   1              if (wsect != sector) {  /* Changed current window */
  86   2      #if !_FS_READONLY
                              BYTE n;
                              if (fs->winflag) {      /* Write back dirty window if needed */
                                      if (disk_write(0, fs->win, wsect, 1) != RES_OK)
                                              return FALSE;
                                      fs->winflag = 0;
                                      if (wsect < (fs->fatbase + fs->sects_fat)) {    /* In FAT area */
                                              for (n = fs->n_fats; n >= 2; n--) {     /* Refrect the change to all FAT copies */
                                                      wsect += fs->sects_fat;
                                                      disk_write(0, fs->win, wsect, 1);
                                              }
                                      }
                              }
              #endif
 100   2                      if (sector) {
 101   3                              if (disk_read(0, fs->win, sector, 1) != RES_OK)
 102   3                                      return FALSE;
 103   3                              fs->winsect = sector;
 104   3                      }
 105   2              }
 106   1              return TRUE;
 107   1      }
 108          
 109          
 110          
 111          
 112          /*-----------------------------------------------------------------------*/
 113          /* Clean-up cached data                                                  */
 114          /*-----------------------------------------------------------------------*/
 115          
 116          #if !_FS_READONLY
              static
C51 COMPILER V8.08   TFF                                                                   10/31/2008 14:44:16 PAGE 3   

              FRESULT sync (void)             /* FR_OK: successful, FR_RW_ERROR: failed */
              {
                      FATFS *fs = FatFs;
              
              
                      fs->winflag = 1;
                      if (!move_window(0)) return FR_RW_ERROR;
              #if _USE_FSINFO
                      /* Update FSInfo sector if needed */
                      if (fs->fs_type == FS_FAT32 && fs->fsi_flag) {
                              fs->winsect = 0;
                              memset(fs->win, 0, 512U);
                              ST_WORD(&fs->win[BS_55AA], 0xAA55);
                              ST_DWORD(&fs->win[FSI_LeadSig], 0x41615252);
                              ST_DWORD(&fs->win[FSI_StrucSig], 0x61417272);
                              ST_DWORD(&fs->win[FSI_Free_Count], fs->free_clust);
                              ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust);
                              disk_write(0, fs->win, fs->fsi_sector, 1);
                              fs->fsi_flag = 0;
                      }
              #endif
                      /* Make sure that no pending write process in the physical drive */
                      if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
                              return FR_RW_ERROR;
                      return FR_OK;
              }
              #endif
 145          
 146          
 147          
 148          
 149          /*-----------------------------------------------------------------------*/
 150          /* Get a cluster status                                                  */
 151          /*-----------------------------------------------------------------------*/
 152          
 153          static
 154          CLUST get_cluster (     /* 0,>=2: successful, 1: failed */
 155                  CLUST clust             /* Cluster# to get the link information */
 156          )
 157          {
 158   1              WORD wc, bc;
 159   1              DWORD fatsect;
 160   1              FATFS *fs = FatFs;
 161   1      
 162   1      
 163   1              if (clust >= 2 && clust < fs->max_clust) {              /* Valid cluster# */
 164   2                      fatsect = fs->fatbase;
 165   2                      switch (fs->fs_type) {
 166   3                      case FS_FAT12 :
 167   3                              bc = (WORD)clust * 3 / 2;
 168   3                              if (!move_window(fatsect + bc / 512U)) break;
 169   3                              wc = fs->win[bc % 512U]; bc++;
 170   3                              if (!move_window(fatsect + bc / 512U)) break;
 171   3                              wc |= (WORD)fs->win[bc % 512U] << 8;
 172   3                              return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
 173   3      
 174   3                      case FS_FAT16 :
 175   3                              if (!move_window(fatsect + clust / 256)) break;
 176   3                              return LD_WORD(&fs->win[((WORD)clust * 2) % 512U]);
 177   3      #if _FAT32
 178   3                      case FS_FAT32 :
 179   3                              if (!move_window(fatsect + clust / 128)) break;
C51 COMPILER V8.08   TFF                                                                   10/31/2008 14:44:16 PAGE 4   

 180   3                              return LD_DWORD(&fs->win[((WORD)clust * 4) % 512U]) & 0x0FFFFFFF;
 181   3      #endif
 182   3                      }
 183   2              }
 184   1      
 185   1              return 1;       /* Out of cluster range, or an error occured */
 186   1      }
 187          
 188          
 189          
 190          
 191          /*-----------------------------------------------------------------------*/
 192          /* Change a cluster status                                               */
 193          /*-----------------------------------------------------------------------*/
 194          
 195          #if !_FS_READONLY
              static
              BOOL put_cluster (      /* TRUE: successful, FALSE: failed */
                      CLUST clust,    /* Cluster# to change (must be 2 to fs->max_clust-1) */
                      CLUST val               /* New value to mark the cluster */
              )
              {
                      WORD bc;
                      BYTE *p;
                      DWORD fatsect;
                      FATFS *fs = FatFs;
              
              
                      fatsect = fs->fatbase;
                      switch (fs->fs_type) {

⌨️ 快捷键说明

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