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.

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