-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeofs.h
More file actions
304 lines (265 loc) · 13.1 KB
/
geofs.h
File metadata and controls
304 lines (265 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* ══════════════════════════════════════════════════════════════════════════════
*
* PHANTOM GeoFS
* Geology FileSystem - Library API
*
* "To Create, Not To Destroy"
*
* This header exposes the GeoFS library functions for use by the
* Phantom kernel and other system components.
*
* ══════════════════════════════════════════════════════════════════════════════
*/
#ifndef GEOFS_H
#define GEOFS_H
#include <stdint.h>
#include <stddef.h>
/* ══════════════════════════════════════════════════════════════════════════════
* CONFIGURATION
* ══════════════════════════════════════════════════════════════════════════════ */
#define GEOFS_VERSION 0x0001
#define GEOFS_MAGIC 0x53464F4547ULL /* "GEOFS" */
#define GEOFS_HASH_SIZE 32
#define GEOFS_MAX_PATH 4096
#define GEOFS_MAX_NAME 255
#define GEOFS_BLOCK_SIZE 4096
/* ══════════════════════════════════════════════════════════════════════════════
* TYPES
* ══════════════════════════════════════════════════════════════════════════════ */
typedef uint8_t geofs_hash_t[GEOFS_HASH_SIZE];
typedef uint64_t geofs_time_t;
typedef uint64_t geofs_view_t;
typedef enum {
GEOFS_OK = 0,
GEOFS_ERR_IO = -1,
GEOFS_ERR_NOMEM = -2,
GEOFS_ERR_NOTFOUND = -3,
GEOFS_ERR_EXISTS = -4,
GEOFS_ERR_INVALID = -5,
GEOFS_ERR_CORRUPT = -6,
GEOFS_ERR_FULL = -7,
} geofs_error_t;
/* ══════════════════════════════════════════════════════════════════════════════
* STRUCTURES
* ══════════════════════════════════════════════════════════════════════════════ */
/* Opaque volume handle */
typedef struct geofs_volume geofs_volume_t;
/* Directory entry returned by listing */
struct geofs_dirent {
char name[GEOFS_MAX_NAME + 1];
geofs_hash_t content_hash;
uint64_t size;
geofs_time_t created;
int is_dir;
};
/* View information */
struct geofs_view_info {
geofs_view_t id;
geofs_view_t parent_id;
geofs_time_t created;
char label[64];
};
/* File history entry (for geology viewer) */
struct geofs_history_entry {
char path[GEOFS_MAX_PATH];
geofs_hash_t content_hash;
geofs_view_t view_id;
geofs_time_t created;
uint64_t size;
int is_hidden;
};
/* ══════════════════════════════════════════════════════════════════════════════
* CALLBACK TYPES
* ══════════════════════════════════════════════════════════════════════════════ */
typedef void (*geofs_dir_callback)(const struct geofs_dirent *entry, void *ctx);
typedef void (*geofs_view_callback)(const struct geofs_view_info *info, void *ctx);
typedef void (*geofs_history_callback)(const struct geofs_history_entry *entry, void *ctx);
/* ══════════════════════════════════════════════════════════════════════════════
* VOLUME OPERATIONS
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* Create a new GeoFS volume.
*
* @param path Path to the volume file (will be created)
* @param size_mb Size of the volume in megabytes
* @param vol_out Output pointer for the opened volume
* @return GEOFS_OK on success, error code otherwise
*/
geofs_error_t geofs_volume_create(const char *path, uint64_t size_mb,
geofs_volume_t **vol_out);
/*
* Open an existing GeoFS volume.
*
* @param path Path to the volume file
* @param vol_out Output pointer for the opened volume
* @return GEOFS_OK on success, error code otherwise
*/
geofs_error_t geofs_volume_open(const char *path, geofs_volume_t **vol_out);
/*
* Close a GeoFS volume.
* All changes are flushed to disk.
*
* @param vol The volume to close
*/
void geofs_volume_close(geofs_volume_t *vol);
/* ══════════════════════════════════════════════════════════════════════════════
* CONTENT OPERATIONS (append-only, content-addressed)
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* Store content in the volume.
* Content is deduplicated by hash - storing the same data twice is a no-op.
*
* @param vol The volume
* @param data Pointer to the data to store
* @param size Size of the data
* @param hash_out Output: the content hash (32 bytes)
* @return GEOFS_OK on success
*/
geofs_error_t geofs_content_store(geofs_volume_t *vol, const void *data,
size_t size, geofs_hash_t hash_out);
/*
* Read content from the volume by hash.
*
* @param vol The volume
* @param hash The content hash
* @param buf Buffer to read into
* @param buf_size Size of the buffer
* @param size_out Output: actual bytes read
* @return GEOFS_OK on success, GEOFS_ERR_NOTFOUND if hash not found
*/
geofs_error_t geofs_content_read(geofs_volume_t *vol, const geofs_hash_t hash,
void *buf, size_t buf_size, size_t *size_out);
/*
* Get the size of content by hash.
*
* @param vol The volume
* @param hash The content hash
* @param size_out Output: the content size
* @return GEOFS_OK on success
*/
geofs_error_t geofs_content_size(geofs_volume_t *vol, const geofs_hash_t hash,
uint64_t *size_out);
/* ══════════════════════════════════════════════════════════════════════════════
* REFERENCE OPERATIONS (path -> content mapping)
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* Create a reference (path -> content hash mapping).
* References are versioned by view - old versions remain accessible.
*
* @param vol The volume
* @param path The file path
* @param content_hash The content hash this path should point to
* @return GEOFS_OK on success
*/
geofs_error_t geofs_ref_create(geofs_volume_t *vol, const char *path,
const geofs_hash_t content_hash);
/*
* Resolve a path to its content hash in the current view.
*
* @param vol The volume
* @param path The file path
* @param hash_out Output: the content hash
* @return GEOFS_OK on success, GEOFS_ERR_NOTFOUND if not found
*/
geofs_error_t geofs_ref_resolve(geofs_volume_t *vol, const char *path,
geofs_hash_t hash_out);
/*
* List files in a directory.
*
* @param vol The volume
* @param dir_path The directory path (e.g., "/" or "/subdir")
* @param callback Called for each entry
* @param ctx User context passed to callback
* @return Number of entries found
*/
int geofs_ref_list(geofs_volume_t *vol, const char *dir_path,
geofs_dir_callback callback, void *ctx);
/* ══════════════════════════════════════════════════════════════════════════════
* VIEW OPERATIONS (geological strata)
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* Create a new view (geological stratum).
* Views provide a way to see different "versions" of the filesystem.
*
* @param vol The volume
* @param label Optional label for the view
* @param view_out Output: the new view ID
* @return GEOFS_OK on success
*/
geofs_error_t geofs_view_create(geofs_volume_t *vol, const char *label,
geofs_view_t *view_out);
/*
* Switch to a different view.
* This changes what files are visible - older views show older state.
*
* @param vol The volume
* @param view_id The view to switch to
* @return GEOFS_OK on success
*/
geofs_error_t geofs_view_switch(geofs_volume_t *vol, geofs_view_t view_id);
/*
* Get the current view ID.
*
* @param vol The volume
* @return The current view ID
*/
geofs_view_t geofs_view_current(geofs_volume_t *vol);
/*
* List all views.
*
* @param vol The volume
* @param callback Called for each view
* @param ctx User context passed to callback
* @return Number of views
*/
int geofs_view_list(geofs_volume_t *vol, geofs_view_callback callback, void *ctx);
/*
* Hide a file from the current view.
* This does NOT delete the file - it creates a new view where the file
* is not visible. The file can still be accessed from earlier views.
*
* @param vol The volume
* @param path The file path to hide
* @return GEOFS_OK on success
*/
geofs_error_t geofs_view_hide(geofs_volume_t *vol, const char *path);
/* ══════════════════════════════════════════════════════════════════════════════
* HISTORY OPERATIONS
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* List all file entries in the geology (file history).
* This includes all versions of all files, including hidden entries.
*
* @param vol The volume
* @param callback Called for each history entry
* @param ctx User context passed to callback
* @return Number of entries
*/
int geofs_ref_history(geofs_volume_t *vol, geofs_history_callback callback, void *ctx);
/* ══════════════════════════════════════════════════════════════════════════════
* UTILITY FUNCTIONS
* ══════════════════════════════════════════════════════════════════════════════ */
/*
* Get a human-readable error message.
*
* @param err The error code
* @return Error message string
*/
const char *geofs_strerror(geofs_error_t err);
/*
* Format a timestamp for display.
*
* @param t The timestamp
* @param buf Buffer to write to
* @param len Buffer length
*/
void geofs_time_format(geofs_time_t t, char *buf, size_t len);
/*
* Convert a hash to a hex string.
*
* @param hash The hash (32 bytes)
* @param buf Buffer for hex string (must be at least 65 bytes)
*/
void geofs_hash_to_string(const geofs_hash_t hash, char *buf);
#endif /* GEOFS_H */