⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat16.h

📁 基于STM32的 模拟时序
💻 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
{
    /** The file's name, truncated to 31 characters. */
    char long_name[32];
    /** The file's attributes. Mask of the FAT16_ATTRIB_* constants. */
    u8 attributes;
#if FAT16_DATETIME_SUPPORT
    /** Compressed representation of modification time. */
    u16 modification_time;
    /** Compressed representation of modification date. */
    u16 modification_date;
#endif
    /** The cluster in which the file's first byte resides. */
    u16 cluster;
    /** The file's size. */
    u32 file_size;
    /** The total disk offset of this directory entry. */
    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_disk_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);

#endif /* FAT16_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -