📄 fat16int.h
字号:
#ifndef __FAT16INT_H__#define __FAT16INT_H__#define FAT16_CLUSTER_FREE 0x0000#define FAT16_CLUSTER_RESERVED_MIN 0xfff0#define FAT16_CLUSTER_RESERVED_MAX 0xfff6#define FAT16_CLUSTER_BAD 0xfff7#define FAT16_CLUSTER_LAST_MIN 0xfff8#define FAT16_CLUSTER_LAST_MAX 0xffff#define FAT16_DIRENTRY_DELETED 0xe5#define FAT16_DIRENTRY_LFNLAST (1 << 6)#define FAT16_DIRENTRY_LFNSEQMASK ((1 << 6) - 1)/* Each entry within the directory table has a size of 32 bytes* and either contains a 8.3 DOS-style file name or a part of a* long file name, which may consist of several directory table* entries at once.** multi-byte integer values are stored little-endian!** 8.3 file name entry:* ====================* offset length description* 0 8 name (space padded)* 8 3 extension (space padded)* 11 1 attributes (FAT16_ATTRIB_*)** long file name (lfn) entry ordering for a single file name:* ===========================================================* LFN entry n* ...* LFN entry 2* LFN entry 1* 8.3 entry (see above)* * lfn entry:* ==========* offset length description* 0 1 ordinal field* 1 2 unicode character 1* 3 3 unicode character 2* 5 3 unicode character 3* 7 3 unicode character 4* 9 3 unicode character 5* 11 1 attribute (always 0x0f)* 12 1 type (reserved, always 0)* 13 1 checksum* 14 2 unicode character 6* 16 2 unicode character 7* 18 2 unicode character 8* 20 2 unicode character 9* 22 2 unicode character 10* 24 2 unicode character 11* 26 2 cluster (unused, always 0)* 28 2 unicode character 12* 30 2 unicode character 13* * The ordinal field contains a descending number, from n to 1.* For the n'th lfn entry the ordinal field is or'ed with 0x40.* For deleted lfn entries, the ordinal field is set to 0xe5.*/struct fat16_header_struct{ uint32_t size; uint32_t fat_offset; uint32_t fat_size; uint16_t sector_size; uint16_t cluster_size; uint32_t root_dir_offset; uint32_t cluster_zero_offset;};struct fat16_fs_struct{ struct partition_struct* partition; struct fat16_header_struct header;};struct fat16_file_struct{ struct fat16_fs_struct* fs; struct fat16_dir_entry_struct dir_entry; uint32_t pos; uint16_t pos_cluster;};struct fat16_dir_struct{ struct fat16_fs_struct* fs; struct fat16_dir_entry_struct dir_entry; uint16_t entry_next;};struct fat16_read_callback_arg{ uint16_t entry_cur; uint16_t entry_num; uint32_t entry_offset; uint8_t byte_count;};struct fat16_usage_count_callback_arg{ uint16_t cluster_count; uint8_t buffer_size;};#if !USE_DYNAMIC_MEMORYstatic struct fat16_fs_struct fat16_fs_handlers[FAT16_FS_COUNT];static struct fat16_file_struct fat16_file_handlers[FAT16_FILE_COUNT];static struct fat16_dir_struct fat16_dir_handlers[FAT16_DIR_COUNT];#endifstatic uint8_t fat16_read_header(struct fat16_fs_struct* fs);static uint8_t fat16_read_root_dir_entry(const struct fat16_fs_struct* fs, uint16_t entry_num, struct fat16_dir_entry_struct* dir_entry);static uint8_t fat16_read_sub_dir_entry(const struct fat16_fs_struct* fs, uint16_t entry_num, const struct fat16_dir_entry_struct* parent, struct fat16_dir_entry_struct* dir_entry);static uint8_t fat16_dir_entry_seek_callback(uint8_t* buffer, uint32_t offset, void* p);static uint8_t fat16_dir_entry_read_callback(uint8_t* buffer, uint32_t offset, void* p);static uint8_t fat16_interpret_dir_entry(struct fat16_dir_entry_struct* dir_entry, const uint8_t* raw_entry);static uint16_t fat16_get_next_cluster(const struct fat16_fs_struct* fs, uint16_t cluster_num);static uint16_t fat16_append_clusters(const struct fat16_fs_struct* fs, uint16_t cluster_num, uint16_t count);static uint8_t fat16_free_clusters(const struct fat16_fs_struct* fs, uint16_t cluster_num);static uint8_t fat16_terminate_clusters(const struct fat16_fs_struct* fs, uint16_t cluster_num);static uint8_t fat16_clear_cluster(const struct fat16_fs_struct* fs, uint16_t cluster_num);static uint16_t fat16_clear_cluster_callback(uint8_t* buffer, uint32_t offset, void* p);static uint32_t fat16_find_offset_for_dir_entry(const struct fat16_fs_struct* fs, const struct fat16_dir_struct* parent, const struct fat16_dir_entry_struct* dir_entry);static uint8_t fat16_write_dir_entry(const struct fat16_fs_struct* fs, struct fat16_dir_entry_struct* dir_entry);static uint8_t fat16_get_fs_free_callback(uint8_t* buffer, uint32_t offset, void* p);static void fat16_set_file_modification_date(struct fat16_dir_entry_struct* dir_entry, uint16_t year, uint8_t month, uint8_t day);static void fat16_set_file_modification_time(struct fat16_dir_entry_struct* dir_entry, uint8_t hour, uint8_t min, uint8_t sec);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -