-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.cpp
128 lines (123 loc) · 2.57 KB
/
user.cpp
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
#include "fileSystem.h"
using namespace std;
string cur_path = ".";
int cur_inode_set = 0;
void help()
{
cout << "创建目录----mkdir [目录名]" << endl;
cout << "删除目录----rmdir [目录名]" << endl;
cout << "修改名称----mv [旧目录名] [新目录名]" << endl;
cout << "创建文件----open [文件名]" << endl;
cout << "修改文件----edit [文件名]" << endl;
cout << "删除文件----rm [文件名]" << endl;
cout << "查看系统目录----ls" << endl;
cout << "查看当前目录----lsc" << endl;
cout << "访问目录----cd [路径]" << endl;
cout << "显示文件内容---cat [文件名]" << endl;
cout << "退出系统----quit" << endl;
}
int main()
{
// 创建共享内存
void *shared_memory = (void *)0;
int shm_id = shmget((key_t)1234, 100*1024*1024, 0666|IPC_CREAT);
if(shm_id < 0)
{
perror("shmget fail!\n");
exit(1);
}
// 共享内存挂入进程
shared_memory = shmat(shm_id, 0, 0);
if(shared_memory < 0)
{
perror("shmat fail!\n");
exit(1);
}
shared_stuff = (struct shared_mem_st*)shared_memory;
cout << "------输入“help”查看功能------" << endl;
string op;
while(1)
{
cout << "\033[33m~:\033[0m";
cin >> op;
if(strcmp(op.data(), "mkdir") == 0)
{
string path;
cin >> path;
Mkdir(cur_inode_set, path);
}
else if(strcmp(op.data(), "rmdir") == 0)
{
string path;
cin >> path;
string s = ".";
path = s+path;
Rmdir(cur_inode_set, path);
}
else if(strcmp(op.data(), "mv") == 0)
{
string name1, name2;
cin >> name1 >> name2;
Mv(cur_inode_set, name1, name2);
}
else if(strcmp(op.data(), "open") == 0)
{
string name;
cin >> name;
Open(cur_inode_set, name);
}
else if(strcmp(op.data(), "edit") == 0)
{
string name;
cin >> name;
Edit(cur_inode_set, name);
}
else if(strcmp(op.data(), "rm") == 0)
{
string name;
cin >> name;
Rm(cur_inode_set, name);
}
else if(strcmp(op.data(), "cd") == 0)
{
string path;
cin >> path;
Cd(cur_inode_set, path);
}
else if(strcmp(op.data(), "cat") == 0)
{
string name;
cin >> name;
Cat(cur_inode_set, name);
}
else if(strcmp(op.data(), "ls") == 0)
{
Ls(root_inode_set, root_path, 0);
}
else if(strcmp(op.data(), "lsc") == 0)
{
Lsc(cur_inode_set);
}
else if(strcmp(op.data(), "help") == 0)
{
help();
}
else if(strcmp(op.data(), "quit") == 0)
{
break;
}
else
{
cout << "无该操作。" << endl;
}
cin.sync();
}
if((shmdt(shared_stuff)) < 0)
{
perror("shmdt");
exit(1);
}
//sem_unlink(queue_mutex);
//sem_unlink(queue_empty);
return 0;
}