A random record (Fatfs study)

Source: Internet
Author: User


"Disclaimer: Copyright All, welcome reprint, do not use for commercial purposes. Contact mailbox: feixiaoxing @163.com "


When you go to school, you are very interested in file systems. However, there is no suitable FS code to learn. The FS code on the market is either too large. Like Linux, it is tens of thousands of rows, hundreds of thousands of rows. Either there is no open source, you only use its interface, but it is not very clear how it is implemented.


Until later, when working, I found fatfs such an open source library code.

Fatfs is the right size. Content is also more compact. Just do a good job of porting the underlying interface to be able to use it. Now Fatfs is used to manage the most or SD card devices, Nandflash use less.


Fatfs is short, but the study on the PC is still not convenient, if let Fatfs in the VC environment to free simulation and debugging is good.

Today. Really find such a code, we can go to http://www.raw-os.org/Download.html to see, among them a copy of Raw-os 1.042 + yaffs + fatfs VC Platform Transplant version of the download document. The execution environment is vs2010. The students who have experience in Windows development are certainly not unfamiliar.

Of course, this code you can not only learn fatfs, but also can learn yaffs file system.


In fact, the ported open source Library basically contains three aspects: (1) The bottom interface porting, usually the device driver and so on; (2) data migration, generally based on compiler to define the data type. (3) OS matching porting, according to the OS design some of its own system functions, such as the creation of thread, generate semaphores, allocate memory and so on. By doing this, you can use the API provided by the library to do what we want to do.

At last. I think it's quite interesting to give a simple code porting method for Fatfs.

< /span>

/*-----------------------------------------------------------------------*//* Low level disk I/O module skeleton for FatFs (C) ChaN, *//*-----------------------------------------------------------------------*//* If a Workin G Storage Control module is available, it should being *//* attached to the FatFs via a glue function rather than Modi   Fying it.  *//* This is a 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 <stri ng.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); Raw_memset (Simulated_space, 0, 5 * 1024 *10 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 + (* sector), * count); return RE S_OK;} /*-----------------------------------------------------------------------*//* Write Sector (s) *//*-----------------------------------------------------------------------*/dresult disk_write (BYTE pdrv, const byte* Buff, DWORD sector, UINT count) {raw_memcpy (Simulated_space + (sector), buff, 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;}



A random record (Fatfs study)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.