From cadab2cbcfa30ddc406d2cfe9a482cb1cf43299a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 20 Mar 2020 13:36:44 +0100 Subject: [PATCH] vfs: define all implementations as esp_vfs_, create aliases This change allows (in the future) to test VFS on host, without having it conflict with the host C library. On host, all aliases would be disabled. --- components/vfs/vfs.c | 117 ++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 39 deletions(-) diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index 7118e83dbe..005d050d48 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -631,35 +631,7 @@ int esp_vfs_rename(struct _reent *r, const char *src, const char *dst) return ret; } -/* Create aliases for newlib syscalls - - These functions are also available in ROM as stubs which use the syscall table, but linking them - directly here saves an additional function call when a software function is linked to one, and - makes linking with -stdlib easier. - */ -int _open_r(struct _reent *r, const char * path, int flags, int mode) - __attribute__((alias("esp_vfs_open"))); -ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) - __attribute__((alias("esp_vfs_write"))); -off_t _lseek_r(struct _reent *r, int fd, off_t size, int mode) - __attribute__((alias("esp_vfs_lseek"))); -ssize_t _read_r(struct _reent *r, int fd, void * dst, size_t size) - __attribute__((alias("esp_vfs_read"))); -int _close_r(struct _reent *r, int fd) - __attribute__((alias("esp_vfs_close"))); -int _fstat_r(struct _reent *r, int fd, struct stat * st) - __attribute__((alias("esp_vfs_fstat"))); -int _stat_r(struct _reent *r, const char * path, struct stat * st) - __attribute__((alias("esp_vfs_stat"))); -int _link_r(struct _reent *r, const char* n1, const char* n2) - __attribute__((alias("esp_vfs_link"))); -int _unlink_r(struct _reent *r, const char *path) - __attribute__((alias("esp_vfs_unlink"))); -int _rename_r(struct _reent *r, const char *src, const char *dst) - __attribute__((alias("esp_vfs_rename"))); - - -DIR* opendir(const char* name) +DIR* esp_vfs_opendir(const char* name) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); @@ -676,7 +648,7 @@ DIR* opendir(const char* name) return ret; } -struct dirent* readdir(DIR* pdir) +struct dirent* esp_vfs_readdir(DIR* pdir) { const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx); struct _reent* r = __getreent(); @@ -689,7 +661,7 @@ struct dirent* readdir(DIR* pdir) return ret; } -int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) +int esp_vfs_readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) { const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx); struct _reent* r = __getreent(); @@ -702,7 +674,7 @@ int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) return ret; } -long telldir(DIR* pdir) +long esp_vfs_telldir(DIR* pdir) { const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx); struct _reent* r = __getreent(); @@ -715,7 +687,7 @@ long telldir(DIR* pdir) return ret; } -void seekdir(DIR* pdir, long loc) +void esp_vfs_seekdir(DIR* pdir, long loc) { const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx); struct _reent* r = __getreent(); @@ -726,12 +698,12 @@ void seekdir(DIR* pdir, long loc) CHECK_AND_CALLV(r, vfs, seekdir, pdir, loc); } -void rewinddir(DIR* pdir) +void esp_vfs_rewinddir(DIR* pdir) { seekdir(pdir, 0); } -int closedir(DIR* pdir) +int esp_vfs_closedir(DIR* pdir) { const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx); struct _reent* r = __getreent(); @@ -744,7 +716,7 @@ int closedir(DIR* pdir) return ret; } -int mkdir(const char* name, mode_t mode) +int esp_vfs_mkdir(const char* name, mode_t mode) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); @@ -758,7 +730,7 @@ int mkdir(const char* name, mode_t mode) return ret; } -int rmdir(const char* name) +int esp_vfs_rmdir(const char* name) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); @@ -772,7 +744,7 @@ int rmdir(const char* name) return ret; } -int access(const char *path, int amode) +int esp_vfs_access(const char *path, int amode) { int ret; const vfs_entry_t* vfs = get_vfs_for_path(path); @@ -786,7 +758,7 @@ int access(const char *path, int amode) return ret; } -int truncate(const char *path, off_t length) +int esp_vfs_truncate(const char *path, off_t length) { int ret; const vfs_entry_t* vfs = get_vfs_for_path(path); @@ -1198,9 +1170,76 @@ int tcsendbreak(int fd, int duration) #endif // CONFIG_VFS_SUPPORT_TERMIOS +/* Create aliases for newlib syscalls + These functions are also available in ROM as stubs which use the syscall table, but linking them + directly here saves an additional function call when a software function is linked to one, and + makes linking with -stdlib easier. + */ +#ifdef CONFIG_VFS_SUPPORT_IO +int _open_r(struct _reent *r, const char * path, int flags, int mode) + __attribute__((alias("esp_vfs_open"))); +int _close_r(struct _reent *r, int fd) + __attribute__((alias("esp_vfs_close"))); +ssize_t _read_r(struct _reent *r, int fd, void * dst, size_t size) + __attribute__((alias("esp_vfs_read"))); +ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) + __attribute__((alias("esp_vfs_write"))); +ssize_t pread(int fd, void *dst, size_t size, off_t offset) + __attribute__((alias("esp_vfs_pread"))); +ssize_t pwrite(int fd, const void *src, size_t size, off_t offset) + __attribute__((alias("esp_vfs_pwrite"))); +off_t _lseek_r(struct _reent *r, int fd, off_t size, int mode) + __attribute__((alias("esp_vfs_lseek"))); +int _fcntl_r(struct _reent *r, int fd, int cmd, int arg) + __attribute__((alias("esp_vfs_fcntl_r"))); +int _fstat_r(struct _reent *r, int fd, struct stat * st) + __attribute__((alias("esp_vfs_fstat"))); +int fsync(int fd) + __attribute__((alias("esp_vfs_fsync"))); +int ioctl(int fd, int cmd, ...) + __attribute__((alias("esp_vfs_ioctl"))); +#endif // CONFIG_VFS_SUPPORT_IO +#ifdef CONFIG_VFS_SUPPORT_SELECT +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout) + __attribute__((alias("esp_vfs_select"))); +#endif // CONFIG_VFS_SUPPORT_SELECT +#ifdef CONFIG_VFS_SUPPORT_DIR +int _stat_r(struct _reent *r, const char * path, struct stat * st) + __attribute__((alias("esp_vfs_stat"))); +int _link_r(struct _reent *r, const char* n1, const char* n2) + __attribute__((alias("esp_vfs_link"))); +int _unlink_r(struct _reent *r, const char *path) + __attribute__((alias("esp_vfs_unlink"))); +int _rename_r(struct _reent *r, const char *src, const char *dst) + __attribute__((alias("esp_vfs_rename"))); +int truncate(const char *path, off_t length) + __attribute__((alias("esp_vfs_truncate"))); +int access(const char *path, int amode) + __attribute__((alias("esp_vfs_access"))); +int utime(const char *path, const struct utimbuf *times) + __attribute__((alias("esp_vfs_utime"))); +int rmdir(const char* name) + __attribute__((alias("esp_vfs_rmdir"))); +int mkdir(const char* name, mode_t mode) + __attribute__((alias("esp_vfs_mkdir"))); +DIR* opendir(const char* name) + __attribute__((alias("esp_vfs_opendir"))); +int closedir(DIR* pdir) + __attribute__((alias("esp_vfs_closedir"))); +int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) + __attribute__((alias("esp_vfs_readdir_r"))); +struct dirent* readdir(DIR* pdir) + __attribute__((alias("esp_vfs_readdir"))); +long telldir(DIR* pdir) + __attribute__((alias("esp_vfs_telldir"))); +void seekdir(DIR* pdir, long loc) + __attribute__((alias("esp_vfs_seekdir"))); +void rewinddir(DIR* pdir) + __attribute__((alias("esp_vfs_rewinddir"))); +#endif // CONFIG_VFS_SUPPORT_DIR void vfs_include_syscalls_impl(void) {