diff options
| author | Jake Mannens <jake72360@gmail.com> | 2018-09-09 00:19:12 +1000 |
|---|---|---|
| committer | Jake Mannens <jake72360@gmail.com> | 2018-09-09 00:19:12 +1000 |
| commit | 02107df3f476c19bb7eaa3c49a368d703898615b (patch) | |
| tree | 7cbace89d150f2f6c39f3ec5766f7263441fea22 /include | |
| parent | 6d87016287ea76afbdf7e16fb2cf9e4fa20cc0de (diff) | |
Re-ordered system call numbers and definitions into alphabetical order
to make management/maintenance easier.
Defined the structures super_block and m_inode in kernel/fs.h for super
blocks and inodes respectively.
Added the new header file sys/stat.h which contains basic definitions
for inode types and permissions. These definitions will be required by
any functions handling m_inode structures.
Moved the sys_read and sys_write system calls to the filesystem's main
source file at kernel/fs/fs.c.
Added the file kernel/fs/mount.c which will contain the super-blocks
table as well as the function mount_root() which will attempt to mount
the root filesystem during boot. Eventually, this file will be expanded
to include a general-purpose mount function to mount any filesystem as
well as the system call handler for sys_mount.
Seperated block I/O functions into their own subsystem under
kernel/fs/block.c which currently supports two functions; block_read()
and block_write() to read and write blocks from block devices.
Currently, no device can be specified since the primary ATA master drive
is the only possible target. This will change in the future however.
Modified the hard disk driver's read and write functions to use
filesystem blocks rather than sectors as the units of transfer. This is
intended to keep the block I/O subsystem simple by ensuring a uniform
transfer unit is used across all block devices and drivers.
The hard disk driver is no longer initialized during the main boot
procedure. Instead, a call is made to the new function fs_init() which
will setup filesystem tables and structures, call hd_init() to
initialize the disk and finally, attempt to load the super-block for the
root filesystem.
The hard disk driver now stores the disk's size and sanity checks
addresses and sizes in read and write calls against this value.
Diffstat (limited to 'include')
| -rw-r--r-- | include/kernel/fs.h | 46 | ||||
| -rw-r--r-- | include/kernel/hd.h | 7 | ||||
| -rw-r--r-- | include/kernel/sys.h | 33 | ||||
| -rw-r--r-- | include/sys/stat.h | 42 | ||||
| -rw-r--r-- | include/unistd.h | 18 |
5 files changed, 117 insertions, 29 deletions
diff --git a/include/kernel/fs.h b/include/kernel/fs.h index 8f21110..a2b0086 100644 --- a/include/kernel/fs.h +++ b/include/kernel/fs.h @@ -4,10 +4,14 @@ #include <stdint.h> #include <sys/types.h> -#define BLOCK_SIZE 1024 +#define NRSUPER 8 #define NRFILE 128 #define NROPEN 32 +/* these shouldn't change */ +#define BLOCK_SIZE 1024 +#define SUPER_MAGIC 0x137F + struct file { uint16_t f_mode; uint16_t f_flags; @@ -15,4 +19,44 @@ struct file { off_t f_pos; }; +struct super_block { + uint16_t s_ninodes; + uint16_t s_nzones; + uint16_t s_imap_blocks; + uint16_t s_zmap_blocks; + uint16_t s_firstdatazone; + uint16_t s_log_zone_size; + uint32_t s_max_size; + uint16_t s_magic; + /* loaded in memory only */ + struct s_buff *s_imap[8]; + struct s_buff *s_zmap[8]; + uint16_t s_dev; + uint16_t s_dirt; + uint16_t s_start; + uint16_t s_super; + uint16_t s_imap_off; + uint16_t s_zmap_off; + uint16_t s_inode_off; +} __attribute__((packed)); + +struct m_inode { + uint16_t i_mode; + uint16_t i_uid; + uint32_t i_size; + uint32_t i_mtime; + uint8_t i_gid; + uint8_t i_nlinks; + uint16_t i_zone[9]; +} __attribute__((packed)); + +extern struct super_block sblocks[NRSUPER]; + +size_t block_read(void*, size_t , size_t); +size_t block_write(void*, size_t , size_t); + +void mount_root(void); + +void fs_init(void); + #endif diff --git a/include/kernel/hd.h b/include/kernel/hd.h index 292b92e..2a2f3c6 100644 --- a/include/kernel/hd.h +++ b/include/kernel/hd.h @@ -2,8 +2,11 @@ #define _HD_H #include <stdint.h> +#include <sys/types.h> -int hd_read(void*, uint32_t, uint8_t); -int hd_write(void*, uint32_t, uint8_t); +void hd_init(void); + +size_t hd_read_block(void*, size_t , size_t); +size_t hd_write_block(void*, size_t , size_t); #endif diff --git a/include/kernel/sys.h b/include/kernel/sys.h index 1b8be8e..95cfb79 100644 --- a/include/kernel/sys.h +++ b/include/kernel/sys.h @@ -1,31 +1,30 @@ typedef int (*syscall_t) (void); -extern int sys_time(void); -extern int sys_time(void); -extern int sys_getpid(void); -extern int sys_getpdir(void); -extern int sys_signal(void); extern int sys_alarm(void); -extern int sys_pause(void); extern int sys_ctty(void); -extern int sys_read(void); -extern int sys_write(void); +extern int sys_getpdir(void); +extern int sys_getpid(void); extern int sys_kill(void); extern int sys_panic(void); +extern int sys_pause(void); +extern int sys_read(void); +extern int sys_signal(void); +extern int sys_time(void); +extern int sys_write(void); extern int sys_dummy(void); syscall_t call_table[256] = { - [0] = &sys_time, - [1] = &sys_getpid, + [0] = &sys_alarm, + [1] = &sys_ctty, [2] = &sys_getpdir, - [3] = &sys_signal, - [4] = &sys_alarm, - [5] = &sys_pause, - [6] = &sys_ctty, + [3] = &sys_getpid, + [4] = &sys_kill, + [5] = &sys_panic, + [6] = &sys_pause, [7] = &sys_read, - [8] = &sys_write, - [9] = &sys_kill, - [10] = &sys_panic, + [8] = &sys_signal, + [9] = &sys_time, + [10] = &sys_write, [11] = &sys_dummy, [12] = &sys_dummy, [13] = &sys_dummy, diff --git a/include/sys/stat.h b/include/sys/stat.h new file mode 100644 index 0000000..fab014c --- /dev/null +++ b/include/sys/stat.h @@ -0,0 +1,42 @@ +#ifndef _SYS_STAT_H +#define _SYS_STAT_H + +/* permission bits */ + +#define S_IRWXU 0700 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 + +#define S_IRWXG 0070 +#define S_IRGRP 0040 +#define S_IWGRP 0020 +#define S_IXGRP 0010 + +#define S_IRWXO 0007 +#define S_IROTH 0004 +#define S_IWOTH 0002 +#define S_IXOTH 0001 + +/* inode type bits */ + +#define S_IFMT 0170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 + +/* inode type conditionals */ + +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#endif diff --git a/include/unistd.h b/include/unistd.h index cc0f766..47e1621 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -10,17 +10,17 @@ typedef int32_t ssize_t; typedef int16_t pid_t; -#define __SYS_time 0 -#define __SYS_getpid 1 +#define __SYS_alarm 0 +#define __SYS_ctty 1 #define __SYS_getpdir 2 -#define __SYS_signal 3 -#define __SYS_alarm 4 -#define __SYS_pause 5 -#define __SYS_ctty 6 +#define __SYS_getpid 3 +#define __SYS_kill 4 +#define __SYS_panic 5 +#define __SYS_pause 6 #define __SYS_read 7 -#define __SYS_write 8 -#define __SYS_kill 9 -#define __SYS_panic 10 +#define __SYS_signal 8 +#define __SYS_time 9 +#define __SYS_write 10 #define _syscall0(type, name) \ type name(void) { \ |
