📄 fat16.lst
字号:
174 3 if(IsEqual(Name, &((DIR*)&BUFFER[m * 32])->FileName, 11))
175 3 {
176 4 *ID = *((DIR*)&BUFFER[m * 32]);
177 4 return 1; //找到对应的目录项,返回1.
178 4 }
179 3 }
180 2 }
181 1 return 0; //没有找到对应的目录项,返回0.
182 1 }
183
184 //********************************************************************************************
185 //获取一个空的FAT项
186 uint16 GetNextFAT(void)
187 //********************************************************************************************
188 {
189 1 uint16 FAT_Count, i;
190 1 FAT_Count = BPB_FATSz16 * 256; //FAT表总项数
191 1 for(i = 0; i < FAT_Count; i++)
192 1 {
193 2 if(ReadFAT(i) == 0)
194 2 return i;
195 2 }
196 1 return 0;
197 1 }
198
199 //********************************************************************************************
200 //读取根目录的指定项
201 void ReadDIR(uint16 Index, DIR* Value)
202 //********************************************************************************************
203 {
204 1 uint32 DirStart = DirStartSec();
205 1 ReadBlock(DirStart + Index / 16);
206 1 CopyBytes(&BUFFER[(Index % 16) * 32], Value, 32);
207 1 }
208
209 //********************************************************************************************
210 //写根目录的指定项
211 void WriteDIR(uint16 Index, DIR* Value)
212 //********************************************************************************************
213 {
214 1 uint32 LBA = DirStartSec() + Index / 16;
215 1 ReadBlock(LBA);
216 1 CopyBytes(Value, &BUFFER[(Index % 16) * 32], 32);
217 1 WriteBlock(LBA);
218 1 }
219 //********************************************************************************************
220 //创建一个空文件
221 void CreateFile(uint8* FileName[11], uint32 Size)
222 //********************************************************************************************
223 {
224 1 uint16 ClusID, ClusNum, ClusNext, i;
225 1 DIR FileDir;
226 1 ClusNum = Size / (BPB_SecPerClus * 512) + 1;
227 1 EmptyBytes(&FileDir, sizeof(DIR));
228 1 CopyBytes(FileName, &FileDir.FileName, 11);
229 1 FileDir.FilePosit.Size = Size;
230 1 FileDir.FilePosit.Start = GetNextFAT();
231 1 ClusID = FileDir.FilePosit.Start;
232 1 for(i = 0; i < ClusNum - 1; i++)
233 1 {
234 2 WriteFAT(ClusID, 0xffff);
235 2 ClusNext = GetNextFAT();
C51 COMPILER V7.50 FAT16 08/25/2007 14:05:33 PAGE 5
236 2 WriteFAT(ClusID, ClusNext);
237 2 ClusID = ClusNext;
238 2 }
239 1 WriteFAT(ClusID, 0xffff);
240 1 WriteDIR(GetEmptyDIR(), &FileDir);
241 1 }
242
243 //********************************************************************************************
244 //复制文件分配表,使其和备份一致
245 void CopyFAT(void)
246 //********************************************************************************************
247 {
248 1 uint16 FATSz16, RsvdSecCnt, i;
249 1 FATSz16 = BPB_FATSz16;
250 1 RsvdSecCnt = BPB_RsvdSecCnt;
251 1 for(i = 0; i < FATSz16; i++)
252 1 {
253 2 ReadBlock(RsvdSecCnt + i);
254 2 WriteBlock(RsvdSecCnt + FATSz16 + i);
255 2 }
256 1 }
257
258 //********************************************************************************************
259 //操作文件的数据
260 void OperateFile(uint8 Write ,uint8 Name[11], uint32 Start, uint32 Length, void* Data)
261 //********************************************************************************************
262 {
263 1 uint8 *data = Data;
*** ERROR C141 IN LINE 263 OF FAT16.C: syntax error near '='
264 1 uint16 BytePerClus, SecPerClus, ClusNum, ClusID, m;
*** ERROR C141 IN LINE 264 OF FAT16.C: syntax error near 'uint16'
*** ERROR C202 IN LINE 264 OF FAT16.C: 'BytePerClus': undefined identifier
265 1 uint32 LBA, i;
*** ERROR C141 IN LINE 265 OF FAT16.C: syntax error near 'uint32'
*** ERROR C202 IN LINE 265 OF FAT16.C: 'LBA': undefined identifier
266 1 DIR FileDir;
*** ERROR C141 IN LINE 266 OF FAT16.C: syntax error near 'DIR'
*** ERROR C202 IN LINE 266 OF FAT16.C: 'FileDir': undefined identifier
267 1 SecPerClus = BPB_SecPerClus;
*** ERROR C202 IN LINE 267 OF FAT16.C: 'SecPerClus': undefined identifier
268 1 BytePerClus = BPB_SecPerClus * 512; // 每簇的字节数
*** ERROR C202 IN LINE 268 OF FAT16.C: 'BytePerClus': undefined identifier
269 1 GetFileID(Name, &FileDir);
*** ERROR C202 IN LINE 269 OF FAT16.C: 'FileDir': undefined identifier
270 1
271 1 //计算开始位置所在簇的簇号
272 1 ClusNum = Start / BytePerClus;
*** ERROR C202 IN LINE 272 OF FAT16.C: 'ClusNum': undefined identifier
273 1 ClusID = FileDir.FilePosit.Start;
*** ERROR C202 IN LINE 273 OF FAT16.C: 'ClusID': undefined identifier
274 1 for(i = 0; i < ClusNum; i++)
*** ERROR C202 IN LINE 274 OF FAT16.C: 'i': undefined identifier
275 1 ClusID = ReadFAT(ClusID);
*** ERROR C202 IN LINE 275 OF FAT16.C: 'ClusID': undefined identifier
276 1
277 1 //计算开始位置所在扇区簇内偏移
278 1 i = (Start % BytePerClus) / 512;
*** ERROR C202 IN LINE 278 OF FAT16.C: 'i': undefined identifier
279 1
280 1 //计算开始位置扇区内偏移
281 1 m = (Start % BytePerClus) % 512;
*** ERROR C202 IN LINE 281 OF FAT16.C: 'm': undefined identifier
C51 COMPILER V7.50 FAT16 08/25/2007 14:05:33 PAGE 6
282 1
283 1 LBA = ClusConvLBA(ClusID) + m;
*** ERROR C202 IN LINE 283 OF FAT16.C: 'LBA': undefined identifier
284 1
285 1 if(Write)
286 1 ReadBlock(LBA);
*** ERROR C202 IN LINE 286 OF FAT16.C: 'LBA': undefined identifier
287 1 else
288 1 ReadBlock(LBA++);
*** ERROR C202 IN LINE 288 OF FAT16.C: 'LBA': undefined identifier
289 1
290 1 goto Start;
291 1
292 1 while(1)
293 1 {
294 2 ClusID = ReadFAT(ClusID); //下一簇簇号
*** ERROR C202 IN LINE 294 OF FAT16.C: 'ClusID': undefined identifier
295 2 LBA = ClusConvLBA(ClusID);
*** ERROR C202 IN LINE 295 OF FAT16.C: 'LBA': undefined identifier
296 2 for(i = 0; i < SecPerClus; i++)
*** ERROR C202 IN LINE 296 OF FAT16.C: 'i': undefined identifier
297 2 {
298 3 if(Write)
299 3 ReadBlock(LBA);
*** ERROR C202 IN LINE 299 OF FAT16.C: 'LBA': undefined identifier
300 3 else
301 3 ReadBlock(LBA++);
*** ERROR C202 IN LINE 301 OF FAT16.C: 'LBA': undefined identifier
302 3
303 3 for(m = 0; m < 512; m++)
*** ERROR C202 IN LINE 303 OF FAT16.C: 'm': undefined identifier
304 3 {
305 4 Start:
306 4 if(Write)
307 4 BUFFER[m] = *data++;
*** ERROR C202 IN LINE 307 OF FAT16.C: 'm': undefined identifier
*** ERROR C141 IN LINE 307 OF FAT16.C: syntax error near 'data'
308 4 else
*** ERROR C141 IN LINE 308 OF FAT16.C: syntax error near 'else'
309 4 *data++ = BUFFER[m];
*** ERROR C141 IN LINE 309 OF FAT16.C: syntax error near 'data'
310 4
311 4 //如果读取完成就退出
312 4 if(--Length == 0)
313 4 {
314 5 if(Write)
315 5 WriteBlock(LBA); //回写扇区
*** ERROR C202 IN LINE 315 OF FAT16.C: 'LBA': undefined identifier
316 5 return;
317 5 }
318 4 }
319 3 if(Write)
320 3 WriteBlock(LBA++); //回写扇区,指针下移
*** ERROR C202 IN LINE 320 OF FAT16.C: 'LBA': undefined identifier
321 3 }
322 2 }
323 1 }
324
325 //--------------------------------------------------------------------------------------------------------
--------------------------
C51 COMPILATION COMPLETE. 4 WARNING(S), 33 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -