#include #include #include #include #include "file.h" #include "ifile.h" #include "inode.h" inode_t create_ifile(unsigned int volume, enum file_type_e type) { struct inode_desc_t inode; inode_t inode_no = new_block(volume); assert(inode_no && "Aucun espace dispo sur le periphérique"); /* Créer l'inoeud */ inode = new_inode(volume, type); inode.size = 0; write_data_to_block(volume, inode_no, &inode, sizeof(struct inode_desc_t)); return inode_no; } int open_ifile(unsigned int volume, inode_t inode_no, struct file_desc_t *fd) { struct inode_desc_t inode; /* Lire l'inode */ read_data_from_block(volume, inode_no, &inode, sizeof(struct inode_desc_t)); assert(inode.magic_key == INODE_MAGIC); fd->volume = volume; fd->inode_block = inode_no; fd->buffer = malloc(block_size()); fd->flags = 0; fd->filesize = inode.size; if ( fd->filesize == 0 ) memset(fd->buffer, 0, block_size()); else read_bloc(volume, inode.ind_direct[0], fd->buffer); fd->type = inode.type; fd->cur_pos = 0; return OPEN_SUCCESS; } int delete_ifile(unsigned int volume, inode_t inode_no) { struct inode_desc_t inode; /* Lire l'inode */ read_data_from_block(volume, inode_no, &inode, sizeof(struct inode_desc_t) ); /* Libérer les blocs */ free_inode_blocks(inode); free_block(inode.volume, inode_no); return 0; }