Compare commits
4 commits
18f1037e03
...
70ce80a440
Author | SHA1 | Date | |
---|---|---|---|
70ce80a440 | |||
5f2c15daa6 | |||
095d4452e5 | |||
c32f7e22ec |
6 changed files with 77 additions and 18 deletions
26
emmafs.h
Normal file
26
emmafs.h
Normal 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_
|
8
inode.h
8
inode.h
|
@ -1,13 +1,7 @@
|
|||
#ifndef INODE_H_
|
||||
#define INODE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "emmafs.h"
|
||||
#include "util.h"
|
||||
|
||||
typedef struct Inode Inode;
|
||||
|
|
25
io.c
Normal file
25
io.c
Normal 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
14
io.h
|
@ -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)
|
||||
|
|
11
util.c
11
util.c
|
@ -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(¤t_time);
|
||||
}
|
||||
// FIXME: Make this actually return a timestamp and not an integer. Stupid Emma.
|
||||
//tmp 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.
|
||||
uint32_t get_file_size(uint16_t block_count) {
|
||||
size_t get_file_size(uint16_t block_count) {
|
||||
return BLOCKSIZE * block_count;
|
||||
}
|
||||
|
||||
|
|
11
util.h
11
util.h
|
@ -1,8 +1,7 @@
|
|||
#ifndef UTIL_H_
|
||||
#define UTIL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "emmafs.h"
|
||||
|
||||
|
||||
#define BLOCKSIZE 4096
|
||||
|
@ -66,9 +65,17 @@ struct tm *local_time;
|
|||
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();
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue