-
Notifications
You must be signed in to change notification settings - Fork 0
/
filemanager.c
104 lines (82 loc) · 1.72 KB
/
filemanager.c
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
#include "types.h"
#include "fcntl.h"
#include "user.h"
char* usage = "Usage : filemanager <command> [command opts]\n";
int createDir(char* path);
int createFile(char* filename);
void firstHeuristicTest(char* folder);
void secondHeuristicTest(char* file, char* folder);
int
createFile(char* filename){
printf(1, "Creating File %s\n", filename);
int fd = open(filename, O_CREATE);
if(fd > 0){
printf(1, "File Creation Successful!\n");
close(fd);
}
else {
printf(2, "There was an error creating the file!\n");
exit();
}
return fd;
}
int
createDir(char* path){
int val;
printf(1, "Creating Folder %s\n", path);
if( (val = mkdir(path))){
printf(2, "There was an error creating the directory\n");
exit();
}
else printf(1, "Dir created successfully!\n");
return val;
}
void
firstHeuristicTest(char* folder){
//Step 1 : Create a dir
createDir(folder);
printStats();
// Not created
}
void
secondHeuristicTest(char* file, char* folder){
//Step 2 : Cd into new dir
if(chdir(folder)){
printf(2, "Error Changing to dir : %s\n", folder);
exit();
}
else printf(1, "Successfully Changed to dir : %s\n", folder);
//Step 3 : Create a file
createFile(file);
//Step 4 : Verify file in same block group
printStats();
}
int
main(int argc, char *argv[])
{
if(argc == 1){
printf(2, usage);
exit();
}
char* cmd = argv[1];
if(0 == strcmp(cmd, "create_file")){
createFile(argv[2]);
}
else if(0 == strcmp(cmd, "create_dir")){
createDir(argv[2]);
}
else if (0 == strcmp(cmd, "tests")){
char *file = "H2F1",
*folder="test2";
if(argc > 2){
file = argv[2];
}
if(argc > 3){
folder = argv[3];
}
firstHeuristicTest(folder);
secondHeuristicTest(file, folder);
}
exit();
return 0;
}