mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
fd: bugfixes
- add an extra check - properly set the fd entry in the table to 0 in a refcount > 0 free - only close the fd node if there's an open node
This commit is contained in:
+5
-3
@@ -13,7 +13,7 @@ int fd_release(fd_t* fd){
|
|||||||
int fd_access(fdtable_t* fdtable, fd_t** fd, int ifd){
|
int fd_access(fdtable_t* fdtable, fd_t** fd, int ifd){
|
||||||
spinlock_acquire(&fdtable->lock);
|
spinlock_acquire(&fdtable->lock);
|
||||||
|
|
||||||
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL){
|
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL || fdtable->fd[ifd]->node == NULL){
|
||||||
spinlock_release(&fdtable->lock);
|
spinlock_release(&fdtable->lock);
|
||||||
return EBADF;
|
return EBADF;
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,7 @@ int fd_free(fdtable_t* fdtable, int ifd){
|
|||||||
spinlock_acquire(&fd->lock);
|
spinlock_acquire(&fd->lock);
|
||||||
|
|
||||||
if(--fd->refcount > 0){
|
if(--fd->refcount > 0){
|
||||||
|
fdtable->fd[ifd] = NULL;
|
||||||
spinlock_release(&fd->lock);
|
spinlock_release(&fd->lock);
|
||||||
spinlock_release(&fdtable->lock);
|
spinlock_release(&fdtable->lock);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -101,8 +102,9 @@ int fd_free(fdtable_t* fdtable, int ifd){
|
|||||||
fdtable->fd[ifd] = NULL;
|
fdtable->fd[ifd] = NULL;
|
||||||
|
|
||||||
spinlock_release(&fdtable->lock);
|
spinlock_release(&fdtable->lock);
|
||||||
|
int err = 0;
|
||||||
int err = vfs_close(fd->node);
|
if(fd->node)
|
||||||
|
err = vfs_close(fd->node);
|
||||||
|
|
||||||
free(fd);
|
free(fd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user