• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   This program can be distributed under the terms of the GNU GPLv2.
3   See the file COPYING.
4 */
5 
6 #define FUSE_USE_VERSION 31
7 
8 #define _GNU_SOURCE
9 
10 #include <fuse.h>
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <errno.h>
16 
xmp_init(struct fuse_conn_info * conn,struct fuse_config * cfg)17 static void *xmp_init(struct fuse_conn_info *conn,
18 		      struct fuse_config *cfg)
19 {
20 	(void) conn;
21 
22 	cfg->use_ino = 1;
23 	cfg->nullpath_ok = 1;
24 	cfg->entry_timeout = 0;
25 	cfg->attr_timeout = 0;
26 	cfg->negative_timeout = 0;
27 
28 	return NULL;
29 }
30 
xmp_getattr(const char * path,struct stat * stbuf,struct fuse_file_info * fi)31 static int xmp_getattr(const char *path, struct stat *stbuf,
32 			struct fuse_file_info *fi)
33 {
34 	int res;
35 
36 	(void) path;
37 
38 	if(fi)
39 		res = fstat(fi->fh, stbuf);
40 	else
41 		res = lstat(path, stbuf);
42 	if (res == -1)
43 		return -errno;
44 
45 	return 0;
46 }
47 
xmp_unlink(const char * path)48 static int xmp_unlink(const char *path)
49 {
50 	int res;
51 
52 	res = unlink(path);
53 	if (res == -1)
54 		return -errno;
55 
56 	return 0;
57 }
58 
xmp_rename(const char * from,const char * to,unsigned int flags)59 static int xmp_rename(const char *from, const char *to, unsigned int flags)
60 {
61 	int res;
62 
63 	if (flags)
64 		return -EINVAL;
65 
66         if(!getenv("RELEASEUNLINKRACE_DELAY_DISABLE")) usleep(100000);
67 
68 	res = rename(from, to);
69 	if (res == -1)
70 		return -errno;
71 
72 	return 0;
73 }
74 
xmp_create(const char * path,mode_t mode,struct fuse_file_info * fi)75 static int xmp_create(const char *path, mode_t mode, struct fuse_file_info *fi)
76 {
77 	int fd;
78 
79 	fd = open(path, fi->flags, mode);
80 	if (fd == -1)
81 		return -errno;
82 
83 	fi->fh = fd;
84 	return 0;
85 }
86 
xmp_release(const char * path,struct fuse_file_info * fi)87 static int xmp_release(const char *path, struct fuse_file_info *fi)
88 {
89 	(void) path;
90 
91         if(!getenv("RELEASEUNLINKRACE_DELAY_DISABLE")) usleep(100000);
92 
93 	close(fi->fh);
94 
95 	return 0;
96 }
97 
98 static const struct fuse_operations xmp_oper = {
99 	.init           = xmp_init,
100 	.getattr	= xmp_getattr,
101 	.unlink		= xmp_unlink,
102 	.rename		= xmp_rename,
103 	.create		= xmp_create,
104 	.release	= xmp_release,
105 };
106 
main(int argc,char * argv[])107 int main(int argc, char *argv[])
108 {
109 	umask(0);
110 	return fuse_main(argc, argv, &xmp_oper, NULL);
111 }
112