亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fat_misc.c

?? 這套代碼已經成功一直到S3C44B0X開發板上
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2003, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
File        : fat_misc.c
Purpose     : File system's FAT File System Layer misc routines
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/

/*********************************************************************
*
*             #include Section
*
**********************************************************************
*/

#include "fs_conf.h"
#include "fs_port.h"
#include "fs_dev.h"
#include "fs_api.h"
#include "fs_fsl.h"
#include "fs_int.h"
#include "fs_os.h"
#include "fs_lbl.h"
#include "fs_fat.h"
#include "fs_clib.h"


/*********************************************************************
*
*             #define constants
*
**********************************************************************
*/

#ifndef FS_FAT_NOFAT32
  #define FS_FAT_NOFAT32        0
#endif /* FS_FAT_NOFAT32 */

#ifndef FS_DIR_MAXOPEN
  #define FS_DIR_MAXOPEN        0
#endif /* FS_DIR_MAXOPEN */

#define FS_MEMBLOCK_NUM   (FS_MAXOPEN+FS_DIR_MAXOPEN)*2


/*********************************************************************
*
*             Local data types
*
**********************************************************************
*/

typedef struct {
  int status;
  char memory[FS_FAT_SEC_SIZE];
} _FS_FAT_block_type;


/*********************************************************************
*
*             Local Variables        
*
**********************************************************************
*/

static _FS_FAT_block_type          _FS_memblock[FS_MEMBLOCK_NUM];


/*********************************************************************
*
*             Local functions section
*
**********************************************************************
*/

/*********************************************************************
*
*             _FS_ReadBPB
*
  Description:
  FS internal function. Read Bios-Parameter-Block from a device and
  copy the relevant data to FS__FAT_aBPBUnit.

  Parameters:
  Idx         - Index of device in the device information table 
                referred by FS__pDevInfo.
  Unit        - Unit number.
 
  Return value:
  ==0         - BPB successfully read.
  <0          - An error has occured.
*/

static int _FS_ReadBPB(int Idx, FS_u32 Unit) {
  int err;
  unsigned char *buffer;
  
  buffer = (unsigned char*)FS__fat_malloc(FS_FAT_SEC_SIZE);
  if (!buffer) {
    return -1;
  }
  err = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, 0, (void*)buffer);
  if (err < 0) {
    FS__fat_free(buffer);
    return -1;
  }
  /* Assign FS__FAT_aBPBUnit */
  FS__FAT_aBPBUnit[Idx][Unit].BytesPerSec   = buffer[11] + 256 * buffer[12];      /* _512_,1024,2048,4096           */
  FS__FAT_aBPBUnit[Idx][Unit].SecPerClus    = buffer[13];                         /* sec in allocation unit         */
  FS__FAT_aBPBUnit[Idx][Unit].RsvdSecCnt    = buffer[14] + 256 * buffer[15];      /* 1 for FAT12 & FAT16            */
  FS__FAT_aBPBUnit[Idx][Unit].NumFATs       = buffer[16];                         /* 2                              */
  FS__FAT_aBPBUnit[Idx][Unit].RootEntCnt    = buffer[17] + 256 * buffer[18];      /* number of root dir entries     */
  FS__FAT_aBPBUnit[Idx][Unit].TotSec16      = buffer[19] + 256 * buffer[20];      /* RSVD + FAT + ROOT + FATA (<64k) */
  FS__FAT_aBPBUnit[Idx][Unit].FATSz16       = buffer[22] + 256 * buffer[23];      /* number of FAT sectors          */
  FS__FAT_aBPBUnit[Idx][Unit].TotSec32      = buffer[32] + 0x100UL * buffer[33]   /* RSVD + FAT + ROOT + FATA (>=64k) */
                                              + 0x10000UL * buffer[34] 
                                              + 0x1000000UL * buffer[35];
  if (FS__FAT_aBPBUnit[Idx][Unit].FATSz16 == 0) {
    FS__FAT_aBPBUnit[Idx][Unit].FATSz32       = buffer[36] + 0x100UL * buffer[37]   /* number of FAT sectors          */
                                                + 0x10000UL * buffer[38] 
                                                + 0x1000000UL * buffer[39];
    FS__FAT_aBPBUnit[Idx][Unit].ExtFlags      = buffer[40] + 256 * buffer[41];      /* mirroring info                 */
    FS__FAT_aBPBUnit[Idx][Unit].RootClus      = buffer[44] + 0x100UL * buffer[45]   /* root dir clus for FAT32        */
                                                + 0x10000UL * buffer[46] 
                                                + 0x1000000UL * buffer[47];
    FS__FAT_aBPBUnit[Idx][Unit].FSInfo        = buffer[48] + 256 * buffer[49];      /* position of FSInfo structure   */
  }
  else {
    FS__FAT_aBPBUnit[Idx][Unit].FATSz32       = 0;
    FS__FAT_aBPBUnit[Idx][Unit].ExtFlags      = 0;
    FS__FAT_aBPBUnit[Idx][Unit].RootClus      = 0;
    FS__FAT_aBPBUnit[Idx][Unit].FSInfo        = 0;
  }
  FS__FAT_aBPBUnit[Idx][Unit].Signature     = buffer[FS_FAT_SEC_SIZE-2] 
                                              + 256 * buffer[FS_FAT_SEC_SIZE-1];
  FS__fat_free(buffer);
  return err;
}


