aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2005-04-07 15:40:21 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2005-04-07 15:40:21 +0000
commitab9745641373d35235b8c0d124f1c355908b575f (patch)
tree4ad92b37432ff7dcbcdd0ba57b85dfe00f89c505 /example
parent670c78a3134f2233b018fa931e1a7e69e4ab11fd (diff)
fix
Diffstat (limited to 'example')
-rw-r--r--example/.cvsignore1
-rw-r--r--example/Makefile.am3
-rw-r--r--example/fusexmp.c18
-rw-r--r--example/fusexmp_fh.c355
-rw-r--r--example/hello.c14
5 files changed, 379 insertions, 12 deletions
diff --git a/example/.cvsignore b/example/.cvsignore
index f9c7884..80eb82b 100644
--- a/example/.cvsignore
+++ b/example/.cvsignore
@@ -2,6 +2,7 @@ Makefile.in
Makefile
.deps
fusexmp
+fusexmp_fh
null
hello
.libs
diff --git a/example/Makefile.am b/example/Makefile.am
index e8c8a6d..be7a674 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -1,8 +1,9 @@
## Process this file with automake to produce Makefile.in
-noinst_PROGRAMS = fusexmp null hello
+noinst_PROGRAMS = fusexmp fusexmp_fh null hello
fusexmp_SOURCES = fusexmp.c
+fusexmp_fh_SOURCES = fusexmp_fh.c
null_SOURCES = null.c
hello_SOURCES = hello.c
diff --git a/example/fusexmp.c b/example/fusexmp.c
index 3230c36..95d26b3 100644
--- a/example/fusexmp.c
+++ b/example/fusexmp.c
@@ -49,24 +49,30 @@ static int xmp_readlink(const char *path, char *buf, size_t size)
}
-static int xmp_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
+static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi)
{
DIR *dp;
struct dirent *de;
- int res = 0;
+
+ (void) offset;
+ (void) fi;
dp = opendir(path);
if(dp == NULL)
return -errno;
while((de = readdir(dp)) != NULL) {
- res = filler(h, de->d_name, de->d_type, de->d_ino);
- if(res != 0)
+ struct stat st;
+ memset(&st, 0, sizeof(st));
+ st.st_ino = de->d_ino;
+ st.st_mode = de->d_type << 12;
+ if (filler(buf, de->d_name, &st, 0))
break;
}
closedir(dp);
- return res;
+ return 0;
}
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
@@ -314,7 +320,7 @@ static int xmp_removexattr(const char *path, const char *name)
static struct fuse_operations xmp_oper = {
.getattr = xmp_getattr,
.readlink = xmp_readlink,
- .getdir = xmp_getdir,
+ .readdir = xmp_readdir,
.mknod = xmp_mknod,
.mkdir = xmp_mkdir,
.symlink = xmp_symlink,
diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c
new file mode 100644
index 0000000..8a40c9e
--- /dev/null
+++ b/example/fusexmp_fh.c
@@ -0,0 +1,355 @@
+/*
+ FUSE: Filesystem in Userspace
+ Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+*/
+
+#include <config.h>
+
+#ifdef linux
+/* For pread()/pwrite() */
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <fuse.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <sys/statfs.h>
+#ifdef HAVE_SETXATTR
+#include <sys/xattr.h>
+#endif
+
+static int xmp_getattr(const char *path, struct stat *stbuf)
+{
+ int res;
+
+ res = lstat(path, stbuf);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_readlink(const char *path, char *buf, size_t size)
+{
+ int res;
+
+ res = readlink(path, buf, size - 1);
+ if(res == -1)
+ return -errno;
+
+ buf[res] = '\0';
+ return 0;
+}
+
+static int xmp_opendir(const char *path, struct fuse_file_info *fi)
+{
+ DIR *dp = opendir(path);
+ if (dp == NULL)
+ return -errno;
+
+ fi->fh = (unsigned long) dp;
+ return 0;
+}
+
+static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi)
+{
+ DIR *dp = (DIR *) fi->fh;
+ struct dirent *de;
+
+ (void) path;
+ seekdir(dp, offset);
+ while ((de = readdir(dp)) != NULL) {
+ struct stat st;
+ memset(&st, 0, sizeof(st));
+ st.st_ino = de->d_ino;
+ st.st_mode = de->d_type << 12;
+ if (filler(buf, de->d_name, &st, de->d_off))
+ break;
+ }
+
+ return 0;
+}
+
+static int xmp_releasedir(const char *path, struct fuse_file_info *fi)
+{
+ DIR *dp = (DIR *) fi->fh;
+ (void) path;
+ closedir(dp);
+ return 0;
+}
+
+static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
+{
+ int res;
+
+ res = mknod(path, mode, rdev);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_mkdir(const char *path, mode_t mode)
+{
+ int res;
+
+ res = mkdir(path, mode);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_unlink(const char *path)
+{
+ int res;
+
+ res = unlink(path);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_rmdir(const char *path)
+{
+ int res;
+
+ res = rmdir(path);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_symlink(const char *from, const char *to)
+{
+ int res;
+
+ res = symlink(from, to);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_rename(const char *from, const char *to)
+{
+ int res;
+
+ res = rename(from, to);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_link(const char *from, const char *to)
+{
+ int res;
+
+ res = link(from, to);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_chmod(const char *path, mode_t mode)
+{
+ int res;
+
+ res = chmod(path, mode);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_chown(const char *path, uid_t uid, gid_t gid)
+{
+ int res;
+
+ res = lchown(path, uid, gid);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_truncate(const char *path, off_t size)
+{
+ int res;
+
+ res = truncate(path, size);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_utime(const char *path, struct utimbuf *buf)
+{
+ int res;
+
+ res = utime(path, buf);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+
+static int xmp_open(const char *path, struct fuse_file_info *fi)
+{
+ int res;
+
+ res = open(path, fi->flags);
+ if(res == -1)
+ return -errno;
+
+ fi->fh = res;
+ return 0;
+}
+
+static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi)
+{
+ int res;
+
+ (void) path;
+ res = pread(fi->fh, buf, size, offset);
+ if(res == -1)
+ res = -errno;
+
+ return res;
+}
+
+static int xmp_write(const char *path, const char *buf, size_t size,
+ off_t offset, struct fuse_file_info *fi)
+{
+ int res;
+
+ (void) path;
+ res = pwrite(fi->fh, buf, size, offset);
+ if(res == -1)
+ res = -errno;
+
+ return res;
+}
+
+static int xmp_statfs(const char *path, struct statfs *stbuf)
+{
+ int res;
+
+ res = statfs(path, stbuf);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+static int xmp_release(const char *path, struct fuse_file_info *fi)
+{
+ (void) path;
+ close(fi->fh);
+
+ return 0;
+}
+
+static int xmp_fsync(const char *path, int isdatasync,
+ struct fuse_file_info *fi)
+{
+ int res;
+ (void) path;
+
+ if (isdatasync)
+ res = fdatasync(fi->fh);
+ else
+ res = fsync(fi->fh);
+ if(res == -1)
+ return -errno;
+
+ return 0;
+}
+
+#ifdef HAVE_SETXATTR
+/* xattr operations are optional and can safely be left unimplemented */
+static int xmp_setxattr(const char *path, const char *name, const char *value,
+ size_t size, int flags)
+{
+ int res = lsetxattr(path, name, value, size, flags);
+ if(res == -1)
+ return -errno;
+ return 0;
+}
+
+static int xmp_getxattr(const char *path, const char *name, char *value,
+ size_t size)
+{
+ int res = lgetxattr(path, name, value, size);
+ if(res == -1)
+ return -errno;
+ return res;
+}
+
+static int xmp_listxattr(const char *path, char *list, size_t size)
+{
+ int res = llistxattr(path, list, size);
+ if(res == -1)
+ return -errno;
+ return res;
+}
+
+static int xmp_removexattr(const char *path, const char *name)
+{
+ int res = lremovexattr(path, name);
+ if(res == -1)
+ return -errno;
+ return 0;
+}
+#endif /* HAVE_SETXATTR */
+
+static struct fuse_operations xmp_oper = {
+ .getattr = xmp_getattr,
+ .readlink = xmp_readlink,
+ .opendir = xmp_opendir,
+ .readdir = xmp_readdir,
+ .releasedir = xmp_releasedir,
+ .mknod = xmp_mknod,
+ .mkdir = xmp_mkdir,
+ .symlink = xmp_symlink,
+ .unlink = xmp_unlink,
+ .rmdir = xmp_rmdir,
+ .rename = xmp_rename,
+ .link = xmp_link,
+ .chmod = xmp_chmod,
+ .chown = xmp_chown,
+ .truncate = xmp_truncate,
+ .utime = xmp_utime,
+ .open = xmp_open,
+ .read = xmp_read,
+ .write = xmp_write,
+ .statfs = xmp_statfs,
+ .release = xmp_release,
+ .fsync = xmp_fsync,
+#ifdef HAVE_SETXATTR
+ .setxattr = xmp_setxattr,
+ .getxattr = xmp_getxattr,
+ .listxattr = xmp_listxattr,
+ .removexattr= xmp_removexattr,
+#endif
+};
+
+int main(int argc, char *argv[])
+{
+ return fuse_main(argc, argv, &xmp_oper);
+}
diff --git a/example/hello.c b/example/hello.c
index 9e4099b..b71bcd6 100644
--- a/example/hello.c
+++ b/example/hello.c
@@ -35,14 +35,18 @@ static int hello_getattr(const char *path, struct stat *stbuf)
return res;
}
-static int hello_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
+static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi)
{
+ (void) offset;
+ (void) fi;
+
if(strcmp(path, "/") != 0)
return -ENOENT;
- filler(h, ".", 0, 0);
- filler(h, "..", 0, 0);
- filler(h, hello_path + 1, 0, 0);
+ filler(buf, ".", NULL, 0);
+ filler(buf, "..", NULL, 0);
+ filler(buf, hello_path + 1, NULL, 0);
return 0;
}
@@ -79,7 +83,7 @@ static int hello_read(const char *path, char *buf, size_t size, off_t offset,
static struct fuse_operations hello_oper = {
.getattr = hello_getattr,
- .getdir = hello_getdir,
+ .readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};