📄 fuse_lowlevel.c
字号:
fuse_reply_err(req, ENOSYS);}static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ (void) inarg; if (req->f->op.readlink) req->f->op.readlink(req, nodeid); else fuse_reply_err(req, ENOSYS);}static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_mknod_in *arg = (struct fuse_mknod_in *) inarg; if (req->f->op.mknod) req->f->op.mknod(req, nodeid, PARAM(arg), arg->mode, arg->rdev); else fuse_reply_err(req, ENOSYS);}static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *) inarg; if (req->f->op.mkdir) req->f->op.mkdir(req, nodeid, PARAM(arg), arg->mode); else fuse_reply_err(req, ENOSYS);}static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ char *name = (char *) inarg; if (req->f->op.unlink) req->f->op.unlink(req, nodeid, name); else fuse_reply_err(req, ENOSYS);}static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ char *name = (char *) inarg; if (req->f->op.rmdir) req->f->op.rmdir(req, nodeid, name); else fuse_reply_err(req, ENOSYS);}static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ char *name = (char *) inarg; char *linkname = ((char *) inarg) + strlen((char *) inarg) + 1; if (req->f->op.symlink) req->f->op.symlink(req, linkname, nodeid, name); else fuse_reply_err(req, ENOSYS);}static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_rename_in *arg = (struct fuse_rename_in *) inarg; char *oldname = PARAM(arg); char *newname = oldname + strlen(oldname) + 1; if (req->f->op.rename) req->f->op.rename(req, nodeid, oldname, arg->newdir, newname); else fuse_reply_err(req, ENOSYS);}static void do_link(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_link_in *arg = (struct fuse_link_in *) inarg; if (req->f->op.link) req->f->op.link(req, arg->oldnodeid, nodeid, PARAM(arg)); else fuse_reply_err(req, ENOSYS);}static void do_create(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_open_in *arg = (struct fuse_open_in *) inarg; if (req->f->op.create) { struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; req->f->op.create(req, nodeid, PARAM(arg), arg->mode, &fi); } else fuse_reply_err(req, ENOSYS);}static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_open_in *arg = (struct fuse_open_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; if (req->f->op.open) req->f->op.open(req, nodeid, &fi); else fuse_reply_open(req, &fi);}static void do_read(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_read_in *arg = (struct fuse_read_in *) inarg; if (req->f->op.read) { struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; req->f->op.read(req, nodeid, arg->size, arg->offset, &fi); } else fuse_reply_err(req, ENOSYS);}static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_write_in *arg = (struct fuse_write_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; fi.writepage = arg->write_flags & 1; if (req->f->op.write) req->f->op.write(req, nodeid, PARAM(arg), arg->size, arg->offset, &fi); else fuse_reply_err(req, ENOSYS);}static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; fi.flush = 1; if (req->f->conn.proto_minor >= 7) fi.lock_owner = arg->lock_owner; if (req->f->op.flush) req->f->op.flush(req, nodeid, &fi); else fuse_reply_err(req, ENOSYS);}static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_release_in *arg = (struct fuse_release_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; fi.fh = arg->fh; fi.fh_old = fi.fh; if (req->f->conn.proto_minor >= 8) { fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0; fi.lock_owner = arg->lock_owner; } if (req->f->op.release) req->f->op.release(req, nodeid, &fi); else fuse_reply_err(req, 0);}static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; if (req->f->op.fsync) req->f->op.fsync(req, nodeid, arg->fsync_flags & 1, &fi); else fuse_reply_err(req, ENOSYS);}static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_open_in *arg = (struct fuse_open_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; if (req->f->op.opendir) req->f->op.opendir(req, nodeid, &fi); else fuse_reply_open(req, &fi);}static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_read_in *arg = (struct fuse_read_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; if (req->f->op.readdir) req->f->op.readdir(req, nodeid, arg->size, arg->offset, &fi); else fuse_reply_err(req, ENOSYS);}static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_release_in *arg = (struct fuse_release_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; fi.fh = arg->fh; fi.fh_old = fi.fh; if (req->f->op.releasedir) req->f->op.releasedir(req, nodeid, &fi); else fuse_reply_err(req, 0);}static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.fh_old = fi.fh; if (req->f->op.fsyncdir) req->f->op.fsyncdir(req, nodeid, arg->fsync_flags & 1, &fi); else fuse_reply_err(req, ENOSYS);}static void do_statfs(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ (void) nodeid; (void) inarg; if (req->f->op.statfs) req->f->op.statfs(req, nodeid); else { struct statvfs buf = { .f_namemax = 255, .f_bsize = 512, }; fuse_reply_statfs(req, &buf); }}static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *) inarg; char *name = PARAM(arg); char *value = name + strlen(name) + 1; if (req->f->op.setxattr) req->f->op.setxattr(req, nodeid, name, value, arg->size, arg->flags); else fuse_reply_err(req, ENOSYS);}static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg; if (req->f->op.getxattr) req->f->op.getxattr(req, nodeid, PARAM(arg), arg->size); else fuse_reply_err(req, ENOSYS);}static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg; if (req->f->op.listxattr) req->f->op.listxattr(req, nodeid, arg->size); else fuse_reply_err(req, ENOSYS);}static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ char *name = (char *) inarg; if (req->f->op.removexattr) req->f->op.removexattr(req, nodeid, name); else fuse_reply_err(req, ENOSYS);}static void convert_fuse_file_lock(struct fuse_file_lock *fl, struct flock *flock){ memset(flock, 0, sizeof(struct flock)); flock->l_type = fl->type; flock->l_whence = SEEK_SET; flock->l_start = fl->start; if (fl->end == OFFSET_MAX) flock->l_len = 0; else flock->l_len = fl->end - fl->start + 1; flock->l_pid = fl->pid;}static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg; struct fuse_file_info fi; struct flock flock; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.lock_owner = arg->owner; convert_fuse_file_lock(&arg->lk, &flock); if (req->f->op.getlk) req->f->op.getlk(req, nodeid, &fi, &flock); else fuse_reply_err(req, ENOSYS);}static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid, const void *inarg, int sleep){ struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg; struct fuse_file_info fi; struct flock flock; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.lock_owner = arg->owner; convert_fuse_file_lock(&arg->lk, &flock); if (req->f->op.setlk) req->f->op.setlk(req, nodeid, &fi, &flock, sleep); else fuse_reply_err(req, ENOSYS);}static void do_setlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ do_setlk_common(req, nodeid, inarg, 0);}static void do_setlkw(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ do_setlk_common(req, nodeid, inarg, 1);}static int find_interrupted(struct fuse_ll *f, struct fuse_req *req){ struct fuse_req *curr; for (curr = f->list.next; curr != &f->list; curr = curr->next) { if (curr->unique == req->u.i.unique) { curr->ctr++; pthread_mutex_unlock(&f->lock); /* Ugh, ugly locking */ pthread_mutex_lock(&curr->lock); pthread_mutex_lock(&f->lock); curr->interrupted = 1; pthread_mutex_unlock(&f->lock); if (curr->u.ni.func) curr->u.ni.func(curr, curr->u.ni.data); pthread_mutex_unlock(&curr->lock); pthread_mutex_lock(&f->lock); curr->ctr--; if (!curr->ctr) destroy_req(curr); return 1; } } for (curr = f->interrupts.next; curr != &f->interrupts; curr = curr->next) { if (curr->u.i.unique == req->u.i.unique) return 1; } return 0;}static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_interrupt_in *arg = (struct fuse_interrupt_in *) inarg; struct fuse_ll *f = req->f; (void) nodeid; if (f->debug) { printf("INTERRUPT: %llu\n", (unsigned long long) arg->unique); fflush(stdout); } req->u.i.unique = arg->unique; pthread_mutex_lock(&f->lock); if (find_interrupted(f, req)) destroy_req(req); else list_add_req(req, &f->interrupts); pthread_mutex_unlock(&f->lock);}static struct fuse_req *check_interrupt(struct fuse_ll *f, struct fuse_req *req){ struct fuse_req *curr; for (curr = f->interrupts.next; curr != &f->interrupts; curr = curr->next) { if (curr->u.i.unique == req->unique) { req->interrupted = 1; list_del_req(curr); free(curr); return NULL; } } curr = f->interrupts.next; if (curr != &f->interrupts) { list_del_req(curr); list_init_req(curr); return curr; } else return NULL;}static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_bmap_in *arg = (struct fuse_bmap_in *) inarg; if (req->f->op.bmap) req->f->op.bmap(req, nodeid, arg->blocksize, arg->block); else fuse_reply_err(req, ENOSYS);}static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg){ struct fuse_init_in *arg = (struct fuse_init_in *) inarg; struct fuse_init_out outarg; struct fuse_ll *f = req->f; size_t bufsize = fuse_chan_bufsize(req->ch); (void) nodeid; if (f->debug) { printf("INIT: %u.%u\n", arg->major, arg->minor); if (arg->major > 7 || (arg->major == 7 && arg->minor >= 6)) { printf("flags=0x%08x\n", arg->flags); printf("max_readahead=0x%08x\n", arg->max_readahead);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -