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