Compare commits
No commits in common. "18f1037e030fa451566018dfcb8dbdb250787c70" and "8272aa245bcca1a82c295bfa8e2db62625319c9b" have entirely different histories.
18f1037e03
...
8272aa245b
4 changed files with 24 additions and 61 deletions
41
inode.c
41
inode.c
|
@ -1,11 +1,9 @@
|
|||
#include "inode.h"
|
||||
#include "util.h"
|
||||
|
||||
Inode* find_inode(char filename[], struct inode_table* itable) {
|
||||
for (uint32_t i = 0; i < itable->size; i++) {
|
||||
if (!strcmp(filename, itable->inodes[i].filename)) {
|
||||
Inode* ret = &itable->inodes[i];
|
||||
return ret;
|
||||
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||
return itable->inodes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -13,7 +11,7 @@ Inode* find_inode(char filename[], struct inode_table* itable) {
|
|||
|
||||
bool inode_exists(struct inode_table* itable, char filename[]) {
|
||||
for (uint32_t i = 0; i < itable->size; i++) {
|
||||
if (!strcmp(filename, itable->inodes[i].filename)) {
|
||||
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -25,36 +23,3 @@ void delete_inode(struct inode_table* itable, char filename[]) {
|
|||
free(wanted_inode);
|
||||
wanted_inode = NULL;
|
||||
}
|
||||
|
||||
Inode* create_inode() {
|
||||
Inode* new_inode = (Inode*) malloc(sizeof(Inode));
|
||||
if (new_inode == NULL) {
|
||||
errno = ENOMEM;
|
||||
perror("Failed to allocate memory for inode");
|
||||
return new_inode;
|
||||
}
|
||||
|
||||
new_inode->filename = NULL;
|
||||
new_inode->filesize = 0;
|
||||
new_inode->owner = 0;
|
||||
new_inode->group = 0;
|
||||
new_inode->created = get_local_time();
|
||||
new_inode->last_modified = get_local_time();
|
||||
new_inode->block_count = 0;
|
||||
new_inode->first_data_block = NULL;
|
||||
new_inode->second_data_block = NULL;
|
||||
new_inode-> third_data_block = NULL;
|
||||
new_inode->fourth_data_block = NULL;
|
||||
new_inode->fifth_data_block = NULL;
|
||||
new_inode->sixth_data_block = NULL;
|
||||
new_inode->seventh_data_block = NULL;
|
||||
new_inode->eighth_data_block = NULL;
|
||||
new_inode->nineth_data_block = NULL;
|
||||
new_inode->tenth_data_block = NULL;
|
||||
new_inode->eleventh_data_block = NULL;
|
||||
new_inode->twelveth_data_block = NULL;
|
||||
new_inode->file_indirect_data_block = NULL;
|
||||
new_inode->file_doubly_indirect_data_block = NULL;
|
||||
new_inode-> file_trebly_indirect_data_block = NULL;
|
||||
return new_inode;
|
||||
}
|
||||
|
|
34
inode.h
34
inode.h
|
@ -5,24 +5,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
typedef struct Inode Inode;
|
||||
|
||||
enum permissions {
|
||||
READ = 1,
|
||||
WRITE = 2,
|
||||
EXECUTE = 4
|
||||
R = 1,
|
||||
W = 2,
|
||||
X = 4
|
||||
};
|
||||
|
||||
// TODO: Add handling for the block bitmap for when a file is deleted and created. That's how you solve the issue of when a block is usable.
|
||||
// NOTE: Add handling for the block bitmap for when a file is deleted and created. That's how you solve the issue of when a block is usable.
|
||||
|
||||
struct inode_table {
|
||||
// the following keyword spam purely exist so I definitely see it with highlighting.
|
||||
// NOTE, TODO, FIXME, DEPRECATED, HACK, IMPORTANT: always initialize all values to be null when the inode table is created!!!!
|
||||
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
|
||||
Inode* inodes[640000];
|
||||
uint32_t size;
|
||||
uint32_t used_inodes;
|
||||
uint32_t free_inodes;
|
||||
};
|
||||
|
||||
struct Inode {
|
||||
// file information
|
||||
char *filename;
|
||||
char name[64];
|
||||
uint32_t filesize;
|
||||
|
||||
// ownership and permissions
|
||||
|
@ -59,17 +67,7 @@ struct Inode {
|
|||
struct trebly_indirect_data_block* file_trebly_indirect_data_block;
|
||||
};
|
||||
|
||||
struct inode_table {
|
||||
// the following keyword spam purely exist so I definitely see it with highlighting.
|
||||
// NOTE, TODO, FIXME, DEPRECATED, HACK, IMPORTANT: always initialize all values to be null when the inode table is created!!!!
|
||||
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
|
||||
Inode inodes[640000];
|
||||
uint32_t size;
|
||||
uint32_t used_inodes;
|
||||
uint32_t free_inodes;
|
||||
};
|
||||
|
||||
Inode* create_inode();
|
||||
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[]);
|
||||
|
|
2
util.c
2
util.c
|
@ -10,7 +10,7 @@ int find_number_of_inodes(uint64_t fs_size) {
|
|||
}
|
||||
|
||||
// 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() {
|
||||
tm* get_local_time() {
|
||||
return localtime(¤t_time);
|
||||
}
|
||||
|
||||
|
|
8
util.h
8
util.h
|
@ -1,5 +1,5 @@
|
|||
#ifndef UTIL_H_
|
||||
#define UTIL_H_
|
||||
#ifndef BLOCK_H_
|
||||
#define BLOCK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
@ -67,7 +67,7 @@ time_t current_time;
|
|||
|
||||
// Provide fs size in bytes
|
||||
int find_number_of_inodes(uint64_t fs_size);
|
||||
tm get_local_time();
|
||||
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);
|
||||
|
@ -75,4 +75,4 @@ 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 // UTIL_H_
|
||||
#endif // BLOCK_H_
|
||||
|
|
Loading…
Reference in a new issue