text/plain
•
1.21 KB
•
47 lines
#pragma once
#include <stdbool.h>
#include <stddef.h>
#define STORAGE_MAX_PATH 256
#define STORAGE_MAX_NAME 64
typedef enum {
STORAGE_TYPE_FILE,
STORAGE_TYPE_DIR,
} storage_entry_type_t;
typedef struct {
char name[STORAGE_MAX_NAME];
storage_entry_type_t type;
size_t size;
} storage_entry_t;
typedef void *storage_file_t;
// Initialize storage subsystem
// Returns true on success, false on failure
bool storage_init(void);
// List directory contents
// Returns number of entries written, or -1 on error
int storage_list_dir(const char *path, storage_entry_t *entries, int max);
// Open a file for reading or writing
// mode: "r" for read, "w" for write, "a" for append
// Returns NULL on failure
storage_file_t storage_open(const char *path, const char *mode);
// Read from an open file
// Returns number of bytes read, or 0 on EOF/error
size_t storage_read(storage_file_t file, void *buf, size_t size);
// Write to an open file
// Returns number of bytes written
size_t storage_write(storage_file_t file, const void *buf, size_t size);
// Close an open file
// Returns 0 on success, -1 on error
int storage_close(storage_file_t file);
// Check if storage is mounted and ready
bool storage_is_mounted(void);