Initial Commit

This commit is contained in:
Emma Nora Theuer 2024-10-08 23:01:29 +02:00
commit caf7b99f2d
6 changed files with 117 additions and 0 deletions

5
inode.c Normal file
View file

@ -0,0 +1,5 @@
#include "inode.h"
tm* get_local_time() {
return localtime(&current_time);
}

43
inode.h Normal file
View file

@ -0,0 +1,43 @@
#ifndef INODE_H_
#define INODE_H_
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#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_

28
io.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef IO_H_
#define IO_H_
#define MAX_FDS 1024
#include <stdlib.h>
#include <sys/types.h>
#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_

16
super.c Normal file
View file

@ -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_

6
util.c Normal file
View file

@ -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;
}

19
util.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef BLOCK_H_
#define BLOCK_H_
#include <stdint.h>
#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_