My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SdFatStructs.h 25KB

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