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

📄 ff.lst

📁 文件系统 :FatFs/Tiny-FatFs Module Source Files R0.06
💻 LST
📖 第 1 页 / 共 5 页
字号:
 414   3                              c = dir[n];
 415   3                              if (c == ' ') break;
 416   3                              if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20;
 417   3                              *p++ = c;
 418   3                      }
 419   2              }
 420   1              *p = '\0';
 421   1      
 422   1              finfo->fattrib = dir[DIR_Attr];                                 /* Attribute */
 423   1              finfo->fsize = LD_DWORD(&dir[DIR_FileSize]);    /* Size */
 424   1              finfo->fdate = LD_WORD(&dir[DIR_WrtDate]);              /* Date */
 425   1              finfo->ftime = LD_WORD(&dir[DIR_WrtTime]);              /* Time */
 426   1      }
 427          #endif /* _FS_MINIMIZE <= 1 */
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 8   

 428          
 429          
 430          
 431          
 432          /*-----------------------------------------------------------------------*/
 433          /* Pick a paragraph and create the name in format of directory entry     */
 434          /*-----------------------------------------------------------------------*/
 435          
 436          static
 437          char make_dirfile (             /* 1: error - detected an invalid format, '\0'or'/': next character */
 438                  const char **path,      /* Pointer to the file path pointer */
 439                  char *dirname           /* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */
 440          )
 441          {
 442   1              BYTE n, t, c, a, b;
 443   1      
 444   1      
 445   1              memset(dirname, ' ', 8+3);      /* Fill buffer with spaces */
 446   1              a = 0; b = 0x18;        /* NT flag */
 447   1              n = 0; t = 8;
 448   1              for (;;) {
 449   2                      c = *(*path)++;
 450   2                      if (c == '\0' || c == '/') {            /* Reached to end of str or directory separator */
 451   3                              if (n == 0) break;
 452   3                              dirname[11] = _USE_NTFLAG ? (a & b) : 0;
 453   3                              return c;
 454   3                      }
 455   2                      if (c <= ' ' || c == 0x7F) break;               /* Reject invisible chars */
 456   2                      if (c == '.') {
 457   3                              if (!(a & 1) && n >= 1 && n <= 8) {     /* Enter extension part */
 458   4                                      n = 8; t = 11; continue;
 459   4                              }
 460   3                              break;
 461   3                      }
 462   2                      if (_USE_SJIS &&
 463   2                              ((c >= 0x81 && c <= 0x9F) ||    /* Accept S-JIS code */
 464   2                          (c >= 0xE0 && c <= 0xFC))) {
 465   3                              if (n == 0 && c == 0xE5)                /* Change heading \xE5 to \x05 */
 466   3                                      c = 0x05;
 467   3                              a ^= 0x01; goto md_l2;
 468   3                      }
 469   2                      if (c == '"') break;                            /* Reject " */
 470   2                      if (c <= ')') goto md_l1;                       /* Accept ! # $ % & ' ( ) */
 471   2                      if (c <= ',') break;                            /* Reject * + , */
 472   2                      if (c <= '9') goto md_l1;                       /* Accept - 0-9 */
 473   2                      if (c <= '?') break;                            /* Reject : ; < = > ? */
 474   2                      if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
 475   3                              if (c == '|') break;                    /* Reject | */
 476   3                              if (c >= '[' && c <= ']') break;/* Reject [ \ ] */
 477   3                              if (_USE_NTFLAG && c >= 'A' && c <= 'Z')
 478   3                                      (t == 8) ? (b &= 0xF7) : (b &= 0xEF);
 479   3                              if (c >= 'a' && c <= 'z') {             /* Convert to upper case */
 480   4                                      c -= 0x20;
 481   4                                      if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
 482   4                              }
 483   3                      }
 484   2              md_l1:
 485   2                      a &= 0xFE;
 486   2              md_l2:
 487   2                      if (n >= t) break;
 488   2                      dirname[n++] = c;
 489   2              }
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 9   

 490   1              return 1;
 491   1      }
 492          
 493          
 494          
 495          
 496          /*-----------------------------------------------------------------------*/
 497          /* Trace a file path                                                     */
 498          /*-----------------------------------------------------------------------*/
 499          
 500          static
 501          FRESULT trace_path (    /* FR_OK(0): successful, !=0: error code */
 502                  DIR *dj,                        /* Pointer to directory object to return last directory */
 503                  char *fn,                       /* Pointer to last segment name to return {file(8),ext(3),attr(1)} */
 504                  const char *path,       /* Full-path string to trace a file or directory */
 505                  BYTE **dir                      /* Pointer to pointer to found entry to retutn */
 506          )
 507          {
 508   1              DWORD clust;
 509   1              char ds;
 510   1              BYTE *dptr = NULL;
 511   1              FATFS *fs = dj->fs;
 512   1      
 513   1      
 514   1              /* Initialize directory object */
 515   1              clust = fs->dirbase;
 516   1              if (fs->fs_type == FS_FAT32) {
 517   2                      dj->clust = dj->sclust = clust;
 518   2                      dj->sect = clust2sect(fs, clust);
 519   2              } else {
 520   2                      dj->clust = dj->sclust = 0;
 521   2                      dj->sect = clust;
 522   2              }
 523   1              dj->index = 0;
 524   1      
 525   1              if (*path == '\0') {                                    /* Null path means the root directory */
 526   2                      *dir = NULL; return FR_OK;
 527   2              }
 528   1      
 529   1              for (;;) {
 530   2                      ds = make_dirfile(&path, fn);                   /* Get a paragraph into fn[] */
 531   2                      if (ds == 1) return FR_INVALID_NAME;
 532   2                      for (;;) {
 533   3                              if (!move_window(fs, dj->sect)) return FR_RW_ERROR;
 534   3                              dptr = &fs->win[(dj->index & ((SS(fs) - 1) / 32)) * 32];        /* Pointer to the directory entry */
 535   3                              if (dptr[DIR_Name] == 0)                                                /* Has it reached to end of dir? */
 536   3                                      return !ds ? FR_NO_FILE : FR_NO_PATH;
 537   3                              if (dptr[DIR_Name] != 0xE5                                              /* Matched? */
 538   3                                      && !(dptr[DIR_Attr] & AM_VOL)
 539   3                                      && !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
 540   3                              if (!next_dir_entry(dj))                                                /* Next directory pointer */
 541   3                                      return !ds ? FR_NO_FILE : FR_NO_PATH;
 542   3                      }
 543   2                      if (!ds) { *dir = dptr; return FR_OK; }                         /* Matched with end of path */
 544   2                      if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH;      /* Cannot trace because it is a file */
 545   2                      clust = ((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) | LD_WORD(&dptr[DIR_FstClusLO]); /* Get cluster# of
             - the directory */
 546   2                      dj->clust = dj->sclust = clust;                         /* Restart scanning at the new directory */
 547   2                      dj->sect = clust2sect(fs, clust);
 548   2                      dj->index = 2;
 549   2              }
 550   1      }
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 10  

 551          
 552          
 553          
 554          
 555          /*-----------------------------------------------------------------------*/
 556          /* Reserve a directory entry                                             */
 557          /*-----------------------------------------------------------------------*/
 558          
 559          #if !_FS_READONLY
              static
              FRESULT reserve_direntry (      /* FR_OK: successful, FR_DENIED: no free entry, FR_RW_ERROR: a disk error occur
             -ed */
                      DIR *dj,                                /* Target directory to create new entry */
                      BYTE **dir                              /* Pointer to pointer to created entry to retutn */
              )
              {
                      DWORD clust, sector;
                      BYTE c, n, *dptr;
                      FATFS *fs = dj->fs;
              
              
                      /* Re-initialize directory object */
                      clust = dj->sclust;
                      if (clust != 0) {       /* Dyanmic directory table */
                              dj->clust = clust;
                              dj->sect = clust2sect(fs, clust);
                      } else {                        /* Static directory table */
                              dj->sect = fs->dirbase;
                      }
                      dj->index = 0;
              
                      do {
                              if (!move_window(fs, dj->sect)) return FR_RW_ERROR;
                              dptr = &fs->win[(dj->index & ((SS(dj->fs) - 1) / 32)) * 32];    /* Pointer to the directory entry */
                              c = dptr[DIR_Name];
                              if (c == 0 || c == 0xE5) {              /* Found an empty entry */
                                      *dir = dptr; return FR_OK;
                              }
                      } while (next_dir_entry(dj));           /* Next directory pointer */
                      /* Reached to end of the directory table */
              
                      /* Abort when it is a static table or could not stretch dynamic table */
                      if (clust == 0 || !(clust = create_chain(fs, dj->clust))) return FR_DENIED;
                      if (clust == 1 || !move_window(fs, 0)) return FR_RW_ERROR;
              
                      /* Cleanup the expanded table */
                      fs->winsect = sector = clust2sect(fs, clust);
                      memset(fs->win, 0, SS(fs));
                      for (n = fs->csize; n; n--) {
                              if (disk_write(fs->drive, fs->win, sector, 1) != RES_OK)
                                      return FR_RW_ERROR;
                              sector++;
                      }
                      fs->winflag = 1;
                      *dir = fs->win;
              
                      return FR_OK;
              }
              #endif /* !_FS_READONLY */
 609          
 610          
 611          
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 11  

 612          
 613          /*-----------------------------------------------------------------------*/
 614          /* Load boot record and check if it is an FAT boot record                */
 615          /*-----------------------------------------------------------------------*/
 616          
 617          static
 618          BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error
             - */
 619                  FATFS *fs,      /* File system object */

⌨️ 快捷键说明

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