26 #define FUSE_USE_VERSION 31 36 #define _XOPEN_SOURCE 700 48 #include <sys/socket.h> 53 #include <sys/xattr.h> 56 #include "passthrough_helpers.h" 78 static int xmp_getattr(
const char *path,
struct stat *stbuf,
84 res = lstat(path, stbuf);
91 static int xmp_access(
const char *path,
int mask)
102 static int xmp_readlink(
const char *path,
char *buf,
size_t size)
106 res =
readlink(path, buf, size - 1);
115 static int xmp_readdir(
const char *path,
void *buf,
fuse_fill_dir_t filler,
130 while ((de = readdir(dp)) != NULL) {
132 memset(&st, 0,
sizeof(st));
133 st.st_ino = de->d_ino;
134 st.st_mode = de->d_type << 12;
135 if (filler(buf, de->d_name, &st, 0, 0))
143 static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
147 res = mknod_wrapper(AT_FDCWD, path, NULL, mode, rdev);
154 static int xmp_mkdir(
const char *path, mode_t mode)
158 res = mkdir(path, mode);
165 static int xmp_unlink(
const char *path)
176 static int xmp_rmdir(
const char *path)
187 static int xmp_symlink(
const char *from,
const char *to)
191 res = symlink(from, to);
198 static int xmp_rename(
const char *from,
const char *to,
unsigned int flags)
205 res = rename(from, to);
212 static int xmp_link(
const char *from,
const char *to)
216 res = link(from, to);
223 static int xmp_chmod(
const char *path, mode_t mode,
229 res = chmod(path, mode);
236 static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
242 res = lchown(path, uid, gid);
249 static int xmp_truncate(
const char *path, off_t size,
255 res = ftruncate(fi->
fh, size);
257 res = truncate(path, size);
264 #ifdef HAVE_UTIMENSAT 265 static int xmp_utimens(
const char *path,
const struct timespec ts[2],
272 res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
280 static int xmp_create(
const char *path, mode_t mode,
285 res = open(path, fi->
flags, mode);
297 res = open(path, fi->
flags);
305 static int xmp_read(
const char *path,
char *buf,
size_t size, off_t offset,
312 fd = open(path, O_RDONLY);
319 res = pread(fd, buf, size, offset);
328 static int xmp_write(
const char *path,
const char *buf,
size_t size,
336 fd = open(path, O_WRONLY);
343 res = pwrite(fd, buf, size, offset);
352 static int xmp_statfs(
const char *path,
struct statvfs *stbuf)
356 res = statvfs(path, stbuf);
363 static int xmp_release(
const char *path,
struct fuse_file_info *fi)
370 static int xmp_fsync(
const char *path,
int isdatasync,
382 #ifdef HAVE_POSIX_FALLOCATE 383 static int xmp_fallocate(
const char *path,
int mode,
395 fd = open(path, O_WRONLY);
402 res = -posix_fallocate(fd, offset, length);
412 static int xmp_setxattr(
const char *path,
const char *name,
const char *value,
413 size_t size,
int flags)
415 int res = lsetxattr(path, name, value, size, flags);
421 static int xmp_getxattr(
const char *path,
const char *name,
char *value,
424 int res = lgetxattr(path, name, value, size);
430 static int xmp_listxattr(
const char *path,
char *list,
size_t size)
432 int res = llistxattr(path, list, size);
438 static int xmp_removexattr(
const char *path,
const char *name)
440 int res = lremovexattr(path, name);
447 #ifdef HAVE_COPY_FILE_RANGE 448 static ssize_t xmp_copy_file_range(
const char *path_in,
450 off_t offset_in,
const char *path_out,
452 off_t offset_out,
size_t len,
int flags)
458 fd_in = open(path_in, O_RDONLY);
466 fd_out = open(path_out, O_WRONLY);
475 res = copy_file_range(fd_in, &offset_in, fd_out, &offset_out, len,
487 static off_t xmp_lseek(
const char *path, off_t off,
int whence,
struct fuse_file_info *fi)
493 fd = open(path, O_RDONLY);
500 res = lseek(fd, off, whence);
511 .getattr = xmp_getattr,
512 .access = xmp_access,
513 .readlink = xmp_readlink,
514 .readdir = xmp_readdir,
517 .symlink = xmp_symlink,
518 .unlink = xmp_unlink,
520 .rename = xmp_rename,
524 .truncate = xmp_truncate,
525 #ifdef HAVE_UTIMENSAT 526 .utimens = xmp_utimens,
529 .create = xmp_create,
532 .statfs = xmp_statfs,
533 .release = xmp_release,
535 #ifdef HAVE_POSIX_FALLOCATE 536 .fallocate = xmp_fallocate,
539 .setxattr = xmp_setxattr,
540 .getxattr = xmp_getxattr,
541 .listxattr = xmp_listxattr,
542 .removexattr = xmp_removexattr,
544 #ifdef HAVE_COPY_FILE_RANGE 545 .copy_file_range = xmp_copy_file_range,
550 int main(
int argc,
char *argv[])
553 return fuse_main(argc, argv, &xmp_oper, NULL);
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)
int(* readlink)(const char *, char *, size_t)
#define fuse_main(argc, argv, op, private_data)
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
int(* access)(const char *, int)