diff --git a/src/dirent.c b/src/dirent.c index caafe52..a1c0015 100644 --- a/src/dirent.c +++ b/src/dirent.c @@ -110,14 +110,10 @@ int closedir(Thread *t, DIR *dir) { if(!descriptor) return -EBADF; // destroy the descriptor - if(!p->io[dd].clone) - free(p->io[dd].data); - p->io[dd].valid = false; p->io[dd].type = 0; p->io[dd].flags = 0; p->io[dd].data = NULL; - p->io[dd].clone = false; p->iodCount--; return 0; diff --git a/src/include/kernel/file.h b/src/include/kernel/file.h index c81519c..77c5ef5 100644 --- a/src/include/kernel/file.h +++ b/src/include/kernel/file.h @@ -30,6 +30,7 @@ typedef struct { char path[MAX_FILE_PATH]; // path relative to device mountpount off_t position; uint64_t id; // unique ID, this is for device files + int refCount; } FileDescriptor; /* file system syscalls */ diff --git a/src/include/kernel/io.h b/src/include/kernel/io.h index d2affb0..96cacd9 100644 --- a/src/include/kernel/io.h +++ b/src/include/kernel/io.h @@ -44,7 +44,7 @@ // TODO: decide whether to implement named pipes as files or an independent type typedef struct IODescriptor { - bool valid, clone; + bool valid; int type; uint16_t flags; void *data; // file or socket-specific data diff --git a/src/io.c b/src/io.c index 381d5e6..21ed087 100644 --- a/src/io.c +++ b/src/io.c @@ -39,7 +39,6 @@ int openIO(void *pv, void **iodv) { if(desc >= MAX_IO_DESCRIPTORS) return -EMFILE; p->io[desc].valid = true; - p->io[desc].clone = false; p->io[desc].type = IO_WAITING; p->io[desc].data = NULL; @@ -134,16 +133,6 @@ int close(Thread *t, int fd) { if(!p->io[fd].valid || !p->io[fd].data) return -EBADF; - if(p->io[fd].clone) { - p->io[fd].valid = false; - p->io[fd].clone = false; - p->io[fd].type = 0; - p->io[fd].flags = 0; - p->io[fd].data = NULL; - - return 0; - } - if(p->io[fd].type == IO_SOCKET) return closeSocket(t, fd); else if(p->io[fd].type == IO_FILE) return closeFile(t, fd); else return -EBADF; diff --git a/src/sched/fork.c b/src/sched/fork.c index 1afc7eb..0901279 100644 --- a/src/sched/fork.c +++ b/src/sched/fork.c @@ -88,9 +88,6 @@ pid_t fork(Thread *t) { memcpy(p->io, parent->io, sizeof(IODescriptor) * MAX_IO_DESCRIPTORS); p->iodCount = parent->iodCount; - for(int i = 0; i < MAX_IO_DESCRIPTORS; i++) - if(p->io[i].valid) p->io[i].clone = true; - // clone working directory strcpy(p->cwd, parent->cwd);