📄 fat.lst
字号:
ARM COMPILER V2.42, fat 27/03/06 10:45:49 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE fat
OBJECT MODULE PLACED IN .\obj\fat.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe src\fat.c THUMB DEBUG PRINT(.\LST\FAT.LST) TABS(4) OBJECT(.\obj\fat.obj)
stmt level source
1 /*****************************************************************************\
2 * efs - General purpose Embedded Filesystem library *
3 * --------------------- ----------------------------------- *
4 * *
5 * Filename : fat.c *
6 * Description : This file contains all the functions dealing with the FAT *
7 * in a Microsoft FAT filesystem. It belongs under fs.c *
8 * *
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2.1 of the License, or (at your option) any later version. *
13 * *
14 * This library is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 * Lesser General Public License for more details. *
18 * *
19 * (c)2004 Lennart Yseboodt *
20 * (c)2005 Michael De Nil *
21 \*****************************************************************************/
22
23 /*****************************************************************************/
24 #include "fs.h"
25 /*****************************************************************************/
26
27 /* ****************************************************************************
28 * unsigned long fat_getSectorAddressFatEntry(FileSystem *fs,unsigned long cluster_addr)
29 * Description: Returns the sectornumber that holds the fat entry for cluster cluster_addr.
30 * This works for all FAT types.
31 * Return value: Sectornumber, or 0. Warning, no boundary check.
32 */
33 euint32 fat_getSectorAddressFatEntry(FileSystem *fs,euint32 cluster_addr)
34 {
35 1 euint32 base = fs->volumeId.ReservedSectorCount,res;
36 1
37 1 switch(fs->type){
38 2 case FAT12:
39 2 res=(cluster_addr*3/1024);
40 2 if(res>=fs->FatSectorCount){
41 3 return(0);
42 3 }else{
43 3 return(base+res);
44 3 }
45 2 break;
46 2 case FAT16:
47 2 res=cluster_addr/256;
48 2 if(res>=fs->FatSectorCount){
49 3 return(0);
50 3 }else{
51 3 return(base+res);
52 3 }
53 2 break;
54 2 case FAT32:
55 2 res=cluster_addr/128;
56 2 if(res>=fs->FatSectorCount){
57 3 return(0);
58 3 }else{
59 3 return(base+res);
ARM COMPILER V2.42, fat 27/03/06 10:45:49 PAGE 2
60 3 }
61 2 break;
62 2 }
63 1 return(0);
64 1 }
65 /*****************************************************************************/
66
67
68 /* ****************************************************************************
69 * unsigned long fat_getNextClusterAddress(FileSystem *fs,unsigned long cluster_addr
70 * Description: This function loads the sector of the fat which contains the entry
71 * for cluster_addr. It then fetches and (if required) calculates it's value.
72 * This value is the EoC marker -or- the number of the next cluster in the chain.
73 * Return value: Clusternumber or EoC
74 */
75 euint32 fat_getNextClusterAddress(FileSystem *fs,euint32 cluster_addr,euint16 *linear)
76 {
77 1 euint8 *buf;
78 1 euint8 hb,lb;
79 1 euint16 offset;
80 1 euint32 sector;
81 1 euint32 nextcluster=0;
82 1
83 1 sector=fat_getSectorAddressFatEntry(fs,cluster_addr);
84 1 if( (fs->FatSectorCount <= (sector-fs->volumeId.ReservedSectorCount)) || sector==0 )
85 1 {
86 2 return(0);
87 2 }
88 1
89 1 buf=part_getSect(fs->part,sector,IOM_MODE_READONLY);
90 1
91 1 switch(fs->type)
92 1 {
93 2 case FAT12:
94 2 offset = ((cluster_addr%1024)*3/2)%512;
95 2 hb = buf[offset];
96 2 if(offset == 511){
97 3 part_relSect(fs->part,buf);
98 3 buf=part_getSect(fs->part,sector+1,IOM_MODE_READONLY);
99 3 lb = buf[0];
100 3 }else{
101 3 lb = buf[offset + 1];
102 3 }
103 2 if(cluster_addr%2==0){
104 3 nextcluster = ( ((lb&0x0F)<<8) + (hb) );
105 3 }else{
106 3 nextcluster = ( (lb<<4) + (hb>>4) );
107 3 }
108 2 break;
109 2 case FAT16:
110 2 offset=cluster_addr%256;
111 2 nextcluster = *((euint16 *)buf + offset);
112 2 break;
113 2 case FAT32:
114 2 offset=cluster_addr%128;
115 2 nextcluster = *((euint32 *)buf + offset);
116 2 break;
117 2 }
118 1
119 1 part_relSect(fs->part,buf);
120 1
121 1 return(nextcluster);
122 1 }
*** WARNING C47 IN LINE 75 OF SRC\FAT.C: 'linear': unreferenced parameter
123 /*****************************************************************************/
124
ARM COMPILER V2.42, fat 27/03/06 10:45:49 PAGE 3
125
126 /* ****************************************************************************
127 * void fat_setNextClusterAddress(FileSystem *fs,unsigned long cluster_addr,unsigned long next_cluster_ad
-dr)
128 * Description: This function makes an entry in the fattable for cluster_addr. The value it puts there
129 * is next_cluster_addr.
130 */
131 void fat_setNextClusterAddress(FileSystem *fs,euint32 cluster_addr,euint32 next_cluster_addr)
132 {
133 1 euint8 *buf,*buf2;
134 1 euint16 offset;
135 1 euint32 sector;
136 1
137 1 sector=fat_getSectorAddressFatEntry(fs,cluster_addr);
138 1 if(fs->FatSectorCount<sector){
139 2 DBG((TXT("HARDERROR:::fat_getNextClusterAddress READ PAST FAT BOUNDARY\n")));
140 2 return;
141 2 }
142 1
143 1 buf=part_getSect(fs->part,sector,IOM_MODE_READWRITE);
144 1
145 1 switch(fs->type){
146 2 case FAT12:
147 2 offset = ((cluster_addr%1024)*3/2)%512;
148 2 if(offset == 511){
149 3 if(cluster_addr%2==0){
150 4 buf[offset]=next_cluster_addr&0xFF;
151 4 }else{
152 4 buf[offset]=(buf[offset]&0xF)+((next_cluster_addr<<4)&0xF0);
153 4 }
154 3 buf2=part_getSect(fs->part,fat_getSectorAddressFatEntry(fs,cluster_addr)+1,IOM_MODE_READWRITE);
155 3 if(cluster_addr%2==0){
156 4 buf2[0]=(buf2[0]&0xF0)+((next_cluster_addr>>8)&0xF);
157 4 }else{
158 4 buf2[0]=(next_cluster_addr>>4)&0xFF;
159 4 }
160 3 part_relSect(fs->part,buf2);
161 3 }else{
162 3 if(cluster_addr%2==0){
163 4 buf[offset]=next_cluster_addr&0xFF;
164 4 buf[offset+1]=(buf[offset+1]&0xF0)+((next_cluster_addr>>8)&0xF);
165 4 }else{
166 4 buf[offset]=(buf[offset]&0xF)+((next_cluster_addr<<4)&0xF0);
167 4 buf[offset+1]=(next_cluster_addr>>4)&0xFF;
168 4 }
169 3 }
170 2 part_relSect(fs->part,buf);
171 2 break;
172 2 case FAT16:
173 2 offset=cluster_addr%256;
174 2 *((euint16*)buf+offset)=next_cluster_addr;
175 2 part_relSect(fs->part,buf);
176 2 break;
177 2 case FAT32:
178 2 offset=cluster_addr%128;
179 2 *((euint32*)buf+offset)=next_cluster_addr;
180 2 part_relSect(fs->part,buf);
181 2 break;
182 2 }
183 1
184 1 }
185 /*****************************************************************************/
186
187
188 /* ****************************************************************************
189 * short fat_isEocMarker(FileSystem *fs,unsigned long fat_entry)
ARM COMPILER V2.42, fat 27/03/06 10:45:49 PAGE 4
190 * Description: Checks if a certain value is the EoC marker for the filesystem
191 * noted in fs->type.
192 * Return value: Returns 0 when it is the EoC marker, and 1 otherwise.
193 */
194 eint16 fat_isEocMarker(FileSystem *fs,euint32 fat_entry)
195 {
196 1 switch(fs->type){
197 2 case FAT12:
198 2 if(fat_entry<0xFF8){
199 3 return(0);
200 3 }
201 2 break;
202 2 case FAT16:
203 2 if(fat_entry<0xFFF8){
204 3 return(0);
205 3 }
206 2 break;
207 2 case FAT32:
208 2 if((fat_entry&0x0FFFFFFF)<0xFFFFFF8){
209 3 return(0);
210 3 }
211 2 break;
212 2 }
213 1 return(1);
214 1 }
215 /*****************************************************************************/
216
217
218 /* ****************************************************************************
219 * unsigned long fat_giveEocMarker(FileSystem *fs)
220 * Description: Returns an EoC markernumber valid for the filesystem noted in
221 * fs->type.
222 * Note, for FAT32, the upper 4 bits are set to zero, although they should be un
223 * touched according to MicroSoft specifications. I didn't care.
224 * Return value: The EoC marker cast to an ulong.
225 */
226 euint32 fat_giveEocMarker(FileSystem *fs)
227 {
228 1 switch(fs->type)
229 1 {
230 2 case FAT12:
231 2 return(0xFFF);
232 2 break;
233 2 case FAT16:
234 2 return(0xFFFF);
235 2 break;
236 2 case FAT32:
237 2 return(0x0FFFFFFF);
238 2 break;
239 2 }
240 1 return(0);
241 1 }
242 /*****************************************************************************/
243
244 /* ****************************************************************************
245 * euint32 fat_getNextClusterAddressWBuf(FileSystem *fs,euint32 cluster_addr, euint8* buf)
246 * Description: This function retrieves the contents of a FAT field. It does not fetch
247 * it's own buffer, it is given as a parameter. (ioman makes this function rather obsolete)
248 * Only in the case of a FAT12 crosssector data entry a sector is retrieved here.
249 * Return value: The value of the clusterfield is returned.
250 */
251 euint32 fat_getNextClusterAddressWBuf(FileSystem *fs,euint32 cluster_addr, euint8* buf)
252 {
253 1 euint8 *buf2; /* For FAT12 fallover only */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -