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