7 #ifndef EXT_FILESYSTEM_INTERFACE_LSEEK_POS_H_
8 #define EXT_FILESYSTEM_INTERFACE_LSEEK_POS_H_
15 #include "../core/superblock.h"
16 #include "../core/descriptors_table.h"
17 #include "../core/defines.h"
18 #include "../core/methods.h"
22 void lseek_pos(
const char* path_to_fs_file,
23 uint16_t file_descriptor,
24 uint32_t pos,
int output_fd) {
26 size_t buffer_size = 0;
27 int fd = open(path_to_fs_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
29 fprintf(stderr,
"Can't open file. Abort!\n");
33 struct superblock superblock;
35 if (superblock.fs_info->magic != MAGIC) {
36 fprintf(stderr,
"Magic does not match. Abort!\n");
42 if (!superblock.reserved_inodes_mask[ROOT_INODE_ID]) {
43 fprintf(stderr,
"Root directory doesn't exist. Abort!\n");
49 struct descriptors_table descriptors_table;
51 fprintf(stderr,
"Can't read descriptors_table. Abort!\n");
57 if (!descriptors_table.reserved_fd[file_descriptor]) {
58 buffered_write(&buffer, &buffer_size,
"Descriptor is closed. Abort!\n", strlen(
"Descriptor is closed. Abort!\n"));
60 send_data(output_fd, buffer, buffer_size);
68 buffered_write(&buffer, &buffer_size,
"Position >= max_data_in_file. Abort!\n", strlen(
"Position >= max_data_in_file. Abort!\n"));
70 send_data(output_fd, buffer, buffer_size);
77 descriptors_table.fd_to_position[file_descriptor] = pos;
80 fprintf(stderr,
"Can't write descriptors_table. Abort!\n");
89 send_data(output_fd, buffer, buffer_size);
100 #endif //EXT_FILESYSTEM_INTERFACE_LSEEK_POS_H_
ssize_t write_descriptor_table(int fd, struct descriptors_table *descriptors_table, const struct superblock *superblock)
Write descriptors_table to memory.
void destruct_descriptors_table(struct descriptors_table *descriptors_table, const struct superblock *superblock)
Destructor of superblock.
uint32_t get_max_data_size_of_all_blocks(const struct superblock *superblock)
void destroy_super_block(struct superblock *superblock)
Destructor of superblock.
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)
int buffered_write(char **buffer, size_t *buffer_size, char *data, size_t size)