My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SdFatStructs.h 22KB

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