From bec327a4ccf60a42c68a78e55d7ed6c5ff9fa66b Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 23 Oct 2023 21:54:32 -0400 Subject: [PATCH] vfs: add tell function --- fs/vfs.c | 12 ++++++++++++ include/fs/vfs.h | 1 + 2 files changed, 13 insertions(+) diff --git a/fs/vfs.c b/fs/vfs.c index 228dcb6..8f635d4 100644 --- a/fs/vfs.c +++ b/fs/vfs.c @@ -152,6 +152,18 @@ int seek(int fd, size_t offset, int whence) return fdesc->pos; } +size_t tell(int fd) +{ + struct rbnode *fdnode = rbt_search(kfd, fd); + + if (!fdnode) + return -EBADF; + + struct file_descriptor *fdesc = (struct file_descriptor *)fdnode->value; + + return fdesc->pos; +} + int mkdir(const char *pathname) { return rootfs->ops.mkdir(rootfs, pathname); diff --git a/include/fs/vfs.h b/include/fs/vfs.h index 8b6d653..d8a7eed 100644 --- a/include/fs/vfs.h +++ b/include/fs/vfs.h @@ -120,6 +120,7 @@ int read(int fd, void *buf, size_t count); int open(const char *pathname, int flags); int close(int fd); int seek(int fd, size_t offset, int whence); +size_t tell(int fd); int statfd(int fd, struct statbuf *statbuf); int mkdir(const char *pathname);