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