-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileSystem.h
More file actions
146 lines (119 loc) · 3.03 KB
/
fileSystem.h
File metadata and controls
146 lines (119 loc) · 3.03 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
** File: fileSystem.c
**
** Authors: Max Roth, Nicholas Jenis, Ernesto Soltero
**
** Description: Header for implementation of Simple File System
*/
#ifndef SFS_H
#define SFS_H
#include "types.h"
#include "klib.h"
//Constants
#define MAX_NAME_LENGTH 256
#define MAX_FILE_NAME_LENGTH 32
#define NUM_ENTRIES 512 //Maximum number of entries in file table
//Size of the disk we are allocating (on RAM for now)
#define DISK_SIZE 32 * 1024 * 1024
#define DATA_BLOCK_SIZE 512
#define NUM_BLOCKS (DISK_SIZE - (NUM_ENTRIES * sizeof(sfs_entry) + \
sizeof(uint8_t))) / DATA_BLOCK_SIZE
#define RAM_START_ADDRESS 0x40000000
//Entry types
#define DIRECTORY 1
#define FILE 2
#define DIR_SEPERATOR '/'
#define ROOT "/"
#define CURRENT_DIR .
#define PREV_DIR ..
/*
** Structure representing a file entry in SFS
*/
typedef struct sfs_entry {
char name[MAX_NAME_LENGTH]; //was uint8_t, no reason not to be char?
uint16_t size; //Remove after sizeOf method is made
uint16_t payload; //This is the first data block where data is stored
uint8_t type;
} sfs_entry;
/*
** Structure representing the data of a file in SFS
*/
typedef struct sfs_data {
uint8_t next;
uint8_t data[DATA_BLOCK_SIZE - sizeof(uint8_t)];
} sfs_data;
/*
typedef struct sfs_read_buffer {
uint32_t start;
uint8_t size;
uint32_t buf;
} sfs_read_buffer;
*/
/*
** Structure representing the SFS file table and underlying structure
*/
typedef struct sfs_file_table {
sfs_entry entries[NUM_ENTRIES];
uint8_t current_location; //Remove once findFreeSpace is implemented
sfs_data blocks[NUM_BLOCKS];
char directory[MAX_NAME_LENGTH - MAX_FILE_NAME_LENGTH - 1];
} sfs_file_table;
/*
** A global pointer to the file system table
** DO NOT REFERENCE BEFORE RUNNING sfs_init();
*/
sfs_file_table* fileSystem;
/*
** Create and initialize a file system, returning it's representative
** sfs_file_table structure
*/
void _sfs_init( void );
/*
** Create a new file - do this
** Return 0 on success, anything else on error
*/
uint8_t _sfs_create(char* name, uint8_t entry_type);
/*
** Delete an existing file - do this
*/
uint8_t _sfs_delete(char* filename);
/*
** Read an existing file
*/
uint8_t* _sfs_read(char* filename);
/*
** Write to an existing file
*/
uint8_t _sfs_write(char* filename, uint16_t size, uint8_t* buffer, int doAppend);
/*
** List all files in the directory
** Weird thing in old SFS file, no directories???
*/
uint8_t* _sfs_list( void );
/*
** Checks if a file/directory exists
**
** Returns a pointer to the file/directory if it exists
** Returns a pointer to address 0 in RAM if it does not
*/
sfs_entry* _sfs_exists( char* filename, uint8_t filetype );
/*
** Return a pointer to the file system file table
*/
sfs_file_table* _get_fileSystem( void );
/*
** Returns a pointer to the string holding the current directory
*/
char* _get_directory( void );
/*
** Change the current directory
**
** Return 0 on success
** Return anything else on failure
*/
uint8_t _set_directory( char* new_dir );
/**
** Update a filename to match the current directory
**/
char* _adjust_filename( char* filename );
#endif