Minimalist FAT library - just find one fixed file and read one block?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to read the content of a very small file on an SD card. I've actually already got the card initialization code and block-level I/O done (because I've got mature code from another block-level project). I've got a function that will read an arbitrary block from the volume. All I need now (ha ha) is code to go find, open and read the first block from a statically named file on the volume.

 

Does anyone have a minimalist FAT library like this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One would think all you need is in fatfs. Strip out what you don't want.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where's that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google fatfs
Would have to be one of the oldest, most used and most maintained fat library in existence!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, well, I didn't think it would be that easy, because I expected fatfs to wind up finding all sorts of FAT implementations for general purpose computers and the like.

Turns out you're right - that first one linked to Petit FatFs, which looks like it's ideal for my purposes.

To save people who come after, it's at http://elm-chan.org/fsw/ff/00index_p.html

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to see something even more "raw" then take a look at this:

 

https://spaces.atmel.com/gf/proj...

 

and specifically the main code file:

 

https://spaces.atmel.com/gf/proj...

 

I started with PetitFS in fact then stripped it all away apart from the lowest level sector reading code. I then added back the absolute minimum amount to find an MBR or boot/BPB (for MBR it then moves onto the boot/BPB). From the BPB I read the drive dimensions and work out where the FATs and data area are, including the root directory and then I locate one file in that directory, open it and read it.

 

In my case I am doing this to make a bootloader than can read SD/MMC to find a .BIN file. With most options switched of this can fit in 1K. With all the options on it requires more like 2K. That is still about half the size of even Petit.