Various stuff I did during lectures
This commit is contained in:
parent
7311470c4c
commit
782d8db162
5 changed files with 88 additions and 18 deletions
4
inode.c
4
inode.c
|
@ -1,5 +1 @@
|
|||
#include "inode.h"
|
||||
|
||||
tm* get_local_time() {
|
||||
return localtime(¤t_time);
|
||||
}
|
||||
|
|
12
inode.h
12
inode.h
|
@ -3,23 +3,15 @@
|
|||
|
||||
#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;
|
||||
uint32_t filesize;
|
||||
|
||||
// ownership and permissions
|
||||
uint16_t permissions;
|
||||
|
@ -36,8 +28,6 @@ struct Inode {
|
|||
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_
|
||||
|
|
33
super.c
33
super.c
|
@ -1,8 +1,8 @@
|
|||
#ifndef SUPER_H_
|
||||
#define SUPER_H_
|
||||
|
||||
#include "inode.h"
|
||||
#include "util.h"
|
||||
#include "inode.h"
|
||||
|
||||
// fs attributes
|
||||
#define MAGIC 0x7F631EC4
|
||||
|
@ -12,5 +12,36 @@
|
|||
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];
|
||||
uint64_t magic;
|
||||
// fs attributes
|
||||
uint16_t blocksize;
|
||||
uint64_t block_count;
|
||||
uint64_t free_bloks;
|
||||
uint64_t inode_count;
|
||||
uint64_t free_inodes;
|
||||
// Timestamps
|
||||
tm fs_creation;
|
||||
tm last_write;
|
||||
|
||||
// inode table
|
||||
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_
|
||||
|
|
40
util.c
40
util.c
|
@ -1,6 +1,44 @@
|
|||
#include "util.h"
|
||||
#include <stdint.h>
|
||||
// NOTE: No idea if that's needed yet. Will see. Might or might not.
|
||||
#include <math.h>
|
||||
|
||||
int find_number_of_inodes(uint64_t fs_size){
|
||||
// DEPRECATED(?) This code will likely never be used. I have to handle it differently.
|
||||
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.
|
||||
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.
|
||||
uint32_t get_file_size(uint16_t block_count) {
|
||||
return BLOCKSIZE * block_count;
|
||||
}
|
||||
|
||||
// Make numbers prettier for the user. Might never be used. Inode will store file size in bytes, this should probably be implemented in user space.
|
||||
uint16_t bytes_to_kb(uint32_t bytes) {
|
||||
return bytes/1024;
|
||||
}
|
||||
|
||||
uint16_t kb_to_mb(uint16_t kb) {
|
||||
return kb/1024;
|
||||
}
|
||||
|
||||
uint16_t mb_to_gb(uint16_t mb) {
|
||||
return mb/1024;
|
||||
}
|
||||
|
||||
uint16_t gb_to_tb(uint16_t gb) {
|
||||
return gb/1024;
|
||||
}
|
||||
|
||||
uint8_t tb_to_pb(uint16_t tb) {
|
||||
return tb/1024;
|
||||
}
|
||||
|
|
17
util.h
17
util.h
|
@ -2,18 +2,33 @@
|
|||
#define BLOCK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#define BLOCKSIZE 4096
|
||||
// NOTE: This is about how many inode get reserved per bit at fs creation. TODO: Come up witha better name.
|
||||
#define BITS_PER_INODE 16384
|
||||
|
||||
|
||||
typedef struct tm tm;
|
||||
typedef struct block block;
|
||||
|
||||
struct block {
|
||||
char data[BLOCKSIZE];
|
||||
};
|
||||
|
||||
struct tm *local_time;
|
||||
|
||||
// Global Variables
|
||||
time_t current_time;
|
||||
|
||||
// Provide fs size in bytes
|
||||
int find_number_of_inodes(uint64_t fs_size);
|
||||
tm* get_local_time();
|
||||
uint32_t get_file_size(uint16_t block_count);
|
||||
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 // BLOCK_H_
|
||||
|
|
Loading…
Reference in a new issue