📄 fat16.h
字号:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef FAT16_H
#define FAT16_H
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/**
* \ingroup fat16_config
* Controls FAT16 write support.
*
* Set to 1 to enable FAT16 write support, set to 0 to disable it.
*/
#define FAT16_WRITE_SUPPORT 1
/**
* \ingroup fat16_config
* Controls FAT16 date and time support.
*
* Set to 1 to enable FAT16 date and time stamping support.
*/
#define FAT16_DATETIME_SUPPORT 0
// 设置簇写的缓冲区大小 64字节属于一个比较平衡适中的参数
// 如果内存紧张 可以把这个数值改小 但是 读写速度也会降低
#define CLUSTER_BUFFER_SIZE 64
/**
* \ingroup fat16_config
* Determines the function used for retrieving current date and time.
*
* Define this to the function call which shall be used to retrieve
* current date and time.
*
* \note Used only when FAT16_DATETIME_SUPPORT is 1.
*
* \param[out] year Pointer to a \c u16 which receives the current year.
* \param[out] month Pointer to a \c u8 which receives the current month.
* \param[out] day Pointer to a \c u8 which receives the current day.
* \param[out] hour Pointer to a \c u8 which receives the current hour.
* \param[out] min Pointer to a \c u8 which receives the current minute.
* \param[out] sec Pointer to a \c u8 which receives the current sec.
*/
#define fat16_get_datetime(year, month, day, hour, min, sec) \
get_datetime(year, month, day, hour, min, sec)
/* forward declaration for the above */
void get_datetime(u16* year, u8* month, u8* day, u8* hour, u8* min, u8* sec);
/**
* \ingroup fat16_config
* Maximum number of filesystem handles.
*/
#define FAT16_FS_COUNT 1
/**
* \ingroup fat16_config
* Maximum number of file handles.
*/
#define FAT16_FILE_COUNT 1
/**
* \ingroup fat16_config
* Maximum number of directory handles.
*/
#define FAT16_DIR_COUNT 2
////////////////////////////////////////////////////////////////////////////////
/**
* \addtogroup fat16
*
* @{
*/
/**
* \file
* FAT16 header (license: GPLv2 or LGPLv2.1)
*
* \author Roland Riegel
*/
/**
* \addtogroup fat16_file
* @{
*/
/** The file is read-only. */
#define FAT16_ATTRIB_READONLY (1 << 0)
/** The file is hidden. */
#define FAT16_ATTRIB_HIDDEN (1 << 1)
/** The file is a system file. */
#define FAT16_ATTRIB_SYSTEM (1 << 2)
/** The file is empty and has the volume label as its name. */
#define FAT16_ATTRIB_VOLUME (1 << 3)
/** The file is a directory. */
#define FAT16_ATTRIB_DIR (1 << 4)
/** The file has to be archived. */
#define FAT16_ATTRIB_ARCHIVE (1 << 5)
/** The given offset is relative to the beginning of the file. */
#define FAT16_SEEK_SET 0
/** The given offset is relative to the current read/write position. */
#define FAT16_SEEK_CUR 1
/** The given offset is relative to the end of the file. */
#define FAT16_SEEK_END 2
/**
* @}
*/
struct Partition_Struct;
struct Fat16_FS_Struct;
struct Fat16_File_Struct;
struct Fat16_Dir_Struct;
/**
* \ingroup fat16_file
* Describes a directory entry.
*/
struct Fat16_Dir_Entry_Struct
{
char Long_Name[32]; /** 长文件名 */
u8 Attributes; /** 文件属性 */
#if FAT16_DATETIME_SUPPORT
u16 Modification_Time; /** 文件修改时间 */
u16 Modification_Date; /** 文件修改日期 */
#endif
u16 Cluster; /** 文件第一个字节的族号 */
u32 File_Size; /** 文件大小 */
u32 Entry_Offset; /** 整个磁盘的 目录列表 偏移地址 */
};
struct Fat16_FS_Struct*
Fat16_Open(struct Partition_Struct* partition);
void
Fat16_Close(struct Fat16_FS_Struct* fs);
struct Fat16_File_Struct*
Fat16_Open_File(struct Fat16_FS_Struct* fs, const struct Fat16_Dir_Entry_Struct* dir_entry);
void
Fat16_Close_File(struct Fat16_File_Struct* fd);
s16
Fat16_Read_File(struct Fat16_File_Struct* fd, u8* buffer, u16 buffer_len);
s16
Fat16_Write_File(struct Fat16_File_Struct* fd, const u8* buffer, u16 buffer_len);
u8
Fat16_Seek_File(struct Fat16_File_Struct* fd, s32* offset, u8 whence);
u8
Fat16_Resize_File(struct Fat16_File_Struct* fd, u32 size);
struct Fat16_Dir_Struct*
Fat16_Open_Dir(struct Fat16_FS_Struct* fs, const struct Fat16_Dir_Entry_Struct* dir_entry);
void
Fat16_Close_Dir(struct Fat16_Dir_Struct* dd);
u8
Fat16_Read_Dir(struct Fat16_Dir_Struct* dd, struct Fat16_Dir_Entry_Struct* dir_entry);
u8
Fat16_Reset_Dir(struct Fat16_Dir_Struct* dd);
u8
Fat16_Create_File(struct Fat16_Dir_Struct* parent,
const char* file,
struct Fat16_Dir_Entry_Struct* dir_entry);
u8
Fat16_Delete_File(struct Fat16_FS_Struct* fs, struct Fat16_Dir_Entry_Struct* dir_entry);
u8
Fat16_Create_Dir(struct Fat16_Dir_Struct* parent,
const char* dir,
struct Fat16_Dir_Entry_Struct* dir_entry);
#define Fat16_Delete_Dir Fat16_Delete_File
void
Fat16_Get_File_Modification_Date(const struct Fat16_Dir_Entry_Struct* dir_entry,
u16* year,
u8* month,
u8* day);
void
Fat16_Get_File_Modification_Time(const struct Fat16_Dir_Entry_Struct* dir_entry,
u8* hour,
u8* min,
u8* sec);
u8
Fat16_Get_Dir_Entry_Of_Path(struct Fat16_FS_Struct* fs,
const char* path,
struct Fat16_Dir_Entry_Struct* dir_entry);
u32
Fat16_Get_FS_Size(const struct Fat16_FS_Struct* fs);
u32
Fat16_Get_FS_Free(const struct Fat16_FS_Struct* fs);
//worm add
u8
Print_SDMMC_Info(const struct Fat16_FS_Struct* fs);
u8
Find_File_In_Dir(struct Fat16_FS_Struct* fs,
struct Fat16_Dir_Struct* dd,
const char* name,
struct Fat16_Dir_Entry_Struct* dir_entry);
struct Fat16_File_Struct*
Open_File_In_Dir(struct Fat16_FS_Struct* fs, struct Fat16_Dir_Struct* dd, const char* name);
extern void FAT16_Test(void);
#endif /* FAT16_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -