fat.h 1.1 KB

12345678910111213141516171819202122232425262728
  1. /* FAT12 filesystem. Root directory only.
  2. * Error conventions: 0 = success, -1 = not found / not ready / full, -2 = disk I/O error. */
  3. #ifndef FAT_H
  4. #define FAT_H
  5. typedef void (*fat_root_callback_t)(const char *name, int is_dir, unsigned int size);
  6. /* Parse BPB from sector 0. Call once before list/read/write.
  7. * Returns 0 on success, -1 if no valid FAT filesystem, -2 on disk I/O error. */
  8. int fat_init(void);
  9. /* Iterate root directory, call callback for each file/dir.
  10. * Returns 0 on success, -1 if not ready, -2 on disk I/O error. */
  11. int fat_list_root(fat_root_callback_t callback);
  12. /* Read file by 8.3 name into buf, max max_len bytes.
  13. * Returns bytes read on success, -1 if not found, -2 on disk I/O error. */
  14. int fat_read_file(const char *name_8_3, void *buf, unsigned int max_len);
  15. /* Create or overwrite a root file with `size` bytes from `buf`.
  16. * Returns 0 on success, -1 if not ready / disk full, -2 on disk I/O error. */
  17. int fat_write_file(const char *name_8_3, const void *buf, unsigned int size);
  18. /* Delete a root file. Returns 0, -1 if not found, -2 on disk I/O error. */
  19. int fat_delete_file(const char *name_8_3);
  20. #endif