My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SdFatStructs.h 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * \file
  24. * \brief FAT file structures
  25. */
  26. /**
  27. * Arduino SdFat Library
  28. * Copyright (C) 2009 by William Greiman
  29. *
  30. * This file is part of the Arduino Sd2Card Library
  31. */
  32. #ifndef SDFATSTRUCTS_H
  33. #define SDFATSTRUCTS_H
  34. #include <stdint.h>
  35. #define PACKED __attribute__((__packed__))
  36. /**
  37. * mostly from Microsoft document fatgen103.doc
  38. * http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
  39. */
  40. uint8_t const BOOTSIG0 = 0x55, // Value for byte 510 of boot block or MBR
  41. BOOTSIG1 = 0xAA, // Value for byte 511 of boot block or MBR
  42. EXTENDED_BOOT_SIG = 0x29; // Value for bootSignature field int FAT/FAT32 boot sector
  43. /**
  44. * \struct partitionTable
  45. * \brief MBR partition table entry
  46. *
  47. * A partition table entry for a MBR formatted storage device.
  48. * The MBR partition table has four entries.
  49. */
  50. struct partitionTable {
  51. /**
  52. * Boot Indicator . Indicates whether the volume is the active
  53. * partition. Legal values include: 0x00. Do not use for booting.
  54. * 0x80 Active partition.
  55. */
  56. uint8_t boot;
  57. /**
  58. * Head part of Cylinder-head-sector address of the first block in
  59. * the partition. Legal values are 0-255. Only used in old PC BIOS.
  60. */
  61. uint8_t beginHead;
  62. /**
  63. * Sector part of Cylinder-head-sector address of the first block in
  64. * the partition. Legal values are 1-63. Only used in old PC BIOS.
  65. */
  66. unsigned beginSector : 6;
  67. /** High bits cylinder for first block in partition. */
  68. unsigned beginCylinderHigh : 2;
  69. /**
  70. * Combine beginCylinderLow with beginCylinderHigh. Legal values
  71. * are 0-1023. Only used in old PC BIOS.
  72. */
  73. uint8_t beginCylinderLow;
  74. /**
  75. * Partition type. See defines that begin with PART_TYPE_ for
  76. * some Microsoft partition types.
  77. */
  78. uint8_t type;
  79. /**
  80. * head part of cylinder-head-sector address of the last sector in the
  81. * partition. Legal values are 0-255. Only used in old PC BIOS.
  82. */
  83. uint8_t endHead;
  84. /**
  85. * Sector part of cylinder-head-sector address of the last sector in
  86. * the partition. Legal values are 1-63. Only used in old PC BIOS.
  87. */
  88. unsigned endSector : 6;
  89. /** High bits of end cylinder */
  90. unsigned endCylinderHigh : 2;
  91. /**
  92. * Combine endCylinderLow with endCylinderHigh. Legal values
  93. * are 0-1023. Only used in old PC BIOS.
  94. */
  95. uint8_t endCylinderLow;
  96. uint32_t firstSector; // Logical block address of the first block in the partition.
  97. uint32_t totalSectors; // Length of the partition, in blocks.
  98. } PACKED;
  99. typedef struct partitionTable part_t; // Type name for partitionTable
  100. /**
  101. * \struct masterBootRecord
  102. *
  103. * \brief Master Boot Record
  104. *
  105. * The first block of a storage device that is formatted with a MBR.
  106. */
  107. struct masterBootRecord {
  108. uint8_t codeArea[440]; // Code Area for master boot program.
  109. uint32_t diskSignature; // Optional Windows NT disk signature. May contain boot code.
  110. uint16_t usuallyZero; // Usually zero but may be more boot code.
  111. part_t part[4]; // Partition tables.
  112. uint8_t mbrSig0; // First MBR signature byte. Must be 0x55
  113. uint8_t mbrSig1; // Second MBR signature byte. Must be 0xAA
  114. } PACKED;
  115. /** Type name for masterBootRecord */
  116. typedef struct masterBootRecord mbr_t;
  117. /**
  118. * \struct fat_boot
  119. *
  120. * \brief Boot sector for a FAT12/FAT16 volume.
  121. *
  122. */
  123. struct fat_boot {
  124. /**
  125. * The first three bytes of the boot sector must be valid,
  126. * executable x 86-based CPU instructions. This includes a
  127. * jump instruction that skips the next nonexecutable bytes.
  128. */
  129. uint8_t jump[3];
  130. /**
  131. * This is typically a string of characters that identifies
  132. * the operating system that formatted the volume.
  133. */
  134. char oemId[8];
  135. /**
  136. * The size of a hardware sector. Valid decimal values for this
  137. * field are 512, 1024, 2048, and 4096. For most disks used in
  138. * the United States, the value of this field is 512.
  139. */
  140. uint16_t bytesPerSector;
  141. /**
  142. * Number of sectors per allocation unit. This value must be a
  143. * power of 2 that is greater than 0. The legal values are
  144. * 1, 2, 4, 8, 16, 32, 64, and 128. 128 should be avoided.
  145. */
  146. uint8_t sectorsPerCluster;
  147. /**
  148. * The number of sectors preceding the start of the first FAT,
  149. * including the boot sector. The value of this field is always 1.
  150. */
  151. uint16_t reservedSectorCount;
  152. /**
  153. * The number of copies of the FAT on the volume.
  154. * The value of this field is always 2.
  155. */
  156. uint8_t fatCount;
  157. /**
  158. * For FAT12 and FAT16 volumes, this field contains the count of
  159. * 32-byte directory entries in the root directory. For FAT32 volumes,
  160. * this field must be set to 0. For FAT12 and FAT16 volumes, this
  161. * value should always specify a count that when multiplied by 32
  162. * results in a multiple of bytesPerSector. FAT16 volumes should
  163. * use the value 512.
  164. */
  165. uint16_t rootDirEntryCount;
  166. /**
  167. * This field is the old 16-bit total count of sectors on the volume.
  168. * This count includes the count of all sectors in all four regions
  169. * of the volume. This field can be 0; if it is 0, then totalSectors32
  170. * must be nonzero. For FAT32 volumes, this field must be 0. For
  171. * FAT12 and FAT16 volumes, this field contains the sector count, and
  172. * totalSectors32 is 0 if the total sector count fits
  173. * (is less than 0x10000).
  174. */
  175. uint16_t totalSectors16;
  176. /**
  177. * This dates back to the old MS-DOS 1.x media determination and is
  178. * no longer usually used for anything. 0xF8 is the standard value
  179. * for fixed (nonremovable) media. For removable media, 0xF0 is
  180. * frequently used. Legal values are 0xF0 or 0xF8-0xFF.
  181. */
  182. uint8_t mediaType;
  183. /**
  184. * Count of sectors occupied by one FAT on FAT12/FAT16 volumes.
  185. * On FAT32 volumes this field must be 0, and sectorsPerFat32
  186. * contains the FAT size count.
  187. */
  188. uint16_t sectorsPerFat16;
  189. uint16_t sectorsPerTrack; // Sectors per track for interrupt 0x13. Not used otherwise.
  190. uint16_t headCount; // Number of heads for interrupt 0x13. Not used otherwise.
  191. /**
  192. * Count of hidden sectors preceding the partition that contains this
  193. * FAT volume. This field is generally only relevant for media
  194. * visible on interrupt 0x13.
  195. */
  196. uint32_t hidddenSectors;
  197. /**
  198. * This field is the new 32-bit total count of sectors on the volume.
  199. * This count includes the count of all sectors in all four regions
  200. * of the volume. This field can be 0; if it is 0, then
  201. * totalSectors16 must be nonzero.
  202. */
  203. uint32_t totalSectors32;
  204. /**
  205. * Related to the BIOS physical drive number. Floppy drives are
  206. * identified as 0x00 and physical hard disks are identified as
  207. * 0x80, regardless of the number of physical disk drives.
  208. * Typically, this value is set prior to issuing an INT 13h BIOS
  209. * call to specify the device to access. The value is only
  210. * relevant if the device is a boot device.
  211. */
  212. uint8_t driveNumber;
  213. uint8_t reserved1; // used by Windows NT - should be zero for FAT
  214. uint8_t bootSignature; // 0x29 if next three fields are valid
  215. /**
  216. * A random serial number created when formatting a disk,
  217. * which helps to distinguish between disks.
  218. * Usually generated by combining date and time.
  219. */
  220. uint32_t volumeSerialNumber;
  221. /**
  222. * A field once used to store the volume label. The volume label
  223. * is now stored as a special file in the root directory.
  224. */
  225. char volumeLabel[11];
  226. /**
  227. * A field with a value of either FAT, FAT12 or FAT16,
  228. * depending on the disk format.
  229. */
  230. char fileSystemType[8];
  231. uint8_t bootCode[448]; // X86 boot code
  232. uint8_t bootSectorSig0; // must be 0x55
  233. uint8_t bootSectorSig1; // must be 0xAA
  234. } PACKED;
  235. typedef struct fat_boot fat_boot_t; // Type name for FAT Boot Sector
  236. /**
  237. * \struct fat32_boot
  238. *
  239. * \brief Boot sector for a FAT32 volume.
  240. */
  241. struct fat32_boot {
  242. /**
  243. * The first three bytes of the boot sector must be valid,
  244. * executable x 86-based CPU instructions. This includes a
  245. * jump instruction that skips the next nonexecutable bytes.
  246. */
  247. uint8_t jump[3];
  248. /**
  249. * This is typically a string of characters that identifies
  250. * the operating system that formatted the volume.
  251. */
  252. char oemId[8];
  253. /**
  254. * The size of a hardware sector. Valid decimal values for this
  255. * field are 512, 1024, 2048, and 4096. For most disks used in
  256. * the United States, the value of this field is 512.
  257. */
  258. uint16_t bytesPerSector;
  259. /**
  260. * Number of sectors per allocation unit. This value must be a
  261. * power of 2 that is greater than 0. The legal values are
  262. * 1, 2, 4, 8, 16, 32, 64, and 128. 128 should be avoided.
  263. */
  264. uint8_t sectorsPerCluster;
  265. /**
  266. * The number of sectors preceding the start of the first FAT,
  267. * including the boot sector. Must not be zero
  268. */
  269. uint16_t reservedSectorCount;
  270. /**
  271. * The number of copies of the FAT on the volume.
  272. * The value of this field is always 2.
  273. */
  274. uint8_t fatCount;
  275. /**
  276. * FAT12/FAT16 only. For FAT32 volumes, this field must be set to 0.
  277. */
  278. uint16_t rootDirEntryCount;
  279. /**
  280. * For FAT32 volumes, this field must be 0.
  281. */
  282. uint16_t totalSectors16;
  283. /**
  284. * This dates back to the old MS-DOS 1.x media determination and is
  285. * no longer usually used for anything. 0xF8 is the standard value
  286. * for fixed (nonremovable) media. For removable media, 0xF0 is
  287. * frequently used. Legal values are 0xF0 or 0xF8-0xFF.
  288. */
  289. uint8_t mediaType;
  290. /**
  291. * On FAT32 volumes this field must be 0, and sectorsPerFat32
  292. * contains the FAT size count.
  293. */
  294. uint16_t sectorsPerFat16;
  295. uint16_t sectorsPerTrack; // Sectors per track for interrupt 0x13. Not used otherwise.
  296. uint16_t headCount; // Number of heads for interrupt 0x13. Not used otherwise.
  297. /**
  298. * Count of hidden sectors preceding the partition that contains this
  299. * FAT volume. This field is generally only relevant for media
  300. * visible on interrupt 0x13.
  301. */
  302. uint32_t hidddenSectors;
  303. /**
  304. * Contains the total number of sectors in the FAT32 volume.
  305. */
  306. uint32_t totalSectors32;
  307. /**
  308. * Count of sectors occupied by one FAT on FAT32 volumes.
  309. */
  310. uint32_t sectorsPerFat32;
  311. /**
  312. * This field is only defined for FAT32 media and does not exist on
  313. * FAT12 and FAT16 media.
  314. * Bits 0-3 -- Zero-based number of active FAT.
  315. * Only valid if mirroring is disabled.
  316. * Bits 4-6 -- Reserved.
  317. * Bit 7 -- 0 means the FAT is mirrored at runtime into all FATs.
  318. * -- 1 means only one FAT is active; it is the one referenced
  319. * in bits 0-3.
  320. * Bits 8-15 -- Reserved.
  321. */
  322. uint16_t fat32Flags;
  323. /**
  324. * FAT32 version. High byte is major revision number.
  325. * Low byte is minor revision number. Only 0.0 define.
  326. */
  327. uint16_t fat32Version;
  328. /**
  329. * Cluster number of the first cluster of the root directory for FAT32.
  330. * This usually 2 but not required to be 2.
  331. */
  332. uint32_t fat32RootCluster;
  333. /**
  334. * Sector number of FSINFO structure in the reserved area of the
  335. * FAT32 volume. Usually 1.
  336. */
  337. uint16_t fat32FSInfo;
  338. /**
  339. * If nonzero, indicates the sector number in the reserved area
  340. * of the volume of a copy of the boot record. Usually 6.
  341. * No value other than 6 is recommended.
  342. */
  343. uint16_t fat32BackBootBlock;
  344. /**
  345. * Reserved for future expansion. Code that formats FAT32 volumes
  346. * should always set all of the bytes of this field to 0.
  347. */
  348. uint8_t fat32Reserved[12];
  349. /**
  350. * Related to the BIOS physical drive number. Floppy drives are
  351. * identified as 0x00 and physical hard disks are identified as
  352. * 0x80, regardless of the number of physical disk drives.
  353. * Typically, this value is set prior to issuing an INT 13h BIOS
  354. * call to specify the device to access. The value is only
  355. * relevant if the device is a boot device.
  356. */
  357. uint8_t driveNumber;
  358. uint8_t reserved1; // Used by Windows NT - should be zero for FAT
  359. uint8_t bootSignature; // 0x29 if next three fields are valid
  360. /**
  361. * A random serial number created when formatting a disk,
  362. * which helps to distinguish between disks.
  363. * Usually generated by combining date and time.
  364. */
  365. uint32_t volumeSerialNumber;
  366. /**
  367. * A field once used to store the volume label. The volume label
  368. * is now stored as a special file in the root directory.
  369. */
  370. char volumeLabel[11];
  371. /**
  372. * A text field with a value of FAT32.
  373. */
  374. char fileSystemType[8];
  375. uint8_t bootCode[420]; // X86 boot code
  376. uint8_t bootSectorSig0; // must be 0x55
  377. uint8_t bootSectorSig1; // must be 0xAA
  378. } PACKED;
  379. typedef struct fat32_boot fat32_boot_t; // Type name for FAT32 Boot Sector
  380. uint32_t const FSINFO_LEAD_SIG = 0x41615252, // 'AaRR' Lead signature for a FSINFO sector
  381. FSINFO_STRUCT_SIG = 0x61417272; // 'aArr' Struct signature for a FSINFO sector
  382. /**
  383. * \struct fat32_fsinfo
  384. *
  385. * \brief FSINFO sector for a FAT32 volume.
  386. *
  387. */
  388. struct fat32_fsinfo {
  389. uint32_t leadSignature; // must be 0x52, 0x52, 0x61, 0x41 'RRaA'
  390. uint8_t reserved1[480]; // must be zero
  391. uint32_t structSignature; // must be 0x72, 0x72, 0x41, 0x61 'rrAa'
  392. /**
  393. * Contains the last known free cluster count on the volume.
  394. * If the value is 0xFFFFFFFF, then the free count is unknown
  395. * and must be computed. Any other value can be used, but is
  396. * not necessarily correct. It should be range checked at least
  397. * to make sure it is <= volume cluster count.
  398. */
  399. uint32_t freeCount;
  400. /**
  401. * This is a hint for the FAT driver. It indicates the cluster
  402. * number at which the driver should start looking for free clusters.
  403. * If the value is 0xFFFFFFFF, then there is no hint and the driver
  404. * should start looking at cluster 2.
  405. */
  406. uint32_t nextFree;
  407. uint8_t reserved2[12]; // must be zero
  408. uint8_t tailSignature[4]; // must be 0x00, 0x00, 0x55, 0xAA
  409. } PACKED;
  410. typedef struct fat32_fsinfo fat32_fsinfo_t; // Type name for FAT32 FSINFO Sector
  411. // End Of Chain values for FAT entries
  412. uint16_t const FAT12EOC = 0xFFF, // FAT12 end of chain value used by Microsoft.
  413. FAT12EOC_MIN = 0xFF8, // Minimum value for FAT12 EOC. Use to test for EOC.
  414. FAT16EOC = 0xFFFF, // FAT16 end of chain value used by Microsoft.
  415. FAT16EOC_MIN = 0xFFF8; // Minimum value for FAT16 EOC. Use to test for EOC.
  416. uint32_t const FAT32EOC = 0x0FFFFFFF, // FAT32 end of chain value used by Microsoft.
  417. FAT32EOC_MIN = 0x0FFFFFF8, // Minimum value for FAT32 EOC. Use to test for EOC.
  418. FAT32MASK = 0x0FFFFFFF; // Mask a for FAT32 entry. Entries are 28 bits.
  419. /**
  420. * \struct directoryEntry
  421. * \brief FAT short directory entry
  422. *
  423. * Short means short 8.3 name, not the entry size.
  424. *
  425. * Date Format. A FAT directory entry date stamp is a 16-bit field that is
  426. * basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the
  427. * format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the
  428. * 16-bit word):
  429. *
  430. * Bits 9-15: Count of years from 1980, valid value range 0-127
  431. * inclusive (1980-2107).
  432. *
  433. * Bits 5-8: Month of year, 1 = January, valid value range 1-12 inclusive.
  434. *
  435. * Bits 0-4: Day of month, valid value range 1-31 inclusive.
  436. *
  437. * Time Format. A FAT directory entry time stamp is a 16-bit field that has
  438. * a granularity of 2 seconds. Here is the format (bit 0 is the LSB of the
  439. * 16-bit word, bit 15 is the MSB of the 16-bit word).
  440. *
  441. * Bits 11-15: Hours, valid value range 0-23 inclusive.
  442. *
  443. * Bits 5-10: Minutes, valid value range 0-59 inclusive.
  444. *
  445. * Bits 0-4: 2-second count, valid value range 0-29 inclusive (0 - 58 seconds).
  446. *
  447. * The valid time range is from Midnight 00:00:00 to 23:59:58.
  448. */
  449. struct directoryEntry {
  450. /**
  451. * Short 8.3 name.
  452. *
  453. * The first eight bytes contain the file name with blank fill.
  454. * The last three bytes contain the file extension with blank fill.
  455. */
  456. uint8_t name[11];
  457. /**
  458. * Entry attributes.
  459. *
  460. * The upper two bits of the attribute byte are reserved and should
  461. * always be set to 0 when a file is created and never modified or
  462. * looked at after that. See defines that begin with DIR_ATT_.
  463. */
  464. uint8_t attributes;
  465. /**
  466. * Reserved for use by Windows NT. Set value to 0 when a file is
  467. * created and never modify or look at it after that.
  468. */
  469. uint8_t reservedNT;
  470. /**
  471. * The granularity of the seconds part of creationTime is 2 seconds
  472. * so this field is a count of tenths of a second and it's valid
  473. * value range is 0-199 inclusive. (WHG note - seems to be hundredths)
  474. */
  475. uint8_t creationTimeTenths;
  476. uint16_t creationTime; // Time file was created.
  477. uint16_t creationDate; // Date file was created.
  478. /**
  479. * Last access date. Note that there is no last access time, only
  480. * a date. This is the date of last read or write. In the case of
  481. * a write, this should be set to the same date as lastWriteDate.
  482. */
  483. uint16_t lastAccessDate;
  484. /**
  485. * High word of this entry's first cluster number (always 0 for a
  486. * FAT12 or FAT16 volume).
  487. */
  488. uint16_t firstClusterHigh;
  489. uint16_t lastWriteTime; // Time of last write. File creation is considered a write.
  490. uint16_t lastWriteDate; // Date of last write. File creation is considered a write.
  491. uint16_t firstClusterLow; // Low word of this entry's first cluster number.
  492. uint32_t fileSize; // 32-bit unsigned holding this file's size in bytes.
  493. } PACKED;
  494. /**
  495. * \struct directoryVFATEntry
  496. * \brief VFAT long filename directory entry
  497. *
  498. * directoryVFATEntries are found in the same list as normal directoryEntry.
  499. * But have the attribute field set to DIR_ATT_LONG_NAME.
  500. *
  501. * Long filenames are saved in multiple directoryVFATEntries.
  502. * Each entry containing 13 UTF-16 characters.
  503. */
  504. struct directoryVFATEntry {
  505. /**
  506. * Sequence number. Consists of 2 parts:
  507. * bit 6: indicates first long filename block for the next file
  508. * bit 0-4: the position of this long filename block (first block is 1)
  509. */
  510. uint8_t sequenceNumber;
  511. uint16_t name1[5]; // First set of UTF-16 characters
  512. uint8_t attributes; // attributes (at the same location as in directoryEntry), always 0x0F
  513. uint8_t reservedNT; // Reserved for use by Windows NT. Always 0.
  514. uint8_t checksum; // Checksum of the short 8.3 filename, can be used to checked if the file system as modified by a not-long-filename aware implementation.
  515. uint16_t name2[6]; // Second set of UTF-16 characters
  516. uint16_t firstClusterLow; // firstClusterLow is always zero for longFilenames
  517. uint16_t name3[2]; // Third set of UTF-16 characters
  518. } PACKED;
  519. // Definitions for directory entries
  520. //
  521. typedef struct directoryEntry dir_t; // Type name for directoryEntry
  522. typedef struct directoryVFATEntry vfat_t; // Type name for directoryVFATEntry
  523. uint8_t const DIR_NAME_0xE5 = 0x05, // escape for name[0] = 0xE5
  524. DIR_NAME_DELETED = 0xE5, // name[0] value for entry that is free after being "deleted"
  525. DIR_NAME_FREE = 0x00, // name[0] value for entry that is free and no allocated entries follow
  526. DIR_ATT_READ_ONLY = 0x01, // file is read-only
  527. DIR_ATT_HIDDEN = 0x02, // File should hidden in directory listings
  528. DIR_ATT_SYSTEM = 0x04, // Entry is for a system file
  529. DIR_ATT_VOLUME_ID = 0x08, // Directory entry contains the volume label
  530. DIR_ATT_DIRECTORY = 0x10, // Entry is for a directory
  531. DIR_ATT_ARCHIVE = 0x20, // Old DOS archive bit for backup support
  532. DIR_ATT_LONG_NAME = 0x0F, // Test value for long name entry. Test is (d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME.
  533. DIR_ATT_LONG_NAME_MASK = 0x3F, // Test mask for long name entry
  534. DIR_ATT_DEFINED_BITS = 0x3F; // defined attribute bits
  535. /**
  536. * Directory entry is part of a long name
  537. * \param[in] dir Pointer to a directory entry.
  538. *
  539. * \return true if the entry is for part of a long name else false.
  540. */
  541. static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
  542. return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
  543. }
  544. /** Mask for file/subdirectory tests */
  545. uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
  546. /**
  547. * Directory entry is for a file
  548. * \param[in] dir Pointer to a directory entry.
  549. *
  550. * \return true if the entry is for a normal file else false.
  551. */
  552. static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
  553. return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
  554. }
  555. /**
  556. * Directory entry is for a subdirectory
  557. * \param[in] dir Pointer to a directory entry.
  558. *
  559. * \return true if the entry is for a subdirectory else false.
  560. */
  561. static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
  562. return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
  563. }
  564. /**
  565. * Directory entry is for a file or subdirectory
  566. * \param[in] dir Pointer to a directory entry.
  567. *
  568. * \return true if the entry is for a normal file or subdirectory else false.
  569. */
  570. static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
  571. return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
  572. }
  573. #endif // SDFATSTRUCTS_H