/*********************************************************************
*
*             _FS__fat_FindFreeCluster
*
  Description:
  FS internal function. Find the next free entry in the FAT.

  Parameters:
  Idx         - Index of device in the device information table 
                referred by FS__pDevInfo.
  Unit        - Unit number.
  pFATSector  - Returns the sector number of the free entry. 
  pLastSector - Returns the sector number of the sector in pBuffer.
  pFATOffset  - Returns the offset of the free FAT entry within the
                sector pFATSector.
  LastClust   - Cluster, which will be used to link the new allocated
                cluster to. Here it is used at hint for where to start
                in the FAT.
  pBuffer     - Pointer to a sector buffer.
  FSysType    - ==1 => FAT12
                ==0 => FAT16
                ==2 => FAT32
  FATSize     - Size of one FAT ind sectors.
  BytesPerSec - Number of bytes in each sector.
 
  Return value:
  >=0         - Number of the free cluster.
  <0          - An error has occured.
*/

static FS_i32 _FS__fat_FindFreeCluster(int Idx, FS_u32 Unit, FS_i32 *pFATSector, 
                                       FS_i32 *pLastSector, FS_i32 *pFATOffset, 
                                       FS_i32 LastClust, unsigned char *pBuffer, 
                                       int FSysType, FS_u32 FATSize, FS_i32 BytesPerSec) {
  FS_u32 totclst;
  FS_u32 rootdirsize;
  FS_i32 curclst;
  FS_i32 fatindex;
  int err;
  int scan;
  unsigned char fatentry;
  unsigned char a;
  unsigned char b;
#if (FS_FAT_NOFAT32==0)  
  unsigned char c;
  unsigned char d;
#endif  
  
  if (LastClust > 0) {
    curclst = LastClust + 1;  /* Start scan after the previous allocated sector */
  }
  else {
    curclst = 0;  /*  Start scan at the beginning of the media */
  }
  scan          = 0;
  *pFATSector   = 0;
  *pLastSector  = -1;
  fatentry      = 0xff;
  /* Calculate total number of data clusters on the media */
  totclst = (FS_u32)FS__FAT_aBPBUnit[Idx][Unit].TotSec16;
  if (totclst == 0) {
    totclst = FS__FAT_aBPBUnit[Idx][Unit].TotSec32;
  }
  rootdirsize = ((FS_u32)((FS_u32)FS__FAT_aBPBUnit[Idx][Unit].RootEntCnt) * FS_FAT_DENTRY_SIZE) / BytesPerSec;
  totclst     = totclst - (FS__FAT_aBPBUnit[Idx][Unit].RsvdSecCnt + FS__FAT_aBPBUnit[Idx][Unit].NumFATs * FATSize + rootdirsize);
  totclst    /= FS__FAT_aBPBUnit[Idx][Unit].SecPerClus;
  while (1) {
    if (curclst >= (FS_i32)totclst) {
      scan++;
      if (scan > 1) {
        break;  /* End of clusters reached after 2nd scan */
      }
      if (LastClust <= 0) {
        break;  /* 1st scan started already at zero */
      }
      curclst   = 0;  /* Try again starting at the beginning of the FAT */
      fatentry  = 0xff;
    }
    if (fatentry == 0) {
      break;  /* Free entry found */
    }
    if (FSysType == 1) {
      fatindex = curclst + (curclst / 2);    /* FAT12 */
    }
    else if (FSysType == 2) {
      fatindex = curclst * 4;               /* FAT32 */
    }
    else {
      fatindex = curclst * 2;               /* FAT16 */
    }
    *pFATSector = FS__FAT_aBPBUnit[Idx][Unit].RsvdSecCnt + (fatindex / BytesPerSec);
    *pFATOffset = fatindex % BytesPerSec;
    if (*pFATSector != *pLastSector) {
      err = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, *pFATSector, (void*)pBuffer);
      if (err < 0) {
        err = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, FATSize + *pFATSector, (void*)pBuffer);
        if (err < 0) {
          return -1;
        }
        /* Try to repair original FAT sector with contents of copy */
        FS__lb_write(FS__pDevInfo[Idx].devdriver, Unit, *pFATSector, (void*)pBuffer);
      }
      *pLastSector = *pFATSector;
    }
    if (FSysType == 1) {
      if (*pFATOffset == (BytesPerSec - 1)) {
        a = pBuffer[*pFATOffset];
        err = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, *pFATSector + 1, (void*)pBuffer);
        if (err < 0) {
          err = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, FATSize + *pFATSector + 1, (void*)pBuffer);
          if (err < 0) {
            return -1;
          }
          /* Try to repair original FAT sector with contents of copy */
          FS__lb_write(FS__pDevInfo[Idx].devdriver, Unit, *pFATSector + 1, (void*)pBuffer);
        }
        *pLastSector = *pFATSector + 1;
        b = pBuffer[0];
      }
      else {
        a = pBuffer[*pFATOffset];
        b = pBuffer[*pFATOffset + 1];
      }
      if (curclst & 1) {
        fatentry = ((a & 0xf0) >> 4 ) | b;
      }
      else {
        fatentry = a | (b & 0x0f);
      }
    }
#if (FS_FAT_NOFAT32==0)
    else if (FSysType == 2) {
      a = pBuffer[*pFATOffset];
      b = pBuffer[*pFATOffset + 1];
      c = pBuffer[*pFATOffset + 2];
      d = pBuffer[*pFATOffset + 3];
      fatentry = a | b | c | d;
    }
#endif /* FS_FAT_NOFAT32==0 */
    else {
      a = pBuffer[*pFATOffset];
      b = pBuffer[*pFATOffset + 1];
      fatentry = a | b;
    }
    if (fatentry != 0) {
      curclst++;  /* Cluster is in use or defect, so try the next one */
    }
  }
  if (fatentry == 0) {
    return curclst;  /* Free cluster found */
  }
  return -1;
}


/*********************************************************************
*
*             _FS__fat_SetEOFMark
*
  Description:
  FS internal function. Set the EOF mark in the FAT for a cluster.
  The function does not write the FAT sector. An exception is FAT12,
  if the FAT entry is in two sectors. 

  Parameters:
  Idx         - Index of device in the device information table 
                referred by FS__pDevInfo.
  Unit        - Unit number.
  FATSector   - FAT sector, where the cluster is located. 
  pLastSector - Pointer to an FS_i32, which contains the number of the 
                sector in pBuffer.
  FATOffset   - Offset of the cluster in the FAT sector.
  Cluster     - Cluster number, where to set the EOF mark.
  pBuffer     - Pointer to a sector buffer.
  FSysType    - ==1 => FAT12
                ==0 => FAT16
                ==2 => FAT32
  FATSize     - Size of one FAT ind sectors.
  BytesPerSec - Number of bytes in each sector.
 
  Return value:
  >=0         - EOF mark set.
  <0          - An error has occured.
*/

