From: quzar <qu...@us...> - 2024-07-05 06:57:22
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 4de3b94311fcff91f860c62cf565dd56dece209f (commit) via dd953d2dcb233506f7292ce84a4e2cd2559ab913 (commit) from d604fc0f7d2b5cbe181d940451592fd280b88caf (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4de3b94311fcff91f860c62cf565dd56dece209f Author: Andy Barajas <and...@gm...> Date: Thu Jul 4 23:56:04 2024 -0700 Returned to some old ways of checking ref counts (#660) * Roll back the behavior of fs_fdtbl_destroy to how it was, before PR #599. This ensures that both all fds are cleaned up and that it's safe for use with dup'd files. * Have fs_shutdown run before shutting down any of the vfses. * Rearrange fs_hnd_unref to ensure that it frees handles even if they have no handler. commit dd953d2dcb233506f7292ce84a4e2cd2559ab913 Author: UnknownShadow200 <unk...@gm...> Date: Thu Jul 4 12:50:21 2024 +1000 CDFS: Set errno on error (#652) ----------------------------------------------------------------------- Summary of changes: kernel/arch/dreamcast/fs/fs_iso9660.c | 34 ++++++++++++++++++++++++++-------- kernel/arch/dreamcast/kernel/init.c | 2 +- kernel/fs/fs.c | 30 ++++++++++-------------------- kernel/fs/fs_pty.c | 10 +++++----- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/kernel/arch/dreamcast/fs/fs_iso9660.c b/kernel/arch/dreamcast/fs/fs_iso9660.c index ce8e2cb8..f8445cad 100644 --- a/kernel/arch/dreamcast/fs/fs_iso9660.c +++ b/kernel/arch/dreamcast/fs/fs_iso9660.c @@ -603,19 +603,26 @@ static void * iso_open(vfs_handler_t * vfs, const char *fn, int mode) { (void)vfs; /* Make sure they don't want to open things as writeable */ - if((mode & O_MODE_MASK) != O_RDONLY) + if((mode & O_MODE_MASK) != O_RDONLY) { + errno = EROFS; return 0; + } /* Do this only when we need to (this is still imperfect) */ - if(!percd_done && init_percd() < 0) + if(!percd_done && init_percd() < 0) { + errno = ENODEV; return 0; + } percd_done = 1; /* Find the file we want */ de = find_object_path(fn, (mode & O_DIR) ? 1 : 0, &root_dirent); - if(!de) return 0; + if(!de) { + errno = ENOENT; + return 0; + } /* Find a free file handle */ mutex_lock(&fh_mutex); @@ -628,8 +635,10 @@ static void * iso_open(vfs_handler_t * vfs, const char *fn, int mode) { mutex_unlock(&fh_mutex); - if(fd >= FS_CD_MAX_FILES) + if(fd >= FS_CD_MAX_FILES) { + errno = ENFILE; return 0; + } /* Fill in the file handle and return the fd */ fh[fd].first_extent = iso_733(de->extent); @@ -660,8 +669,10 @@ static ssize_t iso_read(void * h, void *buf, size_t bytes) { file_t fd = (file_t)h; /* Check that the fd is valid */ - if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) + if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) { + errno = EBADF; return -1; + } rv = 0; outbuf = (uint8 *)buf; @@ -707,7 +718,10 @@ static ssize_t iso_read(void * h, void *buf, size_t bytes) { /* Do the read */ c = bdread(fh[fd].first_extent + fh[fd].ptr / 2048); - if(c < 0) return -1; + if(c < 0) { + errno = EIO; + return -1; + } memcpy(outbuf, dcache[c]->data + (fh[fd].ptr % 2048), toread); /* } */ @@ -776,8 +790,10 @@ static off_t iso_seek(void * h, off_t offset, int whence) { static off_t iso_tell(void * h) { file_t fd = (file_t)h; - if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) + if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) { + errno = EBADF; return -1; + } return fh[fd].ptr; } @@ -786,8 +802,10 @@ static off_t iso_tell(void * h) { static size_t iso_total(void * h) { file_t fd = (file_t)h; - if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) + if(fd >= FS_CD_MAX_FILES || fh[fd].first_extent == 0 || fh[fd].broken) { + errno = EBADF; return -1; + } return fh[fd].size; } diff --git a/kernel/arch/dreamcast/kernel/init.c b/kernel/arch/dreamcast/kernel/init.c index 1c6bbd4d..6c71b278 100644 --- a/kernel/arch/dreamcast/kernel/init.c +++ b/kernel/arch/dreamcast/kernel/init.c @@ -246,12 +246,12 @@ void __weak arch_auto_shutdown(void) { #if defined(__NEWLIB__) && !(__NEWLIB__ < 2 && __NEWLIB_MINOR__ < 4) fs_rnd_shutdown(); #endif + fs_shutdown(); fs_ramdisk_shutdown(); KOS_INIT_FLAG_CALL(fs_romdisk_shutdown); fs_pty_shutdown(); fs_null_shutdown(); fs_dev_shutdown(); - fs_shutdown(); thd_shutdown(); rtc_shutdown(); } diff --git a/kernel/fs/fs.c b/kernel/fs/fs.c index a4e745b1..ee9b7e51 100644 --- a/kernel/fs/fs.c +++ b/kernel/fs/fs.c @@ -169,22 +169,18 @@ static void fs_hnd_ref(fs_hnd_t * ref) { to a raw handle is no longer applicable. This function may destroy the file handle, so under no circumstances should you presume that it will still exist later. */ -static int fs_hnd_unref(fs_hnd_t * ref) { +static int fs_hnd_unref(fs_hnd_t *ref) { int retval = 0; assert(ref); assert(ref->refcnt > 0); - ref->refcnt--; - if(ref->refcnt == 0) { - if(ref->handler != NULL) { - if(ref->handler->close == NULL) return retval; + if(--ref->refcnt > 0) + return retval; /* Still references left, nothing to do */ - retval = ref->handler->close(ref->hnd); - } - - free(ref); - } + if(ref->handler && ref->handler->close) + retval = ref->handler->close(ref->hnd); + free(ref); return retval; } @@ -214,17 +210,11 @@ static int fs_hnd_assign(fs_hnd_t * hnd) { int fs_fdtbl_destroy(void) { int i; - for (i = 0; i < FD_SETSIZE; i++) { - fs_hnd_t *handle = fd_table[i]; + for(i = 0; i < FD_SETSIZE; i++) { + if(fd_table[i]) + fs_hnd_unref(fd_table[i]); - if(handle) { - if(handle->handler && handle->handler->close) { - handle->handler->close(handle->hnd); - } - - free(handle); - fd_table[i] = NULL; - } + fd_table[i] = NULL; } return 0; diff --git a/kernel/fs/fs_pty.c b/kernel/fs/fs_pty.c index 55147fe4..27028ed1 100644 --- a/kernel/fs/fs_pty.c +++ b/kernel/fs/fs_pty.c @@ -108,7 +108,7 @@ static void pty_destroy_unused(void); #define PF_DIR 1 /* Creates a pty pair */ -int fs_pty_create(char * buffer, int maxbuflen, file_t * master_out, file_t * slave_out) { +int fs_pty_create(char *buffer, int maxbuflen, file_t *master_out, file_t *slave_out) { ptyhalf_t *master, *slave; int boot; char mname[16], sname[16]; @@ -208,7 +208,7 @@ cleanup: /* Autoclean totally unreferenced PTYs (zero refcnt). */ /* XXX This is a kinda nasty piece of code... goto!! */ static void pty_destroy_unused(void) { - ptyhalf_t * c, * n; + ptyhalf_t *c, *n; int old; /* Make sure no one else is messing with the list and then disable @@ -427,8 +427,8 @@ static void * pty_open(vfs_handler_t * vfs, const char * fn, int mode) { } /* Close pty or dirlist */ -static int pty_close(void * h) { - pipefd_t * fdobj; +static int pty_close(void *h) { + pipefd_t *fdobj; assert(h); fdobj = (pipefd_t *)h; @@ -699,7 +699,7 @@ static int pty_ioctl(void *h, int cmd, va_list ap) { switch (cmd) { case TIOCGETA: - if (arg == NULL) { + if(arg == NULL) { errno = EINVAL; return -1; } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |