emmafs/util.c

44 lines
1.2 KiB
C

#include "util.h"
#include <stdint.h>
// NOTE: No idea if that's needed yet. Will see. Might or might not.
#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 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(&current_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;
}