My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SdFatStructs.h 23KB

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