2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
12 /* For pread()/pwrite() */
13 #define _XOPEN_SOURCE 500
25 #include <sys/xattr.h>
28 static int xmp_getattr(const char *path
, struct stat
*stbuf
)
32 res
= lstat(path
, stbuf
);
39 static int xmp_access(const char *path
, int mask
)
43 res
= access(path
, mask
);
50 static int xmp_readlink(const char *path
, char *buf
, size_t size
)
54 res
= readlink(path
, buf
, size
- 1);
63 static int xmp_readdir(const char *path
, void *buf
, fuse_fill_dir_t filler
,
64 off_t offset
, struct fuse_file_info
*fi
)
76 while ((de
= readdir(dp
)) != NULL
) {
78 memset(&st
, 0, sizeof(st
));
79 st
.st_ino
= de
->d_ino
;
80 st
.st_mode
= de
->d_type
<< 12;
81 if (filler(buf
, de
->d_name
, &st
, 0))
89 static int xmp_mknod(const char *path
, mode_t mode
, dev_t rdev
)
93 /* On Linux this could just be 'mknod(path, mode, rdev)' but this
96 res
= open(path
, O_CREAT
| O_EXCL
| O_WRONLY
, mode
);
99 } else if (S_ISFIFO(mode
))
100 res
= mkfifo(path
, mode
);
102 res
= mknod(path
, mode
, rdev
);
109 static int xmp_mkdir(const char *path
, mode_t mode
)
113 res
= mkdir(path
, mode
);
120 static int xmp_unlink(const char *path
)
131 static int xmp_rmdir(const char *path
)
142 static int xmp_symlink(const char *from
, const char *to
)
146 res
= symlink(from
, to
);
153 static int xmp_rename(const char *from
, const char *to
)
157 res
= rename(from
, to
);
164 static int xmp_link(const char *from
, const char *to
)
168 res
= link(from
, to
);
175 static int xmp_chmod(const char *path
, mode_t mode
)
179 res
= chmod(path
, mode
);
186 static int xmp_chown(const char *path
, uid_t uid
, gid_t gid
)
190 res
= lchown(path
, uid
, gid
);
197 static int xmp_truncate(const char *path
, off_t size
)
201 res
= truncate(path
, size
);
208 static int xmp_utimes(const char *path
, const struct timespec ts
[2])
211 struct timeval tv
[2];
213 tv
[0].tv_sec
= ts
[0].tv_sec
;
214 tv
[0].tv_usec
= ts
[0].tv_nsec
/ 1000;
215 tv
[1].tv_sec
= ts
[1].tv_sec
;
216 tv
[1].tv_usec
= ts
[1].tv_nsec
/ 1000;
218 res
= utimes(path
, tv
);
225 static int xmp_open(const char *path
, struct fuse_file_info
*fi
)
229 res
= open(path
, fi
->flags
);
237 static int xmp_read(const char *path
, char *buf
, size_t size
, off_t offset
,
238 struct fuse_file_info
*fi
)
244 fd
= open(path
, O_RDONLY
);
248 res
= pread(fd
, buf
, size
, offset
);
256 static int xmp_write(const char *path
, const char *buf
, size_t size
,
257 off_t offset
, struct fuse_file_info
*fi
)
263 fd
= open(path
, O_WRONLY
);
267 res
= pwrite(fd
, buf
, size
, offset
);
275 static int xmp_statfs(const char *path
, struct statvfs
*stbuf
)
279 res
= statvfs(path
, stbuf
);
286 static int xmp_release(const char *path
, struct fuse_file_info
*fi
)
288 /* Just a stub. This method is optional and can safely be left
296 static int xmp_fsync(const char *path
, int isdatasync
,
297 struct fuse_file_info
*fi
)
299 /* Just a stub. This method is optional and can safely be left
309 /* xattr operations are optional and can safely be left unimplemented */
310 static int xmp_setxattr(const char *path
, const char *name
, const char *value
,
311 size_t size
, int flags
)
313 int res
= lsetxattr(path
, name
, value
, size
, flags
);
319 static int xmp_getxattr(const char *path
, const char *name
, char *value
,
322 int res
= lgetxattr(path
, name
, value
, size
);
328 static int xmp_listxattr(const char *path
, char *list
, size_t size
)
330 int res
= llistxattr(path
, list
, size
);
336 static int xmp_removexattr(const char *path
, const char *name
)
338 int res
= lremovexattr(path
, name
);
343 #endif /* HAVE_SETXATTR */
345 static struct fuse_operations xmp_oper
= {
346 .getattr
= xmp_getattr
,
347 .access
= xmp_access
,
348 .readlink
= xmp_readlink
,
349 .readdir
= xmp_readdir
,
352 .symlink
= xmp_symlink
,
353 .unlink
= xmp_unlink
,
355 .rename
= xmp_rename
,
359 .truncate
= xmp_truncate
,
360 .utimes
= xmp_utimes
,
364 .statfs
= xmp_statfs
,
365 .release
= xmp_release
,
368 .setxattr
= xmp_setxattr
,
369 .getxattr
= xmp_getxattr
,
370 .listxattr
= xmp_listxattr
,
371 .removexattr
= xmp_removexattr
,
375 int main(int argc
, char *argv
[])
378 return fuse_main(argc
, argv
, &xmp_oper
, NULL
);