60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
#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;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
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)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void delete_inode(struct inode_table* itable, char filename[]) {
|
|
Inode* wanted_inode = find_inode(filename, itable);
|
|
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;
|
|
}
|