From c32f7e22ec17dec26202dc8617ff56ebad964336 Mon Sep 17 00:00:00 2001 From: Emma Nora Theuer Date: Wed, 13 Nov 2024 17:23:44 +0100 Subject: [PATCH] Streamline code --- inode.h | 14 +++++--------- util.c | 11 ++++++----- util.h | 9 +++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/inode.h b/inode.h index 48495f7..805a6cb 100644 --- a/inode.h +++ b/inode.h @@ -1,11 +1,7 @@ #ifndef INODE_H_ #define INODE_H_ -#include -#include -#include -#include - +#include "emmafs.h" #include "util.h" typedef struct Inode Inode; @@ -67,9 +63,9 @@ struct Inode { struct trebly_indirect_data_block* file_trebly_indirect_data_block; }; -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[]); +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_ diff --git a/util.c b/util.c index 795ab21..66173e5 100644 --- a/util.c +++ b/util.c @@ -4,21 +4,22 @@ #include // 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; } diff --git a/util.h b/util.h index 55fdb83..dd377e0 100644 --- a/util.h +++ b/util.h @@ -1,8 +1,7 @@ #ifndef BLOCK_H_ #define BLOCK_H_ -#include -#include +#include "emmafs.h" #define BLOCKSIZE 4096 @@ -66,9 +65,11 @@ struct tm *local_time; 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);