USBMSD file position help

20 Nov 2012

Hi, I have a pretty simple question. When I write a file (well drag and drop the file) to an SD card using the USBMSD library how do I find out which blocks that file has been written in? Thanks

20 Nov 2012

Hello Martin,

when host writes each block through USBMSD_SD - disk_write() method is called (with number of block as argument) repeatedly until whole file is written. So I imagine You add function to this method which will store those numbers of blocks to say an array. But host will also write to FAT tables and root directory so You will be interested only in numbers of blocks written to data area.

If You want to access this file from mbed using SDfilesystem program, You don't need to know those numbers of blocks.

But if You want to determine blocks after file was transfered You will need to understand FAT filesystem organization, locate ROOT Directory entries, search for name of Your file and find number of first cluster in this file. Then check FAT table and check value of this cluster if it holds number of next cluster in chain or if it is last cluster in chain (end of file marker) and so on until You locate end of file marker(0xFFF8 - 0xFFFF).

I recomend You http://home.teleport.com/~brainy/fat16.htm and http://home.teleport.com/~brainy/lfn.htm to understand it better. Also WINHEX program for PC is very good tool because allows You to look to content of disk (SD card) in sector level.

22 Nov 2012

Thanks Llumpu, this is exactly what I was looking for