libfuse: fuse-3.17.3/test/release_unlink_race.c Source File

libfuse

release_unlink_race.c
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
17static 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
31static 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
48static 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
59static 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
75static 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
87static 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
98static 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
107int main(int argc, char *argv[])
108{
109 umask(0);
110 return fuse_main(argc, argv, &xmp_oper, NULL);
111}
fuse_config
Definition fuse.h:101
fuse_config::nullpath_ok
int32_t nullpath_ok
Definition fuse.h:273
fuse_config::use_ino
int32_t use_ino
Definition fuse.h:198
fuse_config::entry_timeout
double entry_timeout
Definition fuse.h:127
fuse_config::negative_timeout
double negative_timeout
Definition fuse.h:137
fuse_config::attr_timeout
double attr_timeout
Definition fuse.h:143
fuse_conn_info
Definition fuse_common.h:546
fuse_file_info
Definition fuse_common.h:56
fuse_file_info::fh
uint64_t fh
Definition fuse_common.h:113
fuse_file_info::flags
int32_t flags
Definition fuse_common.h:58
fuse_operations
Definition fuse.h:349
fuse_operations::init
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)
Definition fuse.h:641