26 #define FUSE_USE_VERSION 31 
   32 #define _XOPEN_SOURCE 700 
   44 #include <sys/socket.h> 
   49 #include <sys/xattr.h> 
   52 #include "passthrough_helpers.h" 
   54 static int fill_dir_plus = 0;
 
   76 static int xmp_getattr(
const char *path, 
struct stat *stbuf,
 
   82         res = lstat(path, stbuf);
 
   89 static int xmp_access(
const char *path, 
int mask)
 
   93         res = access(path, mask);
 
  100 static int xmp_readlink(
const char *path, 
char *buf, 
size_t size)
 
  104         res = readlink(path, buf, size - 1);
 
  113 static int xmp_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
 
  128         while ((de = readdir(dp)) != NULL) {
 
  130                 memset(&st, 0, 
sizeof(st));
 
  131                 st.st_ino = de->d_ino;
 
  132                 st.st_mode = de->d_type << 12;
 
  133                 if (filler(buf, de->d_name, &st, 0, fill_dir_plus))
 
  141 static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
 
  145         res = mknod_wrapper(AT_FDCWD, path, NULL, mode, rdev);
 
  152 static int xmp_mkdir(
const char *path, mode_t mode)
 
  156         res = mkdir(path, mode);
 
  163 static int xmp_unlink(
const char *path)
 
  174 static int xmp_rmdir(
const char *path)
 
  185 static int xmp_symlink(
const char *from, 
const char *to)
 
  189         res = symlink(from, to);
 
  196 static int xmp_rename(
const char *from, 
const char *to, 
unsigned int flags)
 
  203         res = rename(from, to);
 
  210 static int xmp_link(
const char *from, 
const char *to)
 
  214         res = link(from, to);
 
  221 static int xmp_chmod(
const char *path, mode_t mode,
 
  227         res = chmod(path, mode);
 
  234 static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
 
  240         res = lchown(path, uid, gid);
 
  247 static int xmp_truncate(
const char *path, off_t size,
 
  253                 res = ftruncate(fi->
fh, size);
 
  255                 res = truncate(path, size);
 
  262 #ifdef HAVE_UTIMENSAT 
  263 static int xmp_utimens(
const char *path, 
const struct timespec ts[2],
 
  270         res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
 
  278 static int xmp_create(
const char *path, mode_t mode,
 
  283         res = open(path, fi->
flags, mode);
 
  295         res = open(path, fi->
flags);
 
  303 static int xmp_read(
const char *path, 
char *buf, 
size_t size, off_t offset,
 
  310                 fd = open(path, O_RDONLY);
 
  317         res = pread(fd, buf, size, offset);
 
  326 static int xmp_write(
const char *path, 
const char *buf, 
size_t size,
 
  334                 fd = open(path, O_WRONLY);
 
  341         res = pwrite(fd, buf, size, offset);
 
  350 static int xmp_statfs(
const char *path, 
struct statvfs *stbuf)
 
  354         res = statvfs(path, stbuf);
 
  361 static int xmp_release(
const char *path, 
struct fuse_file_info *fi)
 
  368 static int xmp_fsync(
const char *path, 
int isdatasync,
 
  380 #ifdef HAVE_POSIX_FALLOCATE 
  381 static int xmp_fallocate(
const char *path, 
int mode,
 
  393                 fd = open(path, O_WRONLY);
 
  400         res = -posix_fallocate(fd, offset, length);
 
  410 static int xmp_setxattr(
const char *path, 
const char *name, 
const char *value,
 
  411                         size_t size, 
int flags)
 
  413         int res = lsetxattr(path, name, value, size, flags);
 
  419 static int xmp_getxattr(
const char *path, 
const char *name, 
char *value,
 
  422         int res = lgetxattr(path, name, value, size);
 
  428 static int xmp_listxattr(
const char *path, 
char *list, 
size_t size)
 
  430         int res = llistxattr(path, list, size);
 
  436 static int xmp_removexattr(
const char *path, 
const char *name)
 
  438         int res = lremovexattr(path, name);
 
  445 #ifdef HAVE_COPY_FILE_RANGE 
  446 static ssize_t xmp_copy_file_range(
const char *path_in,
 
  448                                    off_t offset_in, 
const char *path_out,
 
  450                                    off_t offset_out, 
size_t len, 
int flags)
 
  456                 fd_in = open(path_in, O_RDONLY);
 
  464                 fd_out = open(path_out, O_WRONLY);
 
  473         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[])
 
  552         enum { MAX_ARGS = 10 };
 
  554         char *new_argv[MAX_ARGS];
 
  558         for (i=0, new_argc=0; (i<argc) && (new_argc<MAX_ARGS); i++) {
 
  559                 if (!strcmp(argv[i], 
"--plus")) {
 
  562                         new_argv[new_argc++] = argv[i];
 
  565         return fuse_main(new_argc, new_argv, &xmp_oper, NULL);
 
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
#define fuse_main(argc, argv, op, private_data)
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)