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

📄 ff.lst

📁 文件系统 :FatFs/Tiny-FatFs Module Source Files R0.06
💻 LST
📖 第 1 页 / 共 5 页
字号:
 620                  DWORD sect      /* Sector# (lba) to check if it is an FAT boot record or not */
 621          )
 622          {
 623   1              if (disk_read(fs->drive, fs->win, sect, 1) != RES_OK)   /* Load boot record */
 624   1                      return 2;
 625   1              if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55)                               /* Check record signature (always placed at offset 510 even 
             -if the sector size is >512) */
 626   1                      return 2;
 627   1      
 628   1              if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3))                 /* Check FAT signature */
 629   1                      return 0;
 630   1              if (!memcmp(&fs->win[BS_FilSysType32], "FAT32", 5) && !(fs->win[BPB_ExtFlags] & 0x80))
 631   1                      return 0;
 632   1      
 633   1              return 1;
 634   1      }
 635          
 636          
 637          
 638          
 639          /*-----------------------------------------------------------------------*/
 640          /* Make sure that the file system is valid                               */
 641          /*-----------------------------------------------------------------------*/
 642          
 643          static
 644          FRESULT auto_mount (    /* FR_OK(0): successful, !=0: any error occured */
 645                  const char **path,      /* Pointer to pointer to the path name (drive number) */
 646                  FATFS **rfs,            /* Pointer to pointer to the found file system object */
 647                  BYTE chk_wp                     /* !=0: Check media write protection for write access */
 648          )
 649          {
 650   1              BYTE drv, fmt, *tbl;
 651   1              DSTATUS stat;
 652   1              DWORD bootsect, fatsize, totalsect, maxclust;
 653   1              const char *p = *path;
 654   1              FATFS *fs;
 655   1      
 656   1      
 657   1              /* Get drive number from the path name */
 658   1              while (*p == ' ') p++;          /* Strip leading spaces */
 659   1              drv = p[0] - '0';                       /* Is there a drive number? */
 660   1              if (drv <= 9 && p[1] == ':')
 661   1                      p += 2;                         /* Found a drive number, get and strip it */
 662   1              else
 663   1                      drv = 0;                        /* No drive number is given, use drive number 0 as default */
 664   1              if (*p == '/') p++;             /* Strip heading slash */
 665   1              *path = p;                              /* Return pointer to the path name */
 666   1      
 667   1              /* Check if the drive number is valid or not */
 668   1              if (drv >= _DRIVES) return FR_INVALID_DRIVE;    /* Is the drive number valid? */
 669   1              *rfs = fs = FatFs[drv];                                 /* Returen pointer to the corresponding file system object */
 670   1              if (!fs) return FR_NOT_ENABLED;                 /* Is the file system object registered? */
 671   1      
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 12  

 672   1              if (fs->fs_type) {                                              /* If the logical drive has been mounted */
 673   2                      stat = disk_status(fs->drive);
 674   2                      if (!(stat & STA_NOINIT)) {                     /* and physical drive is kept initialized (has not been changed), */
 675   3      #if !_FS_READONLY
                                      if (chk_wp && (stat & STA_PROTECT))     /* Check write protection if needed */
                                              return FR_WRITE_PROTECTED;
              #endif
 679   3                              return FR_OK;                                   /* The file system object is valid */
 680   3                      }
 681   2              }
 682   1      
 683   1              /* The logical drive must be re-mounted. Following code attempts to mount the logical drive */
 684   1      
 685   1              memset(fs, 0, sizeof(FATFS));           /* Clean-up the file system object */
 686   1              fs->drive = LD2PD(drv);                         /* Bind the logical drive and a physical drive */
 687   1              stat = disk_initialize(fs->drive);      /* Initialize low level disk I/O layer */
 688   1              if (stat & STA_NOINIT)                          /* Check if the drive is ready */
 689   1                      return FR_NOT_READY;
 690   1      #if S_MAX_SIZ > 512                                             /* Get disk sector size if needed */
                      if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > S_MAX_SIZ)
                              return FR_NO_FILESYSTEM;
              #endif
 694   1      #if !_FS_READONLY
                      if (chk_wp && (stat & STA_PROTECT))     /* Check write protection if needed */
                              return FR_WRITE_PROTECTED;
              #endif
 698   1              /* Search FAT partition on the drive */
 699   1              fmt = check_fs(fs, bootsect = 0);       /* Check sector 0 as an SFD format */
 700   1              if (fmt == 1) {                                         /* Not an FAT boot record, it may be patitioned */
 701   2                      /* Check a partition listed in top of the partition table */
 702   2                      tbl = &fs->win[MBR_Table + LD2PT(drv) * 16];    /* Partition table */
 703   2                      if (tbl[4]) {                                                                   /* Is the partition existing? */
 704   3                              bootsect = LD_DWORD(&tbl[8]);                           /* Partition offset in LBA */
 705   3                              fmt = check_fs(fs, bootsect);                           /* Check the partition */
 706   3                      }
 707   2              }
 708   1              if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != SS(fs)) /* No valid FAT patition is found */
 709   1                      return FR_NO_FILESYSTEM;
 710   1      
 711   1              /* Initialize the file system object */
 712   1              fatsize = LD_WORD(&fs->win[BPB_FATSz16]);                       /* Number of sectors per FAT */
 713   1              if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]);
 714   1              fs->sects_fat = fatsize;
 715   1              fs->n_fats = fs->win[BPB_NumFATs];                                      /* Number of FAT copies */
 716   1              fatsize *= fs->n_fats;                                                          /* (Number of sectors in FAT area) */
 717   1              fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */
 718   1              fs->csize = fs->win[BPB_SecPerClus];                            /* Number of sectors per cluster */
 719   1              fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]);      /* Nmuber of root directory entries */
 720   1              totalsect = LD_WORD(&fs->win[BPB_TotSec16]);            /* Number of sectors on the file system */
 721   1              if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]);
 722   1              fs->max_clust = maxclust = (totalsect                           /* max_clust = Last cluster# + 1 */
 723   1                      - LD_WORD(&fs->win[BPB_RsvdSecCnt]) - fatsize - fs->n_rootdir / (SS(fs)/32)
 724   1                      ) / fs->csize + 2;
 725   1      
 726   1              fmt = FS_FAT12;                                                                         /* Determine the FAT sub type */
 727   1              if (maxclust >= 0xFF7) fmt = FS_FAT16;
 728   1              if (maxclust >= 0xFFF7) fmt = FS_FAT32;
 729   1      
 730   1              if (fmt == FS_FAT32)
 731   1                      fs->dirbase = LD_DWORD(&fs->win[BPB_RootClus]); /* Root directory start cluster */
 732   1              else
 733   1                      fs->dirbase = fs->fatbase + fatsize;                    /* Root directory start sector (lba) */
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 13  

 734   1              fs->database = fs->fatbase + fatsize + fs->n_rootdir / (SS(fs)/32);     /* Data start sector (lba) */
 735   1      
 736   1      #if !_FS_READONLY
                      /* Initialize allocation information */
                      fs->free_clust = 0xFFFFFFFF;
              #if _USE_FSINFO
                      /* Get fsinfo if needed */
                      if (fmt == FS_FAT32) {
                              fs->fsi_sector = bootsect + LD_WORD(&fs->win[BPB_FSInfo]);
                              if (disk_read(fs->drive, fs->win, fs->fsi_sector, 1) == RES_OK &&
                                      LD_WORD(&fs->win[BS_55AA]) == 0xAA55 &&
                                      LD_DWORD(&fs->win[FSI_LeadSig]) == 0x41615252 &&
                                      LD_DWORD(&fs->win[FSI_StrucSig]) == 0x61417272) {
                                      fs->last_clust = LD_DWORD(&fs->win[FSI_Nxt_Free]);
                                      fs->free_clust = LD_DWORD(&fs->win[FSI_Free_Count]);
                              }
                      }
              #endif
              #endif
 753   1      
 754   1              fs->fs_type = fmt;                      /* FAT syb-type */
 755   1              fs->id = ++fsid;                        /* File system mount ID */
 756   1              return FR_OK;
 757   1      }
