mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
progress on volatileFilesystem and fixed a file descriptor leak
This commit is contained in:
parent
64a6b84b30
commit
79e9a8ac2f
@ -28,6 +28,7 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
|
||||
"src/components/eeprom.c",
|
||||
"src/components/volatileEeprom.c",
|
||||
"src/components/filesystem.c",
|
||||
"src/components/volatileFilesystem.c",
|
||||
"src/components/drive.c",
|
||||
"src/components/volatileDrive.c",
|
||||
"src/components/screen.c",
|
||||
|
@ -46,6 +46,12 @@ void nn_retainFilesystem(nn_filesystem *fs) {
|
||||
|
||||
nn_bool_t nn_destroyFilesystem(nn_filesystem *fs) {
|
||||
if(!nn_decRef(&fs->refc)) return false;
|
||||
|
||||
// close all files
|
||||
for(size_t i = 0; i < NN_MAX_OPEN_FILES; i++) {
|
||||
void *f = fs->files[i];
|
||||
if(f != NULL) fs->table.close(fs->table.userdata, f);
|
||||
}
|
||||
|
||||
if(fs->table.deinit != NULL) {
|
||||
fs->table.deinit(fs->table.userdata);
|
||||
|
41
src/components/volatileFilesystem.c
Normal file
41
src/components/volatileFilesystem.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include "../neonucleus.h"
|
||||
|
||||
typedef struct nn_vfnode {
|
||||
struct nn_vfilesystem *fs;
|
||||
struct nn_vfnode *parent;
|
||||
char name[NN_MAX_PATH];
|
||||
nn_bool_t isDirectory;
|
||||
union {
|
||||
// if directory
|
||||
struct nn_vfnode **entries;
|
||||
// if file
|
||||
char *data;
|
||||
};
|
||||
nn_size_t len;
|
||||
nn_size_t cap;
|
||||
// this is used to block deleting
|
||||
nn_refc handleCount;
|
||||
} nn_vfnode;
|
||||
|
||||
typedef enum nn_vfmode {
|
||||
NN_VFMODE_READ,
|
||||
NN_VFMODE_WRITE,
|
||||
NN_VFMODE_APPEND,
|
||||
} nn_vfmode;
|
||||
|
||||
typedef struct nn_vfhandle {
|
||||
nn_vfnode *node;
|
||||
nn_size_t position;
|
||||
nn_vfmode mode;
|
||||
} nn_vfhandle;
|
||||
|
||||
typedef struct nn_vfilesystem {
|
||||
nn_Context ctx;
|
||||
nn_vfilesystemOptions opts;
|
||||
double birthday;
|
||||
nn_vfnode *root;
|
||||
} nn_vfilesystem;
|
||||
|
||||
nn_filesystem *nn_volatileFilesystem(nn_Context *context, nn_vfilesystemOptions opts, nn_filesystemControl control) {
|
||||
|
||||
}
|
@ -117,6 +117,7 @@ extern "C" {
|
||||
#define NN_MAX_SIGNAL_SIZE 8192
|
||||
#define NN_MAX_OPEN_FILES 128
|
||||
#define NN_MAX_SCREEN_KEYBOARDS 64
|
||||
#define NN_MAX_PATH 256
|
||||
|
||||
#define NN_OVERHEAT_MIN 100
|
||||
#define NN_CALL_HEAT 0.05
|
||||
@ -656,7 +657,6 @@ typedef struct nn_filesystemTable {
|
||||
void *userdata;
|
||||
void (*deinit)(void *userdata);
|
||||
|
||||
nn_filesystemControl (*control)(void *userdata);
|
||||
void (*getLabel)(void *userdata, char *buf, nn_size_t *buflen);
|
||||
nn_size_t (*setLabel)(void *userdata, const char *buf, nn_size_t buflen);
|
||||
|
||||
@ -692,7 +692,18 @@ typedef struct nn_filesystemTable {
|
||||
|
||||
typedef struct nn_filesystem nn_filesystem;
|
||||
|
||||
typedef struct nn_vfilesystemOptions {
|
||||
// used to compute lastModified
|
||||
nn_size_t creationTime;
|
||||
nn_size_t maxDirEntries;
|
||||
nn_size_t capacity;
|
||||
nn_bool_t isReadOnly;
|
||||
char label[NN_LABEL_SIZE];
|
||||
nn_size_t labelLen;
|
||||
} nn_vfilesystemOptions;
|
||||
|
||||
nn_filesystem *nn_newFilesystem(nn_Context *context, nn_filesystemTable table, nn_filesystemControl control);
|
||||
nn_filesystem *nn_volatileFilesystem(nn_Context *context, nn_vfilesystemOptions opts, nn_filesystemControl control);
|
||||
nn_guard *nn_getFilesystemLock(nn_filesystem *fs);
|
||||
void nn_retainFilesystem(nn_filesystem *fs);
|
||||
nn_bool_t nn_destroyFilesystem(nn_filesystem *fs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user