7 #ifndef EXT_FILESYSTEM_INTERFACE_INIT_H_
8 #define EXT_FILESYSTEM_INTERFACE_INIT_H_
16 #include "../core/superblock.h"
17 #include "../core/descriptors_table.h"
18 #include "../core/defines.h"
19 #include "../core/methods.h"
28 void init_fs(
const char* path_to_fs_file) {
29 int fd = open(path_to_fs_file, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
31 fprintf(stderr,
"Can't open file. Abort!");
35 struct superblock superblock;
39 fprintf(stderr,
"Can't write superblock. Abort!");
43 struct descriptors_table descriptors_table;
46 fprintf(stderr,
"Can't write descriptors_table. Abort!");
59 void read_fs(
const char* path_to_fs_file) {
60 int fd = open(path_to_fs_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
62 fprintf(stderr,
"Can't open file. Abort!");
65 struct superblock superblock;
67 if (superblock.fs_info->magic != MAGIC) {
68 fprintf(stderr,
"Magic does not match. Abort!");
77 #endif //EXT_FILESYSTEM_INTERFACE_INIT_H_
ssize_t write_descriptor_table(int fd, struct descriptors_table *descriptors_table, const struct superblock *superblock)
Write descriptors_table to memory.
ssize_t write_super_block(int fd, struct superblock *superblock)
Write sb to memory.
void destruct_descriptors_table(struct descriptors_table *descriptors_table, const struct superblock *superblock)
Destructor of superblock.
void destroy_super_block(struct superblock *superblock)
Destructor of superblock.
Contains some useful methods.
ssize_t read_super_block(int fd, struct superblock *superblock)
Read sb from memory.
void init_super_block(struct superblock *superblock)
Constructor of superblock.
void init_descriptors_table(struct descriptors_table *descriptors_table, const struct superblock *superblock)
Constructor of descriptors_table Init descriptors table with metadata from superblock.
uint16_t create_dir_helper(int fd, const struct superblock *superblock, uint16_t parent_node_id, bool is_root)
Helper for create new directory Creates dir with parent = parent_node_id (or itself if is_root)...
void init_fs(const char *path_to_fs_file)
Init filesystem Trunc file and init our FS in it. Creates superblock, descriptor_table and root_dir...