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

📄 fat32.lst

📁 fat32文件C语言的实现13
💻 LST
📖 第 1 页 / 共 5 页
字号:
 241   2          ((Byte*)&bpb_rsvd_sec_cnt)[0] = Hard_read_byte();
 242   2          /* number of FATs */
 243   2          bpb_num_fat = Hard_read_byte();
 244   2          if (bpb_num_fat == 2)
 245   2            fat_2_is_present = TRUE;
 246   2          else
 247   2            fat_2_is_present = FALSE;    
 248   2          
 249   2          /* read number of dir entries*/
 250   2          ((Byte*)&bpb_root_ent_count)[3] = Hard_read_byte();
 251   2          ((Byte*)&bpb_root_ent_count)[2] = Hard_read_byte();
 252   2      
 253   2          /* read number of sector in partition (<32Mb) */
 254   2          ((Byte*)&fat_nb_sector)[3] = Hard_read_byte();
 255   2          ((Byte*)&fat_nb_sector)[2] = Hard_read_byte();
 256   2          ((Byte*)&fat_nb_sector)[1] = 0x00;
 257   2          ((Byte*)&fat_nb_sector)[0] = 0x00;
 258   2          Hard_read_byte();
 259   2          Hard_read_byte();                               /* FAT size for FAT12/16 */
 260   2          Hard_read_byte();
 261   2          
 262   2          Hard_read_byte();
 263   2          Hard_read_byte();
 264   2          Hard_read_byte();
 265   2          Hard_read_byte();
 266   2          Hard_read_byte();
 267   2          Hard_read_byte();
 268   2          Hard_read_byte();
 269   2          Hard_read_byte();
 270   2      
 271   2          /* read number of sector in partition (>32Mb) */
 272   2          ((Byte*)&fat_nb_sector)[3] += Hard_read_byte();
 273   2          ((Byte*)&fat_nb_sector)[2] += Hard_read_byte();
 274   2          ((Byte*)&fat_nb_sector)[1] += Hard_read_byte();
 275   2          ((Byte*)&fat_nb_sector)[0] += Hard_read_byte();
 276   2      
 277   2          fat_is_fat16 = FALSE;
 278   2          fat_is_fat32 = FALSE;
 279   2      
 280   2          fat_ptr_data = (bpb_root_ent_count * DIR_SIZE) / SECTOR_SIZE;
 281   2      
 282   2          /* Here start the structure for FAT32 */
 283   2          /* Offset 36 : 32 bits size of fat */
 284   2          ((Byte*)&fat_fat_size)[3] = Hard_read_byte();
 285   2          ((Byte*)&fat_fat_size)[2] = Hard_read_byte();
 286   2          ((Byte*)&fat_fat_size)[1] = Hard_read_byte();
 287   2          ((Byte*)&fat_fat_size)[0] = Hard_read_byte();
 288   2      
 289   2          tot_sect = fat_nb_sector - (Uint32)(((Uint32)(bpb_rsvd_sec_cnt) + (Uint32)((bpb_num_fat * (Uint32)(fat
             -_fat_size))) + fat_ptr_data));
 290   2          fat_count_of_clusters = tot_sect / fat_cluster_size;
 291   2             
 292   2          /* Offset 40 : ExtFlags */
 293   2          Hard_read_byte();
 294   2          Hard_read_byte();
 295   2          /* Offset 42 : FS Version */
 296   2          Hard_read_byte();
 297   2          Hard_read_byte();
 298   2          /* Offset 44 : Root Cluster */
 299   2          ((Byte*)&fat_rootclus_fat32)[3] = Hard_read_byte();
 300   2          ((Byte*)&fat_rootclus_fat32)[2] = Hard_read_byte();
 301   2          ((Byte*)&fat_rootclus_fat32)[1] = Hard_read_byte();
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 6   

 302   2          ((Byte*)&fat_rootclus_fat32)[0] = Hard_read_byte();
 303   2      
 304   2          fat_ptr_fats += bpb_rsvd_sec_cnt;
 305   2          fat_ptr_data = fat_ptr_fats + (bpb_num_fat * fat_fat_size);
 306   2      
 307   2          /* Offset 48 : FS Info */
 308   2          /* Offset 50 : Backup Boot Sector */
 309   2          /* Offset 52 : Reserved */
 310   2          /* Offset 64 - 89 : Data */
 311   2          /* Offset 90 : 510 : Free */
 312   2          for (i = 231; i != 0; i--)
 313   2          {
 314   3            Hard_read_byte();
 315   3            Hard_read_byte();
 316   3          }
 317   2          /* check partition signature */
 318   2          if ((Hard_read_byte() != LOW(BR_SIGNATURE)) &&
 319   2              (Hard_read_byte() != HIGH(BR_SIGNATURE)))
 320   2          {
 321   3            Hard_read_close();                    /* close physical read */
 322   3            return KO;
 323   3          }
 324   2          Hard_read_close();                      /* close physical read */
 325   2          return OK;
 326   2        }
 327   1        else
 328   1        { /* low level error */
 329   2          return KO;
 330   2        }
 331   1      }
 332          
 333          #define UPLOAD      0
 334          #define DOWNLOAD    1
 335          #define FETCH_NEXT  0
 336          #define FETCH_PREV  1
 337          
 338          /*F**************************************************************************
 339          * NAME: fat_calc_cluster
 340          *----------------------------------------------------------------------------
 341          * PARAMS:
 342          *   
 343          *
 344          * return:
 345          *----------------------------------------------------------------------------
 346          * PURPOSE:
 347          *   Calculate fat_dir_current_sect and update directory variable from the
 348          *   value of fat_dir_current_offs.
 349          *----------------------------------------------------------------------------
 350          * EXAMPLE:
 351          *----------------------------------------------------------------------------
 352          * NOTE:
 353          *   
 354          *----------------------------------------------------------------------------
 355          * REQUIREMENTS:
 356          *   
 357          *****************************************************************************/
 358          void fat_calc_cluster(void)
 359          {
 360   1      Uint32   i;
 361   1        fat_dchain_index = 0;
 362   1        fat_dchain_nb_clust = 0;
 363   1        for (i = (fat_dir_current_offs / SECTOR_SIZE / fat_cluster_size) + 1; i != 0; i--)
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 7   

 364   1        {
 365   2          if (dclusters[fat_dchain_index].number == fat_dchain_nb_clust)
 366   2          { /* new fragment */
 367   3            fat_dchain_index++;
 368   3            fat_dchain_nb_clust = 1;
 369   3          }
 370   2          else
 371   2          { /* no new fragment */
 372   3            fat_dchain_nb_clust++;
 373   3          }
 374   2        }
 375   1        i = fat_dir_current_offs / SECTOR_SIZE;
 376   1        fat_dir_current_sect = (((Uint32)(dclusters[fat_dchain_index].cluster + fat_dchain_nb_clust - 1) * 
 377   1                                          fat_cluster_size)
 378   1                               + fat_ptr_data + (i % fat_cluster_size));
 379   1      
 380   1        if ((fat_dclust_byte_count == 0)/* && (fat_dchain_index == 0)*/)     /* If we are at the beginning of a 
             -directory */
 381   1          if (fat_dchain_nb_clust == 1)
 382   1            fat_dchain_nb_clust = 0;
 383   1      }
 384          
 385          
 386          /*F**************************************************************************
 387          * NAME: fat_clear_dir_info
 388          *----------------------------------------------------------------------------
 389          * PARAMS:
 390          *   
 391          *
 392          * return:
 393          *----------------------------------------------------------------------------
 394          * PURPOSE:
 395          *   Reset directory chain cluster value
 396          *----------------------------------------------------------------------------
 397          * EXAMPLE:
 398          *----------------------------------------------------------------------------
 399          * NOTE:
 400          *   
 401          *----------------------------------------------------------------------------
 402          * REQUIREMENTS:
 403          *   
 404          *****************************************************************************/
 405          void fat_clear_dir_info(void)
 406          {
 407   1        fat_dchain_nb_clust = 0;    /* position of a cluster for selected chain idx */
 408   1        fat_dchain_index = 0;       /* chain index position */  
 409   1        fat_dclust_byte_count = 0;  /* byte position inside a directory cluster */
 410   1        fat_dir_current_offs = 0;   /* general offset from the start of a directory */
 411   1      }
 412          
 413          /*F**************************************************************************
 414          * NAME: fat_up_down_load_sector
 415          *----------------------------------------------------------------------------
 416          * PARAMS:
 417          *   - sector address to load/download   
 418          *   - bit to indicate if it's a download or an upload
 419          *
 420          * return:
 421          *----------------------------------------------------------------------------
 422          * PURPOSE:
 423          *   Download or upload a sector of 512b
 424          *----------------------------------------------------------------------------
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 8   

 425          * EXAMPLE:
 426          *----------------------------------------------------------------------------
 427          * NOTE:
 428          *   
 429          *----------------------------------------------------------------------------
 430          * REQUIREMENTS:
 431          *   
 432          *****************************************************************************/
 433          void fat_up_down_load_sector(Uint32 sector, bit up_down)
 434          {
 435   1        if (up_down == UPLOAD)
 436   1        {
 437   2          Hard_read_open(sector);     
 438   2          Hard_load_sector();
 439   2          Hard_read_close();
 440   2        }
 441   1        else
 442   1        {
 443   2          Hard_write_open(sector);
 444   2          Hard_download_sector();
 445   2          Hard_write_close();
 446   2        }
 447   1      }
 448          
 449          /*F**************************************************************************
 450          * NAME: fat_get_dir_file_list
 451          *----------------------------------------------------------------------------
 452          * PARAMS:
 453          *   id: file extension to select
 454          *
 455          * return:
 456          *----------------------------------------------------------------------------
 457          * PURPOSE:
 458          *   Give information about the directory :
 459          *     - total number of entries
 460          *     - number of deleted entries
 461          *     - number of filtered entries (filter is done by checking id value)
 462          *     - total number of clusters used by the directory
 463          *----------------------------------------------------------------------------
 464          * EXAMPLE:
 465          *
 466          *----------------------------------------------------------------------------
 467          * NOTE:
 468          *   
 469          *----------------------------------------------------------------------------
 470          * REQUIREMENTS:
 471          *   
 472          *****************************************************************************/
 473          void fat_get_dir_file_list (Byte id)
 474          {
 475   1      Byte   i;
 476   1      bit   exit = FALSE;
 477   1      
 478   1        current_ext = id;                         /* save current extension */
 479   1        fat_last_dir_cluster_full = FALSE;        /* reset flag for full cluster */
 480   1        fat_no_entries_free = FALSE;              /* reset flag for presence of free entries inside a directory 
             -cluster */
 481   1        fat_dir_list_last = 0;                    /* last filtered directory entry */
 482   1        fat_dir_start_sect = fat_dir_current_sect;/* set fat_dir_start_sect (use by fat_dseek()) */
 483   1        fat_nb_deleted_entries = 0;               /* reset the number of entries that is marker as deleted */
 484   1        fat_nb_total_entries = 0;                 /* reset the number of total entries in the directory */
 485   1        fat_total_clusters = 0;                   /* reset the total number of clusters for a directory */
C51 COMPILER V6.20c  FAT32                                                                 10/19/2004 12:22:16 PAGE 9   

 486   1      
 487   1        for (i = 0; i <= fat_last_dclust_index; i++)

⌨️ 快捷键说明

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