filesystem_api_defines.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Access mode flags */
  8. typedef enum {
  9. FSAM_READ = (1 << 0), /**< Read access */
  10. FSAM_WRITE = (1 << 1), /**< Write access */
  11. FSAM_READ_WRITE = FSAM_READ | FSAM_WRITE, /**< Read and write access */
  12. } FS_AccessMode;
  13. /** Open mode flags */
  14. typedef enum {
  15. FSOM_OPEN_EXISTING = 1, /**< Open file, fail if file doesn't exist */
  16. FSOM_OPEN_ALWAYS = 2, /**< Open file. Create new file if not exist */
  17. FSOM_OPEN_APPEND = 4, /**< Open file. Create new file if not exist. Set R/W pointer to EOF */
  18. FSOM_CREATE_NEW = 8, /**< Creates a new file. Fails if the file is exist */
  19. FSOM_CREATE_ALWAYS = 16, /**< Creates a new file. If file exist, truncate to zero size */
  20. } FS_OpenMode;
  21. /** API errors enumeration */
  22. typedef enum {
  23. FSE_OK, /**< No error */
  24. FSE_NOT_READY, /**< FS not ready */
  25. FSE_EXIST, /**< File/Dir already exist */
  26. FSE_NOT_EXIST, /**< File/Dir does not exist */
  27. FSE_INVALID_PARAMETER, /**< Invalid API parameter */
  28. FSE_DENIED, /**< Access denied */
  29. FSE_INVALID_NAME, /**< Invalid name/path */
  30. FSE_INTERNAL, /**< Internal error */
  31. FSE_NOT_IMPLEMENTED, /**< Function not implemented */
  32. FSE_ALREADY_OPEN, /**< File/Dir already opened */
  33. } FS_Error;
  34. /** FileInfo flags */
  35. typedef enum {
  36. FSF_DIRECTORY = (1 << 0), /**< Directory */
  37. } FS_Flags;
  38. /** Structure that hold file index and returned api errors */
  39. typedef struct File File;
  40. /** Structure that hold file info */
  41. typedef struct {
  42. uint8_t flags; /**< flags from FS_Flags enum */
  43. uint64_t size; /**< file size */
  44. } FileInfo;
  45. /** Gets the error text from FS_Error
  46. * @param error_id error id
  47. * @return const char* error text
  48. */
  49. const char* filesystem_api_error_get_desc(FS_Error error_id);
  50. /** Checks if file info is directory
  51. * @param file_info file info pointer
  52. * @return bool is directory
  53. */
  54. bool file_info_is_dir(const FileInfo* file_info);
  55. #ifdef __cplusplus
  56. }
  57. #endif