Compare commits

...

7 commits

8 changed files with 188 additions and 40 deletions

26
emmafs.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef EMMAFS_H_
#define EMMAFS_H_
/* For now, this is just a collection of includes.
* This is for the purpose of avoid redundant importing of
* commonly used includes like stdlib, stdbool or errno,
* that are used in almost all files. It really is meant to make
* The beginning of reach file more readable.
* In the future, I will also use this to define some structs
* that are needed in many other places to help juggling
* loads of different includes. */
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#endif // EMMAFS_H_

24
inode.c
View file

@ -1 +1,25 @@
#include "inode.h"
Inode* find_inode(char filename[], struct inode_table* itable) {
for (uint32_t i = 0; i < itable->size; i++) {
if (strcmp(filename, itable->inodes[i]->name)) {
return itable->inodes[i];
}
}
return NULL;
}
bool inode_exists(struct inode_table* itable, char filename[]) {
for (uint32_t i = 0; i < itable->size; i++) {
if (strcmp(filename, itable->inodes[i]->name)) {
return true;
}
}
return false;
}
void delete_inode(struct inode_table* itable, char filename[]) {
Inode* wanted_inode = find_inode(filename, itable);
free(wanted_inode);
wanted_inode = NULL;
}

54
inode.h
View file

@ -1,33 +1,71 @@
#ifndef INODE_H_
#define INODE_H_
#include <stdint.h>
#include <stdlib.h>
#include "emmafs.h"
#include "util.h"
typedef struct Inode Inode;
enum permissions {
R = 1,
W = 2,
X = 4
};
// NOTE: Add handling for the block bitmap for when a file is deleted and created. That's how you solve the issue of when a block is usable.
struct inode_table {
// the following keyword spam purely exist so I definitely see it with highlighting.
// NOTE, TODO, FIXME, DEPRECATED, HACK, IMPORTANT: always initialize all values to be null when the inode table is created!!!!
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
Inode* inodes[640000];
uint32_t size;
uint32_t used_inodes;
uint32_t free_inodes;
};
struct Inode {
// file information
char name[64];
uint32_t filesize;
// ownership and permissions
uint16_t permissions;
uint8_t user_permissions;
uint8_t group_permissions;
// UID
uint16_t owner;
// GID
uint16_t group;
// timestamps
tm created;
tm last_modified;
// fs attributes
uint32_t index;
// needed to determine file size
uint16_t block_count;
block* data_block;
// Data block pointers!!
struct data_block* first_data_block;
struct data_block* second_data_block;
struct data_block* third_data_block;
struct data_block* fourth_data_block;
struct data_block* fifth_data_block;
struct data_block* sixth_data_block;
struct data_block* seventh_data_block;
struct data_block* eighth_data_block;
struct data_block* nineth_data_block;
struct data_block* tenth_data_block;
struct data_block* eleventh_data_block;
struct data_block* twelveth_data_block;
struct indirect_data_block* file_indirect_data_block;
struct doubly_indirect_data_block* file_doubly_indirect_data_block;
struct trebly_indirect_data_block* file_trebly_indirect_data_block;
};
Inode* create_inode(char name[64], uint16_t owner, uint16_t group, block* data_block);
Inode* create_empty_inode(char name[64], uint8_t user_permissions, uint8_t group_permissions, uint16_t owner, uint16_t group, struct data_block* data_block);
Inode* find_inode(char filename[64], struct inode_table* itable);
bool inode_exists(struct inode_table* itable, char filename[64]);
void delete_inode(struct inode_table* itable, char filename[64]);
#endif // INODE_H_

25
io.c Normal file
View file

@ -0,0 +1,25 @@
#include "io.h"
struct file_descriptor emmafs_stdin {
*inode = NONE;
off_t = NONE;
flags = NONE;
int ref_count = 0;
};
struct Process* initialize_process() {
struct Process* new_proc = (struct Process*) malloc(sizeof(struct Process));
if (new_proc == NULL) {
errno = ENOMEM;
perror("Failed memory allocation for Process");
return NULL;
}
new_proc->fd_table[0] = emmafs_stdin;
}
int allocate_fd(struct Process proc, Inode inode, int flags, ...) {
va_list argptr;
va_start(argptr, flags);
va_end(argptr);
}

14
io.h
View file

@ -3,11 +3,16 @@
#define MAX_FDS 1024
#include <stdlib.h>
#include <sys/types.h>
#include <stdarg.h>
#include "inode.h"
enum Flags {
O_READ = 1,
O_WRITE = 2,
O_APPEND = 4,
O_CREATE = 8
};
struct file_descriptor {
Inode *inode;
off_t offset;
@ -19,7 +24,8 @@ struct Process {
struct file_descriptor fd_table[MAX_FDS];
};
int allocate_fd(struct Process proc, Inode inode, int flags);
struct Process* initialize_process();
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)

