Implement FileTree serialization and deserialization routines

This commit is contained in:
2025-11-17 15:02:22 +01:00
parent fbcfd80f6d
commit eaa3f3a8a1
3 changed files with 241 additions and 11 deletions
+13 -11
View File
@@ -16,8 +16,8 @@ enum {
typedef struct Entity Entity;
typedef struct {
uint64_t chunk_size;
uint64_t num_chunks;
uint64_t chunk_size; // TODO: this should be an u32
uint64_t num_chunks; // TODO: and this too
SHA256 *chunks;
} File;
@@ -49,14 +49,16 @@ typedef struct {
#define MAX_COMPS 32
int file_tree_init(FileTree *ft);
void file_tree_free(FileTree *ft);
bool file_tree_uses_hash(FileTree *ft, SHA256 hash);
int file_tree_list(FileTree *ft, string path, ListItem *items, int max_items);
int file_tree_create_entity(FileTree *ft, string path, bool is_dir, uint64_t chunk_size);
int file_tree_delete_entity(FileTree *ft, string path);
int file_tree_write(FileTree *ft, string path, uint64_t off, uint64_t len, uint32_t num_chunks, uint32_t chunk_size, SHA256 *prev_hashes, SHA256 *hashes, SHA256 *removed_hashes, int *num_removed);
int file_tree_read(FileTree *ft, string path, uint64_t off, uint64_t len, uint64_t *chunk_size, SHA256 *hashes, int max_hashes);
string file_tree_strerror(int code);
int file_tree_init (FileTree *ft);
void file_tree_free (FileTree *ft);
bool file_tree_uses_hash (FileTree *ft, SHA256 hash);
int file_tree_list (FileTree *ft, string path, ListItem *items, int max_items);
int file_tree_create_entity (FileTree *ft, string path, bool is_dir, uint64_t chunk_size);
int file_tree_delete_entity (FileTree *ft, string path);
int file_tree_write (FileTree *ft, string path, uint64_t off, uint64_t len, uint32_t num_chunks, uint32_t chunk_size, SHA256 *prev_hashes, SHA256 *hashes, SHA256 *removed_hashes, int *num_removed);
int file_tree_read (FileTree *ft, string path, uint64_t off, uint64_t len, uint64_t *chunk_size, SHA256 *hashes, int max_hashes);
string file_tree_strerror (int code);
int file_tree_serialize (FileTree *ft, int (*flush_fn)(char*,int,void*), void *flush_data);
int file_tree_deserialize (FileTree *ft, int (*read_fn)(char*,int,void*), void *read_data);
#endif // FILE_TREE_INCLUDED