exfatfs.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. exfatfs.h (29.08.09)
  3. Definitions of structures and constants used in exFAT file system.
  4. Copyright (C) 2010-2013 Andrew Nayenko
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef EXFATFS_H_INCLUDED
  17. #define EXFATFS_H_INCLUDED
  18. #include "byteorder.h"
  19. typedef uint32_t cluster_t; /* cluster number */
  20. #define EXFAT_FIRST_DATA_CLUSTER 2
  21. #define EXFAT_LAST_DATA_CLUSTER 0xfffffff6
  22. #define EXFAT_CLUSTER_FREE 0 /* free cluster */
  23. #define EXFAT_CLUSTER_BAD 0xfffffff7 /* cluster contains bad sector */
  24. #define EXFAT_CLUSTER_END 0xffffffff /* final cluster of file or directory */
  25. #define EXFAT_STATE_MOUNTED 2
  26. struct exfat_super_block
  27. {
  28. uint8_t jump[3]; /* 0x00 jmp and nop instructions */
  29. uint8_t oem_name[8]; /* 0x03 "EXFAT " */
  30. uint8_t __unused1[53]; /* 0x0B always 0 */
  31. le64_t sector_start; /* 0x40 partition first sector */
  32. le64_t sector_count; /* 0x48 partition sectors count */
  33. le32_t fat_sector_start; /* 0x50 FAT first sector */
  34. le32_t fat_sector_count; /* 0x54 FAT sectors count */
  35. le32_t cluster_sector_start; /* 0x58 first cluster sector */
  36. le32_t cluster_count; /* 0x5C total clusters count */
  37. le32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
  38. le32_t volume_serial; /* 0x64 volume serial number */
  39. struct /* 0x68 FS version */
  40. {
  41. uint8_t minor;
  42. uint8_t major;
  43. }
  44. version;
  45. le16_t volume_state; /* 0x6A volume state flags */
  46. uint8_t sector_bits; /* 0x6C sector size as (1 << n) */
  47. uint8_t spc_bits; /* 0x6D sectors per cluster as (1 << n) */
  48. uint8_t fat_count; /* 0x6E always 1 */
  49. uint8_t drive_no; /* 0x6F always 0x80 */
  50. uint8_t allocated_percent; /* 0x70 percentage of allocated space */
  51. uint8_t __unused2[397]; /* 0x71 always 0 */
  52. le16_t boot_signature; /* the value of 0xAA55 */
  53. }
  54. __attribute__((__packed__));
  55. #define EXFAT_ENTRY_VALID 0x80
  56. #define EXFAT_ENTRY_CONTINUED 0x40
  57. #define EXFAT_ENTRY_BITMAP (0x01 | EXFAT_ENTRY_VALID)
  58. #define EXFAT_ENTRY_UPCASE (0x02 | EXFAT_ENTRY_VALID)
  59. #define EXFAT_ENTRY_LABEL (0x03 | EXFAT_ENTRY_VALID)
  60. #define EXFAT_ENTRY_FILE (0x05 | EXFAT_ENTRY_VALID)
  61. #define EXFAT_ENTRY_FILE_INFO (0x00 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
  62. #define EXFAT_ENTRY_FILE_NAME (0x01 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
  63. struct exfat_entry /* common container for all entries */
  64. {
  65. uint8_t type; /* any of EXFAT_ENTRY_xxx */
  66. uint8_t data[31];
  67. }
  68. __attribute__((__packed__));
  69. #define EXFAT_ENAME_MAX 15
  70. struct exfat_entry_bitmap /* allocated clusters bitmap */
  71. {
  72. uint8_t type; /* EXFAT_ENTRY_BITMAP */
  73. uint8_t __unknown1[19];
  74. le32_t start_cluster;
  75. le64_t size; /* in bytes */
  76. }
  77. __attribute__((__packed__));
  78. struct exfat_entry_upcase /* upper case translation table */
  79. {
  80. uint8_t type; /* EXFAT_ENTRY_UPCASE */
  81. uint8_t __unknown1[3];
  82. le32_t checksum;
  83. uint8_t __unknown2[12];
  84. le32_t start_cluster;
  85. le64_t size; /* in bytes */
  86. }
  87. __attribute__((__packed__));
  88. struct exfat_entry_label /* volume label */
  89. {
  90. uint8_t type; /* EXFAT_ENTRY_LABEL */
  91. uint8_t length; /* number of characters */
  92. le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
  93. }
  94. __attribute__((__packed__));
  95. #define EXFAT_ATTRIB_RO 0x01
  96. #define EXFAT_ATTRIB_HIDDEN 0x02
  97. #define EXFAT_ATTRIB_SYSTEM 0x04
  98. #define EXFAT_ATTRIB_VOLUME 0x08
  99. #define EXFAT_ATTRIB_DIR 0x10
  100. #define EXFAT_ATTRIB_ARCH 0x20
  101. struct exfat_entry_meta1 /* file or directory info (part 1) */
  102. {
  103. uint8_t type; /* EXFAT_ENTRY_FILE */
  104. uint8_t continuations;
  105. le16_t checksum;
  106. le16_t attrib; /* combination of EXFAT_ATTRIB_xxx */
  107. le16_t __unknown1;
  108. le16_t crtime, crdate; /* creation date and time */
  109. le16_t mtime, mdate; /* latest modification date and time */
  110. le16_t atime, adate; /* latest access date and time */
  111. uint8_t crtime_cs; /* creation time in cs (centiseconds) */
  112. uint8_t mtime_cs; /* latest modification time in cs */
  113. uint8_t __unknown2[10];
  114. }
  115. __attribute__((__packed__));
  116. #define EXFAT_FLAG_ALWAYS1 (1u << 0)
  117. #define EXFAT_FLAG_CONTIGUOUS (1u << 1)
  118. struct exfat_entry_meta2 /* file or directory info (part 2) */
  119. {
  120. uint8_t type; /* EXFAT_ENTRY_FILE_INFO */
  121. uint8_t flags; /* combination of EXFAT_FLAG_xxx */
  122. uint8_t __unknown1;
  123. uint8_t name_length;
  124. le16_t name_hash;
  125. le16_t __unknown2;
  126. le64_t real_size; /* in bytes, equals to size */
  127. uint8_t __unknown3[4];
  128. le32_t start_cluster;
  129. le64_t size; /* in bytes, equals to real_size */
  130. }
  131. __attribute__((__packed__));
  132. struct exfat_entry_name /* file or directory name */
  133. {
  134. uint8_t type; /* EXFAT_ENTRY_FILE_NAME */
  135. uint8_t __unknown;
  136. le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
  137. }
  138. __attribute__((__packed__));
  139. #endif /* ifndef EXFATFS_H_INCLUDED */