From caf7b99f2d2945f5fd71482d621e9b149b1ef792 Mon Sep 17 00:00:00 2001 From: Emma Nora Theuer Date: Tue, 8 Oct 2024 23:01:29 +0200 Subject: [PATCH] Initial Commit --- inode.c | 5 +++++ inode.h | 43 +++++++++++++++++++++++++++++++++++++++++++ io.h | 28 ++++++++++++++++++++++++++++ super.c | 16 ++++++++++++++++ util.c | 6 ++++++ util.h | 19 +++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 inode.c create mode 100644 inode.h create mode 100644 io.h create mode 100644 super.c create mode 100644 util.c create mode 100644 util.h diff --git a/inode.c b/inode.c new file mode 100644 index 0000000..79beaf1 --- /dev/null +++ b/inode.c @@ -0,0 +1,5 @@ +#include "inode.h" + +tm* get_local_time() { + return localtime(¤t_time); +} diff --git a/inode.h b/inode.h new file mode 100644 index 0000000..3680897 --- /dev/null +++ b/inode.h @@ -0,0 +1,43 @@ +#ifndef INODE_H_ +#define INODE_H_ + +#include +#include +#include + +#include "util.h" + +typedef struct Inode Inode; +typedef struct tm tm; + +// Global Variables +time_t current_time; + +// Structs +struct tm *local_time; + +struct Inode { + // file information + char name[64]; + uint32_t size; + + // ownership and permissions + uint16_t permissions; + uint16_t owner; + uint16_t group; + + // timestamps + tm created; + tm last_modified; + + // fs attributes + uint32_t index; + uint16_t block_count; + block* data_block; +}; + +tm* get_local_time(); +Inode* create_inode(char name[64], uint16_t owner, uint16_t group, block* data_block); +Inode* find_inode(char name[]); + +#endif // INODE_H_ diff --git a/io.h b/io.h new file mode 100644 index 0000000..2c35a1f --- /dev/null +++ b/io.h @@ -0,0 +1,28 @@ +#ifndef IO_H_ +#define IO_H_ + +#define MAX_FDS 1024 + +#include +#include + +#include "inode.h" + +struct file_descriptor { + Inode *inode; + off_t offset; + int flags; + int ref_count; +}; + +struct Process { + struct file_descriptor fd_table[MAX_FDS]; +}; + +int allocate_fd(struct Process proc, Inode inode, int flags); +int emmafs_open(char name[]); +int emmafs_close(char name[]); +//int emmafs_read(int fd) +//int emmafs_write(int fd) + +#endif // IO_H_ diff --git a/super.c b/super.c new file mode 100644 index 0000000..439511f --- /dev/null +++ b/super.c @@ -0,0 +1,16 @@ +#ifndef SUPER_H_ +#define SUPER_H_ + +#include "inode.h" +#include "util.h" + +// fs attributes +#define MAGIC 0x7F631EC4 +#define VERSION 0.0.0.1 +#define BLOCKSIZE 4096 + +uint32_t free_blocks; +uint32_t inode_count; + + +#endif // SUPER_H_ diff --git a/util.c b/util.c new file mode 100644 index 0000000..e639112 --- /dev/null +++ b/util.c @@ -0,0 +1,6 @@ +#include "util.h" + +int find_number_of_inodes(uint64_t fs_size){ + int number_of_inodes = fs_size / BITS_PER_INODE; + return number_of_inodes; +} diff --git a/util.h b/util.h new file mode 100644 index 0000000..6afe680 --- /dev/null +++ b/util.h @@ -0,0 +1,19 @@ +#ifndef BLOCK_H_ +#define BLOCK_H_ + +#include + +#define BLOCKSIZE 4096 +#define BITS_PER_INODE 16384 + + +typedef struct block block; + +struct block { + char data[BLOCKSIZE]; +}; + +// Provide fs size in bytes +int find_number_of_inodes(uint64_t fs_size); + +#endif // BLOCK_H_