Compare commits
No commits in common. "main" and "homedev" have entirely different histories.
7 changed files with 40 additions and 199 deletions
26
emmafs.h
26
emmafs.h
|
@ -1,26 +0,0 @@
|
|||
#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_
|
41
inode.c
41
inode.c
|
@ -1,11 +1,9 @@
|
|||
#include "inode.h"
|
||||
#include "util.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].filename)) {
|
||||
Inode* ret = &itable->inodes[i];
|
||||
return ret;
|
||||
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||
return itable->inodes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -13,7 +11,7 @@ Inode* find_inode(char filename[], struct inode_table* itable) {
|
|||
|
||||
bool inode_exists(struct inode_table* itable, char filename[]) {
|
||||
for (uint32_t i = 0; i < itable->size; i++) {
|
||||
if (!strcmp(filename, itable->inodes[i].filename)) {
|
||||
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -25,36 +23,3 @@ void delete_inode(struct inode_table* itable, char filename[]) {
|
|||
free(wanted_inode);
|
||||
wanted_inode = NULL;
|
||||
}
|
||||
|
||||
Inode* create_inode() {
|
||||
Inode* new_inode = (Inode*) malloc(sizeof(Inode));
|
||||
if (new_inode == NULL) {
|
||||
errno = ENOMEM;
|
||||
perror("Failed to allocate memory for inode");
|
||||
return new_inode;
|
||||
}
|
||||
|
||||
new_inode->filename = NULL;
|
||||
new_inode->filesize = 0;
|
||||
new_inode->owner = 0;
|
||||
new_inode->group = 0;
|
||||
new_inode->created = get_local_time();
|
||||
new_inode->last_modified = get_local_time();
|
||||
new_inode->block_count = 0;
|
||||
new_inode->first_data_block = NULL;
|
||||
new_inode->second_data_block = NULL;
|
||||
new_inode-> third_data_block = NULL;
|
||||
new_inode->fourth_data_block = NULL;
|
||||
new_inode->fifth_data_block = NULL;
|
||||
new_inode->sixth_data_block = NULL;
|
||||
new_inode->seventh_data_block = NULL;
|
||||
new_inode->eighth_data_block = NULL;
|
||||
new_inode->nineth_data_block = NULL;
|
||||
new_inode->tenth_data_block = NULL;
|
||||
new_inode->eleventh_data_block = NULL;
|
||||
new_inode->twelveth_data_block = NULL;
|
||||
new_inode->file_indirect_data_block = NULL;
|
||||
new_inode->file_doubly_indirect_data_block = NULL;
|
||||
new_inode-> file_trebly_indirect_data_block = NULL;
|
||||
return new_inode;
|
||||
}
|
||||
|
|
55
inode.h
55
inode.h
|
@ -1,22 +1,34 @@
|
|||
#ifndef INODE_H_
|
||||
#define INODE_H_
|
||||
|
||||
#include "emmafs.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
typedef struct Inode Inode;
|
||||
|
||||
enum permissions {
|
||||
READ = 1,
|
||||
WRITE = 2,
|
||||
EXECUTE = 4
|
||||
R = 1,
|
||||
W = 2,
|
||||
X = 4
|
||||
};
|
||||
|
||||
// TODO: 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 *filename;
|
||||
char name[64];
|
||||
uint32_t filesize;
|
||||
|
||||
// ownership and permissions
|
||||
|
@ -32,38 +44,11 @@ struct Inode {
|
|||
tm created;
|
||||
tm last_modified;
|
||||
|
||||
// needed to determine file size
|
||||
uint16_t block_count;
|
||||
|
||||
// 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;
|
||||
block* data_block;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Inode* create_inode();
|
||||
Inode* create_inode(char name[64], uint8_t user_permissions, uint8_t group_permissions, uint16_t owner, uint16_t group, block* data_block);
|
||||
Inode* find_inode(char filename[], struct inode_table* itable);
|
||||
bool inode_exists(struct inode_table* itable, char filename[]);
|
||||
void delete_inode(struct inode_table* itable, char filename[]);
|
||||
|
|
25
io.c
25
io.c
|
@ -1,25 +0,0 @@
|
|||
#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
14
io.h
|
@ -3,15 +3,10 @@
|
|||
|
||||
#define MAX_FDS 1024
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "inode.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
enum Flags {
|
||||
O_READ = 1,
|
||||
O_WRITE = 2,
|
||||
O_APPEND = 4,
|
||||
O_CREATE = 8
|
||||
};
|
||||
#include "inode.h"
|
||||
|
||||
struct file_descriptor {
|
||||
Inode *inode;
|
||||
|
@ -24,8 +19,7 @@ struct Process {
|
|||
struct file_descriptor fd_table[MAX_FDS];
|
||||
};
|
||||
|
||||
struct Process* initialize_process();
|
||||
int allocate_fd(struct Process proc, Inode inode, int flags, ...);
|
||||
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)
|
||||
|
|
11
util.c
11
util.c
|
@ -4,22 +4,21 @@
|
|||
#include <math.h>
|
||||
|
||||
// DEPRECATED(?) This code will likely never be used. I have to handle it differently.
|
||||
int find_number_of_inodes(size_t fs_size) {
|
||||
int find_number_of_inodes(uint64_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.
|
||||
// FIXME: Make this actually return a timestamp and not an integer. Stupid Emma.
|
||||
//tmp get_local_time() {
|
||||
// return localtime(¤t_time);
|
||||
//}
|
||||
tm* get_local_time() {
|
||||
return localtime(¤t_time);
|
||||
}
|
||||
|
||||
// TODO Implement file struct so this function can be implemented
|
||||
// uint16_t calc_needed_blocks(struct *file )
|
||||
|
||||
// returns in bytes.
|
||||
size_t get_file_size(uint16_t block_count) {
|
||||
uint32_t get_file_size(uint16_t block_count) {
|
||||
return BLOCKSIZE * block_count;
|
||||
}
|
||||
|
||||
|
|
67
util.h
67
util.h
|
@ -1,7 +1,8 @@
|
|||
#ifndef UTIL_H_
|
||||
#define UTIL_H_
|
||||
#ifndef BLOCK_H_
|
||||
#define BLOCK_H_
|
||||
|
||||
#include "emmafs.h"
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#define BLOCKSIZE 4096
|
||||
|
@ -9,77 +10,25 @@
|
|||
#define BITS_PER_INODE 16384
|
||||
|
||||
typedef struct tm tm;
|
||||
typedef struct block block;
|
||||
|
||||
struct data_block {
|
||||
struct 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
|
||||
<<<<<<< HEAD
|
||||
int find_number_of_inodes(size_t fs_size);
|
||||
tm* get_local_time();
|
||||
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.
|
||||
=======
|
||||
int find_number_of_inodes(uint64_t fs_size);
|
||||
tm get_local_time();
|
||||
tm* get_local_time();
|
||||
uint32_t get_file_size(uint16_t block_count);
|
||||
>>>>>>> 18f1037e030fa451566018dfcb8dbdb250787c70
|
||||
uint16_t bytes_to_kb(uint32_t bytes);
|
||||
uint16_t kb_to_mb(uint16_t kb);
|
||||
uint16_t mb_to_gb(uint16_t mb);
|
||||
uint16_t gb_to_tb(uint16_t gb);
|
||||
uint8_t tb_to_pb(uint16_t tb);
|
||||
|
||||
#endif // UTIL_H_
|
||||
#endif // BLOCK_H_
|
||||
|
|
Loading…
Reference in a new issue