-
Notifications
You must be signed in to change notification settings - Fork 4
/
fslab-handout.tar
executable file
·274 lines (235 loc) · 20 KB
/
fslab-handout.tar
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
fslab-handout/ 0000775 0000764 0000764 00000000000 13460573617 013261 5 ustar ubuntu ubuntu fslab-handout/fs.c 0000664 0000764 0000764 00000005715 13460573617 014045 0 ustar ubuntu ubuntu /*
Filesystem Lab disigned and implemented by Liang Junkai,RUC
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <fuse.h>
#include <errno.h>
#include "disk.h"
#define DIRMODE S_IFDIR|0755
#define REGMODE S_IFREG|0644
//Format the virtual block device in the following function
int mkfs()
{
return 0;
}
//Filesystem operations that you need to implement
int fs_getattr (const char *path, struct stat *attr)
{
printf("Getattr is called:%s\n",path);
return 0;
}
int fs_readdir(const char *path, void *buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
printf("Readdir is called:%s\n", path);
return 0;
}
int fs_read(const char *path, char *buffer, size_t size, off_t offset, struct fuse_file_info *fi)
{
printf("Read is called:%s\n",path);
return 0;
}
int fs_mknod (const char *path, mode_t mode, dev_t dev)
{
printf("Mknod is called:%s\n",path);
return 0;
}
int fs_mkdir (const char *path, mode_t mode)
{
printf("Mkdir is called:%s\n",path);
return 0;
}
int fs_rmdir (const char *path)
{
printf("Rmdir is called:%s\n",path);
return 0;
}
int fs_unlink (const char *path)
{
printf("Unlink is callded:%s\n",path);
return 0;
}
int fs_rename (const char *oldpath, const char *newname)
{
printf("Rename is called:%s\n",path);
return 0;
}
int fs_write (const char *path, const char *buffer, size_t size, off_t offset, struct fuse_file_info *fi)
{
printf("Write is called:%s\n",path);
return 0;
}
int fs_truncate (const char *path, off_t size)
{
printf("Truncate is called:%s\n",path);
return 0;
}
int fs_utime (const char *path, struct utimbuf *buffer)
{
printf("Utime is called:%s\n",path);
return 0;
}
int fs_statfs (const char *path, struct statvfs *stat)
{
printf("Statfs is called:%s\n",path);
return 0;
}
int fs_open (const char *path, struct fuse_file_info *fi)
{
printf("Open is called:%s\n",path);
return 0;
}
//Functions you don't actually need to modify
int fs_release (const char *path, struct fuse_file_info *fi)
{
printf("Release is called:%s\n",path);
return 0;
}
int fs_opendir (const char *path, struct fuse_file_info *fi)
{
printf("Opendir is called:%s\n",path);
return 0;
}
int fs_releasedir (const char * path, struct fuse_file_info *fi)
{
printf("Releasedir is called:%s\n",path);
return 0;
}
static struct fuse_operations fs_operations = {
.getattr = fs_getattr,
.readdir = fs_readdir,
.read = fs_read,
.mkdir = fs_mkdir,
.rmdir = fs_rmdir,
.unlink = fs_unlink,
.rename = fs_rename,
.truncate = fs_truncate,
.utime = fs_utime,
.mknod = fs_mknod,
.write = fs_write,
.statfs = fs_statfs,
.open = fs_open,
.release = fs_release,
.opendir = fs_opendir,
.releasedir = fs_releasedir
};
int main(int argc, char *argv[])
{
if(disk_init())
{
printf("Can't open virtual disk!\n");
return -1;
}
if(mkfs())
{
printf("Mkfs failed!\n");
return -2;
}
return fuse_main(argc, argv, &fs_operations, NULL);
}