首页 > 代码库 > f_mount();

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     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_SHARE18         clear_lock(rfs);19 #endif20 #if _FS_REENTRANT                /* Discard sync object of the current volume */21         if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;22 #endif23         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 #endif31     }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指向分配内存的头地址,一般不为027 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();