text/plain
•
1.65 KB
•
62 lines
#pragma once
#include <stdbool.h>
#include <stddef.h>
#define STORAGE_MAX_PATH 256
#define STORAGE_MAX_NAME 64
#define STORAGE_MAX_DIR_ENTRIES 256
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);
// Create a directory (no-op if it already exists)
// Returns true on success or if directory already exists
bool storage_mkdir(const char *path);
// Remove a file
// Returns true on success or if file didn't exist
bool storage_remove(const char *path);
// Check if storage is mounted and ready
bool storage_is_mounted(void);
// Unmount filesystem (e.g. for USB mass storage access)
void storage_unmount(void);
// Remount filesystem after USB mass storage access
bool storage_remount(void);