-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.c
62 lines (56 loc) · 1.42 KB
/
fs.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
//
// Created by dondish on 7/10/18.
//
#define FUSE_USE_VERSION 31
#include "fs.h"
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
void *do_init(struct fuse_conn_info *conn, struct fuse_config *config) {
config->use_ino = 1;
config->entry_timeout = 0;
config->attr_timeout = 0;
config->negative_timeout = 0;
return NULL;
}
int do_mknod(const char *path, mode_t mode, dev_t dev) {
if (S_ISREG(mode)) { // allow only regular files
return mknod(path, mode, dev);
}
return -1;
}
int do_read(const char *path, char *buffer, size_t size, off_t offset, struct fuse_file_info *fi) {
FILE *fd = fopen(path, "r");
(void) fi;
if (fd==NULL)
return -1;
int res = fseek(fd, offset, 0);
if (res!=0) {
fclose(fd);
return res;
}
res = fread(buffer, size, 1, fd) < 0 ? -1 : 0;
fclose(fd);
return res;
}
int do_write(const char *path, const char *data, size_t size, off_t offset, struct fuse_file_info *fi) {
FILE *fd = fopen(path, "w");
(void) fi;
if (fd==NULL)
return -1;
int res = fseek(fd, offset, 0);
if (res!=0) {
fclose(fd);
return res;
}
res = fwrite(data, size, 1, fd) < 0 ? -1 : 0;
// Add check for permission change
fclose(fd);
return res;
}
int do_mkdir(const char *path, mode_t mode) {
return mkdir(path, mode);
}