From b808d33c6bf30691b8cdb6cc0fd65f49e7db29f8 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sat, 7 Mar 2020 17:37:49 +1100 Subject: Makefile now correctly calls i386 QEMU instead of x86_64 Changed the type for block addresses from size_t to uint16_t. Added the '%c' conversion specifier to vsprintf(), so that it can now output individual characters passed as arguments. Added a an errno.h header containing a list of commonly used error codes, as well as a basic strerror() routine to fetch corresponding human-readable strings from a table. Implemented barebones floppy driver. Currently lacking many (essential) features, see TODO notes in floppy.c for more details. Buffer structs now have a b_present flag to indicate whether or not the data section is populated, as well as a b_wait element, as a queue for any tasks waiting on the buffer. All tasks waiting on a block wait in this queue, however, the task that originally called the driver to read, may wait in a separate queue maintained by the driver. This system may change in the future, and will likely depend on how head scheduling is implemented in the driver. The buffer_get_block() routine is now publically available in kernel/fs.h. It can be called to retrieve a block from the buffer cache (if readily available), or from the specified block device otherwise. This routine returns a pointer to the buffer containing the cache. The block_read() function now passes arguments and return values to the floppy driver regardless of the device specified. The block_write() function now indicates an error condition by setting b_device to zero in the allocated buffer structure, as no devices with write functionality currently exist. This behaviour will be updated in future, as more block devices are added. The mount_root() function has been modified to call buffer_get_block(), instead of calling block_read() directly. As of now, nothing should call block_read() or block_write() directly, as those functions are intended for use by the buffer subsystem only. --- include/kernel/fd.h | 12 ++++++++++++ include/kernel/fs.h | 10 +++++++--- include/string.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 include/kernel/fd.h (limited to 'include') diff --git a/include/kernel/fd.h b/include/kernel/fd.h new file mode 100644 index 0000000..07cf454 --- /dev/null +++ b/include/kernel/fd.h @@ -0,0 +1,12 @@ +#ifndef _FD_H +#define _FD_H + +#include +#include +#include + +void fd_init(void); + +void fd_block_read(struct buffer*); + +#endif diff --git a/include/kernel/fs.h b/include/kernel/fs.h index 4ec4de1..1b4ed24 100644 --- a/include/kernel/fs.h +++ b/include/kernel/fs.h @@ -52,16 +52,20 @@ struct m_inode { struct buffer { void *b_data; + int b_present; uint16_t b_device; uint16_t b_block; + struct task_struct *b_wait; struct buffer *b_next; struct buffer *b_prev; -} __attribute__((packed)); +}; extern struct super_block sblocks[NRSUPER]; -int block_read(void*, size_t); -int block_write(void*, size_t); +void block_read(struct buffer*); +void block_write(struct buffer*); + +struct buffer *buffer_get_block(uint16_t, uint16_t); void mount_root(void); diff --git a/include/string.h b/include/string.h index d2f738b..88a6ac4 100644 --- a/include/string.h +++ b/include/string.h @@ -33,5 +33,6 @@ char *strpbrk(const char*, const char*); char *strstr(const char*, const char*); char *strtok(char*, const char*); size_t strxfrm(char*, const char*, size_t); +char *strerror(int); #endif -- cgit v1.3