Skip to content

Commit

Permalink
vfs: provide function to get internal file information by fd
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Jul 1, 2020
1 parent e1d27cb commit ef844d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sys/include/vfs.h
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sys/vfs/vfs.c
Expand Up @@ -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) {
Expand Down

0 comments on commit ef844d8

Please sign in to comment.