-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemfs.h
56 lines (50 loc) · 1.07 KB
/
memfs.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
#ifndef MEMFS_H
#define MEMFS_H
#include <iostream>
#include <stdexcept>
#include <vector>
#include <thread>
#include <string>
#include <sstream>
#include <unordered_map>
#include <mutex>
#include <ctime>
#include <chrono>
#include <iomanip>
#include <fstream>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
#include <string>
#include <mutex>
#include <atomic>
using namespace std;
// file structure
struct File
{
string name;
string content;
size_t size;
string creation_time;
string last_modified;
};
// class for in-memory file system
class MemFS
{
private:
// searchable by filename
unordered_map<string, File> files;
mutex fs_mutex;
public:
// core operations
void createFiles(const vector<string> &filenames);
void writeFile(const string &filename, const string &content);
void deleteFiles(const vector<string> &filenames);
string readFile(const string &filename);
vector<vector<string>> listFiles(bool detailed = false);
};
#endif