From ef844d88632c8456ed4ddb856bb88f05bcb9fe09 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Fri, 13 Dec 2019 12:30:18 +0100 Subject: [PATCH] vfs: provide function to get internal file information by fd --- sys/include/vfs.h | 15 +++++++++++++++ sys/vfs/vfs.c | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/sys/include/vfs.h b/sys/include/vfs.h index 2b547822e06a..9029e1508027 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 0938e67f86f3..6cf7232d600a 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) {