10 #define FUSE_USE_VERSION 30 13 #include <fuse_lowlevel.h> 27 #include <linux/limits.h> 31 #define FILE_NAME "truncate_me" 34 static mode_t file_mode = S_IFREG | 0644;
36 static int tfs_stat(
fuse_ino_t ino,
struct stat *stbuf) {
39 stbuf->st_mode = S_IFDIR | 0755;
43 else if (ino == FILE_INO) {
44 stbuf->st_mode = file_mode;
58 memset(&e, 0,
sizeof(e));
62 else if (strcmp(name, FILE_NAME) == 0)
67 if (tfs_stat(e.ino, &e.attr) != 0)
82 memset(&stbuf, 0,
sizeof(stbuf));
83 if (tfs_stat(ino, &stbuf) != 0)
94 assert(ino == FILE_INO);
102 if(ino != FILE_INO ||
103 !(to_set & FUSE_SET_ATTR_MODE)) {
109 fprintf(stderr,
"setattr with fi == NULL\n");
110 else if (fi->
fh != FILE_INO)
111 fprintf(stderr,
"setattr with wrong fi->fh\n");
113 fprintf(stderr,
"setattr ok\n");
115 file_mode = attr->st_mode;
118 tfs_getattr(req, ino, fi);
123 .getattr = tfs_getattr,
125 .setattr = tfs_setattr,
128 static void* run_fs(
void *data) {
129 struct fuse_session *se = (
struct fuse_session*) data;
134 static void test_fs(
char *mountpoint) {
135 char fname[PATH_MAX];
138 assert(snprintf(fname, PATH_MAX,
"%s/" FILE_NAME,
140 fd = open(fname, O_WRONLY);
146 assert(fchmod(fd, 0600) == 0);
150 int main(
int argc,
char *argv[]) {
152 struct fuse_session *se;
153 struct fuse_cmdline_opts fuse_opts;
161 sizeof(tfs_oper), NULL);
167 assert(pthread_create(&fs_thread, NULL, run_fs, (
void *)se) == 0);
170 test_fs(fuse_opts.mountpoint);
173 assert(pthread_cancel(fs_thread) == 0);
180 printf(
"Test completed successfully.\n");
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
void(* lookup)(fuse_req_t req, fuse_ino_t parent, const char *name)
struct fuse_req * fuse_req_t
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 fuse_remove_signal_handlers(struct fuse_session *se)