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)
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);
581 .getattr = xmp_getattr,
582 .access = xmp_access,
583 .readlink = xmp_readlink,
584 .opendir = xmp_opendir,
585 .readdir = xmp_readdir,
586 .releasedir = xmp_releasedir,
589 .symlink = xmp_symlink,
590 .unlink = xmp_unlink,
592 .rename = xmp_rename,
596 .truncate = xmp_truncate,
597 #ifdef HAVE_UTIMENSAT 598 .utimens = xmp_utimens,
600 .create = xmp_create,
603 .read_buf = xmp_read_buf,
605 .write_buf = xmp_write_buf,
606 .statfs = xmp_statfs,
608 .release = xmp_release,
610 #ifdef HAVE_POSIX_FALLOCATE 611 .fallocate = xmp_fallocate,
614 .setxattr = xmp_setxattr,
615 .getxattr = xmp_getxattr,
616 .listxattr = xmp_listxattr,
617 .removexattr = xmp_removexattr,
619 #ifdef HAVE_LIBULOCKMGR 625 int main(
int argc,
char *argv[])
628 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)
int(* readlink)(const char *, char *, size_t)
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)
enum fuse_buf_flags flags
int(* access)(const char *, int)