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 25KB

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