-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystem.h
117 lines (82 loc) · 2.89 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
/*
* This is the file system interface header. It defines the basic functions for
* configuring the file system and reading/writing inodes and blocks
* by Jon
*/
#include "DiskEmulator.h"
#include "OpenFileTable.h"
#include "INodeCache.h"
#include "INodeTable.h"
#include "DBlkCache.h"
#include "SuperBlock.h"
#include "Utility.h"
typedef struct FileSystem {
//the superblock of the filesystem
SuperBlock superblock;
//the size, in bytes, of the whole filesystem
LONG nBytes;
//logical id of the first inode block
UINT diskINodeBlkOffset;
//logical id of the first data block
UINT diskDBlkOffset;
//the open file table of the filesystem
OpenFileTable openFileTable;
//the inode table of the filesystem
INodeTable inodeTable;
//the inode cache of the filesystem
INodeCache inodeCache;
//the datablk cache of the filesystem
DBlkCache dCache;
//the disk device of the filesystem
//in Phase 1, this is an in-memory array
DiskArray* disk;
} FileSystem;
// creates the file system
INT makefs(LONG, UINT, FileSystem*);
// destroys a file system
INT closefs(FileSystem*);
// allocate a free inode
INT allocINode(FileSystem*, INode*);
// free an allocated inode
INT freeINode(FileSystem*, UINT);
// reads an inode (iget)
// input: file system inode number
// output: locked inode
INT readINode(FileSystem*, UINT, INode*);
// reads an inode without looking for/adding to the inode cache
INT readINodeNoCache(FileSystem*, UINT, INode*);
// reads from the file section of the inode
// returns the number of bytes read, -1 on failure
LONG readINodeData(FileSystem*, INode*, BYTE*, LONG, LONG);
// writes to an inode
INT writeINode(FileSystem*, UINT, INode*);
// writes to the file section of the inode
// returns the number of bytes written, -1 on failure
LONG writeINodeData(FileSystem*, INode*, BYTE*, LONG, LONG);
// allocate a free data block
LONG allocDBlk(FileSystem*);
// free an allocated data block
INT freeDBlk(FileSystem*, LONG);
// reads a data block
INT readDBlk(FileSystem*, LONG, BYTE*);
// writes a data block
INT writeDBlk(FileSystem*, LONG, BYTE*);
// reads certain number of bytes from a block with offset
INT readDBlkOffset(FileSystem*, LONG, BYTE*, UINT, UINT);
// writes certain number of bytes of a block with offset
INT writeDBlkOffset(FileSystem*, LONG, BYTE*, UINT, UINT);
// converts file byte offset in inode to logical block ID
LONG bmap(FileSystem* fs, INode* inode, LONG fileBlkId);
// map flattened index to internal index of the inode
LONG balloc(FileSystem*, INode *, LONG);
// free file blk in an inode
INT bfree(FileSystem*, INode *, LONG);
#ifdef DEBUG
// prints all the inodes for debugging
void printINodes(FileSystem*);
void printDBlkInts(BYTE *buf);
void printDBlkBytes(BYTE *buf);
void printDBlkChars(BYTE *buf);
// prints all the data blocks for debugging
void printDBlks(FileSystem*);
#endif