00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef FAT_H
00012 #define FAT_H
00013
00014 #include <stdint.h>
00015 #include "fat_config.h"
00016
00017 #ifdef __cplusplus
00018 extern "C"
00019 {
00020 #endif
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define FAT_ATTRIB_READONLY (1 << 0)
00041
00042 #define FAT_ATTRIB_HIDDEN (1 << 1)
00043
00044 #define FAT_ATTRIB_SYSTEM (1 << 2)
00045
00046 #define FAT_ATTRIB_VOLUME (1 << 3)
00047
00048 #define FAT_ATTRIB_DIR (1 << 4)
00049
00050 #define FAT_ATTRIB_ARCHIVE (1 << 5)
00051
00052
00053 #define FAT_SEEK_SET 0
00054
00055 #define FAT_SEEK_CUR 1
00056
00057 #define FAT_SEEK_END 2
00058
00059
00060
00061
00062
00063 struct partition_struct;
00064 struct fat_fs_struct;
00065 struct fat_file_struct;
00066 struct fat_dir_struct;
00067
00068
00069
00070
00071
00072 struct fat_dir_entry_struct
00073 {
00074
00075 char long_name[32];
00076
00077 uint8_t attributes;
00078 #if FAT_DATETIME_SUPPORT
00079
00080 uint16_t modification_time;
00081
00082 uint16_t modification_date;
00083 #endif
00084
00085 cluster_t cluster;
00086
00087 uint32_t file_size;
00088
00089 offset_t entry_offset;
00090 };
00091
00092 struct fat_fs_struct* fat_open(struct partition_struct* partition);
00093 void fat_close(struct fat_fs_struct* fs);
00094
00095 struct fat_file_struct* fat_open_file(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
00096 void fat_close_file(struct fat_file_struct* fd);
00097 intptr_t fat_read_file(struct fat_file_struct* fd, uint8_t* buffer, uintptr_t buffer_len);
00098 intptr_t fat_write_file(struct fat_file_struct* fd, const uint8_t* buffer, uintptr_t buffer_len);
00099 uint8_t fat_seek_file(struct fat_file_struct* fd, int32_t* offset, uint8_t whence);
00100 uint8_t fat_resize_file(struct fat_file_struct* fd, uint32_t size);
00101
00102 struct fat_dir_struct* fat_open_dir(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
00103 void fat_close_dir(struct fat_dir_struct* dd);
00104 uint8_t fat_read_dir(struct fat_dir_struct* dd, struct fat_dir_entry_struct* dir_entry);
00105 uint8_t fat_reset_dir(struct fat_dir_struct* dd);
00106
00107 uint8_t fat_create_file(struct fat_dir_struct* parent, const char* file, struct fat_dir_entry_struct* dir_entry);
00108 uint8_t fat_delete_file(struct fat_fs_struct* fs, struct fat_dir_entry_struct* dir_entry);
00109 uint8_t fat_create_dir(struct fat_dir_struct* parent, const char* dir, struct fat_dir_entry_struct* dir_entry);
00110 #define fat_delete_dir fat_delete_file
00111
00112 void fat_get_file_modification_date(const struct fat_dir_entry_struct* dir_entry, uint16_t* year, uint8_t* month, uint8_t* day);
00113 void fat_get_file_modification_time(const struct fat_dir_entry_struct* dir_entry, uint8_t* hour, uint8_t* min, uint8_t* sec);
00114
00115 uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct* fs, const char* path, struct fat_dir_entry_struct* dir_entry);
00116
00117 offset_t fat_get_fs_size(const struct fat_fs_struct* fs);
00118 offset_t fat_get_fs_free(const struct fat_fs_struct* fs);
00119
00120
00121
00122
00123
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127
00128 #endif
00129