diff --git a/sys/include/vfs.h b/sys/include/vfs.h index 2b547822e0..9029e15080 100644 --- a/sys/include/vfs.h +++ b/sys/include/vfs.h @@ -882,6 +882,21 @@ int vfs_normalize_path(char *buf, const char *path, size_t buflen); */ const vfs_mount_t *vfs_iterate_mounts(const vfs_mount_t *cur); +/** + * @brief Get information about the file for internal purposes + * + * @attention Not thread safe! Do not modify any of the fields in the returned + * struct. + * @note For file descriptor internal usage only. + * + * @internal + * @param[in] fd A file descriptor + * + * @return Pointer to the file information struct if a file with @p fd exists. + * @return NULL, when no file with file descriptor @p fd exists. + */ +const vfs_file_t *vfs_file_get(int fd); + #ifdef __cplusplus } #endif diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 0938e67f86..6cf7232d60 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -864,6 +864,16 @@ const vfs_mount_t *vfs_iterate_mounts(const vfs_mount_t *cur) return container_of(node, vfs_mount_t, list_entry); } +const vfs_file_t *vfs_file_get(int fd) +{ + if (_fd_is_valid(fd) == 0) { + return &_vfs_open_files[fd]; + } + else { + return NULL; + } +} + static inline int _allocate_fd(int fd) { if (fd < 0) {