10 #define FUSE_USE_VERSION 30 13 #include <fuse_lowlevel.h> 27 #include <linux/limits.h> 31 #define FILE_NAME "write_me" 42 #define OPTION(t, p) \ 43 { t, offsetof(struct options, p), 1 } 44 static const struct fuse_opt option_spec[] = {
45 OPTION(
"writeback_cache", writeback),
46 OPTION(
"--data-size=%d", data_size),
55 if(options.writeback) {
61 static int tfs_stat(
fuse_ino_t ino,
struct stat *stbuf) {
64 stbuf->st_mode = S_IFDIR | 0755;
68 else if (ino == FILE_INO) {
69 stbuf->st_mode = S_IFREG | 0222;
83 memset(&e, 0,
sizeof(e));
87 else if (strcmp(name, FILE_NAME) == 0)
92 if (tfs_stat(e.ino, &e.attr) != 0)
107 memset(&stbuf, 0,
sizeof(stbuf));
108 if (tfs_stat(ino, &stbuf) != 0)
119 assert(ino == FILE_INO);
126 (void) fi; (void) buf; (void) off;
129 assert(ino == FILE_INO);
130 expected = options.data_size;
131 if(options.writeback)
135 fprintf(stderr,
"ERROR: Expected %zd bytes, got %zd\n!",
144 .lookup = tfs_lookup,
145 .getattr = tfs_getattr,
150 static void* run_fs(
void *data) {
151 struct fuse_session *se = (
struct fuse_session*) data;
156 static void test_fs(
char *mountpoint) {
157 char fname[PATH_MAX];
159 size_t dsize = options.data_size;
164 assert((fd = open(
"/dev/urandom", O_RDONLY)) != -1);
165 assert(read(fd, buf, dsize) == dsize);
168 assert(snprintf(fname, PATH_MAX,
"%s/" FILE_NAME,
170 fd = open(fname, O_WRONLY);
176 assert(write(fd, buf, dsize) == dsize);
177 assert(write(fd, buf, dsize) == dsize);
181 int main(
int argc,
char *argv[]) {
183 struct fuse_session *se;
184 struct fuse_cmdline_opts fuse_opts;
193 sizeof(tfs_oper), NULL);
199 assert(pthread_create(&fs_thread, NULL, run_fs, (
void *)se) == 0);
202 test_fs(fuse_opts.mountpoint);
205 assert(pthread_cancel(fs_thread) == 0);
208 assert(got_write == 1);
212 printf(
"Test completed successfully.\n");
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
int fuse_reply_write(fuse_req_t req, size_t count)
struct fuse_req * fuse_req_t
#define FUSE_CAP_WRITEBACK_CACHE
void fuse_session_unmount(struct fuse_session *se)
int fuse_session_loop(struct fuse_session *se)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
#define FUSE_ARGS_INIT(argc, argv)
int fuse_reply_err(fuse_req_t req, int err)
int fuse_set_signal_handlers(struct fuse_session *se)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
void(* init)(void *userdata, struct fuse_conn_info *conn)
void fuse_remove_signal_handlers(struct fuse_session *se)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)