- Notifications
You must be signed in to change notification settings - Fork2
francois-berder/fat16
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This aim of this project is to create a small program able to read FAT16 image on Linux. This project has also been ported to a PIC24, seeBoatController.The data folder contains images used to test the program.
The driver can:
- list files in a directory
- read to a file (a file can be opened several times in reading mode)
- write to a file: any previous contents are erased. A file cannot be read while it is opened in write mode.
- append to a file: similar to write mode but any previous content is preserved and writing happen at the end.
- create/delete directories
This driver cannot handle long names.
Names of files and directories must respect the format described here:https://en.wikipedia.org/wiki/8.3_filename. Hence, all valid names can be stored as an array of char of length 13 characters (12 bytes for the filename and one byte for the null character).
make
This creates a shared librarylibfat16_driver.so
in thelib
folder.The test suite must be run as root:
sudo ./bin/run_test
You will need to implement the following functions to construct astruct storage_dev_t
:
int (*read)(void*buffer,uint32_tlength);int (*read_byte)(void*data);int (*write)(constvoid*buffer,uint32_tlength);int (*seek)(uint32_toffset);
You will also need to find out where the fat16 partition starts. If it is a FAT16 image, the address is most likely 0. Otherwise, read the MBR to get the first sector of a FAT16 partition, multiplied by 512 (bytes per sector) and pass it tofat16_init
.
On some compilers such as Microchip XC16, some features from C99 such as printinguint32_t
are not supportedso you may have to change the format in debug print.
Printing content of a file:
voidprint_file_content(void){intfd=fat16_open("DATA.TXT",'r');if (fd<0) {fprintf(stderr,"Failed to read DATA.TXT\n");return; }while (1) {charbuffer[256];inti,n;n=fat16_read(fd,buffer,sizeof(buffer));if (n==0) {/* End of file reached */break; }elseif (n<0) {fprintf(stderr,"Error %d while reading\n",-n);break; }else {for (i=0;i<n;++i)printf("%c",buffer[i]); } }fat16_close(fd);}
Listing files in root directory:
voidlist_files(void){charfilename[13];uint32_ti=0;while(fat16_ls(&i,filename,"/")==1) {printf("%s\n",filename); }}
About
This is a FAT16 driver.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.