diff options
Diffstat (limited to 'firmware/test/fat/fat-bpb_sector.h')
-rw-r--r-- | firmware/test/fat/fat-bpb_sector.h | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/firmware/test/fat/fat-bpb_sector.h b/firmware/test/fat/fat-bpb_sector.h new file mode 100644 index 0000000000..247f53115c --- /dev/null +++ b/firmware/test/fat/fat-bpb_sector.h | |||
@@ -0,0 +1,211 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_FAT_BPB_SECTOR_H__ | ||
20 | #define __LIBRARY_FAT_BPB_SECTOR_H__ | ||
21 | |||
22 | // [Alan]: | ||
23 | // I would like to draw your attention about the fact that SH1 | ||
24 | // cannot use misaligned address access so you must be very cautious | ||
25 | // with structures stored in FAT32 partition because they come from | ||
26 | // PC world where misaligned address accesses are usual and not | ||
27 | // problematic. To avoid such a trouble, I decide to use special | ||
28 | // structures where fields are moved in such a way they can be | ||
29 | // accessed by SH1. It is possible thanks to the callback mechanism | ||
30 | // I use for reading or writing from/to an ATA device in ata.h/c. | ||
31 | // So don't be puzzled if those structures seem odd compared | ||
32 | // with the usual ones from PC world. I use this mechanism for structures | ||
33 | // 'partition_info', 'mbr_sector' and 'fsi_sector' for instance, but | ||
34 | // not for structure 'bpb_sector' which is too much complex to handle | ||
35 | // that way, I think. | ||
36 | // By the way, SH1 is big endian, not little endian as PC is. | ||
37 | |||
38 | /////////////////////////////////////////////////////////////////////////////////// | ||
39 | // BPB SECTOR : | ||
40 | /////////////// | ||
41 | // | ||
42 | // | ||
43 | |||
44 | struct __fat_bpb_sector /* Bios Parameters Block Sector */ | ||
45 | { | ||
46 | // jmp_boot has two valid ways to look like in a FAT BPB. | ||
47 | // Either EBXX90 or E9XXXX. | ||
48 | // Not used by Rockbox. | ||
49 | unsigned char | ||
50 | jmp_boot[3]; | ||
51 | |||
52 | // Creator system of the fat-drive. | ||
53 | // Usually looks like "MSWIN4.x". | ||
54 | char | ||
55 | oem_name[8]; | ||
56 | |||
57 | // It should be 512 if you don't want any trouble | ||
58 | // with Rockbox firmware. | ||
59 | unsigned char | ||
60 | bytes_per_sector[2]; | ||
61 | |||
62 | // Must be a power of two. | ||
63 | unsigned char | ||
64 | sectors_per_cluster[1]; | ||
65 | |||
66 | // Number of reserved sectors in the reserved region of the volume | ||
67 | // starting at the first sector of the volume. | ||
68 | // Usually 32 for FAT32. | ||
69 | unsigned char | ||
70 | reserved_sectors[2]; | ||
71 | |||
72 | // Number of FAT structures. | ||
73 | // This value should always be 2. | ||
74 | unsigned char | ||
75 | number_of_fats[1]; | ||
76 | |||
77 | // For FAT32, this field must be set to zero. | ||
78 | // Not used by Rockbox. | ||
79 | unsigned char | ||
80 | number_of_root_entries[2]; | ||
81 | |||
82 | // Must be zero for FAT32, since the real value | ||
83 | // can be found in total_sectors. | ||
84 | // Not used by Rockbox. | ||
85 | unsigned char | ||
86 | total_sectors_16[2]; | ||
87 | |||
88 | // Not used by Rockbox. | ||
89 | unsigned char | ||
90 | media[1]; | ||
91 | |||
92 | // In FAT32 this must be zero. | ||
93 | // Not used by Rockbox. | ||
94 | unsigned char | ||
95 | sectors_per_fat_16[2]; | ||
96 | |||
97 | // Sectors per track used on this media. | ||
98 | // Not used by Rockbox. | ||
99 | unsigned char | ||
100 | sectors_per_track[2]; | ||
101 | |||
102 | // Number of heads used on this media. | ||
103 | // Not used by Rockbox. | ||
104 | unsigned char | ||
105 | number_of_heads[2]; | ||
106 | |||
107 | // Number of hidden sectors. | ||
108 | // Not used by Rockbox. | ||
109 | unsigned char | ||
110 | hidden_sectors[4]; | ||
111 | |||
112 | // Number of total sectors. | ||
113 | // For FAT32 volumes, this must be specified. | ||
114 | unsigned char | ||
115 | total_sectors[4]; | ||
116 | |||
117 | // Here follows FAT12/16 or FAT32 specific data. */ | ||
118 | |||
119 | // This is the number of sectors for one FAT. | ||
120 | unsigned char | ||
121 | sectors_per_fat[4]; | ||
122 | |||
123 | // Extended FAT32 flags follow. | ||
124 | unsigned char | ||
125 | flags[2]; | ||
126 | // bits 15-8: reserved | ||
127 | // mirroring, bit 7: | ||
128 | // 0 -> FAT is mirrored at runtime into all FATs. | ||
129 | // 1 -> only the one specified in the following field | ||
130 | // is active. | ||
131 | // Rockbox always sets it. | ||
132 | // bits 7-4 : reserved | ||
133 | // active_fat, bits 3-0: | ||
134 | // this specifies the "active" FAT mentioned previously. | ||
135 | |||
136 | // This specifies the file system version. | ||
137 | // High byte is major number, low byte is minor. | ||
138 | // The current version is 0.0. | ||
139 | unsigned char | ||
140 | filesystem_version[2]; | ||
141 | |||
142 | // This is set to the cluster number of the first cluster | ||
143 | // of the root directory. Usually 2, but not required. | ||
144 | unsigned char | ||
145 | root_cluster[4]; | ||
146 | |||
147 | // This specifies the sector number of the 'FSINFO' structure | ||
148 | // in the reserved area. | ||
149 | unsigned char | ||
150 | filesystem_info[2]; | ||
151 | |||
152 | // If zero, this specifies where the backup of bpb | ||
153 | // can be found. | ||
154 | // Usually 6. | ||
155 | // No value other than 6 is recommended by Microsoft. | ||
156 | unsigned char | ||
157 | backup_bpb[2]; | ||
158 | |||
159 | // The following area should always be set to zero | ||
160 | // when the volume is initialised. | ||
161 | unsigned char | ||
162 | zeros[12]; | ||
163 | |||
164 | // Drive number for BIOS. | ||
165 | // Not used by Rockbox. | ||
166 | unsigned char | ||
167 | drive_number[0]; | ||
168 | |||
169 | // Reserved for Windows NT. | ||
170 | // Should always be set to 0. | ||
171 | unsigned char | ||
172 | reserved_for_nt[0]; | ||
173 | |||
174 | // Extended boot signature. | ||
175 | // If this is 0x29, the following three fields are present. | ||
176 | unsigned char | ||
177 | boot_signature[0]; | ||
178 | |||
179 | // Volume serial number. | ||
180 | unsigned char | ||
181 | volume_id[4]; | ||
182 | |||
183 | // Volume label. | ||
184 | // This field must be updated when the volume label | ||
185 | // in the root directory is updated. | ||
186 | char | ||
187 | volume_label[11]; | ||
188 | |||
189 | // One of the strings "FAT12", "FAT16" or "FAT32". | ||
190 | // This can not be used to determine the type of the FAT, | ||
191 | // but it should be updated when creating file systems. | ||
192 | char | ||
193 | filesystem_type[8]; | ||
194 | |||
195 | char | ||
196 | reserved[420]; | ||
197 | |||
198 | long | ||
199 | signature; | ||
200 | }; | ||
201 | |||
202 | static inline int __fat_get_bpb_sector (unsigned long partition_start,unsigned long lba,struct __fat_bpb_sector *bpb_sector) | ||
203 | { return ata_read_sectors (partition_start + lba,1,bpb_sector,0); } | ||
204 | |||
205 | static inline int __fat_put_bpb_sector (unsigned long partition_start,unsigned long lba,struct __fat_bpb_sector *bpb_sector) | ||
206 | { return FAT_RETURN_SUCCESS && ata_write_sectors (partition_start + lba,1,bpb_sector,0); } | ||
207 | |||
208 | // | ||
209 | /////////////////////////////////////////////////////////////////////////////////// | ||
210 | |||
211 | #endif \ No newline at end of file | ||