-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrfs.h
120 lines (115 loc) · 3.08 KB
/
mrfs.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
#include <iostream>
#include <fstream>
#include <random>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
class mrfs {
private:
class block {
char data[256];
};
block *FS;
int _key;
bool init;
class superblock {
public:
int block_count;
int& size;
int& max_inodes;
int& used_inodes;
int* inodes;
int& max_blocks;
int& used_blocks;
int* blocks;
superblock();
superblock(block *FS); //NOLINT
superblock& operator=(block* FS);
};
superblock sb;
class indexnode {
public:
int filetype;
int filesize;
time_t lastModified;
time_t lastRead;
int owner;
int acPermissions;
int direct[8];
int indirect;
int doubleindirect;
};
indexnode *inode;
inline int reqblock() {
if(sb.used_blocks==sb.max_blocks) return -1;
for(int i=0;i<sb.max_blocks;i++)
if(sb.blocks[i]==0) return i;
return -1;
}
inline int16_t reqinode() {
if(sb.used_inodes==sb.max_inodes) return -1;
for(int16_t i=0;i<sb.max_inodes;i++)
if(sb.inodes[i]==0) return i;
return -1;
}
class dirlist {
public:
char name[30];
int16_t inode;
};
int16_t curdir;
class blocklist {
public:
block **list;
int *blist;
int numblocks;
blocklist();
blocklist(block* FS, indexnode& inode);
~blocklist();
inline block* operator[](int i) {
return list[i];
}
};
public:
const int &key;
inline void print() {
using std::cout;
using std::endl;
cout<<"Key: "<<key<<endl;
cout<<"Size: "<<sb.size<<endl;
cout<<"Max Inodes: "<<sb.max_inodes<<endl;
cout<<"Used Inodes: "<<sb.used_inodes<<endl;
cout<<"Max Blocks: "<<sb.max_blocks<<endl;
cout<<"Used Blocks: "<<sb.used_blocks<<endl;
cout<<"Super Blocks: "<<sb.block_count<<endl;
cout<<"FS: "<<FS<<endl;
cout<<"inode: "<<inode<<endl;
}
mrfs();
mrfs(const int& key); //NOLINT
mrfs(const mrfs& other);
mrfs& operator=(const int& key);
mrfs& operator=(const mrfs& other);
~mrfs();
int create_myfs(int size);
int copy_pc2myfs(const char *source, const char *dest);
int copy_myfs2pc(const char *source, const char *dest) const;
int rm_myfs(const char *filename);
int showfile_myfs(const char *filename) const;
int ls_myfs() const;
int mkdir_myfs(const char *dirname);
int chdir_myfs(const char *dirname);
int rmdir_myfs(const char *dirname);
int open_myfs(const char *filename, char mode);
int close_myfs(int fd);
int read_myfs(int fd, int nbytes, char *buff);
int write_myfs(int fd, int nbytes, char *buff);
int eof_myfs(int fd);
int dump_myfs (const char *dumpfile) const;
int restore_myfs (const char *dumpfile);
int status_myfs() const;
int chmod_myfs(const char *name, int mode);
};