-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemTest.c
94 lines (83 loc) · 2.25 KB
/
FileSystemTest.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "FileSystem.h"
void displayOptions();
void commandChoice();
int main(){
char str[20];
char str1[20];
printf("Enter the drive: (Drive2MB , Drive3MB ,Drive5MB , Drive10MB): \n");
scanf("%s" , str1);
setup(str1); // start up the filesystem
while (1){ // display options until user exits
displayOptions();
printf("$ ");
scanf("%s", str);
commandChoice(str); // calls the appropriate filesystem method
}
}
void displayOptions(){
printf("Here are your options:\n");
printf("\"create\"\t\"delete\" \n");
printf("\"read\" \t\"write\" \n");
printf("\"mkdir\" \t\"list\" \n");
printf("\"open\" \t\"exit\" \n");
printf("\"close\" \n");
}
void commandChoice(char str[]){
char fileName[11];
int firstBlock;
if (strcmp(str, "create") == 0){
printf("Enter the name of file: ");
scanf("%s", fileName);
create(fileName, 0); // 0 flag means file
}
else if (strcmp(str, "delete") == 0){ // delete files
printf("Enter the name of file: ");
scanf("%12s", fileName);
fs_delete(fileName);
}
else if (strcmp(str, "read") == 0){ // read data blocks of a file
printf("Enter the name of file: ");
scanf("%12s", fileName);
fs_read(fileName);
}
else if (strcmp(str, "write") == 0){
char *dataBlock = calloc(32768, sizeof(char)); // create an empty larger array
printf("Enter the name of file: ");
scanf("%12s", fileName);
printf("--- Write --- \n");
if(read(STDIN_FILENO, dataBlock, 32768) < 0){
}
fs_write(fileName, dataBlock);
free(dataBlock);
}
else if (strcmp(str, "mkdir") == 0){ // create a directory
printf("Enter the name of directory: ");
scanf("%s", fileName);
create(fileName, 1); // 1 flag means directory
}
else if (strcmp(str, "list") == 0){ // exit program
list();
}
else if(strcmp(str , "open") == 0){
printf("Enter the file name to open: ");
scanf("%12s", fileName);
firstBlock = fs_open(fileName);
printf("First block of the file is: \n");
printf("%d\n" , firstBlock);
}
else if(strcmp(str , "exit") == 0){
fs_exit();
exit(0);
}
else if (strcmp(str, "close") == 0){
fs_close();
printf("Successfully close the file \n");
}
else {
printf("Invalid Command\n");
}
}