📄 fat32.lst
字号:
241 3 return KO;
242 3 }
243 2 /* read cluster size (in sector) */
244 2 fat_cluster_size = Hard_read_byte();
245 2 fat_cluster_mask = HIGH((Uint16)fat_cluster_size * SECTOR_SIZE) - 1;
246 2 /* reserved sector number */
247 2 ((Byte*)&bpb_rsvd_sec_cnt)[1] = Hard_read_byte();
248 2 ((Byte*)&bpb_rsvd_sec_cnt)[0] = Hard_read_byte();
249 2 /* number of FATs */
250 2 bpb_num_fat = Hard_read_byte();
251 2 if (bpb_num_fat == 2)
252 2 fat_2_is_present = TRUE;
253 2 else
254 2 fat_2_is_present = FALSE;
255 2
256 2 /* read number of dir entries*/
257 2 ((Byte*)&bpb_root_ent_count)[3] = Hard_read_byte();
258 2 ((Byte*)&bpb_root_ent_count)[2] = Hard_read_byte();
259 2
260 2 /* read number of sector in partition (<32Mb) */
261 2 ((Byte*)&fat_nb_sector)[3] = Hard_read_byte();
262 2 ((Byte*)&fat_nb_sector)[2] = Hard_read_byte();
263 2 ((Byte*)&fat_nb_sector)[1] = 0x00;
264 2 ((Byte*)&fat_nb_sector)[0] = 0x00;
265 2 Hard_read_byte();
266 2 Hard_read_byte(); /* FAT size for FAT12/16 */
267 2 Hard_read_byte();
268 2
269 2 Hard_read_byte();
270 2 Hard_read_byte();
271 2 Hard_read_byte();
272 2 Hard_read_byte();
273 2 Hard_read_byte();
274 2 Hard_read_byte();
275 2 Hard_read_byte();
276 2 Hard_read_byte();
277 2
278 2 /* read number of sector in partition (>32Mb) */
279 2 ((Byte*)&fat_nb_sector)[3] += Hard_read_byte();
280 2 ((Byte*)&fat_nb_sector)[2] += Hard_read_byte();
281 2 ((Byte*)&fat_nb_sector)[1] += Hard_read_byte();
282 2 ((Byte*)&fat_nb_sector)[0] += Hard_read_byte();
283 2
284 2 fat_is_fat16 = FALSE;
285 2 fat_is_fat32 = TRUE;
286 2
287 2 fat_ptr_data = (bpb_root_ent_count * DIR_SIZE) / SECTOR_SIZE;
288 2
289 2 /* Here start the structure for FAT32 */
290 2 /* Offset 36 : 32 bits size of fat */
291 2 ((Byte*)&fat_fat_size)[3] = Hard_read_byte();
292 2 ((Byte*)&fat_fat_size)[2] = Hard_read_byte();
293 2 ((Byte*)&fat_fat_size)[1] = Hard_read_byte();
294 2 ((Byte*)&fat_fat_size)[0] = Hard_read_byte();
295 2
296 2 tot_sect = fat_nb_sector - (Uint32)(((Uint32)(bpb_rsvd_sec_cnt) + (Uint32)((bpb_num_fat * (Uint32)(fat
-_fat_size))) + fat_ptr_data));
297 2 fat_count_of_clusters = tot_sect / fat_cluster_size;
298 2
299 2 total_capacity = tot_sect;
300 2
301 2 /* Offset 40 : ExtFlags */
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 6
302 2 Hard_read_byte();
303 2 Hard_read_byte();
304 2 /* Offset 42 : FS Version */
305 2 Hard_read_byte();
306 2 Hard_read_byte();
307 2 /* Offset 44 : Root Cluster */
308 2 ((Byte*)&fat_rootclus_fat32)[3] = Hard_read_byte();
309 2 ((Byte*)&fat_rootclus_fat32)[2] = Hard_read_byte();
310 2 ((Byte*)&fat_rootclus_fat32)[1] = Hard_read_byte();
311 2 ((Byte*)&fat_rootclus_fat32)[0] = Hard_read_byte();
312 2
313 2 fat_ptr_fats += bpb_rsvd_sec_cnt;
314 2 fat_ptr_data = fat_ptr_fats + (bpb_num_fat * fat_fat_size);
315 2
316 2 /* Offset 48 : FS Info */
317 2 /* Offset 50 : Backup Boot Sector */
318 2 /* Offset 52 : Reserved */
319 2 /* Offset 64 - 89 : Data */
320 2 /* Offset 90 : 510 : Free */
321 2 for (i = 231; i != 0; i--)
322 2 {
323 3 Hard_read_byte();
324 3 Hard_read_byte();
325 3 }
326 2 /* check partition signature */
327 2 if ((Hard_read_byte() != LOW(BR_SIGNATURE)) &&
328 2 (Hard_read_byte() != HIGH(BR_SIGNATURE)))
329 2 {
330 3 Hard_read_close(); /* close physical read */
331 3 return KO;
332 3 }
333 2 Hard_read_close(); /* close physical read */
334 2 return OK;
335 2 }
336 1 else
337 1 { /* low level error */
338 2 return KO;
339 2 }
340 1 }
341
342 #define UPLOAD 0
343 #define DOWNLOAD 1
344 #define FETCH_NEXT 0
345 #define FETCH_PREV 1
346
347 /*F**************************************************************************
348 * NAME: fat32_calc_cluster
349 *----------------------------------------------------------------------------
350 * PARAMS:
351 *
352 *
353 * return:
354 *----------------------------------------------------------------------------
355 * PURPOSE:
356 * Calculate fat_dir_current_sect and update directory variable from the
357 * value of fat_dir_current_offs.
358 *----------------------------------------------------------------------------
359 * EXAMPLE:
360 *----------------------------------------------------------------------------
361 * NOTE:
362 *
363 *----------------------------------------------------------------------------
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 7
364 * REQUIREMENTS:
365 *
366 *****************************************************************************/
367 void fat32_calc_cluster(void)
368 {
369 1 Uint32 i;
370 1 fat_dchain_index = 0;
371 1 fat_dchain_nb_clust = 0;
372 1 for (i = (fat_dir_current_offs / SECTOR_SIZE / fat_cluster_size) + 1; i != 0; i--)
373 1 {
374 2 if (dclusters[fat_dchain_index].number == fat_dchain_nb_clust)
375 2 { /* new fragment */
376 3 fat_dchain_index++;
377 3 fat_dchain_nb_clust = 1;
378 3 }
379 2 else
380 2 { /* no new fragment */
381 3 fat_dchain_nb_clust++;
382 3 }
383 2 }
384 1 i = fat_dir_current_offs / SECTOR_SIZE;
385 1 fat_dir_current_sect = (((Uint32)(dclusters[fat_dchain_index].cluster + fat_dchain_nb_clust - 1) *
386 1 fat_cluster_size)
387 1 + fat_ptr_data + (i % fat_cluster_size));
388 1
389 1 if ((fat_dclust_byte_count == 0)/* && (fat_dchain_index == 0)*/) /* If we are at the beginning of a
-directory */
390 1 if (fat_dchain_nb_clust == 1)
391 1 fat_dchain_nb_clust = 0;
392 1 }
393
394
395 /*F**************************************************************************
396 * NAME: fat_clear_dir_info
397 *----------------------------------------------------------------------------
398 * PARAMS:
399 *
400 *
401 * return:
402 *----------------------------------------------------------------------------
403 * PURPOSE:
404 * Reset directory chain cluster value
405 *----------------------------------------------------------------------------
406 * EXAMPLE:
407 *----------------------------------------------------------------------------
408 * NOTE:
409 *
410 *----------------------------------------------------------------------------
411 * REQUIREMENTS:
412 *
413 *****************************************************************************/
414 void fat32_clear_dir_info(void)
415 {
416 1 fat_dchain_nb_clust = 0; /* position of a cluster for selected chain idx */
417 1 fat_dchain_index = 0; /* chain index position */
418 1 fat_dclust_byte_count = 0; /* byte position inside a directory cluster */
419 1 fat_dir_current_offs = 0; /* general offset from the start of a directory */
420 1 }
421
422 /*F**************************************************************************
423 * NAME: fat_up_down_load_sector
424 *----------------------------------------------------------------------------
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 8
425 * PARAMS:
426 * - sector address to load/download
427 * - bit to indicate if it's a download or an upload
428 *
429 * return:
430 *----------------------------------------------------------------------------
431 * PURPOSE:
432 * Download or upload a sector of 512b
433 *----------------------------------------------------------------------------
434 * EXAMPLE:
435 *----------------------------------------------------------------------------
436 * NOTE:
437 *
438 *----------------------------------------------------------------------------
439 * REQUIREMENTS:
440 *
441 *****************************************************************************/
442 void fat32_up_down_load_sector(Uint32 sector, bit up_down)
443 {
444 1 if (up_down == UPLOAD)
445 1 {
446 2 Hard_read_open(sector);
447 2 Hard_load_sector();
448 2 Hard_read_close();
449 2 }
450 1 else
451 1 {
452 2 Hard_write_open(sector);
453 2 // Hard_download_sector();
454 2 Hard_write_close();
455 2 }
456 1 }
457
458 /*F**************************************************************************
459 * NAME: fat_get_dir_file_list
460 *----------------------------------------------------------------------------
461 * PARAMS:
462 * id: file extension to select
463 *
464 * return:
465 *----------------------------------------------------------------------------
466 * PURPOSE:
467 * Give information about the directory :
468 * - total number of entries
469 * - number of deleted entries
470 * - number of filtered entries (filter is done by checking id value)
471 * - total number of clusters used by the directory
472 *----------------------------------------------------------------------------
473 * EXAMPLE:
474 *
475 *----------------------------------------------------------------------------
476 * NOTE:
477 *
478 *----------------------------------------------------------------------------
479 * REQUIREMENTS:
480 *
481 *****************************************************************************/
482 void fat32_get_dir_file_list (Byte id)
483 {
484 1 Byte i;
485 1 bit exit = FALSE;
486 1
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 9
487 1 current_ext = id; /* save current extension */
488 1 fat_last_dir_cluster_full = FALSE; /* reset flag for full cluster */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -