-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilesystem.h
94 lines (65 loc) · 1.71 KB
/
filesystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef _FILESYSTEM_H_
#define _FILESYSTEM_H_
#include <inttypes.h>
#include <stdbool.h>
#include "alloc.h"
#define FS_ERROR 0
#define FS_SUCCESS 1
/*
* FS_REGULAR
*/
typedef struct {
uint8_t *start;
uint32_t size;
} fs_regular;
/*
* FS_DIRECTORY
*/
typedef struct fs_list_cell* fs_iterator;
typedef struct {
fs_iterator children;
} fs_directory;
/*
* FS_FILE
*/
enum {FS_TYPE_REGULAR, FS_TYPE_DIRECTORY};
typedef union {
fs_regular regular;
fs_directory directory;
} fs_file_data;
typedef struct {
fs_file_data *data;
uint8_t file_type; // REGULAR, DIRECTORY
char * name;
} fs_file;
typedef struct fs_list_cell {
fs_file *file;
fs_iterator next;
} fs_list_cell;
int8_t fs_new_root(mem_allocator *allocator, fs_file *root);
int8_t fs_delete_root(mem_allocator *allocator, fs_file *root);
int8_t fs_add_regular(mem_allocator *allocator,
fs_file *dir,
const char *filename,
fs_file **newfile);
int8_t fs_add_dir(mem_allocator *allocator,
fs_file *dir,
const char *dirname,
fs_file **newdir);
int8_t fs_remove_file(mem_allocator *allocator,
fs_file *parent,
const char *name);
bool fs_is_directory(fs_file* file);
bool fs_is_regular(fs_file* file);
const char * fs_get_name(fs_file *file);
fs_iterator fs_get_first_child(fs_file *dir);
fs_iterator fs_get_next_child(fs_iterator iterator);
fs_file* fs_get_file_by_iter(fs_iterator iterator);
//void fs_get_root_cursor(fs_file *dir);
int8_t fs_write_regular(mem_allocator *allocator,
fs_file *file,
const uint8_t *data,
uint32_t size);
int8_t fs_get_memdata(fs_file *file, uint8_t **data, uint32_t *size);
fs_file* fs_get_file_by_path(fs_file *root, fs_file *working, const char *filepath);
#endif