fat_io_lib icon indicating copy to clipboard operation
fat_io_lib copied to clipboard

how to create a new Fat16 filesystem

Open AntonHermann opened this issue 1 year ago • 0 comments

Hey :)

I'm trying to create a new FAT16 filesystem like so:

fl_init();

// Attach media access functions to library
if (fl_attach_media(sd_readsector, sd_writesector) != FAT_INIT_OK) {
  printf("ERROR: Failed to init file system\n");
}
  
int ret = fl_format(300, "MyDevice");
...

However, since the media storage doesn't contain a valid filesystem yet, the call to fl_attach_media() fails. This call is however needed in order to run fl_format(). I tried to call fl_attach_media() again after the format, but that fails again with error FAT_INIT_WRONG_FILESYS_TYPE. If I step through the code, the check at https://github.com/ultraembedded/fat_io_lib/blob/master/src/fat_access.c#L169 fails as count_of_clusters is only 0xd.

What am I doing wrong here?

Thanks in advance, Anton

AntonHermann avatar Sep 15 '23 13:09 AntonHermann