diff --git a/headers/private/kernel/fs/fd.h b/headers/private/kernel/fs/fd.h index 4d1559ddec..1ed605b295 100644 --- a/headers/private/kernel/fs/fd.h +++ b/headers/private/kernel/fs/fd.h @@ -79,6 +79,7 @@ extern struct file_descriptor *alloc_fd(void); extern int new_fd_etc(struct io_context *, struct file_descriptor *, int firstIndex); extern int new_fd(struct io_context *, struct file_descriptor *); extern struct file_descriptor *get_fd(struct io_context *, int); +extern struct file_descriptor *get_open_fd(struct io_context *, int); extern void close_fd(struct file_descriptor *descriptor); extern status_t close_fd_index(struct io_context *context, int fd); extern void put_fd(struct file_descriptor *descriptor); diff --git a/src/system/kernel/fs/fd.cpp b/src/system/kernel/fs/fd.cpp index fe50bc2827..b2078231d5 100644 --- a/src/system/kernel/fs/fd.cpp +++ b/src/system/kernel/fs/fd.cpp @@ -303,6 +303,21 @@ get_fd(struct io_context *context, int fd) } +struct file_descriptor * +get_open_fd(struct io_context *context, int fd) +{ + MutexLocker(context->io_mutex); + + file_descriptor *descriptor = get_fd_locked(context, fd); + if (descriptor == NULL) + return NULL; + + atomic_add(&descriptor->open_count, 1); + + return descriptor; +} + + /** Removes the file descriptor from the specified slot. */