26 #define FUSE_USE_VERSION 31 34 #define _XOPEN_SOURCE 700 47 #include <sys/xattr.h> 70 static int xmp_getattr(
const char *path,
struct stat *stbuf,
76 res = lstat(path, stbuf);
83 static int xmp_access(
const char *path,
int mask)
87 res = access(path, mask);
94 static int xmp_readlink(
const char *path,
char *buf,
size_t size)
98 res = readlink(path, buf, size - 1);
107 static int xmp_readdir(
const char *path,
void *buf,
fuse_fill_dir_t filler,
122 while ((de = readdir(dp)) != NULL) {
124 memset(&st, 0,
sizeof(st));
125 st.st_ino = de->d_ino;
126 st.st_mode = de->d_type << 12;
127 if (filler(buf, de->d_name, &st, 0, 0))
135 static int xmp_mknod(
const char *path, mode_t mode, dev_t rdev)
142 res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode);
145 }
else if (S_ISFIFO(mode))
146 res = mkfifo(path, mode);
148 res = mknod(path, mode, rdev);
155 static int xmp_mkdir(
const char *path, mode_t mode)
159 res = mkdir(path, mode);
166 static int xmp_unlink(
const char *path)
177 static int xmp_rmdir(
const char *path)
188 static int xmp_symlink(
const char *from,
const char *to)
192 res = symlink(from, to);
199 static int xmp_rename(
const char *from,
const char *to,
unsigned int flags)
206 res = rename(from, to);
213 static int xmp_link(
const char *from,
const char *to)
217 res = link(from, to);
224 static int xmp_chmod(
const char *path, mode_t mode,
230 res = chmod(path, mode);
237 static int xmp_chown(
const char *path, uid_t uid, gid_t gid,
243 res = lchown(path, uid, gid);
250 static int xmp_truncate(
const char *path, off_t size,
256 res = ftruncate(fi->
fh, size);
258 res = truncate(path, size);
265 #ifdef HAVE_UTIMENSAT 266 static int xmp_utimens(
const char *path,
const struct timespec ts[2],
273 res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
281 static int xmp_create(
const char *path, mode_t mode,
286 res = open(path, fi->
flags, mode);
298 res = open(path, fi->
flags);
306 static int xmp_read(
const char *path,
char *buf,
size_t size, off_t offset,
313 fd = open(path, O_RDONLY);
320 res = pread(fd, buf, size, offset);
329 static int xmp_write(
const char *path,
const char *buf,
size_t size,
337 fd = open(path, O_WRONLY);
344 res = pwrite(fd, buf, size, offset);
353 static int xmp_statfs(
const char *path,
struct statvfs *stbuf)
357 res = statvfs(path, stbuf);
364 static int xmp_release(
const char *path,
struct fuse_file_info *fi)
371 static int xmp_fsync(
const char *path,
int isdatasync,
383 #ifdef HAVE_POSIX_FALLOCATE 384 static int xmp_fallocate(
const char *path,
int mode,
396 fd = open(path, O_WRONLY);
403 res = -posix_fallocate(fd, offset, length);
413 static int xmp_setxattr(
const char *path,
const char *name,
const char *value,
414 size_t size,
int flags)
416 int res = lsetxattr(path, name, value, size, flags);
422 static int xmp_getxattr(
const char *path,
const char *name,
char *value,
425 int res = lgetxattr(path, name, value, size);
431 static int xmp_listxattr(
const char *path,
char *list,
size_t size)
433 int res = llistxattr(path, list, size);
439 static int xmp_removexattr(
const char *path,
const char *name)
441 int res = lremovexattr(path, name);
450 .getattr = xmp_getattr,
451 .access = xmp_access,
452 .readlink = xmp_readlink,
453 .readdir = xmp_readdir,
456 .symlink = xmp_symlink,
457 .unlink = xmp_unlink,
459 .rename = xmp_rename,
463 .truncate = xmp_truncate,
464 #ifdef HAVE_UTIMENSAT 465 .utimens = xmp_utimens,
468 .create = xmp_create,
471 .statfs = xmp_statfs,
472 .release = xmp_release,
474 #ifdef HAVE_POSIX_FALLOCATE 475 .fallocate = xmp_fallocate,
478 .setxattr = xmp_setxattr,
479 .getxattr = xmp_getxattr,
480 .listxattr = xmp_listxattr,
481 .removexattr = xmp_removexattr,
485 int main(
int argc,
char *argv[])
488 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)