emmafs/util.c

46 lines
1.3 KiB
C
Raw Permalink Normal View History

2024-10-08 23:01:29 +02:00
#include "util.h"
2024-10-19 19:52:24 +02:00
#include <stdint.h>
// NOTE: No idea if that's needed yet. Will see. Might or might not.
#include <math.h>
2024-10-08 23:01:29 +02:00
2024-10-19 19:52:24 +02:00
// DEPRECATED(?) This code will likely never be used. I have to handle it differently.
2024-11-13 17:23:44 +01:00
int find_number_of_inodes(size_t fs_size) {
2024-10-08 23:01:29 +02:00
int number_of_inodes = fs_size / BITS_PER_INODE;
return number_of_inodes;
}
2024-10-19 19:52:24 +02:00
// 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.
2024-11-13 17:23:44 +01:00
// FIXME: Make this actually return a timestamp and not an integer. Stupid Emma.
//tmp get_local_time() {
// return localtime(&current_time);
//}
2024-10-19 19:52:24 +02:00
// TODO Implement file struct so this function can be implemented
// uint16_t calc_needed_blocks(struct *file )
// returns in bytes.
2024-11-13 17:23:44 +01:00
size_t get_file_size(uint16_t block_count) {
2024-10-19 19:52:24 +02:00
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;
}