Wed, 06 Dec 2023 23:21:38 +0100
1 files changed,
12 insertions(+),
0 deletions(-)
jump to
M
kernel/file.c
→
kernel/file.c
@@ -79,6 +79,8 @@
file_t *root = get_process_local_file(fd); file_t *handle = &file_table[new_fd]; + if (fd < 0) { return -1; } + if (root->fops->openat == NULL) { return -1; } if (root->fops->openat(root, handle, fname, flags)) { return -1; }@@ -87,6 +89,8 @@ return new_fd;
} int file_read(int fd, char *buffer, uint32_t size) { + if (fd < 0) { return 0; } + file_t *file = get_process_local_file(fd); if (file->fops->read == NULL) { return -1; }@@ -95,6 +99,8 @@ return file->fops->read(file, buffer, size);
} int file_write(int fd, char *buffer, uint32_t size) { + if (fd < 0) { return 0; } + file_t *file = get_process_local_file(fd); if (file->fops->write == NULL) { return -1; }@@ -103,6 +109,8 @@ file->fops->write(file, buffer, size);
} int file_dir_next(int fd, int index, char *fname_buffer) { + if (fd < 0) { return -1; } + file_t *file = get_process_local_file(fd); if (file->fops->dir_next == NULL) { return -1; }@@ -111,6 +119,8 @@ file->fops->dir_next(file, index, fname_buffer);
} off_t file_lseek(int fd, off_t offset, int whence) { + if (fd < 0) { return -1; } + file_t *file = get_process_local_file(fd); if (file->fops->lseek == NULL) { return -1; }@@ -119,6 +129,8 @@ return file->fops->lseek(file, offset, whence);
} off_t file_tell(int fd) { + if (fd < 0) { return -1; } + file_t *file = get_process_local_file(fd); if (file->fops->tell == NULL) { return -1; }