1 #ifndef __FAT_ACCESS_H__
2 #define __FAT_ACCESS_H__
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
11 #define FAT_INIT_MEDIA_ACCESS_ERROR (-1)
12 #define FAT_INIT_INVALID_SECTOR_SIZE (-2)
13 #define FAT_INIT_INVALID_SIGNATURE (-3)
14 #define FAT_INIT_ENDIAN_ERROR (-4)
15 #define FAT_INIT_WRONG_FILESYS_TYPE (-5)
16 #define FAT_INIT_WRONG_PARTITION_TYPE (-6)
17 #define FAT_INIT_STRUCT_PACKING (-7)
19 #define FAT_DIR_ENTRIES_PER_SECTOR (FAT_SECTOR_SIZE / FAT_DIR_ENTRY_SIZE)
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
24 typedef int (*fn_diskio_read
) (uint32 sector
, uint8
*buffer
, uint32 sector_count
);
25 typedef int (*fn_diskio_write
)(uint32 sector
, uint8
*buffer
, uint32 sector_count
);
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
32 // User supplied function pointers for disk IO
33 fn_diskio_read read_media
;
34 fn_diskio_write write_media
;
37 // Forward declaration
42 uint8 sector
[FAT_SECTOR_SIZE
* FAT_BUFFER_SECTORS
];
47 // Next in chain of sector buffers
48 struct fat_buffer
*next
;
60 uint8 sectors_per_cluster
;
61 uint32 cluster_begin_lba
;
62 uint32 rootdir_first_cluster
;
63 uint32 rootdir_first_sector
;
64 uint32 rootdir_sectors
;
66 uint16 fs_info_sector
;
69 uint32 next_free_cluster
;
70 uint16 root_entry_count
;
71 uint16 reserved_sectors
;
76 struct disk_if disk_io
;
78 // [Optional] Thread Safety
79 void (*fl_lock
)(void);
80 void (*fl_unlock
)(void);
83 struct fat_buffer currentsector
;
86 struct fat_buffer
*fat_buffer_head
;
87 struct fat_buffer fat_buffers
[FAT_BUFFERS
];
90 struct fs_dir_list_status
99 char filename
[FATFS_MAX_LONG_FILENAME
];
104 #if FATFS_INC_TIME_DATE_SUPPORT
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
116 int fatfs_init(struct fatfs
*fs
);
117 uint32
fatfs_lba_of_cluster(struct fatfs
*fs
, uint32 Cluster_Number
);
118 int fatfs_sector_reader(struct fatfs
*fs
, uint32 Startcluster
, uint32 offset
, uint8
*target
);
119 int fatfs_sector_read(struct fatfs
*fs
, uint32 lba
, uint8
*target
, uint32 count
);
120 int fatfs_sector_write(struct fatfs
*fs
, uint32 lba
, uint8
*target
, uint32 count
);
121 int fatfs_read_sector(struct fatfs
*fs
, uint32 cluster
, uint32 sector
, uint8
*target
);
122 int fatfs_write_sector(struct fatfs
*fs
, uint32 cluster
, uint32 sector
, uint8
*target
);
123 void fatfs_show_details(struct fatfs
*fs
);
124 uint32
fatfs_get_root_cluster(struct fatfs
*fs
);
125 uint32
fatfs_get_file_entry(struct fatfs
*fs
, uint32 Cluster
, char *nametofind
, struct fat_dir_entry
*sfEntry
);
126 int fatfs_sfn_exists(struct fatfs
*fs
, uint32 Cluster
, char *shortname
);
127 int fatfs_update_file_length(struct fatfs
*fs
, uint32 Cluster
, char *shortname
, uint32 fileLength
);
128 int fatfs_mark_file_deleted(struct fatfs
*fs
, uint32 Cluster
, char *shortname
);
129 void fatfs_list_directory_start(struct fatfs
*fs
, struct fs_dir_list_status
*dirls
, uint32 StartCluster
);
130 int fatfs_list_directory_next(struct fatfs
*fs
, struct fs_dir_list_status
*dirls
, struct fs_dir_ent
*entry
);
131 int fatfs_update_timestamps(struct fat_dir_entry
*directoryEntry
, int create
, int modify
, int access
);