From 841bc2c7be78b30f5d0e13bb344db78da0ed665d Mon Sep 17 00:00:00 2001 From: Minep Date: Mon, 5 Dec 2022 20:23:52 +0000 Subject: [PATCH] refactor: vfs_open: start opening iff there is a empty fd slot available. --- lunaix-os/kernel/fs/vfs.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lunaix-os/kernel/fs/vfs.c b/lunaix-os/kernel/fs/vfs.c index eff233a..9680f2e 100644 --- a/lunaix-os/kernel/fs/vfs.c +++ b/lunaix-os/kernel/fs/vfs.c @@ -266,11 +266,11 @@ vfs_pclose(struct v_file* file, pid_t pid) atomic_fetch_sub(&file->dnode->ref_count, 1); file->inode->open_count--; - // Prevent dead lock. - // This happened when process is terminated while blocking on read. - // In that case, the process is still holding the inode lock and it will - // never get released. /* + * Prevent dead lock. + * This happened when process is terminated while blocking on read. + * In that case, the process is still holding the inode lock and it + will never get released. * The unlocking should also include ownership check. * * To see why, consider two process both open the same file both with @@ -569,18 +569,17 @@ vfs_do_open(const char* path, int options) { int errno, fd; struct v_dnode *dentry, *file; - struct v_file* ofile = 0; + struct v_file* ofile = NULL; errno = __vfs_try_locate_file( path, &dentry, &file, (options & FO_CREATE) ? FLOCATE_CREATE_EMPTY : 0); - if (errno || (errno = vfs_open(file, &ofile))) { - return errno; - } + if (!errno && !(errno = vfs_alloc_fdslot(&fd))) { - struct v_inode* o_inode = ofile->inode; + if (errno || (errno = vfs_open(file, &ofile))) { + return errno; + } - if (!errno && !(errno = vfs_alloc_fdslot(&fd))) { struct v_fd* fd_s = cake_grab(fd_pile); memset(fd_s, 0, sizeof(*fd_s)); -- 2.27.0