static int _FS__fat_SetEOFMark(int Idx, FS_u32 Unit, FS_i32 FATSector, 
                               FS_i32 *pLastSector, FS_i32 FATOffset, 
                               FS_i32 Cluster, unsigned char *pBuffer, 
                               int FSysType, FS_u32 FATSize, FS_i32 BytesPerSec) {
  int err1;
  int err2;
  int lexp;
  
  if (FSysType == 1) {
    if (FATOffset == (BytesPerSec - 1)) {
      /* Entry in 2 sectors (we have 2nd sector in buffer) */
      if (Cluster & 1) {
        pBuffer[0]  = (char)0xff;
      }
      else {
        pBuffer[0] |= (char)0x0f;
      }
      err1 = FS__lb_write(FS__pDevInfo[Idx].devdriver, Unit, FATSector + 1, (void*)pBuffer);
      err2 = FS__lb_write(FS__pDevInfo[Idx].devdriver, Unit, FATSize + FATSector + 1, (void*)pBuffer);
      lexp = (err1 < 0);
      lexp = lexp || (err2 < 0);
      if (lexp) {
        return -1;
      }
      err1 = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, FATSector, (void*)pBuffer);
      if (err1 < 0) {
        err1 = FS__lb_read(FS__pDevInfo[Idx].devdriver, Unit, FATSize + FATSector, (void*)pBuffer);
        if (err1 < 0) {
          return -1;
        }
        /* Try to repair original FAT sector with contents of copy */
        FS__lb_write(FS__pDevInfo[Idx].devdriver, Unit, FATSector, (void*)pBuffer);
      }
      *pLastSector = FATSector;
      if (Cluster & 1) {
        pBuffer[FATOffset] |= (char)0xf0;
      }
      else {
        pBuffer[FATOffset]  = (char)0xff;
      }
    }
    else {
      if (Cluster & 1) {
        pBuffer[FATOffset]   |= (char)0xf0;
        pBuffer[FATOffset+1]  = (char)0xff;
      }
      else {
        pBuffer[FATOffset]    = (char)0xff;
        pBuffer[FATOffset+1] |= (char)0x0f;
      }
    }
  }
#if (FS_FAT_NOFAT32==0)
  else if (FSysType == 2) { /* FAT32 */
    pBuffer[FATOffset]      = (char)0xff;
    pBuffer[FATOffset + 1]  = (char)0xff;
    pBuffer[FATOffset + 2]  = (char)0xff;
    pBuffer[FATOffset + 3]  = (char)0x0f;
  }
#endif /* FS_FAT_NOFAT32==0 */
  else { /* FAT16 */
    pBuffer[FATOffset]      = (char)0xff;
    pBuffer[FATOffset + 1]  = (char)0xff;
  }
  return 0;
}


