码迷,mamicode.com
首页 > 其他好文 > 详细

f_mount();

时间:2014-11-11 15:50:14      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   sp   for   文件   div   log   

 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     if (vol >= _VOLUMES)        /* Check if the drive number is valid */
13         return FR_INVALID_DRIVE;
14     rfs = FatFs[vol];              /* Get current fs object */
15 
16     if (rfs) {  //
17 #if _FS_SHARE
18         clear_lock(rfs);
19 #endif
20 #if _FS_REENTRANT                /* Discard sync object of the current volume */
21         if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;
22 #endif
23         rfs->fs_type = 0;        /* Clear old fs object */
24     }
25 
26     if (fs) {
27         fs->fs_type = 0;        /* Clear new fs object */
28 #if _FS_REENTRANT                /* Create sync object for the new volume */
29         if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
30 #endif
31     }
32     FatFs[vol] = fs;            /* Register new fs object */
33 
34     return FR_OK;
35 }

去掉条件编译后

 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;                     //定义一个FATFS类型的指针
14 rfs = FatFs[vol]; /* Get current fs object FatFs[vol]也是一个FATFS类型的指针,可以表示为之前挂载过的文件系统的头地址*/ 16 if (rfs) { //表示之前有挂载过文件系统 23 rfs->fs_type = 0; /* Clear old fs object 清除掉旧的文件系统*/ 24 } 26 if (fs) { //fs指向分配内存的头地址,一般不为0 27 fs->fs_type = 0; /* Clear new fs object 为什么要执行这条语句?0表示没有挂载,把0赋值过去,为什么呢?*/ 31 } 32 FatFs[vol] = fs; /* Register new fs object 把文件系统的头地址赋值,这就是挂载???感觉多此一举的?直接用也行的啊!?*/ 34 return FR_OK; 35 }

怎么挂载的?把首地址直接赋值给指针变量就行了?,那何必那么麻烦呢?哎,一大堆疑问。算了,以后应该会弄明白吧!

f_mount();

标签:style   blog   color   ar   sp   for   文件   div   log   

原文地址:http://www.cnblogs.com/vhuichen/p/4089397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!