Document communication between metadata server and clients in the misc/PROTOCOL.txt file and add generation counters for files

This commit is contained in:
2025-11-24 13:04:29 +01:00
parent 1c768bb8f1
commit 49091aff6d
7 changed files with 445 additions and 98 deletions
+36 -11
View File
@@ -3,6 +3,8 @@
#include "basic.h"
#define NO_GENERATION ((uint64_t) 0)
enum {
FILETREE_NOMEM = -1,
FILETREE_NOENT = -2,
@@ -29,6 +31,7 @@ typedef struct {
} Dir;
struct Entity {
uint64_t gen;
char name[1<<8];
uint16_t name_len;
bool is_dir;
@@ -40,6 +43,7 @@ struct Entity {
typedef struct {
Entity root;
uint64_t next_gen;
} FileTree;
typedef struct {
@@ -50,16 +54,37 @@ 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, uint64_t *actual_bytes);
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);
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, uint64_t *gen);
int file_tree_create_entity(FileTree *ft, string path,
bool is_dir, uint64_t chunk_size, uint64_t *gen);
int file_tree_delete_entity(FileTree *ft, string path,
uint64_t expected_gen);
int file_tree_write(FileTree *ft, string path,
uint64_t off, uint64_t len, uint32_t num_chunks,
uint64_t expect_gen,
uint64_t *new_gen,
SHA256 *hashes,
SHA256 *removed_hashes,
int *num_removed);
int file_tree_read(FileTree *ft, string path,
uint64_t off, uint64_t len, uint64_t *gen, uint64_t *chunk_size,
SHA256 *hashes, int max_hashes, uint64_t *actual_bytes);
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