SdFatStructs.h

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
parent 0
2c8ba1964db7
permissions
-rw-r--r--

added missing sanguino files

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

mercurial