Nixmd
Nixmd

Reputation: 845

FATFS: How to get address of first sector of a file?

I am using fatfs on stm32 and I want to find the address of first sector of a file which is opened using f_open function. Thus I can use that sector address to access the file as a address offset using low level DMA methods available. How can I get the raw address of the file on disk?

Upvotes: 0

Views: 1064

Answers (1)

JMA
JMA

Reputation: 494

In Chan's FatFS you can known the file starts cluster, it's in fp->sclust variable. You can know cluster size with this expression:clusterSize = fp->fs->csize * SS(fp->fs); and you can also need the funcion clust2sect(fp->fs, fp->clust). You can watch the implementation of Diskio_drvTypeDef.disk_read to see how to convert to adress.

Upvotes: 1

Related Questions