歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

fatfs文件系統(tǒng)源碼分析

  • 資源ID:61671136       資源大小:59.50KB        全文頁數(shù):21頁
  • 資源格式: DOC        下載積分:0積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要0積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付說明:
本站最低充值0.01積分,下載本資源后余額將會(huì)存入您的賬戶,您可在我的個(gè)人中心查看。
驗(yàn)證碼:   換一換

 
賬號(hào):
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請知曉。

fatfs文件系統(tǒng)源碼分析

文檔供參考,可復(fù)制、編制,期待您的好評與關(guān)注! fatfs文件系統(tǒng)源碼分析一、概述 1、目的在移植之前,先將源代碼大概的閱讀一遍,主要是了解文件系統(tǒng)的結(jié)構(gòu)、各個(gè)函數(shù)的功能和接口、與移植相關(guān)的代碼等等。2、準(zhǔn)備工作在官方網(wǎng)站下載了0.07c版本的源代碼,利用記事本進(jìn)行閱讀。二、源代碼的結(jié)構(gòu)1、源代碼組成   源代碼壓縮包解壓后,共兩個(gè)文件夾,doc是說明,src里就是代碼。src文件夾里共五個(gè)文件和一個(gè)文件夾。文件夾是option,還有00readme.txt、diskio.c、diskio.h、ff.c、ff.h、integer.h。對比網(wǎng)上的文章,版本已經(jīng)不同了,已經(jīng)沒有所謂的tff.c和tff.h了,估計(jì)現(xiàn)在都采用條件編譯解決這個(gè)問題了,當(dāng)然文件更少,可能編譯選項(xiàng)可能越復(fù)雜。2、00readme.txt的說明  Low level disk I/O module is not included in this archive because the FatFs module is only a generic file system layer and not depend on any specific storage device. You have to provide a low level disk I/O module that written to control your storage device.主要是說不包含底層IO代碼,這是個(gè)通用文件系統(tǒng)可以在各種介質(zhì)上使用。我們移植時(shí)針對具體存儲(chǔ)設(shè)備提供底層代碼。接下來做了版權(quán)聲明-可以自由使用和傳播。然后對版本的變遷做了說明。3、源代碼閱讀次序  先讀integer.h,了解所用的數(shù)據(jù)類型,然后是ff.h,了解文件系統(tǒng)所用的數(shù)據(jù)結(jié)構(gòu)和各種函數(shù)聲明,然后是diskio.h,了解與介質(zhì)相關(guān)的數(shù)據(jù)結(jié)構(gòu)和操作函數(shù)。再把ff.c和diskio.c兩個(gè)文件所實(shí)現(xiàn)的函數(shù)大致掃描一遍。最后根據(jù)用戶應(yīng)用層程序調(diào)用函數(shù)的次序仔細(xì)閱讀相關(guān)代碼。三、源代碼閱讀1、integer.h頭文件 這個(gè)文件主要是類型聲明。以下是部分代碼。typedef int    INT;typedef unsigned int UINT;typedef signed char  CHAR;/* These types must be 8-bit integer */都是用typedef做類型定義。移植時(shí)可以修改這部分代碼,特別是某些定義與你所在工程的類型定義有沖突的時(shí)候。2、ff.h頭文件以下是部分代碼的分析#include “integer.h” 使用integer.h的類型定義#ifndef _FATFS#define _FATFS 0x007C  版本號(hào)007c,0.07c#define _WORD_ACCESS 0 /如果定義為1,則可以使用word訪問。中間有一些看著說明很容易弄清楚意思。這里就不例舉了。#define _CODE_PAGE 936/* The _CODE_PAGE specifies the OEM code page to be used on the target system./   936  Simplified Chinese GBK (DBCS, OEM, Windows)跟據(jù)這個(gè)中國應(yīng)該是936.打開option文件夾看一下。打開cc936.c文件,里面有一個(gè)很大的數(shù)組static const WCHAR uni2oem 。根據(jù)英文說明,這個(gè)數(shù)組用于unicode碼和OEM碼之間的相互轉(zhuǎn)換。接下來又有兩個(gè)函數(shù)ff_convert()和ff_wtoupper()具體執(zhí)行碼型轉(zhuǎn)換和將字符轉(zhuǎn)換為大寫。百度一下:看OEM碼什么意思。unicode是一種雙字節(jié)字符編碼,無論中文還是英文,或者其他語言統(tǒng)一到2個(gè)字節(jié)。與現(xiàn)有的任何編碼(ASCII,GB等)都不兼容。WindowsNT(2000)的內(nèi)核即使用該編碼,所有數(shù)據(jù)進(jìn)入內(nèi)核前轉(zhuǎn)換成UNICODE,退出內(nèi)核后在轉(zhuǎn)換成版本相關(guān)的編碼(通常稱為OEM,在簡體中文版下即為GB).(百度所得)繼續(xù)往下閱讀。#define _USE_LFN 1   /這個(gè)估計(jì)是長文件名支持了,以前的0.06版本好像是不支持。#define _MAX_LFN 255 /最長支持255個(gè)雙字節(jié)字符。#define _FS_RPATH 0  /是否文件相對路徑選項(xiàng)。/* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir,/  f_chdrive function are available.  /有些函數(shù)會(huì)受影響。/  Note that output of the f_readdir fnction is affected by this option. */#define _FS_REENTRANT 0  /如果要支持文件系統(tǒng)可重入,必須加入幾個(gè)函數(shù)。#define _TIMEOUT  1000 /* Timeout period in unit of time ticks of the OS */#define _SYNC_t   HANDLE /* Type of sync object used on the OS. e.g. HANDLE,OS_EVENT*, ID and etc. */* To make the FatFs module re-entrant, set _FS_REENTRANT to 1 and add user/  provided synchronization handlers, ff_req_grant, ff_rel_grant, ff_del_syncobj/  and ff_cre_syncobj function to the project. */#elif _CODE_PAGE = 936 /* Simplified Chinese GBK */#define _DF1S 0×81#define _DF1E 0xFE#define _DS1S 0×40#define _DS1E 0x7E#define _DS2S 0×80#define _DS2E 0xFE接下來很大一部分都是與語言相關(guān)的因素,略過。/* Character code support macros */ 三個(gè)宏判斷是否大寫、小寫、數(shù)字。#define IsUpper(c) (c)>=A')&&(c)<=Z')#define IsLower(c) (c)>=a')&&(c)<=z')#define IsDigit(c) (c)>=0)&&(c)<=9)#if _DF1S     /* DBCS configuration */雙字節(jié)編碼相關(guān)的設(shè)定,暫時(shí)不理會(huì)它。#if _MULTI_PARTITION         /* Multiple partition configuration */該變量定義為1時(shí),支持一個(gè)磁盤的多個(gè)分區(qū)。typedef struct _PARTITION        BYTE pd;     /* Physical drive# */       BYTE pt;      /* Partition # (0-3) */ PARTITION;Extern  const  PARTITION Drives;/如果支持分區(qū),則聲明變量Drivers  #define LD2PD(drv) (Drivesdrv.pd)      /* 獲得磁盤對應(yīng)的物理磁盤#define LD2PT(drv) (Drivesdrv.pt)       /*獲得磁盤對應(yīng)的分區(qū)#else                                         /* Single partition configuration */#define LD2PD(drv) (drv)  /* Physical drive# is equal to the logical drive# */#define LD2PT(drv) 0        /* Always mounts the 1st partition */#if _MAX_SS = 512  /一般扇區(qū)長度取512字節(jié)。#define   SS(fs)     512U#if _LFN_UNICODE && _USE_LFNtypedef WCHAR XCHAR;       /* Unicode */ XCHAR是文件名的碼型所用。#elsetypedef char XCHAR;        /* SBCS, DBCS */#endiftypedef struct _FATFS_        BYTE    fs_type;         /* FAT sub type */       BYTE    drive;             /*對應(yīng)實(shí)際驅(qū)動(dòng)號(hào)01 */       BYTE    csize;             /* 每個(gè)簇的扇區(qū)數(shù)目 */先查一下簇的含義:應(yīng)該是文件數(shù)據(jù)分配的基本單位。       BYTE    n_fats;           /* 文件分配表的數(shù)目 */FAT文件系統(tǒng)依次應(yīng)該是:引導(dǎo)扇區(qū)、文件分配表兩個(gè)、根目錄區(qū)和數(shù)據(jù)區(qū)。       BYTE    wflag;            /* win dirty flag (1:must be written back) */文件是否改動(dòng)的標(biāo)志,為1時(shí)要回寫。       WORD  id;                 /* File system mount ID 文件系統(tǒng)加載ID*/       WORD  n_rootdir;      /* 根目錄區(qū)目錄項(xiàng)的數(shù)目 */#if _FS_REENTRANT       _SYNC_t     sobj;              /* 允許重入,則定義同步對象 */#endif#if _MAX_SS != 512       WORD  s_size;           /* Sector size */#endif#if !_FS_READONLY  /文件為可寫       BYTE    fsi_flag;   /* fsinfo dirty flag (1:must be written back) */文件需要回寫的標(biāo)志       DWORD      last_clust;      /* Last allocated cluster */       DWORD      free_clust;      /* Number of free clusters */       DWORD      fsi_sector;      /* fsinfo sector */#endif#if _FS_RPATH       DWORD      cdir;              /* 使用相對路徑,則要存儲(chǔ)文件系統(tǒng)當(dāng)前目錄#endif       DWORD      sects_fat;       /*文件分配表占用的扇區(qū)       DWORD      max_clust;     /* 最大簇?cái)?shù)       DWORD      fatbase;  /*文件分配表開始扇區(qū)       DWORD      dirbase;  /*  如果是FAT32,根目錄開始扇區(qū)需要首先得到。       DWORD      database;       /* 數(shù)據(jù)區(qū)開始扇區(qū)       DWORD      winsect;  /* Current sector appearing in the win */目前的扇區(qū)在win里面,這個(gè)win數(shù)組暫時(shí)還不知道含義。       BYTE    win_MAX_SS;/* Disk access window for Directory/FAT */這是一個(gè)win512數(shù)組,存儲(chǔ)著一個(gè)扇區(qū),好像作為扇區(qū)緩沖使用。 FATFS;typedef struct _DIR_        FATFS* fs;/* Pointer to the owner file system object */指向相應(yīng)文件系統(tǒng)對象。       WORD  id;                 /* 文件系統(tǒng)加載ID*/       WORD  index;     /* Current read/write index number */目前讀寫索引代碼       DWORD      sclust;     /* Table start cluster (0:Static table) */文件數(shù)據(jù)區(qū)開始簇       DWORD      clust;             /* Current cluster */ 目前處理的簇       DWORD      sect;              /* Current sector */ 目前簇里對應(yīng)的扇區(qū)       BYTE*  dir;  /* Pointer to the current SFN entry in the win */       BYTE*  fn;                 /* Pointer to the SFN (in/out) file8,ext3,status1 */#if _USE_LFN       WCHAR*     lfn;   /* Pointer to the LFN working buffer */ 指向長文件名緩沖。       WORD  lfn_idx;   /* Last matched LFN index number (0xFFFF:No LFN) */#endif DIR;typedef struct _FIL_        FATFS* fs;                  /* Pointer to the owner file system object */       WORD  id;                 /* Owner file system mount ID */       BYTE    flag;        /* File status flags */文件狀態(tài)標(biāo)志       BYTE    csect;            /* Sector address in the cluster */扇區(qū)偏移       DWORD      fptr;        /* File R/W pointer */ 讀寫指針       DWORD      fsize;              /* File size */       DWORD      org_clust;      /* File start cluster */文件開始簇       DWORD      curr_clust;     /* Current cluster */當(dāng)前簇       DWORD      dsect;            /* Current data sector */文件當(dāng)前扇區(qū)#if !_FS_READONLY       DWORD      dir_sect; /* Sector containing the directory entry */該文件目錄項(xiàng)對應(yīng)所在的扇區(qū)       BYTE*  dir_ptr;   /* Ponter to the directory entry in the window */#endif#if !_FS_TINY       BYTE    buf_MAX_SS;/* File R/W buffer */文件讀寫緩沖#endif FIL;/* File status structure */typedef struct _FILINFO_        DWORD      fsize;              /* File size */       WORD  fdate;             /* Last modified date */       WORD  ftime;             /* Last modified time */       BYTE    fattrib;    /* Attribute */       char fname13;     /* Short file name (8.3 format) */#if _USE_LFN       XCHAR*      lfname;          /* Pointer to the LFN buffer */       int   lfsize;             /* Size of LFN buffer chrs */#endif FILINFO; 這個(gè)結(jié)構(gòu)主要描述文件的狀態(tài)信息,包括文件名13個(gè)字符(8+.+3+0)、屬性、修改時(shí)間等。接下來是函數(shù)的定義,先大概瀏覽一遍。FRESULT f_mount (BYTE, FATFS*);    /加載文件系統(tǒng),BYTE參數(shù)是ID,后一個(gè)是文件系統(tǒng)定義。FRESULT f_open (FIL*, const XCHAR*, BYTE);/打開文件,第一個(gè)參數(shù)是文件信息結(jié)構(gòu),第二個(gè)參數(shù)是文件名,第三是文件打開模式FRESULT f_read (FIL*, void*, UINT, UINT*);   /文件讀取函數(shù),參數(shù)1為文件對象(文件打開函數(shù)中得到),參數(shù)2為文件讀取緩沖區(qū),參數(shù)3為讀取的字節(jié)數(shù),參數(shù)4意義不清晰,等讀到源代碼就清楚了。FRESULT f_write (FIL*, const void*, UINT, UINT*);/寫文件,參數(shù)跟讀差不多FRESULT f_lseek (FIL*, DWORD); /移動(dòng)文件的讀寫指針,參數(shù)2應(yīng)該是移動(dòng)的數(shù)目。FRESULT f_close (FIL*);                /* Close an open file object */FRESULT f_opendir (DIR*, const XCHAR*);      打開目錄,返回目錄對象FRESULT f_readdir (DIR*, FILINFO*);              讀取目錄,獲得文件信息FRESULT f_stat (const XCHAR*, FILINFO*);                        /* Get file status */FRESULT f_getfree (const XCHAR*, DWORD*, FATFS*);   /* Get number of free clusters on the drive */FRESULT f_truncate (FIL*);                   /* Truncate file */FRESULT f_sync (FIL*);   /* Flush cached data of a writing file */將緩沖區(qū)數(shù)據(jù)寫回文件FRESULT f_unlink (const XCHAR*);            刪除目錄中的一個(gè)文件FRESULT     f_mkdir (const XCHAR*);        /* Create a new directory */FRESULT f_chmod (const XCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */FRESULT f_utime (const XCHAR*, const FILINFO*);      /* Change timestamp of the file/dir */FRESULT f_rename (const XCHAR*, const XCHAR*);    /* Rename/Move a file or directory */FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ 這個(gè)函數(shù)還要提供一個(gè)回調(diào)函數(shù)。FRESULT f_mkfs (BYTE, BYTE, WORD);          /* Create a file system on the drive */FRESULT f_chdir (const XCHAR*);      /* Change current directory */改變當(dāng)前目錄FRESULT f_chdrive (BYTE);           /* Change current drive */應(yīng)該說基本能明白這些函數(shù)用于干什么。#if _USE_STRFUNCint f_putc (int, FIL*);                                                    /* Put a character to the file */int f_puts (const char*, FIL*);                                       /* Put a string to the file */int f_printf (FIL*, const char*, );                         /* Put a formatted string to the file */char* f_gets (char*, int, FIL*);                              /* Get a string from the file */#define f_eof(fp) (fp)->fptr = (fp)->fsize) ? 1 : 0)#define f_error(fp) (fp)->flag & FA_ERROR) ? 1 : 0)#if _FS_REENTRANT  /如果定義了重入,則需要實(shí)現(xiàn)以下四個(gè)函數(shù)BOOL ff_cre_syncobj(BYTE, _SYNC_t*); 創(chuàng)建同步對象BOOL ff_del_syncobj(_SYNC_t);  刪除同步對象BOOL ff_req_grant(_SYNC_t);  申請同步對象void ff_rel_grant(_SYNC_t); 釋放同步對象。#endif3、diskio.h文件typedef BYTE      DSTATUS;typedef   DRESULT;  /首先定義了兩個(gè)變量,各個(gè)函數(shù)都有用到。BOOL assign_drives (int argc, char *argv); /這個(gè)函數(shù)不知道干嗎DSTATUS disk_initialize (BYTE); /磁盤初始化DSTATUS disk_status (BYTE); /獲取磁盤狀態(tài)DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);#if   _READONLY = 0DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);#endifDRESULT disk_ioctl (BYTE, BYTE, void*); /磁盤控制接下來還有一些常數(shù)的定義,具體用到時(shí)在看。4、diskio.c的結(jié)構(gòu)DSTATUS disk_initialize (   BYTE drv     /* Physical drive nmuber (0.) */)       DSTATUS stat;       int result;       switch (drv)        case ATA :              result = ATA_disk_initialize();              / translate the reslut code here              return stat;       case MMC :              result = MMC_disk_initialize();              / translate the reslut code here              return stat;       case USB :              result = USB_disk_initialize();              / translate the reslut code here              return stat;              return STA_NOINIT;函數(shù)基本都像這樣,drv表示磁盤的類型。沒有實(shí)現(xiàn),用戶必須實(shí)現(xiàn)這部分代碼。5、ff.c文件簡單瀏覽#include “ff.h”                     /* FatFs configurations and declarations */#include “diskio.h”              /* Declarations of low level disk I/O functions */#define   ENTER_FF(fs)           if (!lock_fs(fs) return FR_TIMEOUT; /獲取文件系統(tǒng)同步對象,不成功返回超時(shí),成功,繼續(xù)執(zhí)行。#define   LEAVE_FF(fs, res)     unlock_fs(fs, res); return res; /釋放文件系統(tǒng)同步對象。Static  FATFS *FatFs_DRIVES; /定義一個(gè)文件系統(tǒng)對象指針數(shù)組,當(dāng)然一般我們也就用到一個(gè)元素。Static WORD LfnBuf_MAX_LFN + 1;  /這個(gè)是與長文件名支持相關(guān)的。#define   NAMEBUF(sp,lp)      BYTE sp12; WCHAR *lp = LfnBuf#define INITBUF(dj,sp,lp) dj.fn = sp; dj.lfn = lp下面都是函數(shù)的定義,很多只在內(nèi)部使用。Static  void mem_cpy (void* dst, const void* src, int cnt)        char *d = (char*)dst;       const char *s = (const char *)src;       while (cnt) *d+ = *s+; /接下來還定義了幾個(gè)內(nèi)存操作的函數(shù),這個(gè)函數(shù)實(shí)現(xiàn)了從一塊內(nèi)存到另一塊的復(fù)制,下面還有mem_set()對一塊內(nèi)存進(jìn)行清0或設(shè)置操作;mem_cmp()比較內(nèi)存的多個(gè)字節(jié)是否相同,相同返回0;chk_chr()檢測字符串中是否存在某個(gè)字符,存在則返回該字符。FRESULT move_window (       FATFS *fs,           /* File system object */       DWORD sector   /* Sector number to make apperance in the fs->win */)/簡單閱讀了一下源代碼,應(yīng)該是改變文件系統(tǒng)的當(dāng)前工作扇區(qū),如果想要操作的扇區(qū)就是當(dāng)前扇區(qū),什么事不做;如果不是,則將原扇區(qū)寫回;如果是FAT表,還得寫入備份區(qū)。這個(gè)函數(shù)內(nèi)部使用,外部無法引用。FRESULT sync (  /* FR_OK: successful, FR_DISK_ERR: failed */       FATFS *fs     /* File system object */)/這個(gè)函數(shù)用于更新FAT32文件系統(tǒng)的FSI_Sector。什么含義還不太清楚。DWORD get_fat (       /* 0xFFFFFFFF:Disk error, 1:Interal error, Else:Cluster status */       FATFS *fs,    /* File system object */       DWORD clst       /* Cluster# to get the link information */)       if (move_window(fs, fsect + (clst / (SS(fs) / 4) break; 獲取簇號(hào)碼對應(yīng)的FAT扇區(qū)       return LD_DWORD(&fs->win(WORD)clst * 4) & (SS(fs) - 1) & 0x0FFFFFFF; /這個(gè)函數(shù)應(yīng)該是獲取簇的下一個(gè)連接簇。綜合起來,這個(gè)函數(shù)應(yīng)該是獲取下一簇,感覺這個(gè)函數(shù)名起得不太好。get_nextcluster感覺更好一點(diǎn)。FRESULT put_fat (       FATFS *fs,    /* File system object */       DWORD clst,      /* Cluster# to be changed in range of 2 to fs->max_clust 1 */       DWORD val /* New value to mark the cluster */)/上個(gè)函數(shù)是獲取連接簇,這個(gè)是寫入新的連接信息。FRESULT remove_chain (       FATFS *fs,                  /* File system object */       DWORD clst                     /* Cluster# to remove a chain from */)/將下一簇號(hào)寫為0,也就是該文件的簇到此為止,同時(shí)系統(tǒng)的自由簇增加1.DWORD create_chain (     /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */       FATFS *fs,                  /* File system object */       DWORD clst                     /* Cluster# to stretch. 0 means create a new chain. */)/跟上一個(gè)相反,在該簇的位置寫入新的下一簇簇號(hào)。DWORD clust2sect (  /* !=0: Sector number, 0: Failed invalid cluster# */       FATFS *fs,           /* File system object */       DWORD clst              /* Cluster# to be converted */) /這個(gè)函數(shù)是將簇號(hào)轉(zhuǎn)變?yōu)閷?yīng)的扇區(qū)號(hào)。clst * fs->csize + fs->database; /這個(gè)是算法FRESULT dir_seek (       DIR *dj,        /* Pointer to directory object */       WORD idx           /* Directory index number */)/這個(gè)函數(shù)的最終目的是根據(jù)索引號(hào)找到目錄項(xiàng)所在簇、所在扇區(qū)、并是目錄對象的對象指針指向文件系統(tǒng)對象窗口扇區(qū)的對應(yīng)位置。FRESULT dir_next (   /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT and could not streach */       DIR *dj,        /* Pointer to directory object */       BOOL streach      /* FALSE: Do not streach table, TRUE: Streach table if needed /) /移動(dòng)當(dāng)前目錄項(xiàng),根據(jù)索引,源代碼簡單看了一下,作用還不是很清晰,先放過。接下來有5個(gè)函數(shù)與長文件名有關(guān),這里先跳過。FRESULT dir_find (       DIR *dj                /* Pointer to the directory object linked to the file name */)/FRESULT dir_read (       DIR *dj                /* Pointer to the directory object that pointing the entry to be read */)FRESULT dir_register (      /* FR_OK:Successful, FR_DENIED:No free entry or too many SFN collision, FR_DISK_ERR:Disk error */       DIR *dj                       /* Target directory with object name to be created */)FRESULT dir_remove (     /* FR_OK: Successful, FR_DISK_ERR: A disk error */       DIR *dj                       /* Directory object pointing the entry to be removed */)/以上這些函數(shù)都是對目錄項(xiàng)的操作函數(shù)。FRESULT create_name (       DIR *dj,               /* Pointer to the directory object */       const XCHAR *path  /* Pointer to pointer to the segment in the path string */)/這個(gè)函數(shù)太長了,具體用到的時(shí)候再說吧。void get_fileinfo (         /* No return code */       DIR *dj,               /* Pointer to the directory object */       FILINFO *fno          /* Pointer to store the file information */)該函數(shù)用于獲取文件狀態(tài)信息。主要是從文件的目錄項(xiàng)中獲取信息。FRESULT follow_path (     /* FR_OK(0): successful, !=0: error code */       DIR *dj,               /* Directory object to return last directory and found object */       const XCHAR *path   /* Full-path string to find a file or directory */)該函數(shù)給定一個(gè)全路徑,得到相應(yīng)的目錄對象。BYTE check_fs (  /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record, 3:Error */       FATFS *fs,    /* File system object */       DWORD sect      /* Sector# (lba) to check if it is an FAT boot record or not */)該函數(shù)用于讀取BOOT扇區(qū),檢查是否FAT文件系統(tǒng)。FRESULT auto_mount (     /* FR_OK(0): successful, !=0: any error occured */       const XCHAR *path,       /* Pointer to pointer to the path name (drive number) */       FATFS *rfs,              /* Pointer to pointer to the found file system object */       BYTE chk_wp                   /* !=0: Check media write protection for write access */)這個(gè)函數(shù)的功能不太明白。FRESULT validate (    /* FR_OK(0): The object is valid, !=0: Invalid */       FATFS *fs,           /* Pointer to the file system object */       WORD id                   /* Member id of the target object to be checked */)/檢查是否合法的文件系統(tǒng)。FRESULT f_mount (       BYTE vol,            /* Logical drive number to be mounted/unmounted */       FATFS *fs            /* Pointer to new file system object (NULL for unmount)*/)這是一個(gè)很重要的函數(shù),裝載文件系統(tǒng)。也是從這個(gè)函數(shù)開始,對外輸出供用戶調(diào)用。if (vol >= _DRIVES)現(xiàn)在只支持卷號(hào)0.FatFsvol = fs;將參數(shù)文件系統(tǒng)對象指針賦給全局文件對象指針。后面的函數(shù)主要是對文件和目錄進(jìn)行操作,這里就不一一例舉了。21 / 21

注意事項(xiàng)

本文(fatfs文件系統(tǒng)源碼分析)為本站會(huì)員(文***)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!