FATFS 初学之 f_mount
生活随笔
收集整理的這篇文章主要介紹了
FATFS 初学之 f_mount
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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)*/
函數(shù)功能:注冊(cè)/注銷一個(gè)工作區(qū)(掛載/注銷分區(qū)文件系統(tǒng))
描述:在使用任何其它文件函數(shù)之前,必須使用該函數(shù)為每個(gè)使用卷注冊(cè)一個(gè)工作區(qū)。要注銷一個(gè)工作區(qū),只要指定 fs為 NULL即可,然后該工作區(qū)可以被丟棄。
該函數(shù)只初始化給定的工作區(qū),以及將該工作區(qū)的地址注冊(cè)到內(nèi)部表中,不訪問磁盤I/O層。卷裝入過程是在 f_mount函數(shù)后或存儲(chǔ)介質(zhì)改變后的第一次文件訪問時(shí)完成的。
通俗了說就是給磁盤分配文件系統(tǒng)的:計(jì)算機(jī)中的盤符是 C: D: E;FATFS的盤符是 0: 1: 2:
f_mount(0,&fs); // 為 0號(hào)盤符分配新的文件系統(tǒng) fs,fs是 FATFS類型,用于記錄邏輯磁盤工作區(qū)
1 /*-----------------------------------------------------------------------*/
2 /* Mount/Unmount a Logical Drive */
3 /*-----------------------------------------------------------------------*/
4 FRESULT f_mount (
5 BYTE vol, /* 邏輯驅(qū)動(dòng)器安裝/卸載 */
6 FATFS *fs /* 新的文件系統(tǒng)對(duì)象指針(卸載NULL) */
7 )
8 {
9 FATFS *rfs;
10
11 if (vol >= _VOLUMES) /* 檢查驅(qū)動(dòng)器號(hào)是否有效 */
12 return FR_INVALID_DRIVE;
13 rfs = FatFs[vol]; /* 獲得原盤符下對(duì)象 */
14
15 if (rfs) { /* 檢查原盤符下是否掛有文件系統(tǒng),若有則釋放掉 */
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) { /* 檢測參數(shù),若為 NULL則表示卸載盤符,下面兩步執(zhí)行無意義 */
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; /* 注冊(cè)新的對(duì)象 */
32
33 return FR_OK;
34 }
總結(jié)
以上是生活随笔為你收集整理的FATFS 初学之 f_mount的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode453. 最小操作次数使
- 下一篇: 【计算机视觉】常用图像数据集