static void read_metadata(input_stream *inp, size_t *count, grpc_metadata **metadata, call_state *cs) { *count = next_byte(inp); *metadata = gpr_malloc(*count * sizeof(**metadata)); memset(*metadata, 0, *count * sizeof(**metadata)); for (size_t i = 0; i < *count; i++) { (*metadata)[i].key = read_string(inp); read_buffer(inp, (char **)&(*metadata)[i].value, &(*metadata)[i].value_length); (*metadata)[i].flags = read_uint32(inp); add_to_free(cs, (void *)(*metadata)[i].key); add_to_free(cs, (void *)(*metadata)[i].value); } add_to_free(cs, *metadata); }
int deleteFile(const char* fileName){ CVFS *vfs=getVFS(); FT *trav = vfs->myft; FT *prev = NULL; //traverse till the required file while(trav!=NULL){ if(strcmp(trav->name,fileName)==0){ BLOCK *del = trav->data,*next; //add data block of the file to free data blocks while(del!=NULL){ next = del->next; add_to_free(del); del = next; } if(prev == NULL) vfs->myft = trav->next; else prev->next = trav->next; //printf("root %d %d\n",vfs->free->offset,vfs->free->size); del = vfs->free; //combine adjacent data blocks in the free to overcome fragmentation of data blocks in free while(del->next != NULL){ if(del->offset+del->size == del->next->offset){ del->size += del->next->size; next = del->next; del->next = del->next->next; free(next); } del = del->next; if(del==NULL) break; } //free the data entry free(trav); return SUCCESS; } prev = trav; trav = trav->next; } return NOTFOUND; }