/firmware/src/Motherboard/lib_sd/fat.h

http://github.com/makerbot/G3Firmware · C Header · 129 lines · 58 code · 22 blank · 49 comment · 0 complexity · bf5e669ebe4dd92f5fa0df7d43098d19 MD5 · raw file

  1. /*
  2. * Copyright (c) 2006-2010 by Roland Riegel <feedback@roland-riegel.de>
  3. *
  4. * This file is free software; you can redistribute it and/or modify
  5. * it under the terms of either the GNU General Public License version 2
  6. * or the GNU Lesser General Public License version 2.1, both as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef FAT_H
  10. #define FAT_H
  11. #include <stdint.h>
  12. #include "fat_config.h"
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /**
  18. * \addtogroup fat
  19. *
  20. * @{
  21. */
  22. /**
  23. * \file
  24. * FAT header (license: GPLv2 or LGPLv2.1)
  25. *
  26. * \author Roland Riegel
  27. */
  28. /**
  29. * \addtogroup fat_file
  30. * @{
  31. */
  32. /** The file is read-only. */
  33. #define FAT_ATTRIB_READONLY (1 << 0)
  34. /** The file is hidden. */
  35. #define FAT_ATTRIB_HIDDEN (1 << 1)
  36. /** The file is a system file. */
  37. #define FAT_ATTRIB_SYSTEM (1 << 2)
  38. /** The file is empty and has the volume label as its name. */
  39. #define FAT_ATTRIB_VOLUME (1 << 3)
  40. /** The file is a directory. */
  41. #define FAT_ATTRIB_DIR (1 << 4)
  42. /** The file has to be archived. */
  43. #define FAT_ATTRIB_ARCHIVE (1 << 5)
  44. /** The given offset is relative to the beginning of the file. */
  45. #define FAT_SEEK_SET 0
  46. /** The given offset is relative to the current read/write position. */
  47. #define FAT_SEEK_CUR 1
  48. /** The given offset is relative to the end of the file. */
  49. #define FAT_SEEK_END 2
  50. /**
  51. * @}
  52. */
  53. struct partition_struct;
  54. struct fat_fs_struct;
  55. struct fat_file_struct;
  56. struct fat_dir_struct;
  57. /**
  58. * \ingroup fat_file
  59. * Describes a directory entry.
  60. */
  61. struct fat_dir_entry_struct
  62. {
  63. /** The file's name, truncated to 31 characters. */
  64. char long_name[32];
  65. /** The file's attributes. Mask of the FAT_ATTRIB_* constants. */
  66. uint8_t attributes;
  67. #if FAT_DATETIME_SUPPORT
  68. /** Compressed representation of modification time. */
  69. uint16_t modification_time;
  70. /** Compressed representation of modification date. */
  71. uint16_t modification_date;
  72. #endif
  73. /** The cluster in which the file's first byte resides. */
  74. cluster_t cluster;
  75. /** The file's size. */
  76. uint32_t file_size;
  77. /** The total disk offset of this directory entry. */
  78. offset_t entry_offset;
  79. };
  80. struct fat_fs_struct* fat_open(struct partition_struct* partition);
  81. void fat_close(struct fat_fs_struct* fs);
  82. struct fat_file_struct* fat_open_file(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
  83. void fat_close_file(struct fat_file_struct* fd);
  84. intptr_t fat_read_file(struct fat_file_struct* fd, uint8_t* buffer, uintptr_t buffer_len);
  85. intptr_t fat_write_file(struct fat_file_struct* fd, const uint8_t* buffer, uintptr_t buffer_len);
  86. uint8_t fat_seek_file(struct fat_file_struct* fd, int32_t* offset, uint8_t whence);
  87. uint8_t fat_resize_file(struct fat_file_struct* fd, uint32_t size);
  88. struct fat_dir_struct* fat_open_dir(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
  89. void fat_close_dir(struct fat_dir_struct* dd);
  90. uint8_t fat_read_dir(struct fat_dir_struct* dd, struct fat_dir_entry_struct* dir_entry);
  91. uint8_t fat_reset_dir(struct fat_dir_struct* dd);
  92. uint8_t fat_create_file(struct fat_dir_struct* parent, const char* file, struct fat_dir_entry_struct* dir_entry);
  93. uint8_t fat_delete_file(struct fat_fs_struct* fs, struct fat_dir_entry_struct* dir_entry);
  94. uint8_t fat_create_dir(struct fat_dir_struct* parent, const char* dir, struct fat_dir_entry_struct* dir_entry);
  95. #define fat_delete_dir fat_delete_file
  96. void fat_get_file_modification_date(const struct fat_dir_entry_struct* dir_entry, uint16_t* year, uint8_t* month, uint8_t* day);
  97. void fat_get_file_modification_time(const struct fat_dir_entry_struct* dir_entry, uint8_t* hour, uint8_t* min, uint8_t* sec);
  98. uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct* fs, const char* path, struct fat_dir_entry_struct* dir_entry);
  99. offset_t fat_get_fs_size(const struct fat_fs_struct* fs);
  100. offset_t fat_get_fs_free(const struct fat_fs_struct* fs);
  101. /**
  102. * @}
  103. */
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif