From 19b5a059b0504a6f429a2a06a5657765bd3038e9 Mon Sep 17 00:00:00 2001 From: jzlv Date: Wed, 25 Aug 2021 17:16:05 +0800 Subject: [PATCH] [feat][fatfs] add posix api support --- components/fatfs/CMakeLists.txt | 2 +- components/fatfs/fatfs_posix_api.c | 622 +++++++++++++++++++++++++++++ components/fatfs/fatfs_posix_api.h | 239 +++++++++++ components/fatfs/ffconf.h | 534 ++++++++++++------------- 4 files changed, 1129 insertions(+), 268 deletions(-) create mode 100644 components/fatfs/fatfs_posix_api.c create mode 100644 components/fatfs/fatfs_posix_api.h diff --git a/components/fatfs/CMakeLists.txt b/components/fatfs/CMakeLists.txt index c8c39f41..1a70dbd0 100644 --- a/components/fatfs/CMakeLists.txt +++ b/components/fatfs/CMakeLists.txt @@ -17,7 +17,7 @@ list(APPEND ADD_SRCS ${sources}) ####################################################### ########### Add required/dependent components ######### -#list(APPEND ADD_REQUIREMENTS xxx) +list(APPEND ADD_REQUIREMENTS common) ####################################################### ############ Add static libs ########################## diff --git a/components/fatfs/fatfs_posix_api.c b/components/fatfs/fatfs_posix_api.c new file mode 100644 index 00000000..f1bbc419 --- /dev/null +++ b/components/fatfs/fatfs_posix_api.c @@ -0,0 +1,622 @@ +/** + * @file fatfs_posix_api.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ + +/** + * @brief POSIX Common File System Interface, + * Based on the fatfs. + * Only part of the interface is implemented + */ + +#include "fatfs_posix_api.h" +#include "ff.h" +#include "stdlib.h" + +/*Memory request interface*/ +static void *(*vfs_malloc)(size_t size) = mmheap_alloc; //默认的内存申请接口 +static void (*vfs_free)(void *ptr) = mmheap_free; //默认的内存释放接口 + +/** + * @brief fs init + * + * @return 0 on successful, -1 on failed. + */ +int ff_vfs_init(void) +{ + return 0; +} + +/** + * @brief FATF error conversion,Used for compatible Linux system error codes + * + * @param Status + * @return int + */ +int ff_vfs_error(FRESULT Status) +{ + switch (Status) { + case FR_OK: + return 0; + case FR_DISK_ERR: + return -EIO; /* (1) A hard error occurred in the low level disk I/O layer */ + case FR_INT_ERR: + return -EPIPE; /* (2) Assertion failed */ + case FR_NOT_READY: + return -EIO; /* (3) The physical drive cannot work */ + case FR_NO_FILE: + return -ENOENT; /* (4) Could not find the file */ + case FR_NO_PATH: + return -ENOENT; /* (5) Could not find the path */ + case FR_INVALID_NAME: + return -ENOEXEC; /* (6) The path name format is invalid */ + case FR_DENIED: + return -ENOSPC; /* (7) Access denied due to prohibited access or directory full */ + case FR_EXIST: + return -EACCES; /* (8) Access denied due to prohibited access */ + case FR_INVALID_OBJECT: + return -ENXIO; /* (9) The file/directory object is invalid */ + case FR_WRITE_PROTECTED: + return -EROFS; /* (10) The physical drive is write protected */ + case FR_INVALID_DRIVE: + return -ENXIO; /* (11) The logical drive number is invalid */ + case FR_NOT_ENABLED: + return -ENXIO; /* (12) The volume has no work area */ + case FR_NO_FILESYSTEM: + return -EPERM; /* (13) There is no valid FAT volume */ + case FR_MKFS_ABORTED: + return -EPERM; /* (14) The f_mkfs() aborted due to any problem */ + case FR_TIMEOUT: + return -EBUSY; /* (15) Could not get a grant to access the volume within defined period */ + case FR_LOCKED: + return -EACCES; /* (16) The operation is rejected according to the file sharing policy */ + case FR_NOT_ENOUGH_CORE: + return -ENOMEM; /* (17) LFN working buffer could not be allocated */ + case FR_TOO_MANY_OPEN_FILES: + return -EMFILE; /* (18) Number of open files > FF_FS_LOCK */ + case FR_INVALID_PARAMETER: + return -EINVAL; /* (19) Given parameter is invalid */ + default: + return -EPERM; + } +} + +/** + * @brief Open the file described in PATH + * + * @param path The file path + * @param flags The file's parameters: + * O_RDONLY: read-only + * O_WRONLY: write-only + * O_RDWR: readable and writable + * O_CREAT: Create a file when it doesn't exist + * O_EXCL: When the file is opened, returned -EEXIST if the file exists and the flag bit O_CREAT is also specified. + * If the file does not exist, the file is created + * O_TRUNC: When opening the file, if the length of the file is not 0, the length of the file will be truncated to 0, + * and the next time the file is written, the data will be written from the file + * O_APPEND: After opening the file, set the write point of the file to the end of the file. The next time the file is written, + * the newly written data will be appended to the end of the file + * @param mode The permissions, not currently supported, ignored + * @return int Positive: File descriptor (actually a pointer); Negative: Error execution, return error code + */ +int ff_open(const char *path, int flags, int mode) +{ + uint8_t OpenMode = 0; + FIL *pFile; + FRESULT Status; + + pFile = (FIL *)vfs_malloc(sizeof(FIL)); + if (pFile == NULL) { + return -ENOMEM; + } + + if (flags & O_WRONLY) { + OpenMode |= FA_WRITE; + } + if (flags & O_RDWR) { + OpenMode |= FA_WRITE | FA_READ; + } + if ((OpenMode & (FA_WRITE | FA_READ)) == 0) /*If no read-write is specified, the default is read-only*/ + { + OpenMode |= FA_READ; + } + if ((flags & O_CREAT) && (flags & O_EXCL)) { + OpenMode |= FA_CREATE_NEW; + } else if (flags & O_CREAT) { + OpenMode |= FA_OPEN_ALWAYS; + } + if (flags & O_TRUNC) { + OpenMode |= FA_CREATE_ALWAYS; + } + if (flags & O_APPEND) { + OpenMode |= FA_OPEN_APPEND; + } + + Status = f_open(pFile, path, OpenMode); + if (Status != FR_OK) { + vfs_free(pFile); + pFile = NULL; + + if ((flags & O_CREAT) && (flags & O_EXCL) && (Status == FR_EXIST)) { + return -EEXIST; + } + return ff_vfs_error(Status); + } + + return (int)pFile; +} + +/** + * @brief Close the file + * + * @param fd The descriptor of the file + * @return int 0: success; Negative: Error execution, return error code + */ +int ff_close(int fd) +{ + FRESULT Status; + + if (fd <= 0) + return -ENXIO; + Status = f_close((FIL *)fd); + if (Status == FR_OK) { + vfs_free((void *)fd); + } + + return ff_vfs_error(Status); +} + +/** + * @brief Read file data + * + * @param fd The descriptor of the file + * @param buf The cache of data read by the file + * @param nbytes Number of bytes to read + * @return int Read successfully, return the number of bytes read; + * Returns 0 if the file offset reached the end of the file when it was read. + * Other error conditions, return the error code + */ +int ff_read(int fd, void *buf, size_t nbytes) +{ + FRESULT Status; + UINT cnt; + + if (fd <= 0) + return -ENXIO; + Status = f_read((FIL *)fd, buf, nbytes, (UINT *)&cnt); + if (Status != FR_OK) { + return ff_vfs_error(Status); + } + return cnt; +} + +/** + * @brief Writes data to a file + * + * @param fd The descriptor of the file + * @param buf The cache of data to write to the file + * @param nbytes The length of the file written + * @return int When successfully written, the number of bytes written to the file is returned. + * The actual number of bytes written may be less than nbytes (insufficient file space). + * Returns an error code (negative) when writing fails + */ +int ff_write(int fd, const void *buf, size_t nbytes) +{ + FRESULT Status; + UINT cnt; + + if (fd <= 0) + return -ENXIO; + Status = f_write((FIL *)fd, buf, nbytes, (UINT *)&cnt); + if (Status != FR_OK) { + return ff_vfs_error(Status); + } + return cnt; +} + +/** + * @brief Resets the offset of the open file + * + * @param fd The descriptor of the file + * @param offset Offset from the third parameter whence + * @param whence File offset basics + * VFS_SEEK_SET: Based on file headers + * VFS_SEEK_CUR: Based on the current location + * VFS_SEEK_END: Based on file end + * @return ff_off_t Non-negative: on success, returns the number of offset bytes relative to the start of the file; + * Negative: Failure, return error code + */ +ff_off_t ff_lseek(int fd, ff_off_t offset, int whence) +{ + FRESULT Status; + long long temp; + + if (fd <= 0) + return -ENXIO; + + switch (whence) { + case VFS_SEEK_SET: { + Status = f_lseek((FIL *)fd, offset); + if (Status == FR_OK) { + return (ff_off_t)((FIL *)fd)->fptr; + } + return ff_vfs_error(Status); + } + case VFS_SEEK_CUR: { + temp = (ff_off_t)((FIL *)fd)->fptr; + temp += offset; + if (temp >= 0xffffffff) + temp = 0xffffffff - 1; + Status = f_lseek((FIL *)fd, temp); + if (Status == FR_OK) { + return (ff_off_t)((FIL *)fd)->fptr; + } + return ff_vfs_error(Status); + } + case VFS_SEEK_END: { + temp = (ff_off_t)((FIL *)fd)->obj.objsize; + temp -= offset; + if (temp <= 0) + temp = 0; + Status = f_lseek((FIL *)fd, temp); + if (Status == FR_OK) { + return (ff_off_t)((FIL *)fd)->fptr; + } + return ff_vfs_error(Status); + } + default: + return -EINVAL; + } +} + +/** + * @brief Update the cache to memory + * + * @param fd The descriptor of the file + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_sync(int fd) +{ + FRESULT Status; + + if (fd <= 0) + return -ENXIO; //文件指针为空,直接返回 + Status = f_sync((FIL *)fd); //存储文件 + return ff_vfs_error(Status); //错误代码转义 +} + +/** + * @brief Get the attributes of the file(path) + * + * @param path The file path + * @param st Pointer to file status information structure + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_stat(const char *path, struct stat *st) +{ + FRESULT Status; + FILINFO *pInfo; + + if (path == NULL || st == NULL) { + return -EINVAL; + } + pInfo = vfs_malloc(sizeof(FILINFO)); + if (pInfo == NULL) { + return -ENOMEM; + } + Status = f_stat(path, pInfo); + if (Status == FR_OK) { + st->st_size = pInfo->fsize; + st->st_mode = pInfo->fattrib; + st->st_actime = 0; + st->st_modtime = 0; + } + vfs_free(pInfo); + return ff_vfs_error(Status); +} + +/** + * @brief Get the property information of the file + * + * @param fd The descriptor of the file + * @param st Pointer to file status information structure + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_fstat(int fd, struct stat *st) +{ + if (fd <= 0) + return -ENXIO; + if (st == NULL) + return -EINVAL; + + st->st_size = ((FIL *)fd)->obj.objsize; + st->st_mode = 0777; + st->st_actime = 0; + st->st_modtime = 0; + + return 0; +} + +/** + * @brief Checks whether the current program has access to PATH + * + * @param path The descriptor of the file + * @param amode The permissions, not currently supported, ignored + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_access(const char *path, int amode) +{ + struct stat st; + + return ff_stat(path, &st); +} + +/** + * @brief Retutn the current working directory, + * If the buf parameter is not empty, the current working directory string is also copied into the buf + * + * @param buf Path string buffer + * @param size Path buffer size + * @return char* Path string buffer + */ +char *ff_getcwd(char *buf, size_t size) +{ + FRESULT Status; + + if (buf == NULL || size == 0) { + return NULL; + } + + Status = f_getcwd(buf, size); + if (Status == FR_OK) { + return buf; + } else { + } + + return NULL; +} + +/************************************************************************************************************************* +* 函数 : int ff_ftruncate(int fd, ff_off_t length) +* 功能 : 指定文件大小 +* 参数 : fd:已经打开的文件描述符,必须由写入权限;length:指定的文件大小 +* 返回 : 0:成功;负数:返回错误码 +* 依赖 : FATFS +* 作者 : cp1300@139.com +* 时间 : 2020-09-29 +* 最后修改时间 : 2020-09-29 +* 说明 : +*************************************************************************************************************************/ +/** + * @brief + * + * @param fd Specify file size,Automatically truncate or fill + * @param length File descriptor that is already open. Must have write permission + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_ftruncate(int fd, ff_off_t length) +{ + FRESULT Status; + UINT cnt; + uint32_t PackCnt; + uint16_t EndPackSize; + uint8_t *pBuff; + uint32_t i; + + if (fd <= 0) + return -ENXIO; + if (length <= ((FIL *)fd)->obj.objsize) { + Status = f_lseek((FIL *)fd, length); + if (Status == FR_OK) { + Status = f_truncate((FIL *)fd); + if (Status == FR_OK) { + return 0; + } else { + } + } else { + } + return ff_vfs_error(Status); + } else { + Status = f_lseek((FIL *)fd, ((FIL *)fd)->obj.objsize); + if (Status == FR_OK) { + PackCnt = (length - ((FIL *)fd)->obj.objsize) / 512; + EndPackSize = (length - ((FIL *)fd)->obj.objsize) % 512; + pBuff = vfs_malloc(512); + if (pBuff == NULL) { + return -ENOMEM; + } + memset(pBuff, 0, 512); + + for (i = 0; i < PackCnt; i++) { + Status = f_write((FIL *)fd, pBuff, 512, (UINT *)&cnt); + if (Status != FR_OK) { + break; + } + } + if ((Status == FR_OK) && EndPackSize) { + Status = f_write((FIL *)fd, pBuff, EndPackSize, (UINT *)&cnt); + if (Status != FR_OK) { + } + } + vfs_free(pBuff); + } else { + } + } + + return ff_vfs_error(Status); +} + +/** + * @brief + * + * @param fd + * @param cmd + * @param lock + * @return int + */ +int ff_fcntl(int fd, int cmd, struct flock *lock) +{ + if (fd <= 0) + return -ENXIO; //文件指针为空,直接返回 + + return 0; +} + +/** + * @brief Change access to existing files + * + * @param fd The file descriptor + * @param mode + * @return int + */ +int ff_fchmod(int fd, ff_mode_t mode) +{ + if (fd <= 0) + return -ENXIO; //文件指针为空,直接返回 + + return 0; +} + +/** + * @brief Delete the file + * + * @param path The file path + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_unlink(const char *path) +{ + FRESULT Status; + FILINFO *pInfo; + + if (path == NULL) + return -ENXIO; + pInfo = vfs_malloc(sizeof(FILINFO)); + if (pInfo == NULL) { + return -ENOMEM; + } + + Status = f_stat(path, pInfo); + if (Status == FR_OK) { + Status = f_unlink(path); + if (Status != FR_OK) { + } + } else { + } + vfs_free(pInfo); + + return ff_vfs_error(Status); +} + +/** + * @brief Create a directory, If it already exists, the creation fails + * + * @param path The directory path + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_mkdir(const char *path) +{ + FRESULT Status; + + if (path == NULL) + return -ENXIO; + Status = f_mkdir(path); + + return ff_vfs_error(Status); +} + +/** + * @brief Delete a directory,When you delete a directory, the directory must be empty + * + * @param path Directory path + * @return int 0: success; + * Negative: Data synchronization failure, return error code + */ +int ff_rmdir(const char *path) +{ + FRESULT Status; + FILINFO *pInfo; + + if (path == NULL) + return -ENXIO; + pInfo = vfs_malloc(sizeof(FILINFO)); + if (pInfo == NULL) { + return -ENOMEM; + } + + Status = f_stat(path, pInfo); + if (Status == FR_INVALID_NAME) { + Status = f_unlink(path); + if (Status != FR_OK) { + } + } else { + if (Status != FR_OK) { + } else { + vfs_free(pInfo); + return -ENOTDIR; + } + } + vfs_free(pInfo); + + return ff_vfs_error(Status); +} + +/** + * @brief + * + * @param fd + * @param owner + * @param group + * @return int + */ + +int ff_fchown(int fd, ff_uid_t owner, ff_gid_t group) +{ + return 0; +} + +/** + * @brief + * + * @return ff_uid_t + */ +ff_uid_t ff_geteuid(void) +{ + return 0; +} + +/** + * @brief + * + * @param path + * @param times + * @return int + */ +int ff_utimes(const char *path, const struct ff_timeval times[2]) +{ + return 0; +} \ No newline at end of file diff --git a/components/fatfs/fatfs_posix_api.h b/components/fatfs/fatfs_posix_api.h new file mode 100644 index 00000000..7d116de6 --- /dev/null +++ b/components/fatfs/fatfs_posix_api.h @@ -0,0 +1,239 @@ +/** + * @file fatfs_posix_api.h + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ + +/************************************************************************************************************* + * 文件名 : ff_vfs.h + * 功能 : VFS虚拟文件系统支持 + * 作者 : cp1300@139.com + * 创建时间 : 2020-09-29 + * 最后修改时间 : 2020-09-29 + * 详细 : 兼容linux的vfs文件系统API支持,需要先初始化fatfs +*************************************************************************************************************/ +#ifndef _FF_VFS_H_ +#define _FF_VFS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "ff.h" +#include "drv_mmheap.h" + +typedef int ff_dev_t; //32为int数据,高12位主设备号,低20位次设备号 + +typedef int ff_off_t; //文件偏移此处使用32bit格式,由于FATFS最大只支持4G大小文件,此处设置为只支持2GB文件大小 + +typedef uint32_t ff_time_t; + +typedef struct { + uint32_t dd_vfs_fd; + uint32_t dd_rsv; +} ff_dir_t; + +struct stat { + ff_dev_t st_dev; + uint32_t st_size; + uint32_t st_mode; + ff_time_t st_actime; + ff_time_t st_modtime; + uint64_t st_ino; + uint32_t st_nlink; + uint32_t st_blksize; + uint32_t st_uid; + uint32_t st_gid; +}; + +typedef struct { + uint32_t d_ino; /* file number */ + uint8_t d_type; /* type of file */ + char d_name[]; /* file name */ +} ff_dirent_t; + +typedef const struct fs_ops fs_ops_t; + +struct ff_utimbuf { + ff_time_t actime; /**< time of last access */ + ff_time_t modtime; /**< time of last modification */ +}; +//用于 utimes 修改文件的访问时间,未实现 +struct ff_timeval { + ff_time_t tv_sec; /* seconds */ + ff_time_t tv_usec; /* microseconds */ +}; + +/* for posix fcntl() and lockf() */ +#define F_RDLCK 0 +#define F_WRLCK 1 +#define F_UNLCK 2 + +//打开文件的参数flags定义 +#define O_RDONLY (1 << 0) //以只读方式打开文件 +#define O_WRONLY (1 << 1) //以只写方式打开 +#define O_RDWR (O_RDONLY | O_WRONLY) //以可读可写方式打开 +#define O_ACCMODE (O_RDWR) +#define O_CREAT (1 << 8) //文件不存在时创建文件 +#define O_EXCL (1 << 9) //在打开文件时,如果文件存在而且同时指定的标志位O_CREAT,则返回-EEXIST;如果文件不存在,则创建文件 +#define O_NOCTTY (1 << 10) +#define O_TRUNC (1 << 11) //打开文件时,如果文件的长度不为0,则将文件的长度截短为0,下次写入文件时,从文件开始出写入数据 +#define O_APPEND (1 << 12) //打开文件后,将文件的写入点设置为文件末尾,下次写入文件时,新写入的数据会追加到文件末尾 +#define O_DSYNC (1 << 13) +#define O_NONBLOCK (1 << 14) +#define O_SYNC (1 << 15) + +//文件偏移参数 +#define VFS_SEEK_SET (0) //文件偏移设置为从文件开始处offset字节处 +#define VFS_SEEK_CUR (1) //文件偏移设置为相对于当前文件位置的offset字节处 +#define VFS_SEEK_END (2) //文件偏移摄者为文件末尾的offset字节处 + +//访问权限测试值 +#define R_OK (1 << 2) +#define W_OK (1 << 1) +#define X_OK (1 << 0) + +//文件特性,并未实现 +struct flock { + short l_type; + short l_whence; + short l_start; + short l_len; +}; +#define F_DUPFD 0 /* dup */ +#define F_GETFD 1 /* get close_on_exec */ +#define F_SETFD 2 /* set/clear close_on_exec */ +#define F_GETFL 3 /* get file->f_flags */ +#define F_SETFL 4 /* set file->f_flags */ +#ifndef F_GETLK +#define F_GETLK 5 +#define F_SETLK 6 +#define F_SETLKW 7 +#endif //F_GETLK + +//文件权限模式,并未实现 +typedef unsigned int ff_mode_t; + +//用户与组id,并未实现 +typedef unsigned int ff_uid_t; +typedef unsigned int ff_gid_t; + +#define F_OK 0 +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math argument out of domain of func */ +#define ERANGE 34 /* Math result not representable */ + +int ff_vfs_init(void); //初始化VFS系统。系统启动流程中组件初始化函数 +int ff_open(const char *path, int flags, int mode); //打开path所描述的文件或者设备 +int ff_close(int fd); //关闭已打开的文件描述符fd +int ff_read(int fd, void *buf, size_t nbytes); //从打开的文件中读取若干字节到buffer +int ff_write(int fd, const void *buf, size_t nbytes); //将buffer开始出的nbytes字节数据写入到已经打开的文件 +ff_off_t ff_lseek(int fd, ff_off_t offset, int whence); //重新设置已打开文件的偏移 +int ff_sync(int fd); //会将对文件系统元数据(metadata)的修改以及文件系统内部缓存中的数据写入底层文件系统中 +int ff_stat(const char *path, struct stat *st); //读取文件的属性信息,如文件大小、文件模式(权限、文件/文件夹) +int ff_fstat(int fd, struct stat *st); //读取文件的属性信息,如文件大小、文件模式(权限、文件/文件夹)等信息到st指针指向的buffer +int ff_link(const char *oldpath, const char *newpath); //为文件创建一个新的链接文件。如果目标文件存在,则不会覆盖 +int ff_unlink(const char *path); //从文件系统中删除文件名 +int ff_remove(const char *path); //从文件系统中删除文件名,它既可以删除文件,也可以删除目录。 +int ff_rename(const char *oldpath, const char *newpath); //重命名一个文件,可以将文件从一个文件夹下通过重命名移动到另外一个文件夹下 +ff_dir_t *ff_opendir(const char *path); //打开目录名path对应的目录流,并返回目录流指针 +int ff_closedir(ff_dir_t *dirp); //关闭目录流。调用ff_closedir()后,目录流指针不再可用 +ff_dirent_t *ff_readdir(ff_dir_t *dirp); //返回一个指向ff_dirent_t的指针,该指针关联的目录流dirp的成员指针指向下一个成员 +int ff_mkdir(const char *path); //创建名为path的目录。如果已经存在path目录,则创建失败 +int ff_rmdir(const char *path); //删除一个目录。删除目录时,目录必须为空。 +void ff_rewinddir(ff_dir_t *dirp); //将目录流dirp的位置重置为目录的开始处。 +int ff_telldir(ff_dir_t *dirp); //返回与目录流dirp相关联的目录流的当前位置。 +void ff_seekdir(ff_dir_t *dir, long loc); //设置目录流的位置,下次调用ff_readdir()时目录流将从设置的位置开始读取目录 +int ff_access(const char *path, int amode); //检查当前程序是否可以访问path文件 +int ff_chdir(const char *path); //改变当前程序的工作目录到path路径。 +char *ff_getcwd(char *buf, size_t size); //返回当当前程序的绝对工作目录字符串指针,同时如果buf参数不为空,也将当前工作目录字符串复制到buf中 +long ff_pathconf(const char *path, int name); //函数返回配置文件的限制值,是与文件或目录相关联的运行时限制。 +long ff_fpathconf(int fd, int name); //返回配置文件的限制值 +int ff_utime(const char *path, const struct ff_utimbuf *times); //通过参数times的actime和modtime成员改变文件的访问时间和修改时间 +int ff_ftruncate(int fd, ff_off_t length); //指定文件大小 +int ff_fcntl(int fd, int cmd, struct flock *lock); //根据文件描述词来操作文件的特性 +int ff_fchmod(int fd, ff_mode_t mode); //改变现有文件的访问权限 +int ff_fchown(int fd, ff_uid_t owner, ff_gid_t group); //更改文件的用户ID和组ID +ff_uid_t ff_geteuid(void); //获取用户有效 UID 值 +int ff_utimes(const char *path, const struct ff_timeval times[2]); //修改一个文件的访问时间和修改时间 + +#define S_ISREG(st_mode) 0 //是否是一个常规文件-未实现 +#define S_ISDIR(st_mode) 0 //是否是一个目录-未实现 + +//标准VFS文件接口 +#define open ff_open //打开文件 +#define close ff_close //关闭已打开的文件 +#define read ff_read //读取已打开的文件 +#define write ff_write //写入已打开的文件 +#define lseek ff_lseek //重新设置已打开文件的偏移 +//#define sync ff_sync //同步文件,刷新缓存 +#define fsync ff_sync //同步文件,刷新缓存 +__inline int stat(const char *path, struct stat *st) +{ + return ff_stat(path, st); +} //获取文件信息,有重名的结构体,这个地方只能使用内联函数 +#define fstat ff_fstat //获取文件信息 +#define access ff_access //测试访问权限 +#define getcwd ff_getcwd //返回当当前程序的绝对工作目录 +#define ftruncate ff_ftruncate //指定文件大小 +#define fcntl ff_fcntl //根据文件描述词来操作文件的特性 +#define fchmod ff_fchmod //改变现有文件的访问权限 +#define unlink ff_unlink //从文件系统中删除文件 +#define mkdir ff_mkdir //创建名为path的目录 +#define rmdir ff_rmdir //删除一个目录 +//#define fchown ff_fchown //更改文件的用户ID和组ID +//#define geteuid ff_geteuid //获取用户有效 UID 值 +#define utimes ff_utimes //修改一个文件的访问时间和修改时间 + +#ifdef __cplusplus +} +#endif + +#endif //_FF_VFS_H_ diff --git a/components/fatfs/ffconf.h b/components/fatfs/ffconf.h index 9916c982..95883460 100644 --- a/components/fatfs/ffconf.h +++ b/components/fatfs/ffconf.h @@ -1,267 +1,267 @@ -/*---------------------------------------------------------------------------/ -/ FatFs Functional Configurations -/---------------------------------------------------------------------------*/ - -#define FFCONF_DEF 86606 /* Revision ID */ - -/*---------------------------------------------------------------------------/ -/ Function Configurations -/---------------------------------------------------------------------------*/ - -#define FF_FS_READONLY 0 -/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) -/ Read-only configuration removes writing API functions, f_write(), f_sync(), -/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() -/ and optional writing functions as well. */ - -#define FF_FS_MINIMIZE 0 -/* This option defines minimization level to remove some basic API functions. -/ -/ 0: Basic functions are fully enabled. -/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() -/ are removed. -/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. -/ 3: f_lseek() function is removed in addition to 2. */ - -#define FF_USE_STRFUNC 0 -/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). -/ -/ 0: Disable string functions. -/ 1: Enable without LF-CRLF conversion. -/ 2: Enable with LF-CRLF conversion. */ - -#define FF_USE_FIND 0 -/* This option switches filtered directory read functions, f_findfirst() and -/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ - -#define FF_USE_MKFS 1 -/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ - -#define FF_USE_FASTSEEK 1 -/* This option switches fast seek function. (0:Disable or 1:Enable) */ - -#define FF_USE_EXPAND 0 -/* This option switches f_expand function. (0:Disable or 1:Enable) */ - -#define FF_USE_CHMOD 0 -/* This option switches attribute manipulation functions, f_chmod() and f_utime(). -/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ - -#define FF_USE_LABEL 0 -/* This option switches volume label functions, f_getlabel() and f_setlabel(). -/ (0:Disable or 1:Enable) */ - -#define FF_USE_FORWARD 0 -/* This option switches f_forward() function. (0:Disable or 1:Enable) */ - -/*---------------------------------------------------------------------------/ -/ Locale and Namespace Configurations -/---------------------------------------------------------------------------*/ - -#define FF_CODE_PAGE 437 -/* This option specifies the OEM code page to be used on the target system. -/ Incorrect code page setting can cause a file open failure. -/ -/ 437 - U.S. -/ 720 - Arabic -/ 737 - Greek -/ 771 - KBL -/ 775 - Baltic -/ 850 - Latin 1 -/ 852 - Latin 2 -/ 855 - Cyrillic -/ 857 - Turkish -/ 860 - Portuguese -/ 861 - Icelandic -/ 862 - Hebrew -/ 863 - Canadian French -/ 864 - Arabic -/ 865 - Nordic -/ 866 - Russian -/ 869 - Greek 2 -/ 932 - Japanese (DBCS) -/ 936 - Simplified Chinese (DBCS) -/ 949 - Korean (DBCS) -/ 950 - Traditional Chinese (DBCS) -/ 0 - Include all code pages above and configured by f_setcp() -*/ - -#define FF_USE_LFN 1 -#define FF_MAX_LFN 255 -/* The FF_USE_LFN switches the support for LFN (long file name). -/ -/ 0: Disable LFN. FF_MAX_LFN has no effect. -/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. -/ 2: Enable LFN with dynamic working buffer on the STACK. -/ 3: Enable LFN with dynamic working buffer on the HEAP. -/ -/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function -/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and -/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. -/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can -/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN -/ specification. -/ When use stack for the working buffer, take care on stack overflow. When use heap -/ memory for the working buffer, memory management functions, ff_memalloc() and -/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */ - -#define FF_LFN_UNICODE 0 -/* This option switches the character encoding on the API when LFN is enabled. -/ -/ 0: ANSI/OEM in current CP (TCHAR = char) -/ 1: Unicode in UTF-16 (TCHAR = WCHAR) -/ 2: Unicode in UTF-8 (TCHAR = char) -/ 3: Unicode in UTF-32 (TCHAR = DWORD) -/ -/ Also behavior of string I/O functions will be affected by this option. -/ When LFN is not enabled, this option has no effect. */ - -#define FF_LFN_BUF 255 -#define FF_SFN_BUF 12 -/* This set of options defines size of file name members in the FILINFO structure -/ which is used to read out directory items. These values should be suffcient for -/ the file names to read. The maximum possible length of the read file name depends -/ on character encoding. When LFN is not enabled, these options have no effect. */ - -#define FF_STRF_ENCODE 3 -/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(), -/ f_putc(), f_puts and f_printf() convert the character encoding in it. -/ This option selects assumption of character encoding ON THE FILE to be -/ read/written via those functions. -/ -/ 0: ANSI/OEM in current CP -/ 1: Unicode in UTF-16LE -/ 2: Unicode in UTF-16BE -/ 3: Unicode in UTF-8 -*/ - -#define FF_FS_RPATH 2 -/* This option configures support for relative path. -/ -/ 0: Disable relative path and remove related functions. -/ 1: Enable relative path. f_chdir() and f_chdrive() are available. -/ 2: f_getcwd() function is available in addition to 1. -*/ - -/*---------------------------------------------------------------------------/ -/ Drive/Volume Configurations -/---------------------------------------------------------------------------*/ - -#define FF_VOLUMES 6 -/* Number of volumes (logical drives) to be used. (1-10) */ - -#define FF_STR_VOLUME_ID 1 -#define FF_VOLUME_STRS "sd2", "sd", "ram", "nand", "cg", "usb", -/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. -/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive -/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each -/ logical drives. Number of items must not be less than FF_VOLUMES. Valid -/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are -/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is -/ not defined, a user defined volume string table needs to be defined as: -/ -/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... -*/ - -#define FF_MULTI_PARTITION 0 -/* This option switches support for multiple volumes on the physical drive. -/ By default (0), each logical drive number is bound to the same physical drive -/ number and only an FAT volume found on the physical drive will be mounted. -/ When this function is enabled (1), each logical drive number can be bound to -/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() -/ funciton will be available. */ - -#define FF_MIN_SS 512 -#define FF_MAX_SS 512 -/* This set of options configures the range of sector size to be supported. (512, -/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and -/ harddisk. But a larger value may be required for on-board flash memory and some -/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured -/ for variable sector size mode and disk_ioctl() function needs to implement -/ GET_SECTOR_SIZE command. */ - -#define FF_LBA64 0 -/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable) -/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */ - -#define FF_MIN_GPT 0x100000000 -/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and -/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */ - -#define FF_USE_TRIM 0 -/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) -/ To enable Trim function, also CTRL_TRIM command should be implemented to the -/ disk_ioctl() function. */ - -/*---------------------------------------------------------------------------/ -/ System Configurations -/---------------------------------------------------------------------------*/ - -#define FF_FS_TINY 0 -/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) -/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. -/ Instead of private sector buffer eliminated from the file object, common sector -/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ - -#define FF_FS_EXFAT 0 -/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) -/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1) -/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ - -#define FF_FS_NORTC 1 -#define FF_NORTC_MON 1 -#define FF_NORTC_MDAY 1 -#define FF_NORTC_YEAR 2019 -/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have -/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable -/ the timestamp function. Every object modified by FatFs will have a fixed timestamp -/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. -/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be -/ added to the project to read current time form real-time clock. FF_NORTC_MON, -/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. -/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */ - -#define FF_FS_NOFSINFO 0 -/* If you need to know correct free space on the FAT32 volume, set bit 0 of this -/ option, and f_getfree() function at first time after volume mount will force -/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. -/ -/ bit0=0: Use free cluster count in the FSINFO if available. -/ bit0=1: Do not trust free cluster count in the FSINFO. -/ bit1=0: Use last allocated cluster number in the FSINFO if available. -/ bit1=1: Do not trust last allocated cluster number in the FSINFO. -*/ - -#define FF_FS_LOCK 0 -/* The option FF_FS_LOCK switches file lock function to control duplicated file open -/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY -/ is 1. -/ -/ 0: Disable file lock function. To avoid volume corruption, application program -/ should avoid illegal open, remove and rename to the open objects. -/ >0: Enable file lock function. The value defines how many files/sub-directories -/ can be opened simultaneously under file lock control. Note that the file -/ lock control is independent of re-entrancy. */ - -/* #include // O/S definitions */ -#define FF_FS_REENTRANT 0 -#define FF_FS_TIMEOUT 1000 -#define FF_SYNC_t HANDLE -/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs -/ module itself. Note that regardless of this option, file access to different -/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() -/ and f_fdisk() function, are always not re-entrant. Only file/directory access -/ to the same volume is under control of this function. -/ -/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. -/ 1: Enable re-entrancy. Also user provided synchronization handlers, -/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() -/ function, must be added to the project. Samples are available in -/ option/syscall.c. -/ -/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. -/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, -/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be -/ included somewhere in the scope of ff.h. */ - -/*--- End of configuration options ---*/ +/*---------------------------------------------------------------------------/ +/ FatFs Functional Configurations +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 86606 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: Basic functions are fully enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + +#define FF_USE_MKFS 1 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + +#define FF_USE_FASTSEEK 1 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 437 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + +#define FF_USE_LFN 1 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function +/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. +/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can +/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN +/ specification. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */ + +#define FF_LFN_UNICODE 0 +/* This option switches the character encoding on the API when LFN is enabled. +/ +/ 0: ANSI/OEM in current CP (TCHAR = char) +/ 1: Unicode in UTF-16 (TCHAR = WCHAR) +/ 2: Unicode in UTF-8 (TCHAR = char) +/ 3: Unicode in UTF-32 (TCHAR = DWORD) +/ +/ Also behavior of string I/O functions will be affected by this option. +/ When LFN is not enabled, this option has no effect. */ + +#define FF_LFN_BUF 255 +#define FF_SFN_BUF 12 +/* This set of options defines size of file name members in the FILINFO structure +/ which is used to read out directory items. These values should be suffcient for +/ the file names to read. The maximum possible length of the read file name depends +/ on character encoding. When LFN is not enabled, these options have no effect. */ + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM in current CP +/ 1: Unicode in UTF-16LE +/ 2: Unicode in UTF-16BE +/ 3: Unicode in UTF-8 +*/ + +#define FF_FS_RPATH 2 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 6 +/* Number of volumes (logical drives) to be used. (1-10) */ + +#define FF_STR_VOLUME_ID 1 +#define FF_VOLUME_STRS "sd2", "sd", "ram", "nand", "cg", "usb", +/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. +/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each +/ logical drives. Number of items must not be less than FF_VOLUMES. Valid +/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are +/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is +/ not defined, a user defined volume string table needs to be defined as: +/ +/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... +*/ + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + +#define FF_LBA64 0 +/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable) +/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */ + +#define FF_MIN_GPT 0x100000000 +/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and +/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */ + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1) +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 1 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2019 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. Every object modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */ + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + +/* #include // O/S definitions */ +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT 1000 +#define FF_SYNC_t HANDLE +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/*--- End of configuration options ---*/