📄 subdir.c
字号:
static int subdir_utimens(const char *path, const struct timespec ts[2]){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_utimens(d->next, newpath, ts); free(newpath); } return err;}static int subdir_create(const char *path, mode_t mode, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_create(d->next, newpath, mode, fi); free(newpath); } return err;}static int subdir_open(const char *path, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_open(d->next, newpath, fi); free(newpath); } return err;}static int subdir_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_read(d->next, newpath, buf, size, offset, fi); free(newpath); } return err;}static int subdir_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_write(d->next, newpath, buf, size, offset, fi); free(newpath); } return err;}static int subdir_statfs(const char *path, struct statvfs *stbuf){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_statfs(d->next, newpath, stbuf); free(newpath); } return err;}static int subdir_flush(const char *path, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_flush(d->next, newpath, fi); free(newpath); } return err;}static int subdir_release(const char *path, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_release(d->next, newpath, fi); free(newpath); } return err;}static int subdir_fsync(const char *path, int isdatasync, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_fsync(d->next, newpath, isdatasync, fi); free(newpath); } return err;}static int subdir_fsyncdir(const char *path, int isdatasync, struct fuse_file_info *fi){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_fsyncdir(d->next, newpath, isdatasync, fi); free(newpath); } return err;}static int subdir_setxattr(const char *path, const char *name, const char *value, size_t size, int flags){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_setxattr(d->next, newpath, name, value, size, flags); free(newpath); } return err;}static int subdir_getxattr(const char *path, const char *name, char *value, size_t size){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_getxattr(d->next, newpath, name, value, size); free(newpath); } return err;}static int subdir_listxattr(const char *path, char *list, size_t size){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_listxattr(d->next, newpath, list, size); free(newpath); } return err;}static int subdir_removexattr(const char *path, const char *name){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_removexattr(d->next, newpath, name); free(newpath); } return err;}static int subdir_lock(const char *path, struct fuse_file_info *fi, int cmd, struct flock *lock){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_lock(d->next, newpath, fi, cmd, lock); free(newpath); } return err;}static int subdir_bmap(const char *path, size_t blocksize, uint64_t *idx){ struct subdir *d = subdir_get(); char *newpath = subdir_addpath(d, path); int err = -ENOMEM; if (newpath) { err = fuse_fs_bmap(d->next, newpath, blocksize, idx); free(newpath); } return err;}static void *subdir_init(struct fuse_conn_info *conn){ struct subdir *d = subdir_get(); fuse_fs_init(d->next, conn); return d;}static void subdir_destroy(void *data){ struct subdir *d = data; fuse_fs_destroy(d->next); free(d->base); free(d);}static struct fuse_operations subdir_oper = { .destroy = subdir_destroy, .init = subdir_init, .getattr = subdir_getattr, .fgetattr = subdir_fgetattr, .access = subdir_access, .readlink = subdir_readlink, .opendir = subdir_opendir, .readdir = subdir_readdir, .releasedir = subdir_releasedir, .mknod = subdir_mknod, .mkdir = subdir_mkdir, .symlink = subdir_symlink, .unlink = subdir_unlink, .rmdir = subdir_rmdir, .rename = subdir_rename, .link = subdir_link, .chmod = subdir_chmod, .chown = subdir_chown, .truncate = subdir_truncate, .ftruncate = subdir_ftruncate, .utimens = subdir_utimens, .create = subdir_create, .open = subdir_open, .read = subdir_read, .write = subdir_write, .statfs = subdir_statfs, .flush = subdir_flush, .release = subdir_release, .fsync = subdir_fsync, .fsyncdir = subdir_fsyncdir, .setxattr = subdir_setxattr, .getxattr = subdir_getxattr, .listxattr = subdir_listxattr, .removexattr= subdir_removexattr, .lock = subdir_lock, .bmap = subdir_bmap,};static struct fuse_opt subdir_opts[] = { FUSE_OPT_KEY("-h", 0), FUSE_OPT_KEY("--help", 0), { "subdir=%s", offsetof(struct subdir, base), 0 }, { "rellinks", offsetof(struct subdir, rellinks), 1 }, { "norellinks", offsetof(struct subdir, rellinks), 0 }, FUSE_OPT_END};static void subdir_help(void){ fprintf(stderr," -o subdir=DIR prepend this directory to all paths (mandatory)\n"" -o [no]rellinks transform absolute symlinks to relative\n");}static int subdir_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs){ (void) data; (void) arg; (void) outargs; if (!key) { subdir_help(); return -1; } return 1;}static struct fuse_fs *subdir_new(struct fuse_args *args, struct fuse_fs *next[]){ struct fuse_fs *fs; struct subdir *d; d = calloc(1, sizeof(struct subdir)); if (d == NULL) { fprintf(stderr, "fuse-subdir: memory allocation failed\n"); return NULL; } if (fuse_opt_parse(args, d, subdir_opts, subdir_opt_proc) == -1) goto out_free; if (!next[0] || next[1]) { fprintf(stderr, "fuse-subdir: exactly one next filesystem required\n"); goto out_free; } if (!d->base) { fprintf(stderr, "fuse-subdir: missing 'subdir' option\n"); goto out_free; } if (d->base[0] && d->base[strlen(d->base)-1] != '/') { char *tmp = realloc(d->base, strlen(d->base) + 2); if (!tmp) { fprintf(stderr, "fuse-subdir: memory allocation failed\n"); goto out_free; } d->base = tmp; strcat(d->base, "/"); } d->baselen = strlen(d->base); d->next = next[0]; fs = fuse_fs_new(&subdir_oper, sizeof(subdir_oper), d); if (!fs) goto out_free; return fs; out_free: free(d->base); free(d); return NULL;}FUSE_REGISTER_MODULE(subdir, subdir_new);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -