posix: fs: implement fstat() via zvfs_fstat()

Route the fstat() call (part of POSIX_FILE_SYSTEM) to
zvfs_fstat() so that other types of file descriptors can also
supply file status information.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2024-06-08 08:39:56 -04:00 committed by Anas Nashif
parent 1a95246f61
commit 1f9ca63b93
3 changed files with 16 additions and 6 deletions

View file

@ -166,6 +166,7 @@ enum {
ZFD_IOCTL_POLL_UPDATE,
ZFD_IOCTL_POLL_OFFLOAD,
ZFD_IOCTL_SET_LOCK,
ZFD_IOCTL_STAT,
/* Codes above 0x5400 and below 0x5500 are reserved for termios, FIO, etc */
ZFD_IOCTL_FIONREAD = 0x541B,

View file

@ -16,13 +16,15 @@
#include <errno.h>
#include <string.h>
#include <zephyr/posix/fcntl.h>
#include <zephyr/kernel.h>
#include <zephyr/posix/fcntl.h>
#include <zephyr/sys/fdtable.h>
#include <zephyr/sys/speculation.h>
#include <zephyr/internal/syscall_handler.h>
#include <zephyr/sys/atomic.h>
struct stat;
struct fd_entry {
void *obj;
const struct fd_op_vtable *vtable;
@ -349,6 +351,15 @@ int zvfs_close(int fd)
return res;
}
int zvfs_fstat(int fd, struct stat *buf)
{
if (_check_fd(fd) < 0) {
return -1;
}
return z_fdtable_call_ioctl(fdtable[fd].vtable, fdtable[fd].obj, ZFD_IOCTL_STAT, buf);
}
int zvfs_fsync(int fd)
{
if (_check_fd(fd) < 0) {

View file

@ -15,6 +15,8 @@
#include <zephyr/posix/fcntl.h>
#include <zephyr/fs/fs.h>
int zvfs_fstat(int fd, struct stat *buf);
BUILD_ASSERT(PATH_MAX >= MAX_FILE_NAME, "PATH_MAX is less than MAX_FILE_NAME");
struct posix_fs_desc {
@ -432,11 +434,7 @@ int zvfs_ftruncate(int fd, off_t length)
int fstat(int fildes, struct stat *buf)
{
ARG_UNUSED(fildes);
ARG_UNUSED(buf);
errno = ENOTSUP;
return -1;
return zvfs_fstat(fildes, buf);
}
#ifdef CONFIG_POSIX_FILE_SYSTEM_ALIAS_FSTAT
FUNC_ALIAS(fstat, _fstat, int);