Keeps track of the hash of deleted blocks.

This will allow an easier recovering providing manually deleted files.
This commit is contained in:
Andrea Mazzoleni 2013-02-24 19:02:53 +01:00
parent 027b6e3fcd
commit 5c4f6dc5c4
10 changed files with 357 additions and 159 deletions

32
elem.c
View file

@ -295,6 +295,36 @@ unsigned block_file_size(struct snapraid_block* block, unsigned block_size)
return block_size;
}
struct snapraid_deleted* deleted_alloc(void)
{
struct snapraid_deleted* deleted;
deleted = malloc_nofail(sizeof(struct snapraid_deleted));
/* set the state as deleted */
deleted->block.file_mixed = BLOCK_STATE_DELETED;
return deleted;
}
struct snapraid_deleted* deleted_dup(struct snapraid_block* block)
{
struct snapraid_deleted* deleted;
deleted = deleted_alloc();
/* copy data from deleted block */
deleted->block.parity_pos = block->parity_pos;
memcpy(deleted->block.hash, block->hash, HASH_SIZE);
return deleted;
}
void deleted_free(struct snapraid_deleted* deleted)
{
free(deleted);
}
struct snapraid_file* file_alloc(unsigned block_size, const char* sub, uint64_t size, uint64_t mtime_sec, int mtime_nsec, uint64_t inode)
{
struct snapraid_file* file;
@ -415,6 +445,7 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev
disk->device = dev;
disk->first_free_block = 0;
tommy_list_init(&disk->filelist);
tommy_list_init(&disk->deletedlist);
tommy_hashdyn_init(&disk->inodeset);
tommy_hashdyn_init(&disk->pathset);
tommy_list_init(&disk->linklist);
@ -429,6 +460,7 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev
void disk_free(struct snapraid_disk* disk)
{
tommy_list_foreach(&disk->filelist, (tommy_foreach_func*)file_free);
tommy_list_foreach(&disk->deletedlist, (tommy_foreach_func*)deleted_free);
tommy_hashdyn_done(&disk->inodeset);
tommy_hashdyn_done(&disk->pathset);
tommy_list_foreach(&disk->linklist, (tommy_foreach_func*)link_free);