*** WARNING C280 IN LINE 647 OF ..\SRC\FF.C: 'chk_wp': unreferenced local variable
 758          
 759          
 760          
 761          
 762          /*-----------------------------------------------------------------------*/
 763          /* Check if the file/dir object is valid or not                          */
 764          /*-----------------------------------------------------------------------*/
 765          
 766          static
 767          FRESULT validate (              /* FR_OK(0): The object is valid, !=0: Invalid */
 768                  const FATFS *fs,        /* Pointer to the file system object */
 769                  WORD id                         /* Member id of the target object to be checked */
 770          )
 771          {
 772   1              if (!fs || !fs->fs_type || fs->id != id)
 773   1                      return FR_INVALID_OBJECT;
 774   1              if (disk_status(fs->drive) & STA_NOINIT)
 775   1                      return FR_NOT_READY;
 776   1      
 777   1              return FR_OK;
 778   1      }
 779          
 780          
 781          
 782          
 783          /*--------------------------------------------------------------------------
 784          
 785             Public Functions
 786          
 787          --------------------------------------------------------------------------*/
 788          
 789          
 790          
 791          /*-----------------------------------------------------------------------*/
 792          /* Mount/Unmount a Locical Drive                                         */
 793          /*-----------------------------------------------------------------------*/
 794          
C51 COMPILER V8.08   FF                                                                    10/31/2008 14:44:16 PAGE 14  

 795          FRESULT f_mount (
 796                  BYTE drv,               /* Logical drive number to be mounted/unmounted */
 797                  FATFS *fs               /* Pointer to new file system object (NULL for unmount)*/
 798          )
 799          {
 800   1              if (drv >= _DRIVES) return FR_INVALID_DRIVE;
 801   1      
 802   1              if (FatFs[drv]) FatFs[drv]->fs_type = 0;        /* Clear old object */
 803   1      
 804   1              FatFs[drv] = fs;                        /* Register and clear new object */
 805   1              if (fs) fs->fs_type = 0;
 806   1      
 807   1              return FR_OK;
 808   1      }
 809          
 810          
 811          
 812          
 813          /*-----------------------------------------------------------------------*/
 814          /* Open or Create a File                                                 */
 815          /*-----------------------------------------------------------------------*/
 816          
 817          FRESULT f_open (
 818                  FIL *fp,                        /* Pointer to the blank file object */
 819                  const char *path,       /* Pointer to the file name */
 820                  BYTE mode                       /* Access mode and file open mode flags */
 821          )
 822          {
 823   1              FRESULT res;
 824   1              DIR dj;
 825   1              BYTE *dir;
 826   1              char fn[8+3+1];
 827   1      
 828   1      

⌨️ 快捷键说明

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