2026-04-02 16:00:27 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2026-04-02 16:25:49 +02:00
|
|
|
// Copyright (C) 2013 Andrea Mazzoleni
|
2013-02-28 22:35:52 +01:00
|
|
|
|
|
|
|
|
#ifndef __IMPORT_H
|
|
|
|
|
#define __IMPORT_H
|
|
|
|
|
|
|
|
|
|
#include "elem.h"
|
|
|
|
|
#include "state.h"
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
/* import */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import block.
|
|
|
|
|
* Block used to import data external when recovering by hash.
|
|
|
|
|
*/
|
|
|
|
|
struct snapraid_import_block {
|
|
|
|
|
struct snapraid_import_file* file; /**< Back pointer to the file owning this block. */
|
2026-06-04 00:34:51 +02:00
|
|
|
size_t size; /**< Size of the block. */
|
2013-02-28 22:35:52 +01:00
|
|
|
data_off_t offset; /**< Position of the block in the file. */
|
2016-04-07 21:39:02 +02:00
|
|
|
unsigned char hash[HASH_MAX]; /**< Hash of the block. */
|
|
|
|
|
unsigned char prevhash[HASH_MAX]; /**< Previous hash of the block. Valid only if we are in rehash state. */
|
2013-02-28 22:35:52 +01:00
|
|
|
|
|
|
|
|
/* nodes for data structures */
|
|
|
|
|
tommy_hashdyn_node nodeset;
|
2013-07-01 23:08:25 +02:00
|
|
|
tommy_hashdyn_node prevnodeset;
|
2013-02-28 22:35:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import file.
|
|
|
|
|
* File used to import data external when recovering by hash.
|
|
|
|
|
*/
|
|
|
|
|
struct snapraid_import_file {
|
|
|
|
|
data_off_t size; /**< Size of the file. */
|
2015-10-01 18:19:48 +02:00
|
|
|
struct snapraid_import_block* blockimp; /**< All the blocks of the file. */
|
2013-02-28 22:35:52 +01:00
|
|
|
block_off_t blockmax; /**< Number of blocks. */
|
|
|
|
|
char* path; /**< Full path of the file. */
|
2026-04-27 14:39:38 +02:00
|
|
|
int is_runtime; /**< If the hash was obtained at runtime */
|
2013-02-28 22:35:52 +01:00
|
|
|
|
|
|
|
|
/* nodes for data structures */
|
|
|
|
|
tommy_node nodelist;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2015-10-07 22:07:20 +02:00
|
|
|
* Deallocate an import file.
|
2013-02-28 22:35:52 +01:00
|
|
|
*/
|
|
|
|
|
void import_file_free(struct snapraid_import_file* file);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch a block from the specified hash.
|
|
|
|
|
* Return ==0 if the block is found, and copied into buffer.
|
|
|
|
|
*/
|
2014-10-19 21:07:17 +02:00
|
|
|
int state_import_fetch(struct snapraid_state* state, int prevhash, struct snapraid_block* missing_block, unsigned char* buffer);
|
2013-02-28 22:35:52 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import files from the specified directory.
|
|
|
|
|
*/
|
|
|
|
|
void state_import(struct snapraid_state* state, const char* dir);
|
|
|
|
|
|
2026-04-27 14:39:38 +02:00
|
|
|
/**
|
|
|
|
|
* Import files from the dealloc list.
|
|
|
|
|
*/
|
|
|
|
|
void state_dealloc(struct snapraid_state* state, const char* dir, tommy_list* dealloclist);
|
|
|
|
|
|
2013-02-28 22:35:52 +01:00
|
|
|
#endif
|
|
|
|
|
|