⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat32.lst

📁 fat32文件C语言的实现13
💻 LST
📖 第 1 页 / 共 5 页
字号:
 735   4              lfn_name[i++] = lfn_name[9];
 736   4              lfn_name[i++] = lfn_name[10];
 737   4              lfn_name[i++] = lfn_name[11];
 738   4              lfn_name[i++] = lfn_name[12];
 739   4            }
 740   3            lfn_name[i] = '\0';        /* end of name */      
 741   3          }
 742   2          else
 743   2          {
 744   3            /* true DOS 8.3 entry format */
 745   3            for (i = 0; i < 8; i++)
 746   3            {
 747   4              lfn_name[i] = gl_buffer[i];
 748   4              
 749   4              if (lfn_name[i] == ' ')
 750   4              { /* space is end of name */
 751   5                break;
 752   5              }
 753   4            }
 754   3            if ((gl_buffer[8] == ' ') &&
 755   3                (gl_buffer[9] == ' ') &&
 756   3                (gl_buffer[10] == ' '))
 757   3              lfn_name[i++] = ' ';
 758   3            else
 759   3              lfn_name[i++] = '.';                                  /* append extension */
 760   3            lfn_name[i++] = gl_buffer[8];
 761   3            lfn_name[i++] = gl_buffer[9];
 762   3            lfn_name[i++] = gl_buffer[10];
 763   3        
 764   3            for (; i != 14; i++)
 765   3            {
 766   4              lfn_name[i] = ' ';                                  /* append spaces for display reason */
 767   4            }
 768   3            lfn_name[i] = '\0';                                   /* end of string */
 769   3          } 
 770   2          fat_cache.current.attributes = gl_buffer[11];       /* filter on the file type */
 771   2          
 772   2          ext[0]= gl_buffer[8];                                   /* store extension */
 773   2          ext[1]= gl_buffer[9];
 774   2          ext[2]= gl_buffer[10];
 775   2      
 776   2          fat_current_end_entry_position++;
 777   2          if ((fat_check_ext() & current_ext) == FILE_XXX)
 778   2          {
 779   3            fat_dir_current_offs += ((fat_current_end_entry_position - fat_current_start_entry_position) << 5); 
             - 
 780   3          }
 781   2        }
 782   1        while ((fat_check_ext() & current_ext) == FILE_XXX);
 783   1      
 784   1      
 785   1        entry->start_cluster  = gl_buffer[26];                    /* starting cluster value */
 786   1        entry->start_cluster += ((Uint32) gl_buffer[27]) << 8;
 787   1        entry->start_cluster += ((Uint32) gl_buffer[20]) << 16;
 788   1        entry->start_cluster += ((Uint32) gl_buffer[21]) << 24;
 789   1        entry->size.b[3]      = gl_buffer[28];                    /* file size value        */
 790   1        entry->size.b[2]      = gl_buffer[29];
 791   1        entry->size.b[1]      = gl_buffer[30];
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 14  

 792   1        entry->size.b[0]      = gl_buffer[31];
 793   1        Hard_read_close();                                        /* close physical read */
 794   1      
 795   1      }
 796          
 797          
 798          /*F**************************************************************************
 799          * NAME: fat_get_root_directory
 800          *----------------------------------------------------------------------------
 801          * PARAMS:
 802          *   id: file extension to select
 803          *
 804          * return:
 805          *   - OK: file available
 806          *   - KO: no requested file found
 807          *   - KO: low_level memory error
 808          *----------------------------------------------------------------------------
 809          * PURPOSE:
 810          *   Select first available file/dir in root diretory
 811          *----------------------------------------------------------------------------
 812          * EXAMPLE:
 813          *----------------------------------------------------------------------------
 814          * NOTE:
 815          *   Fill all the cache information for the first time
 816          *----------------------------------------------------------------------------
 817          * REQUIREMENTS:
 818          *****************************************************************************/
 819          bit fat_get_root_directory (Byte id)
 820          {
 821   1        dir_is_root = TRUE;                                       /* set directory root flag */
 822   1        fat_cache.current.start_cluster = fat_rootclus_fat32 ;    /* #cluster root directory */
 823   1        fat_get_clusters(&dclusters, MAX_DIR_FRAGMENT_NUMBER);    /* Construct root directory cluster chain */
 824   1        fat_last_dclust_index = fat_last_clust_index;             /* save last index position for chain cluster 
             -*/
 825   1      
 826   1                            
 827   1        /* computes sector address from allocation table */
 828   1        fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size)
 829   1                             + fat_ptr_data;
 830   1      
 831   1        fat_get_dir_file_list(id);                                /* create list of entries */
 832   1        if (fat_dir_list_last == 0)
 833   1          return KO;                                              /* no requested (id) entry */
 834   1      
 835   1        fat_dir_list_index = 1;                                   /* point on first root entry */
 836   1        fat_current_start_entry_position = 0;
 837   1        fat_current_end_entry_position = 0;
 838   1        fat_fetch_file_info(&fat_cache.current, FETCH_NEXT);
 839   1        fat_cache.parent.start_cluster = fat_rootclus_fat32;    /* parent dir is also root */   
 840   1        fat_cache.parent.attributes = ATTR_DIRECTORY;           /* mark as directory */
 841   1        return OK;
 842   1      }
 843          
 844          
 845          /*F**************************************************************************
 846          * NAME: fat_goto_next
 847          *----------------------------------------------------------------------------
 848          * PARAMS:
 849          *
 850          * return:
 851          *   - OK: next file available
 852          *   - KO: last file reached
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 15  

 853          *   - KO: low_level memory error
 854          *----------------------------------------------------------------------------
 855          * PURPOSE:
 856          *   Fetch the next dir/file info in cache
 857          *----------------------------------------------------------------------------
 858          * EXAMPLE:
 859          *----------------------------------------------------------------------------
 860          * NOTE:
 861          *----------------------------------------------------------------------------
 862          * REQUIREMENTS:
 863          *****************************************************************************/ 
 864          bit fat_goto_next (void)
 865          {
 866   1        if (fat_dir_list_index < fat_dir_list_last)
 867   1        {
 868   2          fat_dir_list_index++;
 869   2          fat_fetch_file_info(&fat_cache.current, FETCH_NEXT);
 870   2          return OK;
 871   2        }
 872   1        else
 873   1          return KO;                              /* already on last file */
 874   1      }
 875          
 876          
 877          /*F**************************************************************************
 878          * NAME: fat_goto_prev
 879          *----------------------------------------------------------------------------
 880          * PARAMS:
 881          *
 882          * return:
 883          *   - OK: previous file available
 884          *   - KO: first file reached
 885          *   - KO: low_level memory error
 886          *----------------------------------------------------------------------------
 887          * PURPOSE:
 888          *   Fetch the previous directory info in cache
 889          *----------------------------------------------------------------------------
 890          * EXAMPLE:
 891          *----------------------------------------------------------------------------
 892          * NOTE:
 893          *----------------------------------------------------------------------------
 894          * REQUIREMENTS:
 895          *****************************************************************************/ 
 896          bit fat_goto_prev (void)
 897          {
 898   1      Byte min;
 899   1        
 900   1        if (dir_is_root)
 901   1          min = 1;
 902   1        else
 903   1          min = 3;
 904   1      
 905   1        if (fat_dir_list_index != min)            /* first file of the directory? */
 906   1        {
 907   2          fat_dir_list_index--;
 908   2          fat_fetch_file_info(&fat_cache.current, FETCH_PREV);
 909   2          return OK;
 910   2        }
 911   1        else
 912   1          return KO;                              /* already on first file */
 913   1      }
 914          
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 16  

 915          /*F**************************************************************************
 916          * NAME: fat_seek_last
 917          *----------------------------------------------------------------------------
 918          * PARAMS:
 919          *
 920          * return:
 921          *   OK: last file available
 922          *   KO: low level error
 923          *----------------------------------------------------------------------------
 924          * PURPOSE:
 925          *   Fetch the last directory info in cache
 926          *----------------------------------------------------------------------------
 927          * EXAMPLE:
 928          *----------------------------------------------------------------------------
 929          * NOTE:
 930          *----------------------------------------------------------------------------
 931          * REQUIREMENTS:
 932          *****************************************************************************/ 
 933          bit fat_seek_last (void)
 934          {
 935   1      bit result;
 936   1        do
 937   1        {
 938   2          result = fat_goto_next();
 939   2        }
 940   1        while (result == OK);
 941   1        return result;
 942   1      }
 943          
 944          /*F**************************************************************************
 945          * NAME: fat_seek_entry_record
 946          *----------------------------------------------------------------------------
 947          * PARAMS:
 948          *   fat_dir_list_index : # of the fetched entry
 949          *   
 950          * return:
 951          *   OK: file available
 952          *   KO: low level error
 953          *----------------------------------------------------------------------------
 954          * PURPOSE:
 955          *   Fetch the selected entry
 956          *----------------------------------------------------------------------------
 957          * EXAMPLE:
 958          *----------------------------------------------------------------------------
 959          * NOTE:
 960          *----------------------------------------------------------------------------
 961          * REQUIREMENTS:
 962          *****************************************************************************/ 
 963          bit fat_seek_entry_record (void)
 964          {
 965   1      bit result;
 966   1      Uint16 temp;
 967   1      
 968   1        temp = fat_dir_list_index - 1;
 969   1        fat_seek_first();
 970   1        for (; temp != 0; temp--)
 971   1          result = fat_goto_next();
 972   1        return result;
 973   1      }
 974          
 975          /*F**************************************************************************
 976          * NAME: fat_seek_first
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 17  

 977          *----------------------------------------------------------------------------
 978          * PARAMS:
 979          *
 980          * return:
 981          *   - OK: first file found
 982          *   - KO: low level error

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -