-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemfs.h
42 lines (36 loc) · 1.14 KB
/
memfs.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
#ifndef MEMFS_H
#define MEMFS_H
typedef struct File {
char *name;
char *contents;
int size;
} File;
typedef struct Directory {
char *name;
int permission;
struct Directory* parent;
struct Directory** directories;
int directory_count;
struct File** files;
int file_count;
} Directory;
typedef struct FileSystem {
int total_size;
Directory* root_directory;
} FileSystem;
FileSystem *newFileSystem();
Directory *newDirectory(const char *name, int permission);
File *newFile(const char *name);
void addDirectory(Directory *parent, Directory *child);
void addFile(Directory *dir, File *file);
void mkdir(FileSystem *fs, const char *path, int permission);
File* findFile(Directory *dir, const char *name);
void writeFile(FileSystem *fs, const char *path, const char *data);
const char *readFile(FileSystem *fs, const char *path);
void listDirectories(Directory *dir);
void listFiles(Directory *dir);
int calculateDirectoryMemoryHelper(Directory *dir, int total_memory);
int calculateDirectoryMemory(Directory *dir);
int calculateFileSystemMemory(FileSystem *fs);
void freeMemory(Directory *dir);
#endif // MEMFS_H