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

📄 ff.lst

📁 文件系统 :FatFs/Tiny-FatFs Module Source Files R0.06
💻 LST
📖 第 1 页 / 共 5 页
字号:
              )
              {
                      WORD bc;
                      BYTE *p;
                      DWORD fatsect;
              
              
                      fatsect = fs->fatbase;
                      switch (fs->fs_type) {
                      case FS_FAT12 :
                              bc = (WORD)clust * 3 / 2;
                              if (!move_window(fs, fatsect + (bc / SS(fs)))) return FALSE;
                              p = &fs->win[bc & (SS(fs) - 1)];
                              *p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
                              bc++;
                              fs->winflag = 1;
                              if (!move_window(fs, fatsect + (bc / SS(fs)))) return FALSE;
                              p = &fs->win[bc & (SS(fs) - 1)];
                              *p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
                              break;
              
                      case FS_FAT16 :
                              if (!move_window(fs, fatsect + (clust / (SS(fs) / 2)))) return FALSE;
                              ST_WORD(&fs->win[((WORD)clust * 2) & (SS(fs) - 1)], (WORD)val);
                              break;
              
                      case FS_FAT32 :
                              if (!move_window(fs, fatsect + (clust / (SS(fs) / 4)))) return FALSE;
                              ST_DWORD(&fs->win[((WORD)clust * 4) & (SS(fs) - 1)], val);
                              break;
              
                      default :
                              return FALSE;
                      }
                      fs->winflag = 1;
                      return TRUE;
              }
              #endif /* !_FS_READONLY */
 241          
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 5   

 242          
 243          
 244          
 245          /*-----------------------------------------------------------------------*/
 246          /* Remove a cluster chain                                                */
 247          /*-----------------------------------------------------------------------*/
 248          
 249          #if !_FS_READONLY
              static
              BOOL remove_chain (     /* TRUE: successful, FALSE: failed */
                      FATFS *fs,              /* File system object */
                      DWORD clust             /* Cluster# to remove chain from */
              )
              {
                      DWORD nxt;
              
              
                      while (clust >= 2 && clust < fs->max_clust) {
                              nxt = get_cluster(fs, clust);
                              if (nxt == 1) return FALSE;
                              if (!put_cluster(fs, clust, 0)) return FALSE;
                              if (fs->free_clust != 0xFFFFFFFF) {
                                      fs->free_clust++;
              #if _USE_FSINFO
                                      fs->fsi_flag = 1;
              #endif
                              }
                              clust = nxt;
                      }
                      return TRUE;
              }
              #endif
 274          
 275          
 276          
 277          
 278          /*-----------------------------------------------------------------------*/
 279          /* Stretch or create a cluster chain                                     */
 280          /*-----------------------------------------------------------------------*/
 281          
 282          #if !_FS_READONLY
              static
              DWORD create_chain (    /* 0: No free cluster, 1: Error, >=2: New cluster number */
                      FATFS *fs,                      /* File system object */
                      DWORD clust                     /* Cluster# to stretch, 0 means create new */
              )
              {
                      DWORD cstat, ncl, scl, mcl = fs->max_clust;
              
              
                      if (clust == 0) {               /* Create new chain */
                              scl = fs->last_clust;                   /* Get suggested start point */
                              if (scl == 0 || scl >= mcl) scl = 1;
                      }
                      else {                                  /* Stretch existing chain */
                              cstat = get_cluster(fs, clust); /* Check the cluster status */
                              if (cstat < 2) return 1;                /* It is an invalid cluster */
                              if (cstat < mcl) return cstat;  /* It is already followed by next cluster */
                              scl = clust;
                      }
              
                      ncl = scl;                              /* Start cluster */
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 6   

                      for (;;) {
                              ncl++;                                                  /* Next cluster */
                              if (ncl >= mcl) {                               /* Wrap around */
                                      ncl = 2;
                                      if (ncl > scl) return 0;        /* No free custer */
                              }
                              cstat = get_cluster(fs, ncl);   /* Get the cluster status */
                              if (cstat == 0) break;                  /* Found a free cluster */
                              if (cstat == 1) return 1;               /* Any error occured */
                              if (ncl == scl) return 0;               /* No free custer */
                      }
              
                      if (!put_cluster(fs, ncl, 0x0FFFFFFF)) return 1;                        /* Mark the new cluster "in use" */
                      if (clust != 0 && !put_cluster(fs, clust, ncl)) return 1;       /* Link it to previous one if needed */
              
                      fs->last_clust = ncl;                           /* Update fsinfo */
                      if (fs->free_clust != 0xFFFFFFFF) {
                              fs->free_clust--;
              #if _USE_FSINFO
                              fs->fsi_flag = 1;
              #endif
                      }
              
                      return ncl;             /* Return new cluster number */
              }
              #endif /* !_FS_READONLY */
 330          
 331          
 332          
 333          
 334          /*-----------------------------------------------------------------------*/
 335          /* Get sector# from cluster#                                             */
 336          /*-----------------------------------------------------------------------*/
 337          
 338          static
 339          DWORD clust2sect (      /* !=0: sector number, 0: failed - invalid cluster# */
 340                  FATFS *fs,              /* File system object */
 341                  DWORD clust             /* Cluster# to be converted */
 342          )
 343          {
 344   1              clust -= 2;
 345   1              if (clust >= (fs->max_clust - 2)) return 0;             /* Invalid cluster# */
 346   1              return clust * fs->csize + fs->database;
 347   1      }
 348          
 349          
 350          
 351          
 352          /*-----------------------------------------------------------------------*/
 353          /* Move directory pointer to next                                        */
 354          /*-----------------------------------------------------------------------*/
 355          
 356          static
 357          BOOL next_dir_entry (   /* TRUE: successful, FALSE: could not move next */
 358                  DIR *dj                         /* Pointer to directory object */
 359          )
 360          {
 361   1              DWORD clust;
 362   1              WORD idx;
 363   1      
 364   1      
 365   1              idx = dj->index + 1;
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 7   

 366   1              if ((idx & ((SS(dj->fs) - 1) / 32)) == 0) {             /* Table sector changed? */
 367   2                      dj->sect++;                             /* Next sector */
 368   2                      if (dj->clust == 0) {   /* In static table */
 369   3                              if (idx >= dj->fs->n_rootdir) return FALSE;     /* Reached to end of table */
 370   3                      } else {                                        /* In dynamic table */
 371   3                              if (((idx / (SS(dj->fs) / 32)) & (dj->fs->csize - 1)) == 0) {   /* Cluster changed? */
 372   4                                      clust = get_cluster(dj->fs, dj->clust);                 /* Get next cluster */
 373   4                                      if (clust < 2 || clust >= dj->fs->max_clust)    /* Reached to end of table */
 374   4                                              return FALSE;
 375   4                                      dj->clust = clust;                              /* Initialize for new cluster */
 376   4                                      dj->sect = clust2sect(dj->fs, clust);
 377   4                              }
 378   3                      }
 379   2              }
 380   1              dj->index = idx;        /* Lower several bits of dj->index indicates offset in dj->sect */
 381   1              return TRUE;
 382   1      }
 383          
 384          
 385          
 386          
 387          /*-----------------------------------------------------------------------*/
 388          /* Get file status from directory entry                                  */
 389          /*-----------------------------------------------------------------------*/
 390          
 391          #if _FS_MINIMIZE <= 1
 392          static
 393          void get_fileinfo (     /* No return code */
 394                  FILINFO *finfo, /* Ptr to store the file information */
 395                  const BYTE *dir /* Ptr to the directory entry */
 396          )
 397          {
 398   1              BYTE n, c, a;
 399   1              char *p;
 400   1      
 401   1      
 402   1              p = &finfo->fname[0];
 403   1              a = _USE_NTFLAG ? dir[DIR_NTres] : 0;           /* NT flag */
 404   1              for (n = 0; n < 8; n++) {       /* Convert file name (body) */
 405   2                      c = dir[n];
 406   2                      if (c == ' ') break;
 407   2                      if (c == 0x05) c = 0xE5;
 408   2                      if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20;
 409   2                      *p++ = c;
 410   2              }
 411   1              if (dir[8] != ' ') {            /* Convert file name (extension) */
 412   2                      *p++ = '.';
 413   2                      for (n = 8; n < 11; n++) {

⌨️ 快捷键说明

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