FATFS 初学之 f_mount
生活随笔
收集整理的這篇文章主要介紹了
FATFS 初学之 f_mount
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 /*-----------------------------------------------------------------------*/
2 /* Mount/Unmount a Logical Drive */
3 /*-----------------------------------------------------------------------*/
4
5 FRESULT f_mount (
6 BYTE vol, /* Logical drive number to be mounted/unmounted */
7 FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
8 )
9 {
10 FATFS *rfs;
11
12
13 if (vol >= _VOLUMES) /* Check if the drive number is valid */
14 return FR_INVALID_DRIVE;
15 rfs = FatFs[vol]; /* Get current fs object */
16
17 if (rfs) {
18 #if _FS_SHARE
19 clear_lock(rfs);
20 #endif
21 #if _FS_REENTRANT /* Discard sync object of the current volume */
22 if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;
23 #endif
24 rfs->fs_type = 0; /* Clear old fs object */
25 }
26
27 if (fs) {
28 fs->fs_type = 0; /* Clear new fs object */
29 #if _FS_REENTRANT /* Create sync object for the new volume */
30 if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
31 #endif
32 }
33 FatFs[vol] = fs; /* Register new fs object */
34
35 return FR_OK;
36 }
View Code
1FATFS *FatFs[_VOLUMES];/*Pointer to the file system objects (logical drives)*/
函數功能:注冊/注銷一個工作區(掛載/注銷分區文件系統)
描述:在使用任何其它文件函數之前,必須使用該函數為每個使用卷注冊一個工作區。要注銷一個工作區,只要指定 fs為 NULL即可,然后該工作區可以被丟棄。
該函數只初始化給定的工作區,以及將該工作區的地址注冊到內部表中,不訪問磁盤I/O層。卷裝入過程是在 f_mount函數后或存儲介質改變后的第一次文件訪問時完成的。
通俗了說就是給磁盤分配文件系統的:計算機中的盤符是 C: D: E;FATFS的盤符是 0: 1: 2:
f_mount(0,&fs); // 為 0號盤符分配新的文件系統 fs,fs是 FATFS類型,用于記錄邏輯磁盤工作區
1 /*-----------------------------------------------------------------------*/
2 /* Mount/Unmount a Logical Drive */
3 /*-----------------------------------------------------------------------*/
4 FRESULT f_mount (
5 BYTE vol, /* 邏輯驅動器安裝/卸載 */
6 FATFS *fs /* 新的文件系統對象指針(卸載NULL) */
7 )
8 {
9 FATFS *rfs;
10
11 if (vol >= _VOLUMES) /* 檢查驅動器號是否有效 */
12 return FR_INVALID_DRIVE;
13 rfs = FatFs[vol]; /* 獲得原盤符下對象 */
14
15 if (rfs) { /* 檢查原盤符下是否掛有文件系統,若有則釋放掉 */
16 #if _FS_SHARE
17 clear_lock(rfs);
18 #endif
19 #if _FS_REENTRANT /* Discard sync object of the current volume */
20 if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;
21 #endif
22 rfs->fs_type = 0; /* Clear old fs object */
23 }
24
25 if (fs) { /* 檢測參數,若為 NULL則表示卸載盤符,下面兩步執行無意義 */
26 fs->fs_type = 0; /* 0: 未裝載 */
27 #if _FS_REENTRANT /* Create sync object for the new volume */
28 if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
29 #endif
30 }
31 FatFs[vol] = fs; /* 注冊新的對象 */
32
33 return FR_OK;
34 }
總結
以上是生活随笔為你收集整理的FATFS 初学之 f_mount的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode453. 最小操作次数使
- 下一篇: 【计算机视觉】常用图像数据集