From 313abaeb9a29f90b91942d41132bff6f86d41a1d Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 24 Sep 2022 14:55:47 -0300 Subject: [PATCH] misc file bugfixes --- src/fs/devfs.c | 2 +- src/sys/syscalls/lseek.c | 10 +++++++++- src/sys/syscalls/open.c | 1 + src/sys/syscalls/write.c | 3 --- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/fs/devfs.c b/src/fs/devfs.c index 1dabf8d1..e476f684 100644 --- a/src/fs/devfs.c +++ b/src/fs/devfs.c @@ -44,7 +44,7 @@ static int devfs_open(dirnode_t* parent, char* name){ } -static int devfs_close() UNIMPLEMENTED +static int devfs_close(){return 0;} static int devfs_mkdir() UNIMPLEMENTED static int devfs_create() UNIMPLEMENTED static int devfs_write() UNIMPLEMENTED diff --git a/src/sys/syscalls/lseek.c b/src/sys/syscalls/lseek.c index 2c61e8b4..57daa3bf 100644 --- a/src/sys/syscalls/lseek.c +++ b/src/sys/syscalls/lseek.c @@ -24,7 +24,7 @@ syscallret syscall_lseek(int ifd, off_t offset, int whence){ return retv; } - int type = GETTYPE(fd->mode); + int type = GETTYPE(fd->node->st.st_mode); if(type == TYPE_SOCKET || type == TYPE_FIFO){ retv.errno = ESPIPE; @@ -33,6 +33,14 @@ syscallret syscall_lseek(int ifd, off_t offset, int whence){ off_t newoffset = fd->offset; size_t fsize = fd->node->st.st_size; + + if(type == TYPE_CHARDEV || type == TYPE_BLOCKDEV){ + int err = devman_isseekable(fd->node->st.st_rdev, &fsize); + if(err){ + retv.errno = err; + goto _ret; + } + } switch(whence){ case SEEK_SET: diff --git a/src/sys/syscalls/open.c b/src/sys/syscalls/open.c index 8a2d5e97..48d07a9a 100644 --- a/src/sys/syscalls/open.c +++ b/src/sys/syscalls/open.c @@ -79,6 +79,7 @@ syscallret syscall_open(const char* pathname, int flags, mode_t mode){ fd->node = file; + fd->mode = file->st.st_mode; fd_release(fd); diff --git a/src/sys/syscalls/write.c b/src/sys/syscalls/write.c index c2168690..dd029f62 100644 --- a/src/sys/syscalls/write.c +++ b/src/sys/syscalls/write.c @@ -55,9 +55,6 @@ syscallret syscall_write(int ifd, void* buff, size_t count){ fd->offset += writec; - if(fd->node->st.st_size < fd->offset) - fd->offset = fd->node->st.st_size; - retv.errno = 0; retv.ret = writec;