My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SdFatStructs.h 22KB

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