emmafs/util.h

79 lines
2.6 KiB
C
Raw Normal View History

2024-10-08 23:01:29 +02:00
#ifndef BLOCK_H_
#define BLOCK_H_
#include <stdint.h>
2024-10-19 19:52:24 +02:00
#include <time.h>
2024-10-08 23:01:29 +02:00
#define BLOCKSIZE 4096
2024-10-19 19:52:24 +02:00
// NOTE: This is about how many inode get reserved per bit at fs creation. TODO: Come up witha better name.
2024-10-08 23:01:29 +02:00
#define BITS_PER_INODE 16384
2024-10-19 19:52:24 +02:00
typedef struct tm tm;
2024-10-08 23:01:29 +02:00
struct data_block {
2024-10-08 23:01:29 +02:00
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;
};
2024-10-19 19:52:24 +02:00
struct tm *local_time;
// Global Variables
time_t current_time;
2024-10-08 23:01:29 +02:00
// Provide fs size in bytes
int find_number_of_inodes(uint64_t fs_size);
2024-10-19 19:52:24 +02:00
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);
2024-10-08 23:01:29 +02:00
#endif // BLOCK_H_