Login
1 branch 0 tags
Ben (Desktop/Arch) .onigiri -> Onigiri 38f4776 1 month ago 74 Commits
moon / src / storage.h
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "moon.h"

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);