/*********************************************************************
*
*             _FS__fat_LinkCluster
*
  Description:
  FS internal function. Link the new cluster with the EOF mark to the 
  cluster list.

  Parameters:
  Idx         - Index of device in the device information table 
                referred by FS__pDevInfo.
  Unit        - Unit number.
  pLastSector - Pointer to an FS_i32, which contains the number of the 
                sector in pBuffer.
  Cluster     - Cluster number of the new cluster with the EOF mark.
  LastClust   - Number of cluster, to which the new allocated cluster
                is linked to.
  pBuffer     - Pointer to a sector buffer.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人三级伦理片| 日韩黄色在线观看| av不卡一区二区三区| 国产精品国产三级国产aⅴ原创| 福利一区二区在线观看| 国产精品久久久久影院色老大| 波多野结衣中文一区| ...av二区三区久久精品| 色国产精品一区在线观看| 亚洲一区二区高清| 欧美电影影音先锋| 国产在线播放一区| 亚洲欧美国产毛片在线| 777奇米四色成人影色区| 久久精工是国产品牌吗| 中文字幕精品—区二区四季| 在线一区二区三区四区五区| 天天色图综合网| 久久久久久久综合日本| 91免费国产视频网站| 婷婷成人激情在线网| 久久综合色综合88| 色狠狠一区二区三区香蕉| 蜜桃久久av一区| 亚洲婷婷综合久久一本伊一区| 欧美日韩国产天堂| 国产精品18久久久久| 亚洲免费伊人电影| 欧美xxx久久| 99国产精品一区| 麻豆国产91在线播放| 国产精品国产自产拍高清av| 欧美高清视频不卡网| 国产.欧美.日韩| 日韩av在线播放中文字幕| 不卡影院免费观看| 激情小说亚洲一区| 91麻豆精东视频| 久久精品亚洲乱码伦伦中文| 性久久久久久久久久久久| 99精品视频中文字幕| 国产喂奶挤奶一区二区三区| 免费成人av在线| 欧美肥妇毛茸茸| 麻豆中文一区二区| 国产精品久久久久久亚洲伦 | 日韩高清一级片| 中文av一区二区| 精品噜噜噜噜久久久久久久久试看 | a级精品国产片在线观看| 人人超碰91尤物精品国产| 亚洲婷婷在线视频| www国产精品av| 欧美日韩国产电影| 在线电影院国产精品| 91片在线免费观看| 豆国产96在线|亚洲| 精油按摩中文字幕久久| 天天影视色香欲综合网老头| 亚洲欧美成人一区二区三区| 国产精品久久久久aaaa樱花| 亚洲精品在线观看网站| 91精品国产一区二区人妖| 91成人免费在线视频| kk眼镜猥琐国模调教系列一区二区| 国产一区二区在线观看免费| 蜜桃久久久久久久| 免费看欧美女人艹b| 日韩av一区二区在线影视| 亚洲国产成人av好男人在线观看| 国产精品久久久久影视| 欧美国产97人人爽人人喊| 国产婷婷色一区二区三区在线| 日韩欧美国产综合一区| 欧美mv日韩mv| 久久免费美女视频| 久久久国产午夜精品 | 制服丝袜中文字幕亚洲| 欧美人妖巨大在线| 欧美撒尿777hd撒尿| 欧美中文一区二区三区| 欧美日韩精品福利| 欧美老女人第四色| 日韩一区二区在线播放| 日韩视频一区二区三区| 精品久久久久久无| 久久日韩精品一区二区五区| 国产亚洲欧洲一区高清在线观看| 国产欧美日韩在线视频| 国产精品美女一区二区| 亚洲日本丝袜连裤袜办公室| 亚洲卡通动漫在线| 日日摸夜夜添夜夜添国产精品| 日本不卡在线视频| 国内外成人在线| av在线综合网| 欧美特级限制片免费在线观看| 91精品欧美一区二区三区综合在| 日韩精品在线一区二区| 国产精品女同一区二区三区| 亚洲日本va午夜在线影院| 亚洲123区在线观看| 激情偷乱视频一区二区三区| 成人三级伦理片| 欧美日韩国产天堂| 久久久久九九视频| 一区二区三区四区激情| 蜜桃传媒麻豆第一区在线观看| 成人av资源站| 在线观看91av| 中文字幕在线一区免费| 亚洲成人动漫在线观看| 精品一区二区三区免费播放| 成人91在线观看| 亚洲欧洲另类国产综合| 午夜国产精品影院在线观看| 国产精选一区二区三区| 欧美丝袜第三区| 久久综合资源网| 亚洲国产欧美在线人成| 国产乱一区二区| 欧美日韩三级在线| 国产欧美精品一区二区色综合 | 午夜激情久久久| 不卡影院免费观看| 日韩欧美美女一区二区三区| 亚洲柠檬福利资源导航| 精品写真视频在线观看| 在线观看亚洲一区| 中文字幕成人网| 欧美a一区二区| 色av成人天堂桃色av| 久久蜜桃av一区二区天堂| 天天综合日日夜夜精品| 99免费精品在线| 久久蜜桃av一区精品变态类天堂 | 欧美日韩亚州综合| 国产精品萝li| 国产精品综合一区二区| 91精品在线一区二区| 一区二区三区中文免费| 盗摄精品av一区二区三区| 欧美一级片在线观看| 亚洲小说欧美激情另类| 成人免费视频一区| 久久久一区二区三区捆绑**| 奇米精品一区二区三区在线观看一| 欧美在线视频全部完| 国产精品传媒入口麻豆| 国产一区二区不卡| 欧美成人免费网站| 免费在线成人网| 欧美剧在线免费观看网站| 亚洲视频图片小说| www.av亚洲| 国产精品久久久久一区二区三区共| 国产精品小仙女| 国产三级一区二区三区| 国产精品一线二线三线| 久久久99精品免费观看不卡| 美日韩黄色大片| 日韩精品一区二区三区视频播放 | 欧美三级午夜理伦三级中视频| 亚洲免费av观看| 99久久精品免费| 中文字幕日韩精品一区| 波多野结衣91| 中文字幕日本不卡| 91碰在线视频| 亚洲狠狠丁香婷婷综合久久久| 99re热视频这里只精品| 亚洲素人一区二区| 91国产丝袜在线播放| 亚洲美女偷拍久久| 欧美色成人综合| 免费观看久久久4p| 欧美videofree性高清杂交| 狠狠色狠狠色综合日日91app| 亚洲精品在线电影| 国产成人亚洲精品狼色在线| 国产女同性恋一区二区| 91在线视频在线| 亚洲国产一区二区三区| 91精品国产综合久久香蕉的特点 | 久久精品一区二区| 国产成人在线看| 亚洲人成人一区二区在线观看| 91香蕉视频mp4| 午夜久久久久久久久久一区二区| 91精品啪在线观看国产60岁| 国产精品自拍三区| 亚洲欧美一区二区视频| 欧美性大战久久| 久久不见久久见免费视频7| 国产欧美在线观看一区| 91福利区一区二区三区| 九色|91porny| 亚洲理论在线观看| 精品少妇一区二区三区 | 亚洲线精品一区二区三区|