26 #define FUSE_USE_VERSION 31 
   36 #ifdef HAVE_LIBULOCKMGR 
   50 #include <sys/xattr.h> 
   75 static int xmp_getattr(
const char *path, 
struct stat *stbuf,
 
   83                 res = fstat(fi->
fh, stbuf);
 
   85                 res = lstat(path, stbuf);
 
   92 static int xmp_access(
const char *path, 
int mask)
 
   96         res = access(path, mask);
 
  103 static int xmp_readlink(
const char *path, 
char *buf, 
size_t size)
 
  107         res = readlink(path, buf, size - 1);
 
  117         struct dirent *entry;
 
  121 static int xmp_opendir(
const char *path, 
struct fuse_file_info *fi)
 
  124         struct xmp_dirp *d = malloc(
sizeof(
struct xmp_dirp));
 
  128         d->dp = opendir(path);
 
  137         fi->
fh = (
unsigned long) d;
 
  141 static inline struct xmp_dirp *get_dirp(
struct fuse_file_info *fi)
 
  143         return (
struct xmp_dirp *) (uintptr_t) fi->
fh;
 
  146 static int xmp_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
 
  150         struct xmp_dirp *d = get_dirp(fi);
 
  153         if (offset != d->offset) {
 
  155                 seekdir(d->dp, offset);
 
  159                 seekdir(d->dp, offset-1);
 
  170                         d->entry = readdir(d->dp);
 
  178                         res = fstatat(dirfd(d->dp), d->entry->d_name, &st,
 
  179                                       AT_SYMLINK_NOFOLLOW);
 
  185                         memset(&st, 0, 
sizeof(st));
 
  186                         st.st_ino = d->entry->d_ino;
 
  187                         st.st_mode = d->entry->d_type << 12;
 
  189                 nextoff = telldir(d->dp);
 
  197                 if (filler(buf, d->entry->d_name, &st, nextoff, fill_flags))
 
  207 static int xmp_releasedir(
const char *path, 
struct fuse_file_info *fi)
 
  209         struct xmp_dirp *d = get_dirp(fi);
 
  216 static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
 
  221                 res = mkfifo(path, mode);
 
  223                 res = mknod(path, mode, rdev);
 
  230 static int xmp_mkdir(
const char *path, mode_t mode)
 
  234         res = mkdir(path, mode);
 
  241 static int xmp_unlink(
const char *path)
 
  252 static int xmp_rmdir(
const char *path)
 
  263 static int xmp_symlink(
const char *from, 
const char *to)
 
  267         res = symlink(from, to);
 
  274 static int xmp_rename(
const char *from, 
const char *to, 
unsigned int flags)
 
  282         res = rename(from, to);
 
  289 static int xmp_link(
const char *from, 
const char *to)
 
  293         res = link(from, to);
 
  300 static int xmp_chmod(
const char *path, mode_t mode,
 
  306                 res = fchmod(fi->
fh, mode);
 
  308                 res = chmod(path, mode);
 
  315 static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
 
  321                 res = fchown(fi->
fh, uid, gid);
 
  323                 res = lchown(path, uid, gid);
 
  330 static int xmp_truncate(
const char *path, off_t size,
 
  336                 res = ftruncate(fi->
fh, size);
 
  338                 res = truncate(path, size);
 
  346 #ifdef HAVE_UTIMENSAT 
  347 static int xmp_utimens(
const char *path, 
const struct timespec ts[2],
 
  354                 res = futimens(fi->
fh, ts);
 
  356                 res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
 
  364 static int xmp_create(
const char *path, mode_t mode, 
struct fuse_file_info *fi)
 
  368         fd = open(path, fi->
flags, mode);
 
  380         fd = open(path, fi->
flags);
 
  388 static int xmp_read(
const char *path, 
char *buf, 
size_t size, off_t offset,
 
  394         res = pread(fi->
fh, buf, size, offset);
 
  401 static int xmp_read_buf(
const char *path, 
struct fuse_bufvec **bufp,
 
  412         *src = FUSE_BUFVEC_INIT(size);
 
  423 static int xmp_write(
const char *path, 
const char *
buf, 
size_t size,
 
  429         res = pwrite(fi->
fh, 
buf, size, offset);
 
  436 static int xmp_write_buf(
const char *path, 
struct fuse_bufvec *
buf,
 
  450 static int xmp_statfs(
const char *path, 
struct statvfs *stbuf)
 
  454         res = statvfs(path, stbuf);
 
  471         res = close(dup(fi->
fh));
 
  478 static int xmp_release(
const char *path, 
struct fuse_file_info *fi)
 
  486 static int xmp_fsync(
const char *path, 
int isdatasync,
 
  492 #ifndef HAVE_FDATASYNC 
  496                 res = fdatasync(fi->
fh);
 
  506 #ifdef HAVE_POSIX_FALLOCATE 
  507 static int xmp_fallocate(
const char *path, 
int mode,
 
  515         return -posix_fallocate(fi->
fh, offset, length);
 
  521 static int xmp_setxattr(
const char *path, 
const char *name, 
const char *value,
 
  522                         size_t size, 
int flags)
 
  524         int res = lsetxattr(path, name, value, size, flags);
 
  530 static int xmp_getxattr(
const char *path, 
const char *name, 
char *value,
 
  533         int res = lgetxattr(path, name, value, size);
 
  539 static int xmp_listxattr(
const char *path, 
char *list, 
size_t size)
 
  541         int res = llistxattr(path, list, size);
 
  547 static int xmp_removexattr(
const char *path, 
const char *name)
 
  549         int res = lremovexattr(path, name);
 
  556 #ifdef HAVE_LIBULOCKMGR 
  557 static int xmp_lock(
const char *path, 
struct fuse_file_info *fi, 
int cmd,
 
  567 static int xmp_flock(
const char *path, 
struct fuse_file_info *fi, 
int op)
 
  572         res = flock(fi->
fh, op);
 
  579 #ifdef HAVE_COPY_FILE_RANGE 
  580 static ssize_t xmp_copy_file_range(
const char *path_in,
 
  582                                    off_t off_in, 
const char *path_out,
 
  584                                    off_t off_out, 
size_t len, 
int flags)
 
  590         res = copy_file_range(fi_in->
fh, &off_in, fi_out->
fh, &off_out, len,
 
  599 static off_t xmp_lseek(
const char *path, off_t 
off, 
int whence, 
struct fuse_file_info *fi)
 
  604         res = lseek(fi->
fh, 
off, whence);
 
  613         .getattr        = xmp_getattr,
 
  614         .access         = xmp_access,
 
  615         .readlink       = xmp_readlink,
 
  616         .opendir        = xmp_opendir,
 
  617         .readdir        = xmp_readdir,
 
  618         .releasedir     = xmp_releasedir,
 
  621         .symlink        = xmp_symlink,
 
  622         .unlink         = xmp_unlink,
 
  624         .rename         = xmp_rename,
 
  628         .truncate       = xmp_truncate,
 
  629 #ifdef HAVE_UTIMENSAT 
  630         .utimens        = xmp_utimens,
 
  632         .create         = xmp_create,
 
  635         .read_buf       = xmp_read_buf,
 
  637         .write_buf      = xmp_write_buf,
 
  638         .statfs         = xmp_statfs,
 
  640         .release        = xmp_release,
 
  642 #ifdef HAVE_POSIX_FALLOCATE 
  643         .fallocate      = xmp_fallocate,
 
  646         .setxattr       = xmp_setxattr,
 
  647         .getxattr       = xmp_getxattr,
 
  648         .listxattr      = xmp_listxattr,
 
  649         .removexattr    = xmp_removexattr,
 
  651 #ifdef HAVE_LIBULOCKMGR 
  655 #ifdef HAVE_COPY_FILE_RANGE 
  656         .copy_file_range = xmp_copy_file_range,
 
  661 int main(
int argc, 
char *argv[])
 
  664         return fuse_main(argc, 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)
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
@ FUSE_BUF_SPLICE_NONBLOCK
enum fuse_buf_flags flags
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)