7 #ifndef EXT_FILESYSTEM_INTERFACE_CLOSE_FILE_H_
8 #define EXT_FILESYSTEM_INTERFACE_CLOSE_FILE_H_
15 #include "../core/superblock.h"
16 #include "../core/descriptors_table.h"
17 #include "../core/defines.h"
18 #include "../core/methods.h"
28 void close_file(
const char* path_to_fs_file,
const int fd_to_close,
int output_fd) {
30 size_t buffer_size = 0;
31 int fd = open(path_to_fs_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
33 fprintf(stderr,
"Can't open file. Abort!\n");
37 struct superblock superblock;
39 if (superblock.fs_info->magic != MAGIC) {
40 fprintf(stderr,
"Magic does not match. Abort!\n");
46 if (!superblock.reserved_inodes_mask[ROOT_INODE_ID]) {
47 fprintf(stderr,
"Root directory doesn't exist. Abort!\n");
53 struct descriptors_table descriptors_table;
55 fprintf(stderr,
"Can't read descriptors_table. Abort!\n");
63 fprintf(stderr,
"Can't write descriptors_table. Abort!\n");
72 send_data(output_fd, buffer, buffer_size);
82 #endif //EXT_FILESYSTEM_INTERFACE_CLOSE_FILE_H_
ssize_t write_descriptor_table(int fd, struct descriptors_table *descriptors_table, const struct superblock *superblock)
Write descriptors_table to memory.
void close_file(const char *path_to_fs_file, const int fd_to_close, int output_fd)
Close file.
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.
int free_descriptor(struct descriptors_table *descriptors_table, uint16_t fd, const struct superblock *superblock)
Release descriptor for inode_id.
ssize_t read_descriptors_table(int fd, struct descriptors_table *descriptors_table, const struct superblock *superblock)
Read descriptors_table from memory.
Contains some useful methods.
ssize_t read_super_block(int fd, struct superblock *superblock)
Read sb from memory.
int write_while(int fd, const char *buffer, size_t to_write)
Properly writing to memory.
bool send_data(int sockd, char *data, size_t size)