📄 fat32.lst
字号:
489 1 fat_no_entries_free = FALSE; /* reset flag for presence of free entries inside a directory
-cluster */
490 1 fat_dir_list_last = 0; /* last filtered directory entry */
491 1 fat_dir_start_sect = fat_dir_current_sect;/* set fat_dir_start_sect (use by fat_dseek()) */
492 1 fat_nb_deleted_entries = 0; /* reset the number of entries that is marker as deleted */
493 1 fat_nb_total_entries = 0; /* reset the number of total entries in the directory */
494 1 fat_total_clusters = 0; /* reset the total number of clusters for a directory */
495 1
496 1 for (i = 0; i <= fat_last_dclust_index; i++)
497 1 {
498 2 fat_total_clusters += dclusters[i].number; /* calculate the total numbers of clusters */
499 2 }
500 1
501 1 fat32_clear_dir_info(); /* clear directory variable */
502 1
503 1 Hard_read_open(fat_dir_start_sect);
504 1 do
505 1 {
506 2 for (i = 0; i < DIR_SIZE; i++)
507 2 gl_buffer[i] = fat32_dgetc();
508 2
509 2 if (gl_buffer[0] != FILE_NOT_EXIST)
510 2 {
511 3 if (gl_buffer[0] != FILE_DELETED)
512 3 {
513 4 fat_nb_total_entries++; /* increase total number of entries */
514 4 while (gl_buffer[11] == ATTR_LFN_ENTRY)
515 4 {
516 5 for (i = 0; i < DIR_SIZE; i++)
517 5 gl_buffer[i] = fat32_dgetc();
518 5 fat_nb_total_entries++; /* increase total number of entries */
519 5 }
520 4
521 4 fat_cache.current.attributes = gl_buffer[11]; /* filter on the file type */
522 4 ext[0] = gl_buffer[8];
523 4 ext[1] = gl_buffer[9];
524 4 ext[2] = gl_buffer[10];
525 4 if ((fat32_check_ext() & current_ext) != FILE_XXX) /* Check if file type is OK */
526 4 {
527 5 fat_dir_list_last++; /* increase the number of selected entries */
528 5 }
529 4 }
530 3 else
531 3 {
532 4 fat_nb_deleted_entries++; /* increase number of deleted entries */
533 4 fat_nb_total_entries++; /* increase total number of entries */
534 4 }
535 3 }
536 2 else
537 2 {
538 3 exit = TRUE; /* "not exist" entries mark the end of directory */
539 3 }
540 2
541 2 if ((((Byte*)&fat_dclust_byte_count)[1] == 0x00) &&
542 2 ((((Byte*)&fat_dclust_byte_count)[0] & fat_cluster_mask) == 0x00) &&
543 2 (fat_last_dclust_index == fat_dchain_index))
544 2 {
545 3 exit = TRUE; /* if the last entries of the last cluster is reached */
546 3 fat_last_dir_cluster_full = TRUE; /* then exit and set this flag */
547 3 }
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 10
548 2 }
549 1 while (!exit);
550 1
551 1 Hard_read_close(); /* close disk */
552 1 if (fat_last_dir_cluster_full) /* if the last directory cluster is full */
553 1 {
554 2 if (!fat_nb_deleted_entries) /* and if there is no deleted entries detected */
555 2 {
556 3 fat_no_entries_free = TRUE; /* set this flag that there is no free entries */
557 3 }
558 2 }
559 1
560 1 fat_dir_current_sect = fat_dir_start_sect;
561 1 fat32_clear_dir_info(); /* reset directory variable */
562 1
563 1 }
564
565
566 /*F**************************************************************************
567 * NAME: fat_fetch_file_info
568 *----------------------------------------------------------------------------
569 * PARAMS:
570 * entry: directory entry structure
571 *
572 * return:
573 *----------------------------------------------------------------------------
574 * PURPOSE:
575 * Get information about a directory or file entry
576 *----------------------------------------------------------------------------
577 * EXAMPLE:
578 *----------------------------------------------------------------------------
579 * NOTE:
580 *
581 *----------------------------------------------------------------------------
582 * REQUIREMENTS:
583 *****************************************************************************/
584 void fat32_fetch_file_info (fat_st_dir_entry xdata *entry, bit direction)
585 {
586 1 Uint16 i;
587 1 Uint16 j;
588 1 bit entry_found = FALSE;
589 1
590 1 /* clear the name buffer */
591 1 for (i = MAX_FILENAME_LEN; i != 0; lfn_name[--i] = '\0');
592 1
593 1 if (direction == FETCH_PREV)
594 1 {
595 2 /* fetch previous file */
596 2 fat_current_start_entry_position--; /* seek to the previous entry */
597 2 fat_dir_current_offs = (fat_current_start_entry_position) * DIR_SIZE; /* update fat_dir_current_offs *
-/
598 2 fat32_calc_cluster(); /* update directory position variabl
-e */
599 2 j = (fat_current_start_entry_position % 16) * DIR_SIZE; /* seek to the previous entry */
600 2 fat32_up_down_load_sector(fat_dir_current_sect, UPLOAD); /* load the directory sector */
601 2 do
602 2 {
603 3 if (fat_buf_sector[j] != FILE_DELETED) /* if it's not a deleted entries */
604 3 {
605 4 entry->attributes = fat_buf_sector[j + 11];
606 4 ext[0]= fat_buf_sector[j + 8];
607 4 ext[1]= fat_buf_sector[j + 9];
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 11
608 4 ext[2]= fat_buf_sector[j + 10];
609 4 if ((fat32_check_ext() & current_ext) != FILE_XXX) /* check id of entry */
610 4 {
611 5 entry_found = TRUE;
612 5 }
613 4 }
614 3
615 3 if (!entry_found ) /* if id is not correct */
616 3 {
617 4 fat_dir_current_offs -= DIR_SIZE; /* seek to previous entry */
618 4 if (j == 0) /* sector change */
619 4 {
620 5 fat32_calc_cluster();
621 5 fat32_up_down_load_sector(fat_dir_current_sect, UPLOAD); /* load the directory sector */
622 5 j = SECTOR_SIZE - DIR_SIZE;
623 5 }
624 4 else
625 4 {
626 5 j -= DIR_SIZE;
627 5 }
628 4 fat_current_start_entry_position--;
629 4 }
630 3 }
631 2 while (!entry_found);
632 2
633 2 if (fat_current_start_entry_position != 0)
634 2 {
635 3 /* we find an entry. Now seek to previous entry for the process LFN */
636 3 fat_dir_current_offs -= DIR_SIZE; /* seek to previous entry */
637 3 if (j == 0) /* sector change */
638 3 {
639 4 fat32_calc_cluster();
640 4 fat32_up_down_load_sector(fat_dir_current_sect, UPLOAD); /* load the directory sector */
641 4 j = SECTOR_SIZE - DIR_SIZE;
642 4 }
643 3 else
644 3 {
645 4 j -= DIR_SIZE;
646 4 }
647 3 fat_current_start_entry_position--;
648 3 if (fat_buf_sector[j + 11] != ATTR_LFN_ENTRY)
649 3 {
650 4 fat_dir_current_offs += DIR_SIZE;
651 4 fat_current_start_entry_position++;
652 4 }
653 3 else
654 3 {
655 4 while ((fat_buf_sector[j + 11] == ATTR_LFN_ENTRY) && (fat_current_start_entry_position != 0))
656 4 {
657 5 fat_dir_current_offs -= DIR_SIZE;
658 5 fat_current_start_entry_position--;
659 5 if (j == 0) /* sector change */
660 5 {
661 6 fat32_calc_cluster();
662 6 fat32_up_down_load_sector(fat_dir_current_sect, UPLOAD); /* load the directory sector */
663 6 j = SECTOR_SIZE - DIR_SIZE;
664 6 }
665 5 else
666 5 {
667 6 j -= DIR_SIZE;
668 6 }
669 5 }
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 12
670 4
671 4 if (fat_current_start_entry_position)
672 4 {
673 5 fat_dir_current_offs += DIR_SIZE;
674 5 fat_current_start_entry_position++;
675 5 }
676 4 }
677 3
678 3 }
679 2
680 2 fat_current_end_entry_position = fat_current_start_entry_position;
681 2 fat32_dseek(0);
682 2 }
683 1 else /* fetch next file */
684 1 {
685 2 fat32_dseek((fat_current_end_entry_position - fat_current_start_entry_position) << 5);
686 2 }
687 1
688 1 do
689 1 {
690 2 fat_current_start_entry_position = fat_current_end_entry_position;
691 2 for (i = 0; i < DIR_SIZE; i++)
692 2 gl_buffer[i] = fat32_dgetc();
693 2
694 2 while (gl_buffer[0] == FILE_DELETED) /* find a non deleted file */
695 2 {
696 3 fat_current_start_entry_position++;
697 3 fat_dir_current_offs += DIR_SIZE;
698 3 for (i = 0; i < DIR_SIZE; i++)
699 3 gl_buffer[i] = fat32_dgetc();
700 3 }
701 2
702 2 fat_current_end_entry_position = fat_current_start_entry_position;
703 2
704 2 if (gl_buffer[11] == ATTR_LFN_ENTRY)
705 2 {
706 3 for (j = gl_buffer[0] & 0x0F; j != 0; j--) /* computes lfn name */
707 3 {
708 4 for (i = 0; i < 5; i++)
709 4 {
710 5 song_name[i] = gl_buffer[2*i + 1]+gl_buffer[2*i + 1 + 1]*256;
711 5 lfn_name[i + 13 * (j - 1)] = gl_buffer[2 * i + 1];
712 5 }
713 4 for (i = 0; i < 6; i++)
714 4 {
715 5 song_name[i + 5] = gl_buffer[2*i + 14]+gl_buffer[2*i + 14 + 1]*256;
716 5 lfn_name[i + 5 + 13 * (j - 1)] = gl_buffer[2 * i + 14];
717 5 }
718 4 for (i = 0; i < 2; i++)
719 4 lfn_name[i + 11 + 13 * (j - 1)] = gl_buffer[2 * i + 28];
720 4
721 4 for (i = 0; i < DIR_SIZE; i++) /* read the directory entry */
722 4 gl_buffer[i] = fat32_dgetc();
723 4 fat_current_end_entry_position++;
724 4 }
725 3 i = 0;
726 3 while (lfn_name[i] != '\0') /* search for the end of the string */
727 3 {
728 4 i++;
729 4 }
730 3 if (i <= 14) /* append spaces for display reason (no
-scrolling) */
C51 COMPILER V7.50 FAT32 11/27/2007 20:46:00 PAGE 13
731 3 {
732 4 while (i != 14)
733 4 {
734 5 lfn_name[i++] = ' ';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -