📄 fat.lst
字号:
151 1 unsigned int clusterNum,i;
152 1 unsigned long sectorNum;
153 1 clusterNum=0;
154 1 sectorNum=DeviceInfo.FatStartSector;
155 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
156 1 {
157 2
158 2 if(!RBC_Read(sectorNum,1,DBUF))
159 2 return 0x0;
160 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
161 2 {
162 3 //clusterNum++;
163 3
164 3 if((DBUF[i]==0)&&(DBUF[i+1]==0))
165 3 {
166 4 DBUF[i]=0xff;
167 4 DBUF[i+1]=0xff;
168 4 //DelayMs(10);
169 4 if(!RBC_Write(sectorNum,1,DBUF))
170 4 return 0x00;
171 4 //DelayMs(10);
172 4 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,DBUF))
173 4 return 0x00;
174 4
175 4 return clusterNum;
176 4 }
177 3 clusterNum++;
178 3 }
179 2
C51 COMPILER V6.21 FAT 06/13/2005 16:14:57 PAGE 4
180 2 sectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
181 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
182 2 //DelayMs(10);
183 2 }
184 1
185 1 return 0x0;
186 1 }
187
188 unsigned int CreateClusterLink(unsigned int currentCluster)
189 {
190 1 unsigned char bFound;
191 1 unsigned int clusterNum;
192 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
193 1 unsigned long temp;
194 1 bFound=0;
195 1 //////////////////////////////////////////////
196 1 //第一次读FAT
197 1 if((FreeFat.SectorNum==DeviceInfo.FatStartSector)&&(FreeFat.OffsetofSector<3))
198 1 {
199 2 if(!RBC_Read(FreeFat.SectorNum,1,CurFatSector))
200 2 return 0x0;
201 2 }
202 1 //////////////////////////////
203 1 temp=FreeFat.SectorNum-DeviceInfo.FatStartSector;
204 1 temp=temp*DeviceInfo.BPB_BytesPerSec;
205 1 temp=temp/2;
206 1 clusterNum=temp+FreeFat.OffsetofSector/2;
207 1
208 1 while(FreeFat.SectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
209 1 {
210 2
211 2 while(FreeFat.OffsetofSector<DeviceInfo.BPB_BytesPerSec)
212 2 {
213 3
214 3 ///////////////////////////////////////////////
215 3 if((CurFatSector[FreeFat.OffsetofSector]==0)&&(CurFatSector[FreeFat.OffsetofSector+1]==0))
216 3 {
217 4 CurFatSector[FreeFat.OffsetofSector]=0xff;
218 4 CurFatSector[FreeFat.OffsetofSector+1]=0xff;
219 4
220 4 FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
221 4 //return clusterNum;
222 4 bXXGFlags.bits.bFatChanged=1;
223 4 bFound=1;
224 4 break;
225 4 }
226 3 FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
227 3 clusterNum++;
228 3 }
229 2 if(bFound==1)
230 2 break;
231 2 //FreeFat.SectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
232 2 //FreeFat.OldSectorNum=FreeFat.SectorNum;
233 2 //FreeFat.SectorNum++;
234 2 //FreeFat.OffsetofSector=0;
235 2 UpdateFat(FreeFat.SectorNum);
236 2
237 2 FreeFat.SectorNum++;
238 2 FreeFat.OffsetofSector=0;
239 2
240 2 if(!RBC_Read(FreeFat.SectorNum,1,CurFatSector))
241 2 return 0x0;
C51 COMPILER V6.21 FAT 06/13/2005 16:14:57 PAGE 5
242 2
243 2
244 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
245 2 //DelayMs(10);
246 2 }
247 1 //////////////////////////////////////////////
248 1 if(bFound==0)
249 1 return 0x00;
250 1
251 1 /////////////////////////////////////////////////////////////////////
252 1 xxgFatSecNum=ThisFatSecNum(currentCluster);
253 1 xxgFatEntOffset=ThisFatEntOffset(currentCluster);
254 1
255 1 if(xxgFatSecNum!=FreeFat.SectorNum)
256 1 {
257 2 RBC_Read(xxgFatSecNum,1,DBUF);
258 2
259 2 //FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
260 2
261 2 DBUF[xxgFatEntOffset]=clusterNum;
262 2 DBUF[xxgFatEntOffset+1]=clusterNum>>8;
263 2 //DelayMs(5);
264 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
265 2 return 0x00;
266 2 //DelayMs(10);
267 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
268 2 return 0x00;
269 2 }
270 1 else
271 1 {
272 2 CurFatSector[xxgFatEntOffset]=clusterNum;
273 2 CurFatSector[xxgFatEntOffset+1]=clusterNum>>8;
274 2
275 2 bXXGFlags.bits.bFatChanged=1;
276 2 }
277 1 return clusterNum;
278 1 }
279
280 void UpdateFat(unsigned long sectorNum)
281 {
282 1
283 1 if(bXXGFlags.bits.bFatChanged==1)
284 1 {
285 2 if(!RBC_Write(sectorNum,1,CurFatSector))
286 2 return ;
287 2 //DelayMs(10);
288 2 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,CurFatSector))
289 2 return ;
290 2 bXXGFlags.bits.bFatChanged=0;
291 2 }
292 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2017 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 1034 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 55
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V6.21 FAT 06/13/2005 16:14:57 PAGE 6
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -