-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_system.h
92 lines (69 loc) · 2.1 KB
/
file_system.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
//Joshua Guempel
//CS 3800
//File system header
#ifndef FILE_SYSTEM_H
#define FILE_SYSTEM_H
#include <iostream>
#include <unordered_map>
#include <memory>
#include <stack>
#include <string>
#include <vector>
#include <ctime>
#include <math.h>
#include <algorithm>
struct file {
std::string name = "UNNAMED";
std::string permissions = "----------";
std::string date = "----------";
file(){}
file(const std::string& file_name);
};
struct folder {
std::string name = "UNNAMED";
std::string permissions = "----------";
std::string date = "----------";
//The main implementation of this system: map of strings to folder/file pointers,
//with a pointer to the parent for traversal, NOT resource management
folder* parent = nullptr;
std::unordered_map<std::string, std::shared_ptr<folder>> folders;
std::unordered_map<std::string, std::shared_ptr<file>> files;
folder(){}
folder(const std::string& folder_name, folder* folder_parent = nullptr);
};
class shell {
private:
folder* curr_dir = nullptr; //Pointer for traversal
folder root_folder;
public:
//list file in current directory
void ls(const std::string& args);
//Connect to a directory
void cd(const std::string& args);
//Print directory and parents
void pwd();
//print directory for shell (slightly different than pwd)
void print_dir_for_shell();
//Make a directory
void mkdir(const std::string& args);
//remove a directory
void rmdir(const std::string& args);
//remove a file
void rm(const std::string& args);
//Change permissions
void chmod(const std::string& args, const std::string& args1);
//Create a file
void touch(const std::string& args);
//Quit
void quit();
//Parse out command arguments and call one of the above functions
void process_command(const std::string& args);
shell(){}
//construct shell with root folder (/)
shell(folder& root_dir);
};
//get date in a formatted string.
std::string get_date();
//convert octal to binary
std::vector<int> octal_to_binary(std::string octal_num);
#endif