summaryrefslogtreecommitdiffstats
path: root/sw-old/z80/kernel/include/fs
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-10-30 11:41:24 +0100
committerNao Pross <naopross@thearcway.org>2018-10-30 11:41:24 +0100
commit43be150dc6e84f6f6eeb071cd3cdb7fc21125d60 (patch)
tree541fd3d690c1bdfd7b68d684029a400b80f4aa06 /sw-old/z80/kernel/include/fs
parentAdd datasheets for ATmega328 and 74LS259 (diff)
downloadz80uPC-43be150dc6e84f6f6eeb071cd3cdb7fc21125d60.tar.gz
z80uPC-43be150dc6e84f6f6eeb071cd3cdb7fc21125d60.zip
Move sw to sw-old and hw to hw-altium, add kicad files
Diffstat (limited to 'sw-old/z80/kernel/include/fs')
-rw-r--r--sw-old/z80/kernel/include/fs/dev.h29
-rw-r--r--sw-old/z80/kernel/include/fs/dirent.h17
-rw-r--r--sw-old/z80/kernel/include/fs/fd.h102
-rw-r--r--sw-old/z80/kernel/include/fs/fdop.h140
-rw-r--r--sw-old/z80/kernel/include/fs/fs.h63
-rw-r--r--sw-old/z80/kernel/include/fs/iter.h17
-rw-r--r--sw-old/z80/kernel/include/fs/users.h21
7 files changed, 389 insertions, 0 deletions
diff --git a/sw-old/z80/kernel/include/fs/dev.h b/sw-old/z80/kernel/include/fs/dev.h
new file mode 100644
index 0000000..8e550f3
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/dev.h
@@ -0,0 +1,29 @@
+#ifndef DEV_H
+#define DEV_H
+
+#include "types.h"
+
+#define FS_MOUNT_LIMIT 16
+
+struct fs_superblock
+{
+ uint8_t magic; // identifier
+
+ size_t blk_size; // size of a single block
+ size_t imap_size; // quantity of inodes
+ size_t dmap_size; // quantity of blocks
+};
+
+struct fs_dev
+{
+ uint enabled :1; // in use
+ uint port_no :3; // serial port number
+ uint :4;
+ inode_t inode; // dir mounted
+ struct fs_superblock superblock; // block informations
+};
+
+/* list of devices */
+extern struct fs_dev devices[FS_MOUNT_LIMIT];
+
+#endif
diff --git a/sw-old/z80/kernel/include/fs/dirent.h b/sw-old/z80/kernel/include/fs/dirent.h
new file mode 100644
index 0000000..2fd224a
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/dirent.h
@@ -0,0 +1,17 @@
+#ifndef __DIRENT_H__
+#define __DIRENT_H__
+
+#include "types.h"
+
+struct dirent
+{
+ ino_t inode; // inode referred
+ uint8_t name_size; // size of the name
+ char name[]; // name of the referred inode
+};
+
+/* if inode is FS_INO_NULL, then the dirent is a memory leak */
+/* Warning: dirent leaks are generated by rm or rmdir operations */
+/* Filesystem must be periodically checked and cleaned */
+
+#endif // __DIRENT_H__
diff --git a/sw-old/z80/kernel/include/fs/fd.h b/sw-old/z80/kernel/include/fs/fd.h
new file mode 100644
index 0000000..d2fea2a
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/fd.h
@@ -0,0 +1,102 @@
+#ifndef __FD_H__
+#define __FD_H__
+
+#include "types.h"
+
+#define FD_MAX 32
+
+#define OPEN_READ 0x1
+#define OPEN_WRITE 0x2
+#define OPEN_BIN 0x4
+#define OPEN_APPEND 0x8
+#define OPEN_ERASE 0x10
+#define OPEN_DIR 0x20
+#define OPEN_LINK 0x40
+
+#define LS_ALL 0x1
+
+/* declare dirent, not include */
+#ifndef __DIRENT_H__
+struct dirent;
+#endif
+
+/* set of operations callback for fd */
+struct fd_operations
+{
+ size_t (*readline)(inode_t, fsize_t, char *, char term);
+ size_t (*print)(inode_t, fsize_t, const char *);
+ size_t (*append)(inode_t, fsize_t*, const char *);
+
+ size_t (*read)(inode_t, fsize_t, void *, size_t);
+ size_t (*write)(inode_t, fsize_t, const void *, size_t);
+ size_t (*bin_append)(inode_t, fsize_t*, const void *, size_t);
+
+ size_t (*ls)(inode_t, struct dirent *, uint8_t);
+ size_t (*find)(inode_t, struct dirent *, const char *);
+ int8_t (*mkdir)(inode_t, const char *);
+ int8_t (*rmdir)(inode_t, const char *);
+ int8_t (*touch)(inode_t, const char *);
+ int8_t (*rm)(inode_t, const char *);
+ int8_t (*ln)(inode_t, const char *, const char *);
+
+ int8_t (*special)(inode_t, void *, size_t);
+};
+
+/* file descriptor */
+struct file_desc
+{
+ inode_t inode; // inode pointed
+ fsize_t seek; // virtual seek
+ devsize_t begin; // beginning of blocks
+ struct fd_operations opers; // bound operations
+};
+
+/* bitmap of used file descriptors */
+extern struct uint8_t fd_bmap[FD_TABLE_SIZE / 8];
+
+/* table of file descriptors */
+extern struct file_desc fd_table[FD_TABLE_SIZE];
+
+/* returns a free file descriptor */
+int8_t __fd_new();
+
+/* opens a file streaming of the cwd */
+int8_t __open_c_inode(uint8_t flags);
+
+/* opens a file streaming by a path */
+int8_t open(const char *path, uint8_t flags);
+
+/* list content of directory */
+size_t ls(int8_t fd, struct dirent *buf, uint8_t all);
+
+/* find name through the directory entries */
+size_t find(int8_t fd, struct dirent *buf, const char *name);
+
+/* creates a new directory inside fd with the specified name */
+int8_t mkdir(int8_t fd, const char *name);
+
+/* creates a new file inside fd with the specified name */
+int8_t touch(int8_t fd, const char *name);
+
+/* creates a new symlink inside fd with the specified name */
+int8_t ln(int8_t fd, const char *name);
+
+/* change virtual seek position of the fd */
+int8_t seek(int8_t fd, fsize_t pos);
+
+/* reads a string from the fd until the terminator is reached */
+size_t readline(int8_t fd, char *buf, char term);
+
+/* writes a string into the fd */
+int8_t print(int8_t fd, const char *str);
+
+/* reads n bytes from the fd */
+size_t read(int8_t fd, void *buf, size_t n);
+
+/* writes n bytes into the fd */
+int8_t write(int8_t fd, const void *buf, size_t n);
+
+/* frees fd space */
+void close(int8_t fd);
+
+#endif // __FD_H__
diff --git a/sw-old/z80/kernel/include/fs/fdop.h b/sw-old/z80/kernel/include/fs/fdop.h
new file mode 100644
index 0000000..d4b1b77
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/fdop.h
@@ -0,0 +1,140 @@
+#ifndef __FDOP_H__
+#define __FDOP_H__
+
+#include "types.h"
+
+#ifndef __DIRENT_H__
+struct dirent;
+#endif
+
+/* macro for direct binding */
+
+#define FD_BIND_AS_DIR(oper) { \
+ oper.ls = &as_ls; \
+ oper.find = &as_find; \
+ oper.mkdir = &as_mkdir; \
+ oper.rmdir = &as_rmdir; \
+ oper.touch = &as_touch; \
+ oper.rm = &as_rm; \
+ oper.ln = &as_ln; \
+ }
+
+#define FD_BIND_SS_DIR(oper) { \
+ oper.ls = &ss_ls; \
+ oper.find = &ss_find; \
+ oper.mkdir = &ss_mkdir; \
+ oper.rmdir = &ss_rmdir; \
+ oper.touch = &ss_touch; \
+ oper.rm = &ss_rm; \
+ oper.ln = &ss_ln; \
+ }
+
+#define FD_BIND_AS_FILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.readline = as_readline; \
+ if (flags & OPEN_APPEND) \
+ opers.append = as_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.print = as_print; \
+ }
+
+#define FD_BIND_SS_FILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.readline = ss_readline; \
+ if (flags & OPEN_APPEND) \
+ opers.append = ss_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.print = ss_print; \
+ }
+
+#define FD_BIND_AS_BINFILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.read = as_read; \
+ if (flags & OPEN_APPEND) \
+ opers.bin_append = as_bin_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.write = as_write; \
+ }
+
+#define FD_BIND_SS_BINFILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.read = ss_read; \
+ if (flags & OPEN_APPEND) \
+ opers.bin_append = ss_bin_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.write = ss_write; \
+ }
+
+/* Set of file descriptors operations */
+/* Determines if to use the serial interface or the address space */
+
+/* Address space section */
+
+/* File functions */
+
+size_t as_readline(inode_t inode, fsize_t seek, char *buf, char term);
+
+size_t as_print(inode_t inode, fsize_t seek, const char *str);
+
+size_t as_append(inode_t inode, fsize_t *seek_ptr, const char *str);
+
+
+size_t as_read(inode_t inode, fsize_t seek, void *buf, size_t n);
+
+size_t as_write(inode_t inode, fsize_t seek, const void *buf, size_t n);
+
+size_t as_bin_append(inode_t inode, fsize_t *seek_ptr, const void *buf, size_t
+n);
+
+/* Directory functions */
+
+size_t as_ls(inode_t inode, struct dirent *buf, uint8_t all);
+
+size_t as_find(inode_t inode, struct dirent *buf, const char *name);
+
+int8_t as_mkdir(inode_t inode, const char *name);
+
+int8_t as_rmdir(inode_t inode, const char *name);
+
+int8_t as_touch(inode_t inode, const char *name);
+
+int8_t as_rm(inode_t inode, const char *name);
+
+int8_t as_ln(inode_t inode, const char *path, const char *name);
+
+/* Serial Space section */
+/* Warning, it doesn't switch to the right driver */
+
+/* File functions */
+
+size_t ss_readline(inode_t inode, fsize_t seek, char *buf, char term);
+
+size_t ss_print(inode_t inode, fsize_t seek, const char *str);
+
+size_t ss_append(inode_t inode, fsize_t *seek_ptr, const char *str);
+
+
+size_t ss_read(inode_t inode, fsize_t seek, void *buf, size_t n);
+
+size_t ss_write(inode_t inode, fsize_t seek, const void *buf, size_t n);
+
+size_t ss_bin_append(inode_t inode, fsize_t *seek_ptr, const void *buf, size_t
+n);
+
+/* Directory functions */
+
+size_t ss_ls(inode_t inode, struct dirent *buf, uint8_t all);
+
+size_t ss_find(inode_t inode, struct dirent *buf, const char *name);
+
+int8_t ss_mkdir(inode_t inode, const char *name);
+
+int8_t ss_rmdir(inode_t inode, const char *name);
+
+int8_t ss_touch(inode_t inode, const char *name);
+
+int8_t ss_rm(inode_t inode, const char *name);
+
+int8_t ss_ln(inode_t, const char *path, const char *name);
+
+#endif // __FDOP_H__
diff --git a/sw-old/z80/kernel/include/fs/fs.h b/sw-old/z80/kernel/include/fs/fs.h
new file mode 100644
index 0000000..ad20adb
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/fs.h
@@ -0,0 +1,63 @@
+#ifndef __FS_H__
+#define __FS_H__
+
+#include "types.h"
+
+#define FS_OFFSET 0x1000
+
+#define FS_BLOCKS_SIZE 512
+#define FS_BLOCKS_N 8
+#define FS_BLOCKS_IND 6
+
+#define INODE_TYPE_FILE 0x0
+#define INODE_TYPE_DIR 0x1
+#define INODE_TYPE_SLINK 0x2
+#define INODE_TYPE_SPECIAL 0x3
+
+#define INODE_META_SIZE 8
+
+/* inode basic structure */
+struct fs_inode
+{
+ /* inode meta data */
+
+ uint mode :3; // chmod
+ uint uid :3; // chown
+ uint type :2; // file, dir, sym-link, special
+
+ time_t ctime; // creation time
+
+ uint24_t size; // inode size
+
+ /* data storage informations */
+ /* it doesn't allocate memory, virtual size FS_BLOCKS_N */
+ blk_t blocks[];
+};
+
+#define FS_DEV_ROM 0x7f /* 01111111 */
+#define FS_DEV_NULL 0x80 /* 10000000 */
+
+#define FS_ROM_SPACE 0x2000 // second rom
+
+#define FS_INO_ROOT 0x0 // first inode
+
+#define FS_INODE_ROOT(inode) {inode.dev = 0xff; inode.inode = 0x0}
+#define FS_INODE_NULL(inode) {inode.dev = 0x80; inode.inode = 0x0}
+
+#define FS_USE_ROM(inode) {inode.dev == 0x7f}
+
+/* get block seek in current device */
+devsize_t fs_block(blk_t block);
+
+/* get common inode seek in current device */
+/* c_inode must be set first */
+/* returns seek at the beginning of blocks field */
+devsize_t fs_inode(struct fs_inode *buf);
+
+/* common inode for syscalls */
+extern inode_t c_inode;
+
+/* parse a path, absolute or relative to c_inode */
+inode_t fs_parse_path(const char *path);
+
+#endif // __FS_H__
diff --git a/sw-old/z80/kernel/include/fs/iter.h b/sw-old/z80/kernel/include/fs/iter.h
new file mode 100644
index 0000000..41f011d
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/iter.h
@@ -0,0 +1,17 @@
+#ifndef __ITER_H__
+#define __ITER_H__
+
+struct inode_iter
+{
+ devsize_t dev_seek; /* seek position in the volume */
+ devsize_t blk_end; /* end of the block */
+
+ int16_t blk_index; /* index of the block */
+
+ int8_t blk_level; /* recursion level, indirect blocks */
+
+ fsize_t fseek; /* virtual seek in the file */
+ fsize_t size; /* file size */
+};
+
+#endif // __ITER_H__
diff --git a/sw-old/z80/kernel/include/fs/users.h b/sw-old/z80/kernel/include/fs/users.h
new file mode 100644
index 0000000..83980e5
--- /dev/null
+++ b/sw-old/z80/kernel/include/fs/users.h
@@ -0,0 +1,21 @@
+#ifndef USERS_H
+#define USERS_H
+
+#include "types.h"
+
+#define USERS_MAX 8
+#define USER_ROOT 0
+
+/* current user in use */
+extern struct fs_user c_user;
+
+struct fs_user
+{
+ char name[32];
+ ino_t home;
+ uint8_t perm; // TODO, permissions
+};
+
+/* all users are in rom device */
+
+#endif