-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathShell.h
91 lines (64 loc) · 2.23 KB
/
Shell.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
// CPSC 3500: Shell
// Implements a basic shell (command line interface) for the file system
#ifndef SHELL_H
#define SHELL_H
#include <cstring>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
// Shell
class Shell {
public:
//constructor, do not change it!!
Shell() : cs_sock(-1), is_mounted(false) {}
// Mount a network file system located in host:port, set is_mounted = true if success
void mountNFS(string fs_loc); //fs_loc must be in the format of server:port
//unmount the mounted network file syste,
void unmountNFS();
// Executes the shell until the user quits.
void run();
// Execute a script.
void run_script(char *file_name);
private:
int cs_sock; //socket to the network file system server
bool is_mounted; //true if the network file system is mounted, false otherise
// data structure for command line
struct Command
{
string name; // name of command
string file_name; // name of file
string append_data; // append data (append only)
};
// Executes the command. Returns true for quit and false otherwise.
bool execute_command(string command_str);
// Parses a command line into a command struct. Returned name is blank
// for invalid command lines.
struct Command parse_command(string command_str);
// Remote procedure call on mkdir
void mkdir_rpc(string dname);
// Remote procedure call on cd
void cd_rpc(string dname);
// Remote procedure call on home
void home_rpc();
// Remote procedure call on rmdir
void rmdir_rpc(string dname);
// Remote procedure call on ls
void ls_rpc();
// Remote procedure call on create
void create_rpc(string fname);
// Remote procedure call on append
void append_rpc(string fname, string data);
// Remote procesure call on cat
void cat_rpc(string fname);
// Remote procedure call on head
void head_rpc(string fname, int n);
// Remote procedure call on rm
void rm_rpc(string fname);
// Remote procedure call on stat
void stat_rpc(string fname);
// Prints the response from the server
void print_response(string command, string response);
};
#endif