2024-10-08 23:01:29 +02:00
|
|
|
#ifndef INODE_H_
|
|
|
|
#define INODE_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2024-10-19 22:20:31 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2024-10-08 23:01:29 +02:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
typedef struct Inode Inode;
|
|
|
|
|
2024-10-19 22:20:31 +02:00
|
|
|
enum permissions {
|
|
|
|
R = 1,
|
|
|
|
W = 2,
|
|
|
|
X = 4
|
|
|
|
};
|
|
|
|
|
2024-10-23 03:00:36 +02:00
|
|
|
// 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.
|
|
|
|
|
2024-10-19 22:20:31 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-10-08 23:01:29 +02:00
|
|
|
struct Inode {
|
|
|
|
// file information
|
|
|
|
char name[64];
|
2024-10-19 19:52:24 +02:00
|
|
|
uint32_t filesize;
|
2024-10-08 23:01:29 +02:00
|
|
|
|
|
|
|
// ownership and permissions
|
2024-10-19 22:20:31 +02:00
|
|
|
uint8_t user_permissions;
|
|
|
|
uint8_t group_permissions;
|
|
|
|
|
|
|
|
// UID
|
2024-10-08 23:01:29 +02:00
|
|
|
uint16_t owner;
|
2024-10-19 22:20:31 +02:00
|
|
|
// GID
|
2024-10-08 23:01:29 +02:00
|
|
|
uint16_t group;
|
|
|
|
|
|
|
|
// timestamps
|
|
|
|
tm created;
|
|
|
|
tm last_modified;
|
|
|
|
|
2024-10-23 03:00:36 +02:00
|
|
|
// needed to determine file size
|
2024-10-08 23:01:29 +02:00
|
|
|
uint16_t block_count;
|
2024-10-23 03:00:36 +02:00
|
|
|
|
|
|
|
// Data block pointers!!
|
|
|
|
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 indirect_data_block* file_indirect_data_block;
|
|
|
|
struct doubly_indirect_data_block* file_doubly_indirect_data_block;
|
|
|
|
struct trebly_indirect_data_block* file_trebly_indirect_data_block;
|
2024-10-08 23:01:29 +02:00
|
|
|
};
|
|
|
|
|
2024-10-19 22:20:31 +02:00
|
|
|
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[]);
|
2024-10-08 23:01:29 +02:00
|
|
|
|
|
|
|
#endif // INODE_H_
|