26#define FUSE_USE_VERSION 31
32#ifdef HAVE_LIBULOCKMGR
71static int xmp_getattr(
const char *path,
struct stat *stbuf,
79 res = fstat(fi->
fh, stbuf);
81 res = lstat(path, stbuf);
88static int xmp_access(
const char *path,
int mask)
92 res = access(path, mask);
99static int xmp_readlink(
const char *path,
char *buf,
size_t size)
103 res = readlink(path, buf, size - 1);
113 struct dirent *entry;
117static int xmp_opendir(
const char *path,
struct fuse_file_info *fi)
120 struct xmp_dirp *d = malloc(
sizeof(
struct xmp_dirp));
124 d->dp = opendir(path);
133 fi->
fh = (
unsigned long) d;
139 return (
struct xmp_dirp *) (uintptr_t) fi->
fh;
142static int xmp_readdir(
const char *path,
void *buf,
fuse_fill_dir_t filler,
146 struct xmp_dirp *d = get_dirp(fi);
149 if (offset != d->offset) {
151 seekdir(d->dp, offset);
155 seekdir(d->dp, offset-1);
166 d->entry = readdir(d->dp);
174 res = fstatat(dirfd(d->dp), d->entry->d_name, &st,
175 AT_SYMLINK_NOFOLLOW);
181 memset(&st, 0,
sizeof(st));
182 st.st_ino = d->entry->d_ino;
183 st.st_mode = d->entry->d_type << 12;
185 nextoff = telldir(d->dp);
193 if (filler(buf, d->entry->d_name, &st, nextoff, fill_flags))
203static int xmp_releasedir(
const char *path,
struct fuse_file_info *fi)
205 struct xmp_dirp *d = get_dirp(fi);
212static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
217 res = mkfifo(path, mode);
219 res = mknod(path, mode, rdev);
226static int xmp_mkdir(
const char *path, mode_t mode)
230 res = mkdir(path, mode);
237static int xmp_unlink(
const char *path)
248static int xmp_rmdir(
const char *path)
259static int xmp_symlink(
const char *from,
const char *to)
263 res = symlink(from, to);
270static int xmp_rename(
const char *from,
const char *to,
unsigned int flags)
278 res = rename(from, to);
285static int xmp_link(
const char *from,
const char *to)
289 res = link(from, to);
296static int xmp_chmod(
const char *path, mode_t mode,
302 res = fchmod(fi->
fh, mode);
304 res = chmod(path, mode);
311static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
317 res = fchown(fi->
fh, uid, gid);
319 res = lchown(path, uid, gid);
326static int xmp_truncate(
const char *path, off_t size,
332 res = ftruncate(fi->
fh, size);
334 res = truncate(path, size);
343static int xmp_utimens(
const char *path,
const struct timespec ts[2],
350 res = futimens(fi->
fh, ts);
352 res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
360static int xmp_create(
const char *path, mode_t mode,
struct fuse_file_info *fi)
364 fd = open(path, fi->
flags, mode);
376 fd = open(path, fi->
flags);
384static int xmp_read(
const char *path,
char *buf,
size_t size, off_t offset,
390 res = pread(fi->
fh, buf, size, offset);
397static int xmp_read_buf(
const char *path,
struct fuse_bufvec **bufp,
408 *src = FUSE_BUFVEC_INIT(size);
419static int xmp_write(
const char *path,
const char *
buf,
size_t size,
425 res = pwrite(fi->
fh,
buf, size, offset);
432static int xmp_write_buf(
const char *path,
struct fuse_bufvec *
buf,
446static int xmp_statfs(
const char *path,
struct statvfs *stbuf)
450 res = statvfs(path, stbuf);
467 res = close(dup(fi->
fh));
474static int xmp_release(
const char *path,
struct fuse_file_info *fi)
482static int xmp_fsync(
const char *path,
int isdatasync,
488#ifndef HAVE_FDATASYNC
492 res = fdatasync(fi->
fh);
502#ifdef HAVE_POSIX_FALLOCATE
503static int xmp_fallocate(
const char *path,
int mode,
511 return -posix_fallocate(fi->
fh, offset, length);
517static int xmp_setxattr(
const char *path,
const char *name,
const char *value,
518 size_t size,
int flags)
520 int res = lsetxattr(path, name, value, size, flags);
526static int xmp_getxattr(
const char *path,
const char *name,
char *value,
529 int res = lgetxattr(path, name, value, size);
535static int xmp_listxattr(
const char *path,
char *list,
size_t size)
537 int res = llistxattr(path, list, size);
543static int xmp_removexattr(
const char *path,
const char *name)
545 int res = lremovexattr(path, name);
552#ifdef HAVE_LIBULOCKMGR
553static int xmp_lock(
const char *path,
struct fuse_file_info *fi,
int cmd,
563static int xmp_flock(
const char *path,
struct fuse_file_info *fi,
int op)
568 res = flock(fi->
fh, op);
575#ifdef HAVE_COPY_FILE_RANGE
576static ssize_t xmp_copy_file_range(
const char *path_in,
578 off_t off_in,
const char *path_out,
580 off_t off_out,
size_t len,
int flags)
586 res = copy_file_range(fi_in->
fh, &off_in, fi_out->
fh, &off_out, len,
595static off_t xmp_lseek(
const char *path, off_t
off,
int whence,
struct fuse_file_info *fi)
600 res = lseek(fi->
fh,
off, whence);
609 .getattr = xmp_getattr,
610 .access = xmp_access,
611 .readlink = xmp_readlink,
612 .opendir = xmp_opendir,
613 .readdir = xmp_readdir,
614 .releasedir = xmp_releasedir,
617 .symlink = xmp_symlink,
618 .unlink = xmp_unlink,
620 .rename = xmp_rename,
624 .truncate = xmp_truncate,
626 .utimens = xmp_utimens,
628 .create = xmp_create,
631 .read_buf = xmp_read_buf,
633 .write_buf = xmp_write_buf,
634 .statfs = xmp_statfs,
636 .release = xmp_release,
638#ifdef HAVE_POSIX_FALLOCATE
639 .fallocate = xmp_fallocate,
642 .setxattr = xmp_setxattr,
643 .getxattr = xmp_getxattr,
644 .listxattr = xmp_listxattr,
645 .removexattr = xmp_removexattr,
647#ifdef HAVE_LIBULOCKMGR
651#ifdef HAVE_COPY_FILE_RANGE
652 .copy_file_range = xmp_copy_file_range,
657int main(
int argc,
char *argv[])
660 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)