From 09f1ed4b3e26c7ed69faaca3851db4b4885cf6f6 Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Mon, 17 Nov 2025 11:50:22 +0100 Subject: [PATCH] Reorganize types in ToastyFS.h by placing them near function interfaces that reference them --- inc/ToastyFS.h | 72 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/inc/ToastyFS.h b/inc/ToastyFS.h index 6dd6ec7..6cda758 100644 --- a/inc/ToastyFS.h +++ b/inc/ToastyFS.h @@ -29,40 +29,9 @@ typedef struct { // Macro to convert string literals to ToastyStrings #define TOASTY_STR(X) ((ToastyString) { (X), (int) sizeof(X)-1 }) -// Handle representing a pending operation -typedef uint32_t ToastyHandle; - -// Invalid value for a ToastyHandle -#define TOASTY_INVALID ((ToastyHandle) 0) - -typedef struct { - char name[128]; // TODO: Implement a proper name length - bool is_dir; -} ToastyListingEntry; - -typedef struct { - int count; - ToastyListingEntry *items; -} ToastyListing; - -typedef enum { - TOASTY_RESULT_EMPTY, - TOASTY_RESULT_CREATE_ERROR, - TOASTY_RESULT_CREATE_SUCCESS, - TOASTY_RESULT_DELETE_ERROR, - TOASTY_RESULT_DELETE_SUCCESS, - TOASTY_RESULT_LIST_ERROR, - TOASTY_RESULT_LIST_SUCCESS, - TOASTY_RESULT_READ_ERROR, - TOASTY_RESULT_READ_SUCCESS, - TOASTY_RESULT_WRITE_ERROR, - TOASTY_RESULT_WRITE_SUCCESS, -} ToastyResultType; - -typedef struct { - ToastyResultType type; - ToastyListing listing; -} ToastyResult; +////////////////////////////////////////////////////////////////////////////////// +// PRIMARY +////////////////////////////////////////////////////////////////////////////////// // Instanciate a ToastyFS client object. The "addr" and "port" // arguments refer to the address and port of the cluster's @@ -90,6 +59,16 @@ int toasty_create_file(ToastyFS *toasty, ToastyString path, // Returns 0 on success, -1 on error. int toasty_delete(ToastyFS *toasty, ToastyString path); +typedef struct { + char name[128]; // TODO: Implement a proper name length + bool is_dir; +} ToastyListingEntry; + +typedef struct { + int count; + ToastyListingEntry *items; +} ToastyListing; + // Lists all files and directories within the given // path. Returns 0 and fills up the listing argument // on success, returns -1 on error. The listing is @@ -117,6 +96,12 @@ int toasty_write(ToastyFS *toasty, ToastyString path, int off, // ASYNCHRONOUS API ////////////////////////////////////////////////////////////////////////////////// +// Handle representing a pending operation +typedef uint32_t ToastyHandle; + +// Invalid value for a ToastyHandle +#define TOASTY_INVALID ((ToastyHandle) 0) + // Begins a directory creation operation and returns // a handle to it. On error, TOASTY_INVALID is returned. ToastyHandle toasty_begin_create_dir(ToastyFS *toasty, ToastyString path); @@ -146,6 +131,25 @@ ToastyHandle toasty_begin_read(ToastyFS *toasty, ToastyString path, ToastyHandle toasty_begin_write(ToastyFS *toasty, ToastyString path, int off, void *src, int len); +typedef enum { + TOASTY_RESULT_EMPTY, + TOASTY_RESULT_CREATE_ERROR, + TOASTY_RESULT_CREATE_SUCCESS, + TOASTY_RESULT_DELETE_ERROR, + TOASTY_RESULT_DELETE_SUCCESS, + TOASTY_RESULT_LIST_ERROR, + TOASTY_RESULT_LIST_SUCCESS, + TOASTY_RESULT_READ_ERROR, + TOASTY_RESULT_READ_SUCCESS, + TOASTY_RESULT_WRITE_ERROR, + TOASTY_RESULT_WRITE_SUCCESS, +} ToastyResultType; + +typedef struct { + ToastyResultType type; + ToastyListing listing; +} ToastyResult; + // If the operation specified by "handle" is complete, // its result is stored in "result" and 0 is returned. // If the operation is still in progress, 1 is returned.