-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfile.c
66 lines (60 loc) · 1.62 KB
/
file.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
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include "fat32disk.h"
#include "directory.h"
#include "recover.h"
int main(int argc, char **argv){
int flag=0, anyOption=0;
int information=0, listRootDir=0, recoverFiles=0, sha=0;
char *recOptarg, *shaOptarg;
// go through all of the flags
while((flag=getopt(argc, argv, "ilr:s:")) != -1){
anyOption=1;
switch(flag){
case 'i':
information=1;
break;
case 'l':
listRootDir=1;
break;
case 'r':
recoverFiles=1;
recOptarg = optarg;
break;
case 's':
sha = 1;
shaOptarg = optarg;
break;
default:
showUsage();
break;
}
}
if (anyOption==0 || optind==argc)
showUsage();
// get file system information
int fd = getFileDirectory(argv[optind]);
BootEntry* disk = readFileSystem(fd);
if (information)
showDiskInformation(disk);
else if (listRootDir)
getRootDirectoryEntries(fd, disk);
else if(sha){ // use sha only when -r flag is given
if(recoverFiles){
if (recOptarg == NULL)
showUsage();
recoverFile(fd, disk, recOptarg, shaOptarg);
}
else{
showUsage();
}
}
else if(recoverFiles && !sha){ // only recover; no sha
if (recOptarg == NULL)
showUsage();
recoverFile(fd, disk, recOptarg, NULL);
}
}