2
FUSE: Filesystem in Userspace
3
Copyright (C) 2001-2005 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
23
#include <sys/statfs.h>
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_readlink(const char *path, char *buf, size_t size)
43
res = readlink(path, buf, size - 1);
51
static int xmp_opendir(const char *path, struct fuse_file_info *fi)
53
DIR *dp = opendir(path);
57
fi->fh = (unsigned long) dp;
61
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
62
off_t offset, struct fuse_file_info *fi)
64
DIR *dp = (DIR *) fi->fh;
69
while ((de = readdir(dp)) != NULL) {
71
memset(&st, 0, sizeof(st));
72
st.st_ino = de->d_ino;
73
st.st_mode = de->d_type << 12;
74
if (filler(buf, de->d_name, &st, de->d_off))
81
static int xmp_releasedir(const char *path, struct fuse_file_info *fi)
83
DIR *dp = (DIR *) fi->fh;
89
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
93
res = mknod(path, mode, rdev);
100
static int xmp_mkdir(const char *path, mode_t mode)
104
res = mkdir(path, mode);
111
static int xmp_unlink(const char *path)
122
static int xmp_rmdir(const char *path)
133
static int xmp_symlink(const char *from, const char *to)
137
res = symlink(from, to);
144
static int xmp_rename(const char *from, const char *to)
148
res = rename(from, to);
155
static int xmp_link(const char *from, const char *to)
159
res = link(from, to);
166
static int xmp_chmod(const char *path, mode_t mode)
170
res = chmod(path, mode);
177
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
181
res = lchown(path, uid, gid);
188
static int xmp_truncate(const char *path, off_t size)
192
res = truncate(path, size);
199
static int xmp_utime(const char *path, struct utimbuf *buf)
203
res = utime(path, buf);
211
static int xmp_open(const char *path, struct fuse_file_info *fi)
215
res = open(path, fi->flags);
223
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
224
struct fuse_file_info *fi)
229
res = pread(fi->fh, buf, size, offset);
236
static int xmp_write(const char *path, const char *buf, size_t size,
237
off_t offset, struct fuse_file_info *fi)
242
res = pwrite(fi->fh, buf, size, offset);
249
static int xmp_statfs(const char *path, struct statfs *stbuf)
253
res = statfs(path, stbuf);
260
static int xmp_release(const char *path, struct fuse_file_info *fi)
268
static int xmp_fsync(const char *path, int isdatasync,
269
struct fuse_file_info *fi)
275
res = fdatasync(fi->fh);
285
/* xattr operations are optional and can safely be left unimplemented */
286
static int xmp_setxattr(const char *path, const char *name, const char *value,
287
size_t size, int flags)
289
int res = lsetxattr(path, name, value, size, flags);
295
static int xmp_getxattr(const char *path, const char *name, char *value,
298
int res = lgetxattr(path, name, value, size);
304
static int xmp_listxattr(const char *path, char *list, size_t size)
306
int res = llistxattr(path, list, size);
312
static int xmp_removexattr(const char *path, const char *name)
314
int res = lremovexattr(path, name);
319
#endif /* HAVE_SETXATTR */
321
static struct fuse_operations xmp_oper = {
322
.getattr = xmp_getattr,
323
.readlink = xmp_readlink,
324
.opendir = xmp_opendir,
325
.readdir = xmp_readdir,
326
.releasedir = xmp_releasedir,
329
.symlink = xmp_symlink,
330
.unlink = xmp_unlink,
332
.rename = xmp_rename,
336
.truncate = xmp_truncate,
341
.statfs = xmp_statfs,
342
.release = xmp_release,
345
.setxattr = xmp_setxattr,
346
.getxattr = xmp_getxattr,
347
.listxattr = xmp_listxattr,
348
.removexattr= xmp_removexattr,
352
int main(int argc, char *argv[])
354
return fuse_main(argc, argv, &xmp_oper);