17
super.c
View file

@ -9,14 +9,6 @@
#define VERSION 0.0.0.1
#define BLOCKSIZE 4096
uint32_t free_blocks;
uint32_t inode_count;
struct inode_table {
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
Inode* inodes[640000];
};
struct super_block {
// fs info
char version[8];
@ -35,13 +27,4 @@ struct super_block {
struct inode_table* inode_table;
};
// TODO: Do research on how the fuck to actually do this kind of Array operation
Inode* find_inode(char filename[], struct super_block sblock) {
struct inode_table* itable = sblock.inode_table;
// while (itable[inode] != NULL; inode++) {
// if (strcmp(filename, itable[inode]->filesize))
// }
return NULL;
}
#endif // SUPER_H_

11
util.c
View file

@ -4,21 +4,22 @@
#include <math.h>
// DEPRECATED(?) This code will likely never be used. I have to handle it differently.
int find_number_of_inodes(uint64_t fs_size) {
int find_number_of_inodes(size_t fs_size) {
int number_of_inodes = fs_size / BITS_PER_INODE;
return number_of_inodes;
}
// NOTE: formerly part of inode. Now transferred to util because it's both used in Inodes and the Superblock. The superblock does include inode.h, but this makes the code ordering easier to understand.
tm* get_local_time() {
return localtime(&current_time);
}
// FIXME: Make this actually return a timestamp and not an integer. Stupid Emma.
//tmp get_local_time() {
// return localtime(&current_time);
//}
// TODO Implement file struct so this function can be implemented
// uint16_t calc_needed_blocks(struct *file )
// returns in bytes.
uint32_t get_file_size(uint16_t block_count) {
size_t get_file_size(uint16_t block_count) {
return BLOCKSIZE * block_count;
}

57
util.h
View file

@ -1,8 +1,7 @@
#ifndef BLOCK_H_
#define BLOCK_H_
#include <stdint.h>
#include <time.h>
#include "emmafs.h"
#define BLOCKSIZE 4096
@ -10,21 +9,67 @@
#define BITS_PER_INODE 16384
typedef struct tm tm;
typedef struct block block;
struct block {
struct data_block {
char data[BLOCKSIZE];
};
struct indirect_data_block {
struct data_block* first_data_block;
struct data_block* second_data_block;
struct data_block* third_data_block;
struct data_block* fourth_data_block;
struct data_block* fifth_data_block;
struct data_block* sixth_data_block;
struct data_block* seventh_data_block;
struct data_block* eighth_data_block;
struct data_block* nineth_data_block;
struct data_block* tenth_data_block;
struct data_block* eleventh_data_block;
struct data_block* twelveth_data_block;
};
struct doubly_indirect_data_block {
struct data_block* first_indirect_data_block;
struct data_block* second_indirect_data_block;
struct data_block* third_indirect_data_block;
struct data_block* fourth_indirect_data_block;
struct data_block* fifth_indirect_data_block;
struct data_block* sixth_indirect_data_block;
struct data_block* seventh_indirect_data_block;
struct data_block* eighth_indirect_data_block;
struct data_block* nineth_indirect_data_block;
struct data_block* tenth_indirect_data_block;
struct data_block* eleventh_indirect_data_block;
struct data_block* twelveth_indirect_data_block;
};
struct trebly_indirect_data_block {
struct data_block* first_doubly_indirect_data_block;
struct data_block* second_doubly_indirect_data_block;
struct data_block* third_doubly_indirect_data_block;
struct data_block* fourth_doubly_indirect_data_block;
struct data_block* fifth_doubly_indirect_data_block;
struct data_block* sixth_doubly_indirect_data_block;
struct data_block* seventh_doubly_indirect_data_block;
struct data_block* eighth_doubly_indirect_data_block;
struct data_block* nineth_doubly_indirect_data_block;
struct data_block* tenth_doubly_indirect_data_block;
struct data_block* eleventh_doubly_indirect_data_block;
struct data_block* twelveth_doubly_indirect_data_block;
};
struct tm *local_time;
// Global Variables
time_t current_time;
// Provide fs size in bytes
int find_number_of_inodes(uint64_t fs_size);
int find_number_of_inodes(size_t fs_size);
tm* get_local_time();
uint32_t get_file_size(uint16_t block_count);
size_t get_file_size(uint16_t block_count);
// DEPRECATED? Probably unneeded and will soon be removed. This should not be handled on the fs level.
uint16_t bytes_to_kb(uint32_t bytes);
uint16_t kb_to_mb(uint16_t kb);
uint16_t mb_to_gb(uint16_t mb);