26 #define FUSE_USE_VERSION 31    36 #define _XOPEN_SOURCE 700    49 #include <sys/xattr.h>    72 static int xmp_getattr(
const char *path, 
struct stat *stbuf,
    78         res = lstat(path, stbuf);
    85 static int xmp_access(
const char *path, 
int mask)
    89         res = access(path, mask);
    96 static int xmp_readlink(
const char *path, 
char *buf, 
size_t size)
   100         res = readlink(path, buf, size - 1);
   109 static int xmp_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
   124         while ((de = readdir(dp)) != NULL) {
   126                 memset(&st, 0, 
sizeof(st));
   127                 st.st_ino = de->d_ino;
   128                 st.st_mode = de->d_type << 12;
   129                 if (filler(buf, de->d_name, &st, 0, 0))
   137 static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
   144                 res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode);
   147         } 
else if (S_ISFIFO(mode))
   148                 res = mkfifo(path, mode);
   150                 res = mknod(path, mode, rdev);
   157 static int xmp_mkdir(
const char *path, mode_t mode)
   161         res = mkdir(path, mode);
   168 static int xmp_unlink(
const char *path)
   179 static int xmp_rmdir(
const char *path)
   190 static int xmp_symlink(
const char *from, 
const char *to)
   194         res = symlink(from, to);
   201 static int xmp_rename(
const char *from, 
const char *to, 
unsigned int flags)
   208         res = rename(from, to);
   215 static int xmp_link(
const char *from, 
const char *to)
   219         res = link(from, to);
   226 static int xmp_chmod(
const char *path, mode_t mode,
   232         res = chmod(path, mode);
   239 static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
   245         res = lchown(path, uid, gid);
   252 static int xmp_truncate(
const char *path, off_t size,
   258                 res = ftruncate(fi->
fh, size);
   260                 res = truncate(path, size);
   267 #ifdef HAVE_UTIMENSAT   268 static int xmp_utimens(
const char *path, 
const struct timespec ts[2],
   275         res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
   283 static int xmp_create(
const char *path, mode_t mode,
   288         res = open(path, fi->
flags, mode);
   300         res = open(path, fi->
flags);
   308 static int xmp_read(
const char *path, 
char *buf, 
size_t size, off_t offset,
   315                 fd = open(path, O_RDONLY);
   322         res = pread(fd, buf, size, offset);
   331 static int xmp_write(
const char *path, 
const char *buf, 
size_t size,
   339                 fd = open(path, O_WRONLY);
   346         res = pwrite(fd, buf, size, offset);
   355 static int xmp_statfs(
const char *path, 
struct statvfs *stbuf)
   359         res = statvfs(path, stbuf);
   366 static int xmp_release(
const char *path, 
struct fuse_file_info *fi)
   373 static int xmp_fsync(
const char *path, 
int isdatasync,
   385 #ifdef HAVE_POSIX_FALLOCATE   386 static int xmp_fallocate(
const char *path, 
int mode,
   398                 fd = open(path, O_WRONLY);
   405         res = -posix_fallocate(fd, offset, length);
   415 static int xmp_setxattr(
const char *path, 
const char *name, 
const char *value,
   416                         size_t size, 
int flags)
   418         int res = lsetxattr(path, name, value, size, flags);
   424 static int xmp_getxattr(
const char *path, 
const char *name, 
char *value,
   427         int res = lgetxattr(path, name, value, size);
   433 static int xmp_listxattr(
const char *path, 
char *list, 
size_t size)
   435         int res = llistxattr(path, list, size);
   441 static int xmp_removexattr(
const char *path, 
const char *name)
   443         int res = lremovexattr(path, name);
   450 #ifdef HAVE_COPY_FILE_RANGE   451 static ssize_t xmp_copy_file_range(
const char *path_in,
   453                                    off_t offset_in, 
const char *path_out,
   455                                    off_t offset_out, 
size_t len, 
int flags)
   461                 fd_in = open(path_in, O_RDONLY);
   469                 fd_out = open(path_out, O_WRONLY);
   478         res = copy_file_range(fd_in, &offset_in, fd_out, &offset_out, len,
   492         .getattr        = xmp_getattr,
   493         .access         = xmp_access,
   494         .readlink       = xmp_readlink,
   495         .readdir        = xmp_readdir,
   498         .symlink        = xmp_symlink,
   499         .unlink         = xmp_unlink,
   501         .rename         = xmp_rename,
   505         .truncate       = xmp_truncate,
   506 #ifdef HAVE_UTIMENSAT   507         .utimens        = xmp_utimens,
   510         .create         = xmp_create,
   513         .statfs         = xmp_statfs,
   514         .release        = xmp_release,
   516 #ifdef HAVE_POSIX_FALLOCATE   517         .fallocate      = xmp_fallocate,
   520         .setxattr       = xmp_setxattr,
   521         .getxattr       = xmp_getxattr,
   522         .listxattr      = xmp_listxattr,
   523         .removexattr    = xmp_removexattr,
   525 #ifdef HAVE_COPY_FILE_RANGE   526         .copy_file_range = xmp_copy_file_range,
   530 int main(
int argc, 
char *argv[])
   533         return fuse_main(argc, argv, &xmp_oper, NULL);
 
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)
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)