-
Notifications
You must be signed in to change notification settings - Fork 0
/
inodesystem.h
229 lines (196 loc) · 6.5 KB
/
inodesystem.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
#ifndef INODESYSTEM_H
#define INODESYSTEM_H
#include <vector>
#include <map>
#include <QDate>
#include "disk.h"
#include <string>
#include <string.h>
#include <sstream>
#include <QMessageBox>
#include "blockstatus.h"
using namespace std;
#define BLOCKSIZE 512
#define MAX_FILES 10
/**
* @struct INode
* @brief Represents an inode in the file system.
*/
struct INode {
int iNodeNum; /**< Inode number */
string name; /**< Name of the file or folder */
vector<int> blockList; /**< List of blocks associated with the inode */
string author; /**< Author of the file or folder */
QDateTime date; /**< Date of creation or modification */
int size; /**< Size of the file or folder */
bool isFolder; /**< Flag indicating if the inode is a folder */
};
/**
* @class INODESYSTEM
* @brief Manages inodes and file operations in the file system.
*/
class INODESYSTEM {
map<int, INode *> nodes; /**< Map of inode numbers to inode pointers */
Disk *disk; /**< Pointer to the disk */
vector<BlockStatus> blockStatus; /**< Vector of block statuses */
int totalBlocks; /**< Total number of blocks in the disk */
public:
/**
* @brief Constructor for INODESYSTEM.
* @param diskSize Size of the disk.
* @param disk_ Pointer to the disk.
*/
INODESYSTEM(int diskSize, Disk *disk_);
/**
* @brief Displays the file allocation table (FAT).
*/
void showINodes();
/**
* @brief Deletes a file from the file system.
* @param fileName Name of the file to delete.
* @param deleteFolderInFolder Flag to delete folders within folders.
* @param ignoreFolderTyp Flag to ignore folder type.
*/
void deleteFile(string fileName, bool deleteFolderInFolder = false, bool ignoreFolderTyp = false);
/**
* @brief Finds a file by name.
* @param fileName Name of the file to find.
* @return Inode number of the file.
*/
int findFile(string fileName);
/**
* @brief Finds a file by inode number.
* @param num Inode number of the file to find.
* @return Inode number of the file.
*/
int findFile(int num);
/**
* @brief Creates a file in the file system.
* @param name_ Name of the file.
* @param author_ Author of the file.
* @param data Data to be stored in the file.
* @param parentName Name of the parent folder.
* @param isFolder Flag indicating if the file is a folder.
* @return Name of the created file.
*/
string createFile(string name_, string author_, string data, string parentName, bool isFolder = false);
/**
* @brief Finds the lowest available inode number.
* @return Lowest available inode number.
*/
int findLowestNumber();
/**
* @brief Finds the second lowest available inode number.
* @return Second lowest available inode number.
*/
int findLowestNumber2();
/**
* @brief Gets the free disk space.
* @return Free disk space.
*/
int getFreeDiskSpace();
/**
* @brief Renames a file in the file system.
* @param fileName Current name of the file.
* @param newName New name of the file.
*/
void renameFile(string fileName, string newName);
/**
* @brief Gets the nodes in the file system.
* @return Map of inode numbers to inode pointers.
*/
map<int, INode *> getNodes() const;
/**
* @brief Sets the nodes in the file system.
* @param newNodes Map of inode numbers to inode pointers.
*/
void setNodes(const map<int, INode *> &newNodes);
/**
* @brief Gets the disk.
* @return Pointer to the disk.
*/
Disk *getDisk() const;
/**
* @brief Sets the disk.
* @param newDisk Pointer to the new disk.
*/
void setDisk(Disk *newDisk);
/**
* @brief Gets the fragmentation of the disk.
* @return Fragmentation percentage.
*/
float getFragmentation();
/**
* @brief Defragments the disk.
*/
void defragDisk();
/**
* @brief Edits the data of a file.
* @param fileToBeEditedId Inode number of the file to be edited.
* @param data New data to be stored in the file.
* @return Status of the edit operation.
*/
int editData(int fileToBeEditedId, string data);
/**
* @brief Finds the folder containing a file.
* @param fileName Name of the file.
* @return Name of the folder containing the file.
*/
string findFolderofFile(string fileName);
/**
* @brief Gets the folders in a folder.
* @param folderName Name of the folder.
* @return List of inodes representing the folders.
*/
QList<INode *> getFoldersInFolder(string folderName);
/**
* @brief Gets the files in a folder.
* @param folderName Name of the folder.
* @return List of inodes representing the files.
*/
QList<INode *> getFilesInFolder(string folderName);
/**
* @brief Splits a string into a vector of integers.
* @param inputString String to be split.
* @return Vector of integers.
*/
vector<int> splitStringIntoInts(string inputString);
/**
* @brief Deletes a folder from the file system.
* @param fileName Name of the folder to delete.
*/
void deleteFolder(string fileName);
/**
* @brief Checks if a file exists in a folder.
* @param fileName Name of the file.
* @param folderName Name of the folder.
* @return true if the file exists, false otherwise.
*/
bool existFileInFolder(string fileName, string folderName);
/**
* @brief Gets the data of a file.
* @param fileName Name of the file.
* @return Data of the file.
*/
string getDataOfFile(string fileName);
/**
* @brief Creates a unique name for a file.
* @param fileName Base name of the file.
* @param uniqueText Text to make the name unique.
* @return Unique name of the file.
*/
string createUniqueName(string fileName, string uniqueText = "-C");
/**
* @brief Copies a file to a folder.
* @param fileName Name of the file to copy.
* @param folderName Name of the folder to copy the file to.
*/
void copyFile(string fileName, string folderName);
/**
* @brief Checks if a file exists in the file system.
* @param fileName Name of the file.
* @return true if the file exists, false otherwise.
*/
bool existFile(string fileName);
};
#endif // INODESYSTEM_H