fat.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* FAT12 filesystem with subdirectory support.
  2. * A "directory" is identified by its first data cluster; 0 means the root dir.
  3. * Error conventions: 0 = success, -1 = not found / not ready / full, -2 = disk I/O error. */
  4. #ifndef FAT_H
  5. #define FAT_H
  6. typedef void (*fat_root_callback_t)(const char *name, int is_dir, unsigned int size);
  7. /* Parse BPB from sector 0. Call once before list/read/write.
  8. * Returns 0 on success, -1 if no valid FAT filesystem, -2 on disk I/O error. */
  9. int fat_init(void);
  10. /* Iterate root directory, call callback for each file/dir. */
  11. int fat_list_root(fat_root_callback_t callback);
  12. /* Iterate a directory (0 = root, else first cluster). */
  13. int fat_list_dir(unsigned int dir_cluster, fat_root_callback_t callback);
  14. /* Read file by 8.3 name into buf, max max_len bytes (root only). */
  15. int fat_read_file(const char *name_8_3, void *buf, unsigned int max_len);
  16. /* Read a file in a directory (0 = root). */
  17. int fat_read_file_in(unsigned int dir_cluster, const char *name_8_3, void *buf, unsigned int max_len);
  18. /* Create or overwrite a file in the root directory. */
  19. int fat_write_file(const char *name_8_3, const void *buf, unsigned int size);
  20. /* Create or overwrite a file in a directory (0 = root). */
  21. int fat_write_file_in(unsigned int dir_cluster, const char *name_8_3, const void *buf, unsigned int size);
  22. /* Delete a file from the root directory. */
  23. int fat_delete_file(const char *name_8_3);
  24. /* Delete a file from a directory (0 = root). */
  25. int fat_delete_file_in(unsigned int dir_cluster, const char *name_8_3);
  26. /* Create a subdirectory in `parent_cluster` (0 = root). */
  27. int fat_mkdir(unsigned int parent_cluster, const char *name_8_3);
  28. /* Remove an empty subdirectory from `parent_cluster` (0 = root). */
  29. int fat_rmdir(unsigned int parent_cluster, const char *name_8_3);
  30. /* Resolve a path "a/b/c" into (parent dir cluster, final 8.3 name).
  31. * The returned name_8_3 is uppercase and space-padded (11 bytes + NUL). */
  32. int fat_resolve_path(const char *path, unsigned int *dir_cluster, char name_8_3[12]);
  33. /* Resolve a full path (all components directories) to a directory cluster.
  34. * An empty path resolves to the root (cluster 0). */
  35. int fat_resolve_dir(const char *path, unsigned int *dir_cluster);
  36. #endif