【 声明:版权全部,欢迎转载,请勿用于商业用途。  联系信箱:feixiaoxing @163.com】

上学的时候就对文件系统非常有兴趣。可是苦于没有合适的fs代码能够学习。市面上的fs代码,要么太大。像linux一样,动不动就是几万行,几十万行。要么就是没有开源,你仅仅会使用它的接口,却不太清楚里面是怎么实现的。

一直到后来工作的时候,发现了fatfs这么一个开源库代码。

fatfs大小合适。内容也比較紧凑。仅仅要做好底层的接口移植就能够使用了。眼下fatfs用来管理最多的还是sd卡设备,nandflash用的比較少。

fatfs固然短小精悍,可是在pc上学习确实还是不方便,要是让fatfs能够在vc环境下自由地仿真调试就好了。

今天。还真找了这么一份代码,大家能够到http://www.raw-os.org/Download.html看一看,当中有一份Raw-OS 1.042 + yaffs + fatfs VC平台移植版的下载文档。执行环境是vs2010。有过windows开发经验的同学肯定不陌生。

当然,这份代码你不光能够学习fatfs,还能够学习yaffs文件系统。

事实上移植开源库基本上包含三个方面:(1)底层接口移植,通常是设备驱动等等;(2)数据移植,一般依据编译器重定义数据类型。(3)os的匹配移植,依据os设计自己须要的一些系统函数,比方创建thread、生成信号量、分配内存等等。等到做好了这些,就能够使用库提供的api,做我们自己想做的事情了。

最后。给出fatfs底层简单的代码移植方法,我认为还是蛮有意思的。

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2012 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control module to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "raw_api.h"
#include "diskio.h" /* FatFs lower layer API */
#include "ff.h"
//#include "usbdisk.h" /* Example: USB drive control */
#include <string.h>
#include <stdio.h> static RAW_U8 *simulated_space;
static int init_flag;
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/ DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
)
{ if (init_flag == 0) {
simulated_space = malloc(5 * 1024 *1024);
raw_memset(simulated_space, 0, 5 * 1024 *1024); if (simulated_space == 0) { RAW_ASSERT(0); } init_flag = 1;
} return 0;
} /*-----------------------------------------------------------------------*/
/* Get Disk Status */
/*-----------------------------------------------------------------------*/ DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{ return 0;
} /*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/ DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count) { raw_memcpy(buff, simulated_space + (512 * sector), 512 * count); return RES_OK;
} /*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/ DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
{ raw_memcpy(simulated_space + (512 * sector), buff, 512 * count); return RES_OK;
} /*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/ DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res = RES_PARERR; switch (ctrl) {
case CTRL_SYNC:
res = RES_OK;
break; case GET_SECTOR_COUNT:
*(DWORD*)buff = (10240); /*5M space*/
res = RES_OK;
break; case GET_SECTOR_SIZE:
*(WORD*)buff = 512;
res = RES_OK;
break; default:
break; } return res;
} DWORD get_fattime (void)
{ return 0;
}

最新文章

  1. 如何在windows 10 x64安装佳能 CP900 驱动
  2. springmvc学习第三天
  3. hive索引表
  4. Linux下Tomcat重新启动
  5. Linux Command Line 备忘
  6. [转]IP_ADD_MEMBERSHIP : 组播错误 的解决方法:
  7. SOLID 原则
  8. SharePoint2013 SharePoint-Hosted 模式 分页方法
  9. COOKIE漫谈
  10. 【转】oracle数据库NUMBER数据类型
  11. HDOJ 2073 无限的路
  12. hbase权威指南学习笔记--架构--存储
  13. postgres-xl 集体搭建(1)
  14. CDONTS组件
  15. WebGL文字渲染的那些问题
  16. 后端分布式系列:分布式存储-HDFS DataNode 设计实现解析
  17. @EnableFeignClients 注解
  18. Log4j2 设置控制台打印彩色日志
  19. Spring 基于构造函数的依赖注入
  20. lambda正则化参数的大小影响

热门文章

  1. loj2005 「SDOI2017」相关分析
  2. Clickonce - Change deployment URL after publish
  3. 实施生成树 STP 高级
  4. MFC拾遗
  5. C语言知识点(4)
  6. 九度oj 题目1372:最大子向量和(连续子数组的最大和)
  7. koa2源码解读
  8. Codeforces 899B Months and Years
  9. [luoguP1129] [ZJOI2007]矩阵游戏(二分图最大匹配)
  10. 群论 - Group Theory