Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE 500
- #define _GNU_SOURCE
- #define FUSE_USE_VERSION 26
- #include <stdio.h>
- #include <fuse.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <errno.h>
- #define PATH_MAX 1024
- #define BASEDIR "/tmp/RACE"
- void get_path(char *fpath, const char *path) {
- snprintf(fpath, PATH_MAX, "%s%s.%d", BASEDIR, path, fuse_get_context()->uid);
- }
- int r_open(const char *path, struct fuse_file_info *fi)
- {
- char *fpath = malloc(PATH_MAX);
- get_path(fpath, path);
- fi->fh = open(fpath, fi->flags);
- free(fpath);
- if (fi->fh < 0) {
- return -errno;
- } else {
- return 0;
- }
- }
- int r_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
- return pread(fi->fh, buf, size, offset);
- }
- int r_release(const char *path, struct fuse_file_info *fi) {
- return close(fi->fh);
- }
- int r_getattr(const char *path, struct stat *statbuf) {
- int retstat = 0;
- if (strcmp(path, "/") == 0) {
- statbuf->st_mode = S_IFDIR | 0755;
- statbuf->st_nlink = 2;
- } else if (strcmp(path, "/a") == 0) {
- char *fpath = malloc(PATH_MAX);
- get_path(fpath, path);
- retstat = lstat(fpath, statbuf);
- free(fpath);
- }
- return retstat;
- }
- struct fuse_operations r_oper = {
- .getattr = r_getattr,
- .open = r_open,
- .read = r_read,
- .release = r_release,
- };
- int main(int argc, char *argv[]) {
- return fuse_main(argc, argv, &r_oper, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement