📄 fat.lst
字号:
757 1
758 1 for (i = fat_dir_list_index + 1, gl_offset = 0; i < fat_dir_list_last; fat_dir_list_index++, i++)
759 1 gl_offset += fat_dir_entry_list[i];
760 1
761 1 if (fat_dseek(gl_offset * DIR_SIZE) == OK)
762 1 {
763 2 fat_get_dir_entry(&fat_cache.current);
764 2 return OK;
765 2 }
766 1 else
767 1 return KO; /* low level error */
768 1 }
769
770 /*F**************************************************************************
771 * NAME: fat_seek_entry_record
772 *----------------------------------------------------------------------------
773 * PARAMS:
774 * fat_dir_list_index : # of the fetched entry
775 *
776 * return:
777 * OK: file available
778 * KO: low level error
779 *----------------------------------------------------------------------------
780 * PURPOSE:
781 * Fetch the selected entry
782 *----------------------------------------------------------------------------
783 * EXAMPLE:
784 *----------------------------------------------------------------------------
785 * NOTE:
786 *----------------------------------------------------------------------------
787 * REQUIREMENTS:
788 *****************************************************************************/
789 bit fat_seek_entry_record (void)
790 {
791 1 Uint16 gl_offset = 0;
792 1 Uint16 i;
793 1 if (dir_is_root)
794 1 {
795 2 fat_dir_current_sect = fat_ptr_rdir;
796 2 }
C51 COMPILER V7.02a FAT 09/13/2007 11:53:07 PAGE 14
797 1 else
798 1 {
799 2 fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size)
800 2 + fat_ptr_data;
801 2 }
802 1 fat_dir_current_offs = 0; /* reset the global offset */
803 1
804 1 for (i = 0; i <= fat_dir_list_index; i++)
805 1 gl_offset += fat_dir_entry_list[i];
806 1
807 1 return fat_dseek(gl_offset * DIR_SIZE);
808 1 }
809
810 /*F**************************************************************************
811 * NAME: fat_seek_first
812 *----------------------------------------------------------------------------
813 * PARAMS:
814 *
815 * return:
816 * - OK: first file found
817 * - KO: low level error
818 *----------------------------------------------------------------------------
819 * PURPOSE:
820 * Fetch the first directory info in cache
821 *----------------------------------------------------------------------------
822 * EXAMPLE:
823 *----------------------------------------------------------------------------
824 * NOTE:
825 *----------------------------------------------------------------------------
826 * REQUIREMENTS:
827 *****************************************************************************/
828 bit fat_seek_first (void)
829 {
830 1 fat_dir_current_offs = 0; /* reset the global offset */
831 1
832 1 if (dir_is_root)
833 1 { /* root diretory */
834 2 fat_dir_list_index = 0; /* point first root entry */
835 2 if (fat_dseek((Int16)(fat_dir_entry_list[0] * DIR_SIZE)) == OK)
836 2 {
837 3 fat_get_dir_entry(&fat_cache.current);/* update first file info */
838 3 return OK;
839 3 }
840 2 else
841 2 {
842 3 return KO; /* low level error */
843 3 }
844 2 }
845 1 else
846 1 { /* not root dir */
847 2 fat_dir_list_index = 1; /* point ".." entry */
848 2 if (fat_dseek((Int16)(fat_dir_entry_list[1] * DIR_SIZE)) == OK)
849 2 {
850 3 fat_get_dir_entry(&fat_cache.parent); /* update parent dir info */
851 3 return fat_goto_next(); /* update first file info */
852 3 }
853 2 else
854 2 return KO; /* low level error */
855 2 }
856 1 }
857
858
C51 COMPILER V7.02a FAT 09/13/2007 11:53:07 PAGE 15
859 /*F**************************************************************************
860 * NAME: fat_goto_subdir
861 *----------------------------------------------------------------------------
862 * PARAMS:
863 * id: file extension to select
864 *
865 * return:
866 * - OK: subdir selected
867 * - KO: current entry not a directory
868 * - KO: no file in subdir
869 * - KO: low level error
870 *----------------------------------------------------------------------------
871 * PURPOSE:
872 * Go to the subdir if current is a directory
873 *----------------------------------------------------------------------------
874 * EXAMPLE:
875 *----------------------------------------------------------------------------
876 * NOTE:
877 * Also called by goto_parentdir() with current info from parent info
878 *----------------------------------------------------------------------------
879 * REQUIREMENTS:
880 *****************************************************************************/
881 bit fat_goto_subdir (Byte id)
882 {
883 1 /* check if current file is a directory */
884 1 if ((fat_cache.current.attributes & ATTR_DIRECTORY) == ATTR_DIRECTORY)
885 1 {
886 2 /* computes the sector address (RELATIVE) */
887 2 if (fat_cache.current.start_cluster != 0)
888 2 { /* go to not root dir */
889 3 dir_is_root = FALSE; /* not the root dir */
890 3 /* get directory allocation table */
891 3 fat_get_clusters(&dclusters, MAX_DIR_FRAGMENT_NUMBER);
892 3
893 3 /* Save last index position for chain cluster */
894 3 fat_last_dclust_index = fat_last_clust_index;
895 3 /* initialize fat pointers */
896 3 fat_dchain_nb_clust = 0;
897 3 fat_dchain_index = 0;
898 3 fat_dclust_byte_count = 0;
899 3
900 3 /* computes sector address from allocation table */
901 3 fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size)
902 3 + fat_ptr_data;
903 3 }
904 2 else
905 2 { /* go to root dir */
906 3 return fat_get_root_directory(id);
907 3 }
908 2
909 2 fat_get_dir_file_list(id); /* create list of entries */
910 2
911 2 fat_dir_list_index = 1; /* point ".." entry */
912 2 if (fat_dseek((Int16)(fat_dir_entry_list[1] * DIR_SIZE)) == OK)
913 2 {
914 3 fat_get_dir_entry(&fat_cache.parent); /* update parent dir info */
915 3 return fat_goto_next(); /* update first file info */
916 3 }
917 2 else
918 2 return KO; /* low level error */
919 2 }
920 1 else
C51 COMPILER V7.02a FAT 09/13/2007 11:53:07 PAGE 16
921 1 return KO; /* current entry is not a dir */
922 1 }
923
924
925 /*F**************************************************************************
926 * NAME: fat_goto_parentdir
927 *----------------------------------------------------------------------------
928 * PARAMS:
929 * id: file extension to select
930 *
931 * return:
932 * status: OK: parent_dir selected
933 * KO: no parent dir (root)
934 *----------------------------------------------------------------------------
935 * PURPOSE:
936 * Go to the parent directory
937 *----------------------------------------------------------------------------
938 * EXAMPLE:
939 *----------------------------------------------------------------------------
940 * NOTE:
941 * File pointed is sub-dir if parent dir is not root or first file if root
942 *----------------------------------------------------------------------------
943 * REQUIREMENTS:
944 *****************************************************************************/
945 bit fat_goto_parentdir (Byte id)
946 {
947 1 Uint16 temp_cluster;
948 1
949 1 if (dir_is_root)
950 1 { /* already in root dir */
951 2 fat_seek_first(); /* point on first file */
952 2 return KO;
953 2 }
954 1 else
955 1 { /* not in root dir */
956 2 temp_cluster = dclusters[0].cluster + 2;/* save cluster info */
957 2 fat_cache.current = fat_cache.parent; /* goto the parent directory */
958 2
959 2 /* issue the equivalent to a cd .. DOS command */
960 2 if (fat_goto_subdir(id))
961 2 { /* reselect the dir entry in list */
962 3 while (temp_cluster != fat_cache.current.start_cluster)
963 3 {
964 4 if (fat_goto_next() == KO)
965 4 break;
966 4 }
967 3 if (temp_cluster == fat_cache.current.start_cluster)
968 3 return OK;
969 3 else
970 3 return KO;
971 3 }
972 2 else
973 2 {
974 3 return KO;
975 3 }
976 2 }
977 1 }
978
979
980 /*F**************************************************************************
981 * NAME: fat_update_fat_sector
982 *----------------------------------------------------------------------------
C51 COMPILER V7.02a FAT 09/13/2007 11:53:07 PAGE 17
983 * PARAMS:
984 * sector_number : fat sector position
985 *
986 * return:
987 *----------------------------------------------------------------------------
988 * PURPOSE:
989 * update a sector of fat
990 *----------------------------------------------------------------------------
991 * EXAMPLE:
992 *----------------------------------------------------------------------------
993 * NOTE:
994 * This function check if there is 2 fats to be updated
995 *----------------------------------------------------------------------------
996 * REQUIREMENTS:
997 *****************************************************************************/
998 void fat_update_fat_sector (Uint16 sector_number)
999 {
1000 1 Uint16 i;
1001 1
1002 1 /* FAT 1 update */
1003 1 Hard_write_open(fat_ptr_fats + sector_number);
1004 1 for (i = 0; i < SECTOR_SIZE; i++)
1005 1 Hard_write_byte(fat_buf_sector[i]);
1006 1 Hard_write_close();
1007 1 if (fat_2_is_present == TRUE)
1008 1 {
1009 2 /* FAT 2 update */
1010 2 Hard_write_open(fat_ptr_fats + sector_number + fat_fat_size);
1011 2 for (i = 0; i < SECTOR_SIZE; i++)
1012 2 Hard_write_byte(fat_buf_sector[i]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -