XFusion API v1.3.0
载入中...
搜索中...
未找到
xf_vfs.c 文件参考
#include "xf_vfs.h"
#include "xf_vfs_private.h"
xf_vfs.c 的引用(Include)关系图:

浏览源代码.

结构体

struct  fd_table_t
 
struct  fds_triple_t
 
struct  vfs_component_proxy_t
 

宏定义

#define FD_TABLE_ENTRY_UNUSED   (fd_table_t) { .permanent = false, .has_pending_close = false, .has_pending_select = false, .vfs_index = -1, .local_fd = -1 }
 
#define STATIC_ASSERT(EXPR, ...)   extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(EXPR)])]
 
#define _lock_acquire(lock)   xf_lock_lock(lock)
 
#define _lock_release(lock)   xf_lock_unlock(lock)
 
#define xf_strncpy(dst, src, len)   strncpy((dst), (src), (len))
 
#define _LOCAL_FD_T_   uint8_t
 
#define CHECK_AND_CALL(ret, r, pvfs, func, ...)
 
#define CHECK_AND_CALL_SUBCOMPONENT(ret, r, pvfs, component, func, ...)
 
#define CHECK_AND_CALLV(r, pvfs, func, ...)
 
#define CHECK_AND_CALL_SUBCOMPONENTV(r, pvfs, component, func, ...)
 
#define CHECK_AND_CALLP(ret, r, pvfs, func, ...)
 
#define CHECK_AND_CALL_SUBCOMPONENTP(ret, r, pvfs, component, func, ...)
 
#define CHECK_VFS_READONLY_FLAG(flags)
 

类型定义

typedef _LOCAL_FD_T_ local_fd_t
 
typedef int8_t vfs_index_t
 

函数

 STATIC_ASSERT ((1<<(sizeof(local_fd_t) *8)) >=XF_VFS_FDS_MAX, "file descriptor type too small")
 
 STATIC_ASSERT ((1<<(sizeof(vfs_index_t) *8)) >=XF_VFS_MAX_COUNT, "VFS index type too small")
 
 STATIC_ASSERT (((vfs_index_t) -1)< 0, "vfs_index_t must be a signed type")
 
static xf_vfs_ssize_t xf_get_free_index (void)
 
static void xf_vfs_free_fs_ops (xf_vfs_fs_ops_t *vfs)
 
static void xf_vfs_free_entry (xf_vfs_entry_t *entry)
 
static xf_vfs_fs_ops_txf_minify_vfs (const xf_vfs_t *const vfs, vfs_component_proxy_t proxy)
 
static void free_proxy_members (vfs_component_proxy_t *proxy)
 
static xf_vfs_fs_ops_txf_vfs_duplicate_fs_ops (const xf_vfs_fs_ops_t *orig)
 
static xf_err_t xf_vfs_make_fs_ops (const xf_vfs_t *vfs, xf_vfs_fs_ops_t **min)
 
static xf_err_t xf_vfs_register_fs_common (const char *base_path, size_t len, const xf_vfs_fs_ops_t *vfs, int flags, void *ctx, int *vfs_index)
 
static bool fd_valid (int fd)
 
static const xf_vfs_entry_tget_vfs_for_fd (int fd)
 
static int get_local_fd (const xf_vfs_entry_t *vfs, int fd)
 
static const char * translate_path (const xf_vfs_entry_t *vfs, const char *src_path)
 
xf_err_t xf_vfs_register_fs (const char *base_path, const xf_vfs_fs_ops_t *vfs, int flags, void *ctx)
 
xf_err_t xf_vfs_register_common (const char *base_path, size_t len, const xf_vfs_t *vfs, void *ctx, int *vfs_index)
 
xf_err_t xf_vfs_register (const char *base_path, const xf_vfs_t *vfs, void *ctx)
 
xf_err_t xf_vfs_register_fd_range (const xf_vfs_t *vfs, void *ctx, int min_fd, int max_fd)
 
xf_err_t xf_vfs_register_fs_with_id (const xf_vfs_fs_ops_t *vfs, int flags, void *ctx, xf_vfs_id_t *vfs_id)
 
xf_err_t xf_vfs_register_with_id (const xf_vfs_t *vfs, void *ctx, xf_vfs_id_t *vfs_id)
 
xf_err_t xf_vfs_unregister_with_id (xf_vfs_id_t vfs_id)
 
xf_err_t xf_vfs_unregister_fs_with_id (xf_vfs_id_t vfs_id)
 
xf_err_t xf_vfs_unregister (const char *base_path)
 
xf_err_t xf_vfs_unregister_fs (const char *base_path)
 
xf_err_t xf_vfs_register_fd (xf_vfs_id_t vfs_id, int *fd)
 
xf_err_t xf_vfs_register_fd_with_local_fd (xf_vfs_id_t vfs_id, int local_fd, bool permanent, int *fd)
 
xf_err_t xf_vfs_unregister_fd (xf_vfs_id_t vfs_id, int fd)
 
void xf_vfs_dump_fds (void)
 Dump the existing VFS FDs data to FILE* fp
 
void xf_vfs_dump_registered_paths (void)
 Dump all registered FSs to the provided FILE*
 
xf_err_t xf_vfs_set_readonly_flag (const char *base_path)
 
const xf_vfs_entry_txf_vfs_get_vfs_for_index (int index)
 
const xf_vfs_entry_txf_vfs_get_vfs_for_path (const char *path)
 
int xf_vfs_open (const char *path, int flags, int mode)
 
xf_vfs_ssize_t xf_vfs_write (int fd, const void *data, size_t size)
 
xf_vfs_off_t xf_vfs_lseek (int fd, xf_vfs_off_t size, int mode)
 
xf_vfs_ssize_t xf_vfs_read (int fd, void *dst, size_t size)
 
xf_vfs_ssize_t xf_vfs_pread (int fd, void *dst, size_t size, xf_vfs_off_t offset)
 Implements the VFS layer of POSIX pread()
 
xf_vfs_ssize_t xf_vfs_pwrite (int fd, const void *src, size_t size, xf_vfs_off_t offset)
 Implements the VFS layer of POSIX pwrite()
 
int xf_vfs_close (int fd)
 
int xf_vfs_fstat (int fd, xf_vfs_stat_t *st)
 
int xf_vfs_fcntl_r (int fd, int cmd, int arg)
 
int xf_vfs_ioctl (int fd, int cmd,...)
 
int xf_vfs_fsync (int fd)
 
int xf_vfs_stat (const char *path, xf_vfs_stat_t *st)
 
int xf_vfs_utime (const char *path, const xf_vfs_utimbuf_t *times)
 
int xf_vfs_link (const char *n1, const char *n2)
 
int xf_vfs_unlink (const char *path)
 
int xf_vfs_rename (const char *src, const char *dst)
 
xf_vfs_dir_txf_vfs_opendir (const char *name)
 
xf_vfs_dirent_txf_vfs_readdir (xf_vfs_dir_t *pdir)
 
int xf_vfs_readdir_r (xf_vfs_dir_t *pdir, xf_vfs_dirent_t *entry, xf_vfs_dirent_t **out_dirent)
 
long xf_vfs_telldir (xf_vfs_dir_t *pdir)
 
void xf_vfs_seekdir (xf_vfs_dir_t *pdir, long loc)
 
void xf_vfs_rewinddir (xf_vfs_dir_t *pdir)
 
int xf_vfs_closedir (xf_vfs_dir_t *pdir)
 
int xf_vfs_mkdir (const char *name, xf_vfs_mode_t mode)
 
int xf_vfs_rmdir (const char *name)
 
int xf_vfs_access (const char *path, int amode)
 
int xf_vfs_truncate (const char *path, xf_vfs_off_t length)
 
int xf_vfs_ftruncate (int fd, xf_vfs_off_t length)
 
static void call_end_selects (int end_index, const fds_triple_t *vfs_fds_triple, void **driver_args)
 
static bool xf_vfs_safe_fd_isset (int fd, const xf_fd_set *fds)
 
static int set_global_fd_sets (const fds_triple_t *vfs_fds_triple, int size, xf_fd_set *readfds, xf_fd_set *writefds, xf_fd_set *errorfds)
 
static void xf_vfs_log_fd_set (const char *fds_name, const xf_fd_set *fds)
 
int xf_vfs_select (int nfds, xf_fd_set *readfds, xf_fd_set *writefds, xf_fd_set *errorfds, xf_vfs_timeval_t *timeout)
 Synchronous I/O multiplexing which implements the functionality of POSIX select() for VFS
 
void xf_vfs_select_triggered (xf_vfs_select_sem_t sem)
 Notification from a VFS driver about a read/write/error condition
 
void xf_vfs_select_triggered_isr (xf_vfs_select_sem_t sem, int *woken)
 Notification from a VFS driver about a read/write/error condition (ISR version)
 

变量

static const char *const TAG = "xf_vfs"
 
static xf_vfs_entry_ts_vfs [XF_VFS_MAX_COUNT] = { 0 }
 
static size_t s_vfs_count = 0
 
static fd_table_t s_fd_table [XF_VFS_FDS_MAX] = { [0 ... XF_VFS_FDS_MAX - 1] = FD_TABLE_ENTRY_UNUSED }
 
static xf_lock_t s_fd_table_lock
 

详细描述

作者
catcatBlue (catca.nosp@m.tblu.nosp@m.e@qq..nosp@m.com)
版本
1.0
日期
2025-01-13

在文件 xf_vfs.c 中定义.

宏定义说明

◆ FD_TABLE_ENTRY_UNUSED

#define FD_TABLE_ENTRY_UNUSED   (fd_table_t) { .permanent = false, .has_pending_close = false, .has_pending_select = false, .vfs_index = -1, .local_fd = -1 }

Copyright (c) 2024, CorAL. This file has been modified by CorAL under the terms of the Apache License, Version 2.0.

Modifications:

  • Modified by CorAL on 2025-01-10:
    1. modified the naming to prevent conflict with the original project.
    2. Remove posix docking, compatible with other platforms.
    3. removed esp-idf related dependencies.
    4. trimmed termios and other functions.

在文件 xf_vfs.c34 行定义.

◆ STATIC_ASSERT

#define STATIC_ASSERT (   EXPR,
  ... 
)    extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(EXPR)])]

在文件 xf_vfs.c37 行定义.

◆ _lock_acquire

#define _lock_acquire (   lock)    xf_lock_lock(lock)

在文件 xf_vfs.c40 行定义.

◆ _lock_release

#define _lock_release (   lock)    xf_lock_unlock(lock)

在文件 xf_vfs.c41 行定义.

◆ xf_strncpy

#define xf_strncpy (   dst,
  src,
  len 
)    strncpy((dst), (src), (len))

在文件 xf_vfs.c44 行定义.

◆ _LOCAL_FD_T_

#define _LOCAL_FD_T_   uint8_t

在文件 xf_vfs.c50 行定义.

◆ CHECK_AND_CALL

#define CHECK_AND_CALL (   ret,
  r,
  pvfs,
  func,
  ... 
)
值:
if (pvfs->vfs->func == NULL) { \
errno = ENOSYS; \
return -1; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
ret = (*pvfs->vfs->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
ret = (*pvfs->vfs->func)(__VA_ARGS__); \
}
#define XF_VFS_FLAG_CONTEXT_PTR

在文件 xf_vfs.c466 行定义.

◆ CHECK_AND_CALL_SUBCOMPONENT

#define CHECK_AND_CALL_SUBCOMPONENT (   ret,
  r,
  pvfs,
  component,
  func,
  ... 
)
值:
if (pvfs->vfs->component == NULL || pvfs->vfs->component->func == NULL) { \
errno = ENOSYS; \
return -1; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
ret = (*pvfs->vfs->component->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
ret = (*pvfs->vfs->component->func)(__VA_ARGS__); \
}

在文件 xf_vfs.c477 行定义.

◆ CHECK_AND_CALLV

#define CHECK_AND_CALLV (   r,
  pvfs,
  func,
  ... 
)
值:
if (pvfs->vfs->func == NULL) { \
errno = ENOSYS; \
return; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
(*pvfs->vfs->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
(*pvfs->vfs->func)(__VA_ARGS__); \
}

在文件 xf_vfs.c488 行定义.

◆ CHECK_AND_CALL_SUBCOMPONENTV

#define CHECK_AND_CALL_SUBCOMPONENTV (   r,
  pvfs,
  component,
  func,
  ... 
)
值:
if (pvfs->vfs->component == NULL || pvfs->vfs->component->func == NULL) { \
errno = ENOSYS; \
return; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
(*pvfs->vfs->component->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
(*pvfs->vfs->component->func)(__VA_ARGS__); \
}

在文件 xf_vfs.c499 行定义.

◆ CHECK_AND_CALLP

#define CHECK_AND_CALLP (   ret,
  r,
  pvfs,
  func,
  ... 
)
值:
if (pvfs->vfs->func == NULL) { \
errno = ENOSYS; \
return NULL; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
ret = (*pvfs->vfs->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
ret = (*pvfs->vfs->func)(__VA_ARGS__); \
}

在文件 xf_vfs.c510 行定义.

◆ CHECK_AND_CALL_SUBCOMPONENTP

#define CHECK_AND_CALL_SUBCOMPONENTP (   ret,
  r,
  pvfs,
  component,
  func,
  ... 
)
值:
if (pvfs->vfs->component == NULL || pvfs->vfs->component->func == NULL) { \
errno = ENOSYS; \
return NULL; \
} \
if (pvfs->flags & XF_VFS_FLAG_CONTEXT_PTR) { \
ret = (*pvfs->vfs->component->func ## _p)(pvfs->ctx, __VA_ARGS__); \
} else { \
ret = (*pvfs->vfs->component->func)(__VA_ARGS__); \
}

在文件 xf_vfs.c521 行定义.

◆ CHECK_VFS_READONLY_FLAG

#define CHECK_VFS_READONLY_FLAG (   flags)
值:
if (flags & XF_VFS_FLAG_READONLY_FS) { \
errno = EROFS; \
return -1; \
}
#define XF_VFS_FLAG_READONLY_FS

在文件 xf_vfs.c532 行定义.

类型定义说明

◆ local_fd_t

在文件 xf_vfs.c55 行定义.

◆ vfs_index_t

typedef int8_t vfs_index_t

在文件 xf_vfs.c58 行定义.

函数说明

◆ STATIC_ASSERT() [1/3]

STATIC_ASSERT ( (1<<(sizeof(local_fd_t) *8)) >=  XF_VFS_FDS_MAX,
"file descriptor type too small"   
)

◆ STATIC_ASSERT() [2/3]

STATIC_ASSERT ( (1<<(sizeof(vfs_index_t) *8)) >=  XF_VFS_MAX_COUNT,
"VFS index type too small"   
)

◆ STATIC_ASSERT() [3/3]

STATIC_ASSERT ( )

◆ xf_get_free_index()

static xf_vfs_ssize_t xf_get_free_index ( void  )
static

在文件 xf_vfs.c1323 行定义.

◆ xf_vfs_free_fs_ops()

static void xf_vfs_free_fs_ops ( xf_vfs_fs_ops_t vfs)
static

在文件 xf_vfs.c1333 行定义.

◆ xf_vfs_free_entry()

static void xf_vfs_free_entry ( xf_vfs_entry_t entry)
static

在文件 xf_vfs.c1348 行定义.

◆ xf_minify_vfs()

static xf_vfs_fs_ops_t * xf_minify_vfs ( const xf_vfs_t *const  vfs,
vfs_component_proxy_t  proxy 
)
static

在文件 xf_vfs.c1361 行定义.

◆ free_proxy_members()

static void free_proxy_members ( vfs_component_proxy_t proxy)
static

在文件 xf_vfs.c1437 行定义.

◆ xf_vfs_duplicate_fs_ops()

static xf_vfs_fs_ops_t * xf_vfs_duplicate_fs_ops ( const xf_vfs_fs_ops_t orig)
static

在文件 xf_vfs.c1447 行定义.

◆ xf_vfs_make_fs_ops()

static xf_err_t xf_vfs_make_fs_ops ( const xf_vfs_t vfs,
xf_vfs_fs_ops_t **  min 
)
static

在文件 xf_vfs.c1506 行定义.

◆ xf_vfs_register_fs_common()

static xf_err_t xf_vfs_register_fs_common ( const char *  base_path,
size_t  len,
const xf_vfs_fs_ops_t vfs,
int  flags,
void *  ctx,
int *  vfs_index 
)
static

在文件 xf_vfs.c1578 行定义.

◆ fd_valid()

static bool fd_valid ( int  fd)
inlinestatic

在文件 xf_vfs.c1634 行定义.

◆ get_vfs_for_fd()

static const xf_vfs_entry_t * get_vfs_for_fd ( int  fd)
static

在文件 xf_vfs.c1639 行定义.

◆ get_local_fd()

static int get_local_fd ( const xf_vfs_entry_t vfs,
int  fd 
)
inlinestatic

在文件 xf_vfs.c1649 行定义.

◆ translate_path()

static const char * translate_path ( const xf_vfs_entry_t vfs,
const char *  src_path 
)
static

在文件 xf_vfs.c1660 行定义.

◆ xf_vfs_register_common()

xf_err_t xf_vfs_register_common ( const char *  base_path,
size_t  len,
const xf_vfs_t vfs,
void *  ctx,
int *  vfs_index 
)

Register a virtual filesystem.

参数
base_pathfile path prefix associated with the filesystem. Must be a zero-terminated C string, may be empty. If not empty, must be up to XF_VFS_PATH_MAX characters long, and at least 2 characters long. Name must start with a "/" and must not end with "/". For example, "/data" or "/dev/spi" are valid. These VFSes would then be called to handle file paths such as "/data/myfile.txt" or "/dev/spi/0". In the special case of an empty base_path, a "fallback" VFS is registered. Such VFS will handle paths which are not matched by any other registered VFS.
lenLength of the base_path.
vfsPointer to xf_vfs_t, a structure which maps syscalls to the filesystem driver functions. VFS component doesn't assume ownership of this pointer.
ctxIf vfs->flags has XF_VFS_FLAG_CONTEXT_PTR set, a pointer which should be passed to VFS functions. Otherwise, NULL.
vfs_indexIndex for getting the vfs content.
返回
XF_OK if successful. XF_ERR_NO_MEM if too many VFSes are registered. XF_ERR_INVALID_ARG if given an invalid parameter.

在文件 xf_vfs.c146 行定义.

◆ xf_vfs_set_readonly_flag()

xf_err_t xf_vfs_set_readonly_flag ( const char *  base_path)

在文件 xf_vfs.c388 行定义.

◆ xf_vfs_get_vfs_for_index()

const xf_vfs_entry_t * xf_vfs_get_vfs_for_index ( int  index)

Get vfs fd with given vfs index.

参数
indexVFS index.
返回
Pointer to the xf_vfs_entry_t corresponding to the given path, which cannot be NULL.

在文件 xf_vfs.c405 行定义.

◆ xf_vfs_get_vfs_for_path()

const xf_vfs_entry_t * xf_vfs_get_vfs_for_path ( const char *  path)

Get vfs fd with given path.

参数
pathfile path prefix associated with the filesystem.
返回
Pointer to the xf_vfs_entry_t corresponding to the given path, which cannot be NULL.

在文件 xf_vfs.c414 行定义.

◆ call_end_selects()

static void call_end_selects ( int  end_index,
const fds_triple_t vfs_fds_triple,
void **  driver_args 
)
static

在文件 xf_vfs.c971 行定义.

◆ xf_vfs_safe_fd_isset()

static bool xf_vfs_safe_fd_isset ( int  fd,
const xf_fd_set fds 
)
inlinestatic

在文件 xf_vfs.c989 行定义.

◆ set_global_fd_sets()

static int set_global_fd_sets ( const fds_triple_t vfs_fds_triple,
int  size,
xf_fd_set readfds,
xf_fd_set writefds,
xf_fd_set errorfds 
)
static

在文件 xf_vfs.c994 行定义.

◆ xf_vfs_log_fd_set()

static void xf_vfs_log_fd_set ( const char *  fds_name,
const xf_fd_set fds 
)
static

在文件 xf_vfs.c1028 行定义.

变量说明

◆ TAG

const char* const TAG = "xf_vfs"
static

在文件 xf_vfs.c105 行定义.

◆ s_vfs

xf_vfs_entry_t* s_vfs[XF_VFS_MAX_COUNT] = { 0 }
static

在文件 xf_vfs.c107 行定义.

◆ s_vfs_count

size_t s_vfs_count = 0
static

在文件 xf_vfs.c108 行定义.

◆ s_fd_table

fd_table_t s_fd_table[XF_VFS_FDS_MAX] = { [0 ... XF_VFS_FDS_MAX - 1] = FD_TABLE_ENTRY_UNUSED }
static

在文件 xf_vfs.c110 行定义.

◆ s_fd_table_lock

xf_lock_t s_fd_table_lock
static

在文件 xf_vfs.c111 行定义.