vfs: provide function to get internal file information by fd

This commit is contained in:
Martine S. Lenders 2019-12-13 12:30:18 +01:00
parent e1d27cb7d5
commit ef844d8863
No known key found for this signature in database
GPG Key ID: CCD317364F63286F
2 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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) {