Skip to content

Commit

Permalink
chore: better naming for file system (nervosnetwork#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong authored Jan 24, 2025
1 parent 97dc827 commit 82c5f38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
18 changes: 6 additions & 12 deletions libc/ckb_cell_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ typedef struct FSEntry {
FSBlob content;
} FSEntry;

typedef struct CellFileSystemNode {
typedef struct FSCellNode {
uint32_t count;
FSEntry *files;
void *start;
const char *prefix;
} CellFileSystemNode;
} FSCellNode;

typedef struct CellFileSystem {
CellFileSystemNode *current;
struct CellFileSystem *next;
} CellFileSystem;
typedef struct FSCell {
FSCellNode *current;
struct FSCell *next;
} FSCell;

typedef struct FSFile {
const char *filename;
Expand All @@ -33,14 +33,8 @@ typedef struct FSFile {
uint8_t rc;
} FSFile;

int get_file(const CellFileSystem *fs, const char *filename, FSFile **f);

int ckb_get_file(const char *filename, FSFile **file);

int load_fs(CellFileSystem **fs, const char *prefix, void *buf, uint64_t buflen);

int ckb_load_fs(const char *prefix, void *buf, uint64_t buflen);

void ckb_reset_fs();

#endif
14 changes: 7 additions & 7 deletions libc/src/ckb_cell_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

#include "ckb_cell_fs.h"

static CellFileSystem *CELL_FILE_SYSTEM = NULL;
static FSCell *CELL_FILE_SYSTEM = NULL;

int get_file(const CellFileSystem *fs, const char *filename, FSFile **f) {
static int get_file(const FSCell *fs, const char *filename, FSFile **f) {
if (fs == NULL) {
return -1;
}
FSFile *file = malloc(sizeof(FSFile));
if (file == 0) {
return -1;
}
CellFileSystem *cfs = (CellFileSystem *)fs;
CellFileSystemNode *node = cfs->current;
FSCell *cfs = (FSCell *)fs;
FSCellNode *node = cfs->current;
while (node != NULL) {
if (strncmp(node->prefix + 1, filename, strlen(node->prefix) - 1) != 0) {
if (cfs->next == NULL) {
Expand Down Expand Up @@ -53,17 +53,17 @@ int get_file(const CellFileSystem *fs, const char *filename, FSFile **f) {

int ckb_get_file(const char *filename, FSFile **file) { return get_file(CELL_FILE_SYSTEM, filename, file); }

int load_fs(CellFileSystem **fs, const char *prefix, void *buf, uint64_t buflen) {
static int load_fs(FSCell **fs, const char *prefix, void *buf, uint64_t buflen) {
if (fs == NULL || buf == NULL) {
return -1;
}

CellFileSystemNode *node = (CellFileSystemNode *)malloc(sizeof(CellFileSystemNode));
FSCellNode *node = (FSCellNode *)malloc(sizeof(FSCellNode));
if (node == NULL) {
return -1;
}

CellFileSystem *newfs = (CellFileSystem *)malloc(sizeof(CellFileSystem));
FSCell *newfs = (FSCell *)malloc(sizeof(FSCell));
if (newfs == NULL) {
free(node);
return -1;
Expand Down

0 comments on commit 82c5f38

Please sign in to comment.