Repository navigation
Expand file tree
/
Copy pathSFSFuse.c
More file actions
117 lines (96 loc) · 3.25 KB
/
Copy pathSFSFuse.c
File metadata and controls
117 lines (96 loc) · 3.25 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
SafeFS
(c) 2016 2016 INESC TEC. Written by J. Paulo and R. Pontes
*/
#include <stdio.h>
#include <stdlib.h>
#include "SFSFuse.h"
#include "utils.h"
int compose_layers(struct fuse_operations** operations, configuration config) {
DEBUG_MSG("Going to compose layers\n");
GSList* current = config.layers;
do {
// DEBUG_MSG("Going to read layer number %p\n", current);
int layer = GPOINTER_TO_INT(current->data);
DEBUG_MSG("Going to init driver %d\n", layer);
switch (layer) {
case BLOCK_ALIGN:
init_align_driver(operations, config);
break;
case SFUSE:
init_sfuse_driver(operations, config);
break;
case MULTI_LOOPBACK:
init_multi_loopback_driver(operations, config);
break;
case NOPFUSE:
init_nop_layer(operations, config);
break;
default:
return 1;
}
current = current->next;
} while (current != NULL);
return 0;
}
int clean_layers(configuration config) {
DEBUG_MSG("Going to clean layers\n");
GSList* current = config.layers;
do {
int layer = GPOINTER_TO_INT(current->data);
DEBUG_MSG("Going to clean drivers %d\n", layer);
switch (layer) {
case BLOCK_ALIGN:
clean_align_driver(config);
break;
case SFUSE:
clean_sfuse_driver(config);
break;
case MULTI_LOOPBACK:
clean_multi_loopback_driver(config);
break;
case NOPFUSE:
clean_nop_layer(config);
break;
default:
return 1;
}
current = current->next;
} while (current != NULL);
return 0;
}
int main(int argc, char* argv[]) {
char* local_file_path = LOCAL_SDSCONFIG_PATH;
char* default_file_path = DEFAULT_SDSCONFIG_PATH;
int res;
configuration* config = NULL;
LOG_INIT();
DEBUG_MSG("Trying to load local configuration file %s\n", local_file_path);
if (file_exists(local_file_path)) {
res = init_config(local_file_path, &config);
DEBUG_MSG("Local configuration file successfully loaded\n");
} else if (file_exists(default_file_path)) {
DEBUG_MSG("Could not find local configuration file (%s)\n", local_file_path);
DEBUG_MSG("Trying to load default configuration file (%s)\n", default_file_path);
res = init_config(default_file_path, &config);
} else {
DEBUG_MSG("Could not find default configuration file (%s)\n", default_file_path);
DEBUG_MSG("Will now exit\n");
exit(EXIT_FAILURE);
}
struct fuse_operations* operations;
DEBUG_MSG("Configuration structure is setup\n");
compose_layers(&operations, *config);
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
int i;
for (i = 0; i < argc; i++) {
fuse_opt_add_arg(&args, argv[i]);
}
fuse_opt_add_arg(&args, "-omodules=subdir,subdir=/");
fuse_main(args.argc, args.argv, operations, NULL);
DEBUG_MSG("Going to clean layers\n");
clean_layers(*config);
res = clean_config(config);
LOG_EXIT();
return res;
}