📄 fat.lst
字号:
503 1 fat_dir_start_sect = fat_dir_current_sect;
504 1 fat_dir_current_offs = 0;
505 1
506 1 Hard_read_open(fat_dir_start_sect);
507 1
508 1 do /* scan all entries */
509 1 {
510 2 if (dir_is_root == TRUE)
511 2 { /* root dir is linear -> Hard_read_byte() */
512 3 for (i = 0; i < DIR_SIZE; i++)
513 3 gl_buffer[i] = Hard_read_byte();
514 3 }
515 2 else
516 2 { /* subdir can be fragmented -> dgetc() */
517 3 for (i = 0; i < DIR_SIZE; i++)
518 3 gl_buffer[i] = fat_dgetc();
519 3 }
520 2 counter_entry++; /* increase the # entry */
521 2
522 2 if ((gl_buffer[0] != FILE_DELETED) && (gl_buffer[0] != FILE_NOT_EXIST))
523 2 { /* Existing file ? */
524 3 fat_dir_entry_list[index] = entry_pos; /* save the relative position */
525 3 entry_pos_saved = entry_pos;
526 3 entry_pos = 1; /* reset the relative position */
527 3 index++; /* increase the index */
528 3
529 3 while (gl_buffer[11] == ATTR_LFN_ENTRY) /* LFN entry ? */
530 3 { /* then read all the LFN entry */
531 4 if (dir_is_root == TRUE)
532 4 { /* root dir is linear -> Hard_read_byte() */
533 5 for (i = 0; i < DIR_SIZE; i++)
534 5 gl_buffer[i] = Hard_read_byte();
535 5 }
536 4 else
537 4 { /* subdir can be fragmented -> dgetc() */
538 5 for (i = 0; i < DIR_SIZE; i++)
539 5 gl_buffer[i] = fat_dgetc();
540 5 }
541 4
542 4 counter_entry++; /* increase the # entry */
543 4 entry_pos++; /* increase the relative position */
544 4 /* for the next file */
545 4 }
546 3
547 3 /* filter on the file type */
548 3 fat_cache.current.attributes = gl_buffer[11];
549 3 ext[0] = gl_buffer[8];
550 3 ext[1] = gl_buffer[9];
C51 COMPILER V7.50 FAT 09/20/2005 21:47:47 PAGE 10
551 3 ext[2] = gl_buffer[10];
552 3 if ((fat_check_ext() & id) == FILE_XXX)
553 3 { /* Don't valid the entry */
554 4 index--;
555 4 entry_pos += entry_pos_saved;
556 4 }
557 3 }
558 2 else /* Not an existing file */
559 2 entry_pos++;
560 2
561 2 fat_dir_list_last = index; /* update last file index */
562 2 /* For sub-directory, there is no logical limit for the number of entries */
563 2 /* In order to detect the last file, we check gl_buffer[0] */
564 2 /* We can put in the chain directory MAX_DIRECTORY_FILE selected file */
565 2 if (gl_buffer[0] == FILE_NOT_EXIST)
566 2 index = MAX_DIRECTORY_FILE;
567 2 /* Overflow of entry_pos */
568 2 if (entry_pos > MAX_DIRECTORY_GAP_FILE)
569 2 index = MAX_DIRECTORY_FILE;
570 2 /* For Root directory, the maximum entries is 512! */
571 2 if ((dir_is_root == TRUE) && (counter_entry == MAX_DIRECTORY_FILE))
572 2 index = MAX_DIRECTORY_FILE;
573 2 if (dir_is_root == FALSE)
574 2 {
575 3 /* check if we are at the end of the directory */
576 3 if ((((Byte*)&fat_dclust_byte_count)[1] == 0x00) &&
577 3 ((((Byte*)&fat_dclust_byte_count)[0] & fat_cluster_mask) == 0x00) &&
578 3 (fat_last_dclust_index == fat_dchain_index))
579 3 index = MAX_DIRECTORY_FILE;
580 3 }
581 2 }
582 1 while (index < MAX_DIRECTORY_FILE);
583 1
584 1 fat_dir_current_sect = fat_dir_start_sect;
585 1 Hard_read_close();
586 1 }
587
588
589 /*F**************************************************************************
590 * NAME: fat_get_root_directory
591 *----------------------------------------------------------------------------
592 * PARAMS:
593 * id: file extension to select
594 *
595 * return:
596 * - OK: file available
597 * - KO: no requested file found
598 * - KO: low_level memory error
599 *----------------------------------------------------------------------------
600 * PURPOSE:
601 * Select first available file/dir in root diretory
602 *----------------------------------------------------------------------------
603 * EXAMPLE:
604 *----------------------------------------------------------------------------
605 * NOTE:
606 * Fill all the cache information for the first time
607 *----------------------------------------------------------------------------
608 * REQUIREMENTS:
609 *****************************************************************************/
610 bit fat_get_root_directory (Byte id)
611 {
612 1 /* select first root dir entry */
C51 COMPILER V7.50 FAT 09/20/2005 21:47:47 PAGE 11
613 1 fat_dir_current_sect = fat_ptr_rdir;
614 1 fat_dclust_byte_count = 0;
615 1 dir_is_root = TRUE;
616 1
617 1 fat_get_dir_file_list(id); /* create list of entries */
618 1 if (fat_dir_list_last == 0)
619 1 return KO; /* no requested (id) entry */
620 1
621 1 fat_dir_list_index = 0; /* point on first root entry */
622 1
623 1 /* extract info from table */
624 1 if (fat_dseek(fat_dir_entry_list[0] * DIR_SIZE) == OK)
625 1 {
626 2 fat_get_dir_entry(&fat_cache.current); /* update current file info */
627 2 /* parent dir is also root */
628 2 fat_cache.parent.start_cluster = 0;
629 2 fat_cache.parent.attributes = ATTR_ROOT_DIR; /* mark as root dir */
630 2 return OK;
631 2 }
632 1 else
633 1 return KO; /* low level error */
634 1 }
635
636
637 /*F**************************************************************************
638 * NAME: fat_goto_next
639 *----------------------------------------------------------------------------
640 * PARAMS:
641 *
642 * return:
643 * - OK: next file available
644 * - KO: last file reached
645 * - KO: low_level memory error
646 *----------------------------------------------------------------------------
647 * PURPOSE:
648 * Fetch the next dir/file info in cache
649 *----------------------------------------------------------------------------
650 * EXAMPLE:
651 *----------------------------------------------------------------------------
652 * NOTE:
653 *----------------------------------------------------------------------------
654 * REQUIREMENTS:
655 *****************************************************************************/
656 bit fat_goto_next (void)
657 {
658 1 if (fat_dir_list_index < (fat_dir_list_last - 1))
659 1 {
660 2 fat_dir_list_index++;
661 2
662 2 if (fat_dseek((Int16)(fat_dir_entry_list[fat_dir_list_index] * DIR_SIZE)) == OK)
663 2 {
664 3 fat_get_dir_entry(&fat_cache.current);/* update current file info */
665 3 return OK;
666 3 }
667 2 else
668 2 return KO; /* low level error */
669 2 }
670 1 else
671 1 return KO; /* already on last file */
672 1 }
673
674
C51 COMPILER V7.50 FAT 09/20/2005 21:47:47 PAGE 12
675 /*F**************************************************************************
676 * NAME: fat_goto_prev
677 *----------------------------------------------------------------------------
678 * PARAMS:
679 *
680 * return:
681 * - OK: previous file available
682 * - KO: first file reached
683 * - KO: low_level memory error
684 *----------------------------------------------------------------------------
685 * PURPOSE:
686 * Fetch the previous directory info in cache
687 *----------------------------------------------------------------------------
688 * EXAMPLE:
689 *----------------------------------------------------------------------------
690 * NOTE:
691 *----------------------------------------------------------------------------
692 * REQUIREMENTS:
693 *****************************************************************************/
694 bit fat_goto_prev (void)
695 {
696 1 Byte min;
697 1
698 1 if (dir_is_root)
699 1 min = 0;
700 1 else
701 1 min = 2;
702 1
703 1 if (fat_dir_list_index != min) /* first file of the directory? */
704 1 {
705 2 if (fat_dseek((Int16)(fat_dir_entry_list[fat_dir_list_index] * (-DIR_SIZE))) == OK)
706 2 { /* go to previous file */
707 3 fat_dir_list_index--;
708 3 fat_get_dir_entry(&fat_cache.current);/* update current file info */
709 3 return OK;
710 3 }
711 2 else
712 2 return KO; /* low level error */
713 2 }
714 1 else
715 1 return KO; /* already on first file */
716 1 }
717
718 /*F**************************************************************************
719 * NAME: fat_seek_last
720 *----------------------------------------------------------------------------
721 * PARAMS:
722 *
723 * return:
724 * OK: last file available
725 * KO: low level error
726 *----------------------------------------------------------------------------
727 * PURPOSE:
728 * Fetch the last directory info in cache
729 *----------------------------------------------------------------------------
730 * EXAMPLE:
731 *----------------------------------------------------------------------------
732 * NOTE:
733 *----------------------------------------------------------------------------
734 * REQUIREMENTS:
735 *****************************************************************************/
736 bit fat_seek_last (void)
C51 COMPILER V7.50 FAT 09/20/2005 21:47:47 PAGE 13
737 {
738 1 Uint16 gl_offset;
739 1 Uint16 i;
740 1
741 1 for (i = fat_dir_list_index + 1, gl_offset = 0; i < fat_dir_list_last; fat_dir_list_index++, i++)
742 1 gl_offset += fat_dir_entry_list[i];
743 1
744 1 if (fat_dseek(gl_offset * DIR_SIZE) == OK)
745 1 {
746 2 fat_get_dir_entry(&fat_cache.current);
747 2 return OK;
748 2 }
749 1 else
750 1 return KO; /* low level error */
751 1 }
752
753 /*F**************************************************************************
754 * NAME: fat_seek_entry_record
755 *----------------------------------------------------------------------------
756 * PARAMS:
757 * fat_dir_list_index : # of the fetched entry
758 *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -