-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (55 loc) · 1.59 KB
/
main.cpp
File metadata and controls
70 lines (55 loc) · 1.59 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parser.h"
#include "commands.h"
#include "fileio.h"
int main() {
char input[30];
char disk[] = "harddisk.hdd";
Metadata metadata;
char *buffer = (char *)malloc(sizeof(char) * BLOCKSIZE);
read_block(buffer, 0, disk);
memcpy(&metadata, buffer, sizeof(Metadata));
free(buffer);
while (1) {
printf(">>");
if (format_required(metadata, disk)) {
printf("format required!(y/n): ");
gets(input);
if (input[0] == 'y') {
format(disk);
read_block(buffer, 0, disk);
memcpy(&metadata, buffer, sizeof(Metadata));
printf(">>");
}
else {
printf("Format terminated\n");
break;
}
}
gets(input);
Command *command = parse_command(input);
if (command -> type == -1)
break;
if (command -> type == 0) {
printf("Not a valid command");
continue;
}
if (command -> type == 1) {
metadata = copyfrom(command -> file_name, disk, metadata);
}
if (command -> type == 2) {
copyto(command -> file_name, command -> file_name2, metadata, disk);
}
if (command -> type == 3) {
ls(metadata);
}
if (command -> type == 4) {
metadata = delete_file(command -> file_name, metadata, disk);
}
free(command -> file_name);
free(command);
}
return 0;
}