FAT32code.zip

  • pao001
    了解作者
  • Borland C++
    开发工具
  • 17KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2018-05-04 12:57
    上传日期
fat32 program source code
FAT32code.zip
  • fat32.h
    8.6KB
  • fat32.c
    105KB
内容介绍
/*C************************************************************************** * NAME: fat32.c *---------------------------------------------------------------------------- * Copyright (c) 2003 Atmel. *---------------------------------------------------------------------------- * RELEASE: snd1c-refd-nf-4_0_3 * REVISION: 1.4 *---------------------------------------------------------------------------- * PURPOSE: * FAT32 file-system basics functions * * NOTES: * Supports only the first partition * Supports only 512 bytes sector size * Supports only file fragmentation < MAX_FILE_FRAGMENT_NUMBER * Supports only one file openned at a time * * Global Variables: * - gl_buffer: array of bytes in pdata space *****************************************************************************/ /*_____ I N C L U D E S ____________________________________________________*/ #include "config.h" /* system configuration */ #include "..\mem\hard.h" /* low level function definition */ #include "file.h" /* file function definition */ #include "fat32.h" /* fat32 file-system definition */ /*_____ M A C R O S ________________________________________________________*/ /*_____ D E F I N I T I O N ________________________________________________*/ extern pdata Byte gl_buffer[]; extern char pdata *lfn_name; /* long filename limited to MAX_FILENAME_LEN chars */ extern xdata Byte fat_buf_sector[]; /* 512 bytes buffer */ /* disk management */ extern data Uint32 fat_ptr_fats; /* address of the first byte of FAT */ extern data Uint32 fat_ptr_data; /* address of the first byte of data */ extern data Byte fat_cluster_size; /* cluster size (sector count) */ extern idata Byte fat_cluster_mask; /* mask for end of cluster test */ extern bdata bit dir_is_root; /* TRUE: point the root directory */ extern bdata bit fat_is_fat16; /* TRUE: FAT16 - FALSE: FAT12 */ extern bdata bit fat_is_fat32; /* TRUE: FAT32 - FALSE: FAT12/FAT16 */ extern bdata bit fat_open_mode; /* READ or WRITE */ extern bdata bit fat_2_is_present; /* TRUE: 2 FATs - FALSE: 1 FAT */ extern bdata bit flag_end_disk_file; extern xdata Uint32 fat_count_of_clusters;/* number of cluster - 2 */ extern xdata Union32 fat_file_size; extern xdata Uint32 fat_fat_size; /* FAT size in sector count */ /* directory management */ extern xdata fat_st_clust_chain dclusters[MAX_DIR_FRAGMENT_NUMBER]; /* cluster chain for the current directory */ extern idata Uint16 fat_dclust_byte_count;/* byte counter in directory sector */ extern idata Uint16 fat_dchain_index; /* the number of the fragment of the dir, in fact the index of the table in the cluster chain */ extern idata Byte fat_dchain_nb_clust; /* the offset of the cluster from the first cluster of the dir fragment */ extern xdata Byte fat_last_dclust_index;/* index of the last cluster in directory chain */ extern xdata Uint16 fat_dir_list_index; /* index of current entry in dir list */ extern xdata Uint16 fat_dir_list_last; /* index of last entry in dir list */ extern xdata Uint32 fat_dir_start_sect; /* start sector of dir list */ extern idata Uint32 fat_dir_current_sect; /* sector of selected entry in dir list */ extern xdata Uint32 fat_dir_current_offs; /* entry offset from fat_dir_current_sect */ extern xdata fat_st_cache fat_cache; /* The cache structure, see the .h for more info */ extern xdata char ext[3]; /* file extension (limited to 3 characters) */ /* file management */ extern xdata fat_st_clust_chain fclusters[MAX_FILE_FRAGMENT_NUMBER]; /* cluster chain for the current file */ extern idata Byte fat_last_clust_index; /* index of the last cluster in file chain */ extern data Uint16 fat_fclust_byte_count;/* byte counter in file cluster */ extern idata Byte fat_fchain_index; /* the number of the fragment of the file, in fact the index of the table in the cluster chain */ extern idata Uint16 fat_fchain_nb_clust; /* the offset of the cluster from the first cluster of the file fragment */ extern xdata Uint32 fat_current_file_size; extern xdata Uint32 fat_rootclus_fat32; /* root cluster address */ extern bdata bit fat_last_dir_cluster_full; extern bdata bit fat_no_entries_free; extern xdata Uint16 fat_total_clusters; extern xdata Uint32 last_free_cluster; /* Mode repeat A/B variables */ extern xdata Byte fat_fchain_index_save; extern xdata Byte fat_fchain_nb_clust_save; extern xdata Uint16 fat_fclust_byte_count_save; extern xdata Byte current_ext; extern idata Uint16 fat_current_end_entry_position; extern idata Uint16 fat_current_start_entry_position; extern xdata Uint16 fat_nb_deleted_entries; extern xdata Uint16 fat_nb_total_entries; /*_____ D E C L A R A T I O N ______________________________________________*/ static void fat_get_dir_entry (fat_st_dir_entry xdata *); static void fat_get_dir_file_list (Byte); static bit fat_get_clusters (fat_st_clust_chain xdata *, Byte); static bit fat_get_free_clusters (bit); static bit fat_dseek (Int16); static Byte fat_dgetc (void); /*F************************************************************************** * NAME: fat_install *---------------------------------------------------------------------------- * PARAMS: * * return: * - OK: intallation succeeded * - KO: - partition 1 not active * - FAT type is not FAT16 * - sector size is not 512 bytes * - MBR or PBR signatures are not correct * - low level read open failure *---------------------------------------------------------------------------- * PURPOSE: * Install the fat system, read mbr, bootrecords... *---------------------------------------------------------------------------- * EXAMPLE: *---------------------------------------------------------------------------- * NOTE: * if MBR not found, try to mount unpartitionned FAT * sector size is fixed to 512 bytes to simplify low level drivers * fat_ptr_fats = partition offset + nb_reserved_sector *---------------------------------------------------------------------------- * REQUIREMENTS: *****************************************************************************/ bit fat_install (void) { Byte i; Uint32 tot_sect; Uint32 fat_nb_sector; Uint16 bpb_rsvd_sec_cnt; Byte bpb_num_fat; Uint16 bpb_root_ent_count; /* read and check usefull MBR info */ /* go to the first partition field */ Hard_read_open(MBR_ADDRESS); Hard_load_sector(); Hard_read_close(); fat_ptr_fats = 0x01; if ((fat_buf_sector[0] == 0xEB) && (fat_buf_sector[2] == 0x90)) /* Jump instruction to boot code */ { if ((fat_buf_sector[21] & 0xF0) == 0xF0) /* Media byte */ { if ((fat_buf_sector[510] == 0x55) && (fat_buf_sector[511] == 0xAA)) /* signature */ { fat_ptr_fats = 0x00000000; /* disk may not be partitionned : first sector */ } /* is PBR */ else { return KO; /* no signature -> low level error */ } } } if (fat_ptr_fats) /* if first sector is not a PBR */ { if (Hard_read_open(MBR_ADDRESS) == OK) { for (i = 446/2; i != 0; i--) { Hard_read_byte();
评论
    相关推荐
    • FAT32SD.zip
      读写FAT32文件系统的SD卡实验源代码,直接可以使用
    • fat32.zip
      FAT32 文件系统详解 主要是MBR DBR
    • FAT32.zip
      是网上找到的一份关于FAT32文件系统介绍的详细资料,对研究FAT32格式和进行嵌入式开发的人员特别有用。
    • FAT.zip
      基于MSP430F149 FAT的源码,用于SD卡的开发
    • FAT32文件系统详解.zip
      存储设备都离不开与文件系统打交道,常用不超过32G存储设备都采用FAT32文件系统,资料中是对FAT32文件系统(计算根目录起始位置、文件起始位置、文件存储、删除)较为详细的说明,自己根据文档也做了简单的思维图
    • fat32_recovery.zip
      纯正linux取证源代码,主要是分析linux环境下fat32硬盘分区,使用python语言实现,需加载类库
    • FAT32 specification.zip
      fat32 file system description
    • fat32.zip
      2. Add dynamical sorting feature for Folder as Workspace. 3. Make MRU tab activate instead of rightmost tab while tab closure (if MRU enabled). 4. Fix folding state lost on the next startup issue. ...
    • m32 fat.zip
      BASCOM FAT DOS FOR ATMEGA32
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等