#ifndef FS_CORE_H
#define FS_CORE_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FS_CORE_OK = 0,
FS_CORE_IO = 1,
FS_CORE_SHORT_READ = 2,
FS_CORE_READ_ONLY = 3,
FS_CORE_OUT_OF_BOUNDS = 4,
FS_CORE_CUSTOM = 5,
FS_CORE_NULL_ARG = 6,
FS_CORE_PANIC = 7,
FS_CORE_BAD_STRING = 8,
} FsCoreErrorCode;
typedef struct FsCoreDevice FsCoreDevice;
const char *fs_core_last_error_message(void);
void fs_core_device_close(FsCoreDevice *handle);
uint64_t fs_core_device_size_bytes(const FsCoreDevice *handle);
bool fs_core_device_is_writable(const FsCoreDevice *handle);
FsCoreErrorCode fs_core_device_read_at(const FsCoreDevice *handle,
uint64_t offset,
uint8_t *buf,
size_t len);
FsCoreErrorCode fs_core_device_write_at(const FsCoreDevice *handle,
uint64_t offset,
const uint8_t *buf,
size_t len);
FsCoreErrorCode fs_core_device_flush(const FsCoreDevice *handle);
FsCoreDevice *fs_core_file_open(const char *path, bool writable);
typedef int (*FsCoreReadCb)(void *ctx, uint64_t offset, uint8_t *buf, size_t len);
typedef int (*FsCoreWriteCb)(void *ctx, uint64_t offset, const uint8_t *buf, size_t len);
typedef int (*FsCoreFlushCb)(void *ctx);
typedef struct {
FsCoreReadCb read;
FsCoreWriteCb write;
FsCoreFlushCb flush;
void *ctx;
uint64_t size;
} FsCoreCallbackCfg;
FsCoreDevice *fs_core_device_from_callbacks(const FsCoreCallbackCfg *cfg);
FsCoreDevice *fs_core_device_slice_ro(const FsCoreDevice *parent,
uint64_t start, uint64_t length);
FsCoreDevice *fs_core_device_slice_rw(const FsCoreDevice *parent,
uint64_t start, uint64_t length);
#ifdef __cplusplus
}
#endif
#endif