-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfileSystem.h
240 lines (188 loc) · 5.28 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef FILESYS_H
#define FILESYS_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include "disk.h"
/*
Declarations of Disk parameters
*/
#define BLOCK_SIZE 512
#define WORD_SIZE 16
#define OS_STARTUP_CODE 0
#define EX_HANDLER 1
#define TIMERINT 3
#define INT1 5
#define INT2 7
#define INT3 9
#define INT4 11
#define INT5 13
#define INT6 15
#define INT7 17
#define OS_STARTUP_CODE_SIZE 1
#define EX_HANDLER_SIZE 2
#define TIMERINT_SIZE 2
#define INT1_SIZE 2
#define INT2_SIZE 2
#define INT3_SIZE 2
#define INT4_SIZE 2
#define INT5_SIZE 2
#define INT6_SIZE 2
#define INT7_SIZE 2
#define FAT 19
#define NO_OF_FAT_BLOCKS 1
#define DISK_FREE_LIST 20
#define NO_OF_FREE_LIST_BLOCKS 1
#define INIT_BASIC_BLOCK 21
#define INIT_NAME "init.xsm"
#define NO_OF_INIT_BLOCKS 3
#define NO_OF_INTERRUPTS 7
#define DATA_START_BLOCK 24
#define NO_OF_DATA_BLOCKS 424
#define SWAP_START_BLOCK 448
#define NO_OF_SWAP_BLOCKS 64
#define NO_OF_DISK_BLOCKS 512
#define DISK_SIZE (NO_OF_DISK_BLOCKS * BLOCK_SIZE)
/*
Declarations for FAT Entry
*/
#define FATENTRY_FILENAME 0
#define FATENTRY_FILESIZE 1
#define FATENTRY_BASICBLOCK 2
#define FATENTRY_SIZE 8
#define FAT_SIZE (NO_OF_FAT_BLOCKS * BLOCK_SIZE)
/*
Declarations for files
*/
#define SIZE_EXEFILE_BASIC 4
#define SIZE_EXEFILE 3
#define MAX_DATAFILE_SIZE_BASIC 257
#define MAX_DATAFILE_SIZE 256
/*
Other declarations
*/
#define NO_BLOCKS_TO_COPY 21 //Rest of the blocks have data. Blocks 0-12 need to be copied
#define EXTRA_BLOCKS 1 // Need a temporary block
#define TEMP_BLOCK 21 //Temporary block no: starting from 0.
#define ASSEMBLY_CODE 0
#define DATA_FILE 1
typedef struct{
char word[BLOCK_SIZE][WORD_SIZE];
}BLOCK;
BLOCK disk[NO_BLOCKS_TO_COPY + EXTRA_BLOCKS]; // disk contains the memory copy of the necessary blocks of the actual disk file.
/*
This function lists all the files present on the disk.
*/
void listAllFiles();
/*
This function deletes an executable file from the disk.
*/
int deleteExecutableFromDisk(char *name);
/*
This function removes the fat entry corresponding to the first arguement.
*/
int removeFatEntry(int locationOfFat);
/*
This function returns the basic block entry(pass by pointer) corresponding to the address specified by the second arguement.
*/
int getDataBlocks(int *basicBlockAddr, int locationOfFat);
/*
This function loads the executable file corresponding to the first arguement to an appropriate location on the disk.
*/
int loadExecutableToDisk(char *name);
/*
This function checks if a file having name as the first arguement is present on the disk file.
*/
int CheckRepeatedName(char *name);
/*
This function returns the address of a free block on the disk.
*/
int FindFreeBlock();
/*
This function returns an empty fat entry if present.
*/
int FindEmptyFatEntry();
/*
This function frees the blocks specified by the block numbers present in the first arguement. The second arguement is the size
of the first argument.
*/
void FreeUnusedBlock(int *freeBlock, int size);
/*
This function adds the name, size and basic block address of the file to corresponding entry in the fat.
*/
void AddEntryToMemFat(int startIndexInFat, char *nameOfFile, int sizeOfFile, int addrOfBasicBlock);
/*
This function copies the necessary contents of a file to the corresponding location specified by the second arguemnt on the disk. The type specifies the type of file
to be copied.
*/
int writeFileToDisk(FILE *f, int blockNum, int type);
/*
This function loads the OS startup code specified by the first arguement to its appropriate location on disk.
*/
int loadOSCode(char* name);
/*
This function copies the interrupts to the proper location on the disk.
*/
int loadIntCode(char* name, int intNo);
/*
This function copies the timer interrupt to the proper location on the disk.
*/
int loadTimerCode(char* name);
/*
This function copies the exception handler to the proper location on the disk.
*/
int loadExHandlerToDisk(char* name);
/*
This function copies the init program to its proper location on the disk.
*/
int loadINITCode(char* name);
/*
This function displays the content of the files stored in the disk.
*/
void displayFileContents(char *name);
/*
This function copies the contents of the disk starting from <startBlock> to <endBlock> to a unix file.
*/
void copyBlocksToFile (int startBlock,int endBlock,char *name);
/*
This function deletes the INIT code from the disk.
*/
int deleteINITFromDisk();
/*
This function deletes the OS code from the disk.
*/
int deleteOSCodeFromDisk();
/*
This function deletes the Timer Interrupt from the disk.
*/
int deleteTimerFromDisk();
/*
This function deletes the Interrupt <intNo> from the disk.
*/
int deleteIntCode(int intNo);
/*
This function deletes the Exception Handler from the disk.
*/
int deleteExHandlerFromDisk();
/*
This function displays disk free list and the amount of free space in the disk.
*/
void displayDiskFreeList();
/*
This function loads a data file to the disk.
*/
int loadDataToDisk(char *name);
/*
This function deletes a data file from the disk.
*/
int deleteDataFromDisk(char *name);
/*
This function expands environment variables in path
*/
void expandpath(char *path);
/*
This function adds extensions (.dat or .xsm) for files loaded into xfs
*/
void addext(char *filename, char *ext);
#endif