12#define LUAT_WEAK __attribute__((weak))
230#ifdef LUAT_USE_FS_VFS
232#ifndef LUAT_VFS_FILESYSTEM_MAX
233#define LUAT_VFS_FILESYSTEM_MAX 8
236#ifndef LUAT_VFS_FILESYSTEM_MOUNT_MAX
237#define LUAT_VFS_FILESYSTEM_MOUNT_MAX 8
240#ifndef LUAT_VFS_FILESYSTEM_FD_MAX
241#define LUAT_VFS_FILESYSTEM_FD_MAX 16
244struct luat_vfs_file_opts {
245 FILE* (*fopen)(
void* fsdata,
const char *filename,
const char *mode);
246 int (*getc)(
void* fsdata, FILE* stream);
247 int (*fseek)(
void* fsdata, FILE* stream,
long int offset,
int origin);
248 int (*ftell)(
void* fsdata, FILE* stream);
249 int (*fclose)(
void* fsdata, FILE* stream);
250 int (*feof)(
void* fsdata, FILE* stream);
251 int (*ferror)(
void* fsdata, FILE *stream);
252 size_t (*fread)(
void* fsdata,
void *ptr,
size_t size,
size_t nmemb, FILE *stream);
253 size_t (*fwrite)(
void* fsdata,
const void *ptr,
size_t size,
size_t nmemb, FILE *stream);
254 void* (*mmap)(
void* fsdata, FILE *stream);
255 int (*fflush)(
void* fsdata, FILE *stream);
258struct luat_vfs_filesystem_opts {
259 int (*remove)(
void* fsdata,
const char *filename);
260 int (*rename)(
void* fsdata,
const char *old_filename,
const char *new_filename);
261 size_t (*fsize)(
void* fsdata,
const char *filename);
262 int (*fexist)(
void* fsdata,
const char *filename);
267 int (*info)(
void* fsdata,
const char* path,
luat_fs_info_t *conf);
269 int (*mkdir)(
void* fsdata,
char const* _DirName);
270 int (*rmdir)(
void* fsdata,
char const* _DirName);
271 int (*lsdir)(
void* fsdata,
char const* _DirName,
luat_fs_dirent_t* ents,
size_t offset,
size_t len);
273 int (*truncate)(
void* fsdata,
char const* _DirName,
size_t nsize);
276typedef struct luat_vfs_filesystem {
278 struct luat_vfs_filesystem_opts opts;
279 struct luat_vfs_file_opts fopts;
280}luat_vfs_filesystem_t;
282typedef struct luat_vfs_mount {
283 struct luat_vfs_filesystem *fs;
289typedef struct luat_vfs_fd{
291 luat_vfs_mount_t *fsMount;
295typedef struct luat_vfs
297 struct luat_vfs_filesystem* fsList[LUAT_VFS_FILESYSTEM_MAX];
298 luat_vfs_mount_t mounted[LUAT_VFS_FILESYSTEM_MOUNT_MAX];
299 luat_vfs_fd_t fds[LUAT_VFS_FILESYSTEM_FD_MAX+1];
302int luat_vfs_init(
void* params);
303int luat_vfs_reg(
const struct luat_vfs_filesystem* fs);
304FILE* luat_vfs_add_fd(FILE* fd, luat_vfs_mount_t * mount);
305int luat_vfs_rm_fd(FILE* fd);
306const char* luat_vfs_mmap(FILE* fd);
struct luat_fs_conf luat_fs_conf_t
int luat_fs_init(void)
文件系统初始化
int luat_fs_fexist(const char *filename)
文件是否存在,类似于fexist
struct luat_fs_info luat_fs_info_t
int luat_fs_fclose(FILE *stream)
关闭句柄位置,类似于fclose
int luat_fs_fflush(FILE *stream)
int luat_fs_umount(luat_fs_conf_t *conf)
文件系统取消挂载
int luat_fs_ferror(FILE *stream)
是否有文件系统错误,类似于ferror
int luat_fs_dexist(const char *dir)
文件夹是否存在
int luat_fs_feof(FILE *stream)
是否已经到文件结尾,类似于feof
size_t luat_fs_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
读取文件,类似于fread
int luat_fs_readline(char *buf, int bufsize, FILE *stream)
行读取
size_t luat_fs_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
写入文件,类似于fwrite
int luat_fs_fseek(FILE *stream, long int offset, int origin)
设置句柄位置,类似于fseek
struct luat_fs_dirent luat_fs_dirent_t
int luat_fs_rmdir(char const *_DirName)
删除文件夹,必须为空文件夹
int luat_fs_ftell(FILE *stream)
获取句柄位置,类似于ftell
int luat_fs_mount(luat_fs_conf_t *conf)
文件系统挂载
size_t luat_fs_fsize(const char *filename)
文件大小,类似于fsize
int luat_fs_rename(const char *old_filename, const char *new_filename)
文件改名,类似于rename
int luat_fs_getc(FILE *stream)
读到单个字节,类似于getc
FILE * luat_fs_fopen(const char *filename, const char *mode)
打开文件,类似于fopen
int luat_fs_lsdir(char const *_DirName, luat_fs_dirent_t *ents, size_t offset, size_t len)
遍历文件夹
void * luat_fs_mmap(FILE *stream)
获取文件映射地址
int luat_fs_truncate(const char *filename, size_t len)
文件截断
int luat_fs_info(const char *path, luat_fs_info_t *conf)
获取文件系统状态
int luat_fs_mkdir(char const *_DirName)
创建文件夹
int luat_fs_remove(const char *filename)
删除文件,类似于remove
int luat_fs_mkfs(luat_fs_conf_t *conf)
文件系统格式化