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

📄 fs_fcheck.c

📁 keil arm flash fs 最新版 在Keil arm下使用
💻 C
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  F l a s h   F i l e   S y s t e m
 *----------------------------------------------------------------------------
 *      Name:    FS_FCHECK.C 
 *      Purpose: File System Analyse Function
 *      Rev.:    V3.22
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "File_Config.h"

/*--------------------------- fcheck ----------------------------------------*/

int fcheck (const char *drive) {
   /* Analyse the FlashFS and check for allocation errors. */
   FALLOC fa;
   IOB *fcb;
   int handle;
   U32 bl,adr,prev,sa;

   /* Find an unused _iob structure. */
   if ((handle = fs_find_iob ()) == EOF) {
      return (1);
   }
   fcb = &_iob[handle];
   /* Get the drive index. */
   fcb->drive = fs_get_drive (drive);
   if (fcb->drive == DRV_NONE && *drive == 0) {
      /* Empty string provided for a drive name. */
      fcb->drive = _DEF_DRIVE;
   }
   if (fcb->drive == DRV_MCARD) {
      /* Memory Card currently not supported. */
      return (1);
   }
   /* Set drive parameters. */
   if (fs_set_params (fcb) == __FALSE) {
      return (1);
   }

   for (bl = 0; bl < fcb->NumSect; bl++) {
      /* Check all File Blocks for invalid FID and check file pointers for */
      /* reasonable values in ascending order.                             */
      adr = fs_adr_sig (bl, fcb);
      adr = fs_rd_sig (adr, &fa.end);
      if (fa.end != fcb->InitVal) {
         sa = ((DEVCONF *)fcb->DevCfg)[bl].bStart;
         for (prev = 0; ; prev = fa.end) {
            adr = fs_rd_alloc (adr, &fa);
            if (fa.end == fcb->InitVal) {
               /* End of Allocation info. */
               break;
            }
            if (fa.fileID == 0x8000) {
               /* Error, not existing file ID. */
               return (1);
            }
            if (fa.end < prev) {
               /* Error, not ascending allocation pointers. */
               return (1);
            }
            if ((sa + fa.end) > (adr & ~1)) {
               /* Error, overlapping file allocation record. */
               return (1);
            }
         }
      }
   }
   /* OK, file integrity passed. */
   return (0);
}

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

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