Prusa3d Marlin fork
SdFatStructs.h
Go to the documentation of this file.
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 
23 #ifndef SdFatStructs_h
24 #define SdFatStructs_h
25 
26 #define PACKED __attribute__((__packed__))
31 /*
32  * mostly from Microsoft document fatgen103.doc
33  * http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
34  */
35 //------------------------------------------------------------------------------
37 uint8_t const BOOTSIG0 = 0X55;
39 uint8_t const BOOTSIG1 = 0XAA;
41 uint8_t const EXTENDED_BOOT_SIG = 0X29;
42 //------------------------------------------------------------------------------
56  uint8_t boot;
61  uint8_t beginHead;
66  unsigned beginSector : 6;
68  unsigned beginCylinderHigh : 2;
78  uint8_t type;
83  uint8_t endHead;
88  unsigned endSector : 6;
90  unsigned endCylinderHigh : 2;
95  uint8_t endCylinderLow;
97  uint32_t firstSector;
99  uint32_t totalSectors;
100 } PACKED;
102 typedef struct partitionTable part_t;
103 //------------------------------------------------------------------------------
113  uint8_t codeArea[440];
115  uint32_t diskSignature;
117  uint16_t usuallyZero;
121  uint8_t mbrSig0;
123  uint8_t mbrSig1;
124 } PACKED;
126 typedef struct masterBootRecord mbr_t;
127 //------------------------------------------------------------------------------
134 struct fat_boot {
140  uint8_t jump[3];
145  char oemId[8];
151  uint16_t bytesPerSector;
167  uint8_t fatCount;
186  uint16_t totalSectors16;
193  uint8_t mediaType;
199  uint16_t sectorsPerFat16;
201  uint16_t sectorsPerTrack;
203  uint16_t headCount;
209  uint32_t hidddenSectors;
216  uint32_t totalSectors32;
225  uint8_t driveNumber;
227  uint8_t reserved1;
229  uint8_t bootSignature;
240  char volumeLabel[11];
245  char fileSystemType[8];
247  uint8_t bootCode[448];
249  uint8_t bootSectorSig0;
251  uint8_t bootSectorSig1;
252 } PACKED;
254 typedef struct fat_boot fat_boot_t;
255 //------------------------------------------------------------------------------
262 struct fat32_boot {
268  uint8_t jump[3];
273  char oemId[8];
279  uint16_t bytesPerSector;
295  uint8_t fatCount;
303  uint16_t totalSectors16;
310  uint8_t mediaType;
315  uint16_t sectorsPerFat16;
317  uint16_t sectorsPerTrack;
319  uint16_t headCount;
325  uint32_t hidddenSectors;
329  uint32_t totalSectors32;
333  uint32_t sectorsPerFat32;
345  uint16_t fat32Flags;
350  uint16_t fat32Version;
360  uint16_t fat32FSInfo;
371  uint8_t fat32Reserved[12];
380  uint8_t driveNumber;
382  uint8_t reserved1;
384  uint8_t bootSignature;
395  char volumeLabel[11];
399  char fileSystemType[8];
401  uint8_t bootCode[420];
403  uint8_t bootSectorSig0;
405  uint8_t bootSectorSig1;
406 } PACKED;
408 typedef struct fat32_boot fat32_boot_t;
409 //------------------------------------------------------------------------------
411 uint32_t const FSINFO_LEAD_SIG = 0x41615252;
413 uint32_t const FSINFO_STRUCT_SIG = 0x61417272;
420 struct fat32_fsinfo {
422  uint32_t leadSignature;
424  uint8_t reserved1[480];
426  uint32_t structSignature;
434  uint32_t freeCount;
441  uint32_t nextFree;
443  uint8_t reserved2[12];
445  uint8_t tailSignature[4];
446 } PACKED;
448 typedef struct fat32_fsinfo fat32_fsinfo_t;
449 //------------------------------------------------------------------------------
450 // End Of Chain values for FAT entries
452 uint16_t const FAT12EOC = 0XFFF;
454 uint16_t const FAT12EOC_MIN = 0XFF8;
456 uint16_t const FAT16EOC = 0XFFFF;
458 uint16_t const FAT16EOC_MIN = 0XFFF8;
460 uint32_t const FAT32EOC = 0X0FFFFFFF;
462 uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
464 uint32_t const FAT32MASK = 0X0FFFFFFF;
465 //------------------------------------------------------------------------------
502  uint8_t name[11];
509  uint8_t attributes;
514  uint8_t reservedNT;
522  uint16_t creationTime;
524  uint16_t creationDate;
530  uint16_t lastAccessDate;
537  uint16_t lastWriteTime;
539  uint16_t lastWriteDate;
541  uint16_t firstClusterLow;
543  uint32_t fileSize;
544 } PACKED;
561  uint8_t sequenceNumber;
563  uint16_t name1[5];//UTF-16
565  uint8_t attributes;
567  uint8_t reservedNT;
569  uint8_t checksum;
571  uint16_t name2[6];//UTF-16
573  uint16_t firstClusterLow;
575  uint16_t name3[2];//UTF-16
576 } PACKED;
577 //------------------------------------------------------------------------------
578 // Definitions for directory entries
579 //
581 typedef struct directoryEntry dir_t;
583 typedef struct directoryVFATEntry vfat_t;
585 uint8_t const DIR_NAME_0XE5 = 0X05;
587 uint8_t const DIR_NAME_DELETED = 0XE5;
589 uint8_t const DIR_NAME_FREE = 0X00;
591 uint8_t const DIR_ATT_READ_ONLY = 0X01;
593 uint8_t const DIR_ATT_HIDDEN = 0X02;
595 uint8_t const DIR_ATT_SYSTEM = 0X04;
597 uint8_t const DIR_ATT_VOLUME_ID = 0X08;
599 uint8_t const DIR_ATT_DIRECTORY = 0X10;
601 uint8_t const DIR_ATT_ARCHIVE = 0X20;
604 uint8_t const DIR_ATT_LONG_NAME = 0X0F;
606 uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
608 uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
614 static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
615  return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
616 }
624 static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
625  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
626 }
632 static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
633  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
634 }
640 static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
641  return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
642 }
643 #endif // SdFatStructs_h
644 
645 
646 #endif
uint32_t const FAT32MASK
Definition: SdFatStructs.h:464
uint8_t const DIR_ATT_LONG_NAME_MASK
Definition: SdFatStructs.h:606
uint8_t const DIR_ATT_LONG_NAME
Definition: SdFatStructs.h:604
uint8_t const BOOTSIG1
Definition: SdFatStructs.h:39
uint8_t const DIR_NAME_FREE
Definition: SdFatStructs.h:589
uint8_t const DIR_NAME_0XE5
Definition: SdFatStructs.h:585
uint8_t const DIR_ATT_HIDDEN
Definition: SdFatStructs.h:593
uint8_t const DIR_ATT_DIRECTORY
Definition: SdFatStructs.h:599
uint8_t const DIR_ATT_FILE_TYPE_MASK
Definition: SdFatStructs.h:618
uint16_t const FAT16EOC
Definition: SdFatStructs.h:456
static uint8_t DIR_IS_LONG_NAME(const dir_t *dir)
Definition: SdFatStructs.h:614
uint16_t const FAT12EOC
Definition: SdFatStructs.h:452
static uint8_t DIR_IS_FILE(const dir_t *dir)
Definition: SdFatStructs.h:624
uint8_t const DIR_NAME_DELETED
Definition: SdFatStructs.h:587
uint8_t const DIR_ATT_ARCHIVE
Definition: SdFatStructs.h:601
uint16_t const FAT16EOC_MIN
Definition: SdFatStructs.h:458
static uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t *dir)
Definition: SdFatStructs.h:640
uint8_t const BOOTSIG0
Definition: SdFatStructs.h:37
uint32_t const FSINFO_STRUCT_SIG
Definition: SdFatStructs.h:413
uint8_t const DIR_ATT_READ_ONLY
Definition: SdFatStructs.h:591
uint32_t const FAT32EOC
Definition: SdFatStructs.h:460
uint32_t const FSINFO_LEAD_SIG
Definition: SdFatStructs.h:411
uint8_t const EXTENDED_BOOT_SIG
Definition: SdFatStructs.h:41
static uint8_t DIR_IS_SUBDIR(const dir_t *dir)
Definition: SdFatStructs.h:632
uint8_t const DIR_ATT_DEFINED_BITS
Definition: SdFatStructs.h:608
uint8_t const DIR_ATT_SYSTEM
Definition: SdFatStructs.h:595
uint16_t const FAT12EOC_MIN
Definition: SdFatStructs.h:454
uint8_t const DIR_ATT_VOLUME_ID
Definition: SdFatStructs.h:597
uint32_t const FAT32EOC_MIN
Definition: SdFatStructs.h:462
FAT short directory entry.
Definition: SdFatStructs.h:496
uint8_t name[11]
Definition: SdFatStructs.h:502
uint16_t lastWriteDate
Definition: SdFatStructs.h:539
uint8_t attributes
Definition: SdFatStructs.h:509
uint16_t firstClusterHigh
Definition: SdFatStructs.h:535
uint16_t creationTime
Definition: SdFatStructs.h:522
uint16_t firstClusterLow
Definition: SdFatStructs.h:541
uint16_t creationDate
Definition: SdFatStructs.h:524
uint16_t lastWriteTime
Definition: SdFatStructs.h:537
uint8_t creationTimeTenths
Definition: SdFatStructs.h:520
uint16_t lastAccessDate
Definition: SdFatStructs.h:530
uint32_t fileSize
Definition: SdFatStructs.h:543
uint8_t reservedNT
Definition: SdFatStructs.h:514
VFAT long filename directory entry.
Definition: SdFatStructs.h:555
uint8_t reservedNT
Definition: SdFatStructs.h:567
uint8_t attributes
Definition: SdFatStructs.h:565
uint16_t name2[6]
Definition: SdFatStructs.h:571
uint16_t firstClusterLow
Definition: SdFatStructs.h:573
uint16_t name1[5]
Definition: SdFatStructs.h:563
uint8_t sequenceNumber
Definition: SdFatStructs.h:561
uint8_t checksum
Definition: SdFatStructs.h:569
uint16_t name3[2]
Definition: SdFatStructs.h:575
Boot sector for a FAT32 volume.
Definition: SdFatStructs.h:262
uint16_t bytesPerSector
Definition: SdFatStructs.h:279
uint16_t fat32FSInfo
Definition: SdFatStructs.h:360
char fileSystemType[8]
Definition: SdFatStructs.h:399
uint16_t headCount
Definition: SdFatStructs.h:319
uint8_t bootSectorSig0
Definition: SdFatStructs.h:403
uint32_t volumeSerialNumber
Definition: SdFatStructs.h:390
uint16_t fat32Version
Definition: SdFatStructs.h:350
uint8_t jump[3]
Definition: SdFatStructs.h:268
uint8_t fat32Reserved[12]
Definition: SdFatStructs.h:371
uint8_t mediaType
Definition: SdFatStructs.h:310
uint8_t bootSectorSig1
Definition: SdFatStructs.h:405
uint8_t sectorsPerCluster
Definition: SdFatStructs.h:285
uint8_t reserved1
Definition: SdFatStructs.h:382
uint8_t fatCount
Definition: SdFatStructs.h:295
uint8_t bootCode[420]
Definition: SdFatStructs.h:401
uint16_t reservedSectorCount
Definition: SdFatStructs.h:290
char volumeLabel[11]
Definition: SdFatStructs.h:395
uint16_t rootDirEntryCount
Definition: SdFatStructs.h:299
uint16_t sectorsPerTrack
Definition: SdFatStructs.h:317
uint32_t sectorsPerFat32
Definition: SdFatStructs.h:333
uint32_t fat32RootCluster
Definition: SdFatStructs.h:355
uint16_t fat32Flags
Definition: SdFatStructs.h:345
uint32_t hidddenSectors
Definition: SdFatStructs.h:325
uint32_t totalSectors32
Definition: SdFatStructs.h:329
uint8_t bootSignature
Definition: SdFatStructs.h:384
uint16_t fat32BackBootBlock
Definition: SdFatStructs.h:366
uint8_t driveNumber
Definition: SdFatStructs.h:380
uint16_t totalSectors16
Definition: SdFatStructs.h:303
uint16_t sectorsPerFat16
Definition: SdFatStructs.h:315
char oemId[8]
Definition: SdFatStructs.h:273
FSINFO sector for a FAT32 volume.
Definition: SdFatStructs.h:420
uint8_t tailSignature[4]
Definition: SdFatStructs.h:445
uint32_t nextFree
Definition: SdFatStructs.h:441
uint32_t freeCount
Definition: SdFatStructs.h:434
uint8_t reserved2[12]
Definition: SdFatStructs.h:443
uint32_t structSignature
Definition: SdFatStructs.h:426
uint32_t leadSignature
Definition: SdFatStructs.h:422
uint8_t reserved1[480]
Definition: SdFatStructs.h:424
Boot sector for a FAT12/FAT16 volume.
Definition: SdFatStructs.h:134
uint8_t fatCount
Definition: SdFatStructs.h:167
uint16_t sectorsPerFat16
Definition: SdFatStructs.h:199
uint16_t reservedSectorCount
Definition: SdFatStructs.h:162
uint32_t hidddenSectors
Definition: SdFatStructs.h:209
uint16_t rootDirEntryCount
Definition: SdFatStructs.h:176
uint16_t bytesPerSector
Definition: SdFatStructs.h:151
uint8_t mediaType
Definition: SdFatStructs.h:193
uint16_t sectorsPerTrack
Definition: SdFatStructs.h:201
uint8_t bootSignature
Definition: SdFatStructs.h:229
uint8_t bootSectorSig0
Definition: SdFatStructs.h:249
uint8_t jump[3]
Definition: SdFatStructs.h:140
char volumeLabel[11]
Definition: SdFatStructs.h:240
uint8_t sectorsPerCluster
Definition: SdFatStructs.h:157
uint32_t volumeSerialNumber
Definition: SdFatStructs.h:235
uint16_t totalSectors16
Definition: SdFatStructs.h:186
uint8_t bootCode[448]
Definition: SdFatStructs.h:247
char oemId[8]
Definition: SdFatStructs.h:145
uint32_t totalSectors32
Definition: SdFatStructs.h:216
uint16_t headCount
Definition: SdFatStructs.h:203
uint8_t driveNumber
Definition: SdFatStructs.h:225
char fileSystemType[8]
Definition: SdFatStructs.h:245
uint8_t bootSectorSig1
Definition: SdFatStructs.h:251
uint8_t reserved1
Definition: SdFatStructs.h:227
Master Boot Record.
Definition: SdFatStructs.h:111
uint8_t codeArea[440]
Definition: SdFatStructs.h:113
uint8_t mbrSig0
Definition: SdFatStructs.h:121
uint32_t diskSignature
Definition: SdFatStructs.h:115
part_t part[4]
Definition: SdFatStructs.h:119
uint8_t mbrSig1
Definition: SdFatStructs.h:123
uint16_t usuallyZero
Definition: SdFatStructs.h:117
MBR partition table entry.
Definition: SdFatStructs.h:50
uint32_t firstSector
Definition: SdFatStructs.h:97
unsigned endSector
Definition: SdFatStructs.h:88
unsigned endCylinderHigh
Definition: SdFatStructs.h:90
uint8_t type
Definition: SdFatStructs.h:78
uint8_t endHead
Definition: SdFatStructs.h:83
unsigned beginCylinderHigh
Definition: SdFatStructs.h:68
uint8_t beginHead
Definition: SdFatStructs.h:61
uint8_t beginCylinderLow
Definition: SdFatStructs.h:73
uint32_t totalSectors
Definition: SdFatStructs.h:99
uint8_t endCylinderLow
Definition: SdFatStructs.h:95
uint8_t boot
Definition: SdFatStructs.h:56
unsigned beginSector
Definition: SdFatStructs.h:66