diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2007-12-12 14:25:40 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2007-12-12 14:25:40 +0000 |
commit | cdb8b79bad5fea81b74931a9027f1d5ca344af8e (patch) | |
tree | 11ab550f265dc3eb546b7c26f3745e6d139b1fcc /example | |
parent | 918f0ad95b73e506d20488cb8ddd35d1a2524c7c (diff) | |
download | android_external_fuse-cdb8b79bad5fea81b74931a9027f1d5ca344af8e.tar.gz android_external_fuse-cdb8b79bad5fea81b74931a9027f1d5ca344af8e.tar.bz2 android_external_fuse-cdb8b79bad5fea81b74931a9027f1d5ca344af8e.zip |
change indenting
Diffstat (limited to 'example')
-rw-r--r-- | example/fusexmp.c | 412 | ||||
-rw-r--r-- | example/fusexmp_fh.c | 468 | ||||
-rw-r--r-- | example/hello.c | 106 | ||||
-rw-r--r-- | example/hello_ll.c | 231 | ||||
-rw-r--r-- | example/null.c | 90 |
5 files changed, 654 insertions, 653 deletions
diff --git a/example/fusexmp.c b/example/fusexmp.c index 8df474c..083bbea 100644 --- a/example/fusexmp.c +++ b/example/fusexmp.c @@ -1,11 +1,11 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. - gcc -Wall `pkg-config fuse --cflags --libs` fusexmp.c -o fusexmp + gcc -Wall `pkg-config fuse --cflags --libs` fusexmp.c -o fusexmp */ #define FUSE_USE_VERSION 26 @@ -33,353 +33,353 @@ static int xmp_getattr(const char *path, struct stat *stbuf) { - int res; + int res; - res = lstat(path, stbuf); - if (res == -1) - return -errno; + res = lstat(path, stbuf); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_access(const char *path, int mask) { - int res; + int res; - res = access(path, mask); - if (res == -1) - return -errno; + res = access(path, mask); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_readlink(const char *path, char *buf, size_t size) { - int res; + int res; - res = readlink(path, buf, size - 1); - if (res == -1) - return -errno; + res = readlink(path, buf, size - 1); + if (res == -1) + return -errno; - buf[res] = '\0'; - return 0; + buf[res] = '\0'; + return 0; } static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - DIR *dp; - struct dirent *de; - - (void) offset; - (void) fi; - - dp = opendir(path); - if (dp == NULL) - return -errno; - - 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, 0)) - break; - } - - closedir(dp); - return 0; + DIR *dp; + struct dirent *de; + + (void) offset; + (void) fi; + + dp = opendir(path); + if (dp == NULL) + return -errno; + + 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, 0)) + break; + } + + closedir(dp); + return 0; } static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { - int res; - - /* On Linux this could just be 'mknod(path, mode, rdev)' but this - is more portable */ - if (S_ISREG(mode)) { - res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode); - if (res >= 0) - res = close(res); - } else if (S_ISFIFO(mode)) - res = mkfifo(path, mode); - else - res = mknod(path, mode, rdev); - if (res == -1) - return -errno; - - return 0; + int res; + + /* On Linux this could just be 'mknod(path, mode, rdev)' but this + is more portable */ + if (S_ISREG(mode)) { + res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode); + if (res >= 0) + res = close(res); + } else if (S_ISFIFO(mode)) + res = mkfifo(path, mode); + else + res = mknod(path, mode, rdev); + if (res == -1) + return -errno; + + return 0; } static int xmp_mkdir(const char *path, mode_t mode) { - int res; + int res; - res = mkdir(path, mode); - if (res == -1) - return -errno; + res = mkdir(path, mode); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_unlink(const char *path) { - int res; + int res; - res = unlink(path); - if (res == -1) - return -errno; + res = unlink(path); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_rmdir(const char *path) { - int res; + int res; - res = rmdir(path); - if (res == -1) - return -errno; + res = rmdir(path); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_symlink(const char *from, const char *to) { - int res; + int res; - res = symlink(from, to); - if (res == -1) - return -errno; + res = symlink(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_rename(const char *from, const char *to) { - int res; + int res; - res = rename(from, to); - if (res == -1) - return -errno; + res = rename(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_link(const char *from, const char *to) { - int res; + int res; - res = link(from, to); - if (res == -1) - return -errno; + res = link(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_chmod(const char *path, mode_t mode) { - int res; + int res; - res = chmod(path, mode); - if (res == -1) - return -errno; + res = chmod(path, mode); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_chown(const char *path, uid_t uid, gid_t gid) { - int res; + int res; - res = lchown(path, uid, gid); - if (res == -1) - return -errno; + res = lchown(path, uid, gid); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_truncate(const char *path, off_t size) { - int res; + int res; - res = truncate(path, size); - if (res == -1) - return -errno; + res = truncate(path, size); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_utimens(const char *path, const struct timespec ts[2]) { - int res; - struct timeval tv[2]; + int res; + struct timeval tv[2]; - tv[0].tv_sec = ts[0].tv_sec; - tv[0].tv_usec = ts[0].tv_nsec / 1000; - tv[1].tv_sec = ts[1].tv_sec; - tv[1].tv_usec = ts[1].tv_nsec / 1000; + tv[0].tv_sec = ts[0].tv_sec; + tv[0].tv_usec = ts[0].tv_nsec / 1000; + tv[1].tv_sec = ts[1].tv_sec; + tv[1].tv_usec = ts[1].tv_nsec / 1000; - res = utimes(path, tv); - if (res == -1) - return -errno; + res = utimes(path, tv); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_open(const char *path, struct fuse_file_info *fi) { - int res; + int res; - res = open(path, fi->flags); - if (res == -1) - return -errno; + res = open(path, fi->flags); + if (res == -1) + return -errno; - close(res); - return 0; + close(res); + return 0; } static int xmp_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int fd; - int res; + int fd; + int res; - (void) fi; - fd = open(path, O_RDONLY); - if (fd == -1) - return -errno; + (void) fi; + fd = open(path, O_RDONLY); + if (fd == -1) + return -errno; - res = pread(fd, buf, size, offset); - if (res == -1) - res = -errno; + res = pread(fd, buf, size, offset); + if (res == -1) + res = -errno; - close(fd); - return res; + close(fd); + return res; } static int xmp_write(const char *path, const char *buf, size_t size, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - int fd; - int res; + int fd; + int res; - (void) fi; - fd = open(path, O_WRONLY); - if (fd == -1) - return -errno; + (void) fi; + fd = open(path, O_WRONLY); + if (fd == -1) + return -errno; - res = pwrite(fd, buf, size, offset); - if (res == -1) - res = -errno; + res = pwrite(fd, buf, size, offset); + if (res == -1) + res = -errno; - close(fd); - return res; + close(fd); + return res; } static int xmp_statfs(const char *path, struct statvfs *stbuf) { - int res; + int res; - res = statvfs(path, stbuf); - if (res == -1) - return -errno; + res = statvfs(path, stbuf); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_release(const char *path, struct fuse_file_info *fi) { - /* Just a stub. This method is optional and can safely be left - unimplemented */ + /* Just a stub. This method is optional and can safely be left + unimplemented */ - (void) path; - (void) fi; - return 0; + (void) path; + (void) fi; + return 0; } static int xmp_fsync(const char *path, int isdatasync, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - /* Just a stub. This method is optional and can safely be left - unimplemented */ + /* Just a stub. This method is optional and can safely be left + unimplemented */ - (void) path; - (void) isdatasync; - (void) fi; - return 0; + (void) path; + (void) isdatasync; + (void) fi; + 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) + size_t size, int flags) { - int res = lsetxattr(path, name, value, size, flags); - if (res == -1) - return -errno; - return 0; + 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) + size_t size) { - int res = lgetxattr(path, name, value, size); - if (res == -1) - return -errno; - return res; + 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; + 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; + int res = lremovexattr(path, name); + if (res == -1) + return -errno; + return 0; } #endif /* HAVE_SETXATTR */ static struct fuse_operations xmp_oper = { - .getattr = xmp_getattr, - .access = xmp_access, - .readlink = xmp_readlink, - .readdir = xmp_readdir, - .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, - .utimens = xmp_utimens, - .open = xmp_open, - .read = xmp_read, - .write = xmp_write, - .statfs = xmp_statfs, - .release = xmp_release, - .fsync = xmp_fsync, + .getattr = xmp_getattr, + .access = xmp_access, + .readlink = xmp_readlink, + .readdir = xmp_readdir, + .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, + .utimens = xmp_utimens, + .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, + .setxattr = xmp_setxattr, + .getxattr = xmp_getxattr, + .listxattr = xmp_listxattr, + .removexattr = xmp_removexattr, #endif }; int main(int argc, char *argv[]) { - umask(0); - return fuse_main(argc, argv, &xmp_oper, NULL); + umask(0); + return fuse_main(argc, argv, &xmp_oper, NULL); } diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c index 6565cf9..616c263 100644 --- a/example/fusexmp_fh.c +++ b/example/fusexmp_fh.c @@ -1,11 +1,11 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. - gcc -Wall `pkg-config fuse --cflags --libs` -lulockmgr fusexmp_fh.c -o fusexmp_fh + gcc -Wall `pkg-config fuse --cflags --libs` -lulockmgr fusexmp_fh.c -o fusexmp_fh */ #define FUSE_USE_VERSION 26 @@ -31,430 +31,430 @@ static int xmp_getattr(const char *path, struct stat *stbuf) { - int res; + int res; - res = lstat(path, stbuf); - if (res == -1) - return -errno; + res = lstat(path, stbuf); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_fgetattr(const char *path, struct stat *stbuf, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int res; + int res; - (void) path; + (void) path; - res = fstat(fi->fh, stbuf); - if (res == -1) - return -errno; + res = fstat(fi->fh, stbuf); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_access(const char *path, int mask) { - int res; + int res; - res = access(path, mask); - if (res == -1) - return -errno; + res = access(path, mask); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_readlink(const char *path, char *buf, size_t size) { - int res; + int res; - res = readlink(path, buf, size - 1); - if (res == -1) - return -errno; + res = readlink(path, buf, size - 1); + if (res == -1) + return -errno; - buf[res] = '\0'; - return 0; + 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; + DIR *dp = opendir(path); + if (dp == NULL) + return -errno; - fi->fh = (unsigned long) dp; - return 0; + fi->fh = (unsigned long) dp; + return 0; } static inline DIR *get_dirp(struct fuse_file_info *fi) { - return (DIR *) (uintptr_t) fi->fh; + return (DIR *) (uintptr_t) fi->fh; } static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - DIR *dp = get_dirp(fi); - struct dirent *de; + DIR *dp = get_dirp(fi); + 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, telldir(dp))) - break; - } + (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, telldir(dp))) + break; + } - return 0; + return 0; } static int xmp_releasedir(const char *path, struct fuse_file_info *fi) { - DIR *dp = get_dirp(fi); - (void) path; - closedir(dp); - return 0; + DIR *dp = get_dirp(fi); + (void) path; + closedir(dp); + return 0; } static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { - int res; + int res; - if (S_ISFIFO(mode)) - res = mkfifo(path, mode); - else - res = mknod(path, mode, rdev); - if (res == -1) - return -errno; + if (S_ISFIFO(mode)) + res = mkfifo(path, mode); + else + res = mknod(path, mode, rdev); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_mkdir(const char *path, mode_t mode) { - int res; + int res; - res = mkdir(path, mode); - if (res == -1) - return -errno; + res = mkdir(path, mode); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_unlink(const char *path) { - int res; + int res; - res = unlink(path); - if (res == -1) - return -errno; + res = unlink(path); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_rmdir(const char *path) { - int res; + int res; - res = rmdir(path); - if (res == -1) - return -errno; + res = rmdir(path); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_symlink(const char *from, const char *to) { - int res; + int res; - res = symlink(from, to); - if (res == -1) - return -errno; + res = symlink(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_rename(const char *from, const char *to) { - int res; + int res; - res = rename(from, to); - if (res == -1) - return -errno; + res = rename(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_link(const char *from, const char *to) { - int res; + int res; - res = link(from, to); - if (res == -1) - return -errno; + res = link(from, to); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_chmod(const char *path, mode_t mode) { - int res; + int res; - res = chmod(path, mode); - if (res == -1) - return -errno; + res = chmod(path, mode); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_chown(const char *path, uid_t uid, gid_t gid) { - int res; + int res; - res = lchown(path, uid, gid); - if (res == -1) - return -errno; + res = lchown(path, uid, gid); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_truncate(const char *path, off_t size) { - int res; + int res; - res = truncate(path, size); - if (res == -1) - return -errno; + res = truncate(path, size); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_ftruncate(const char *path, off_t size, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int res; + int res; - (void) path; + (void) path; - res = ftruncate(fi->fh, size); - if (res == -1) - return -errno; + res = ftruncate(fi->fh, size); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_utimens(const char *path, const struct timespec ts[2]) { - int res; - struct timeval tv[2]; + int res; + struct timeval tv[2]; - tv[0].tv_sec = ts[0].tv_sec; - tv[0].tv_usec = ts[0].tv_nsec / 1000; - tv[1].tv_sec = ts[1].tv_sec; - tv[1].tv_usec = ts[1].tv_nsec / 1000; + tv[0].tv_sec = ts[0].tv_sec; + tv[0].tv_usec = ts[0].tv_nsec / 1000; + tv[1].tv_sec = ts[1].tv_sec; + tv[1].tv_usec = ts[1].tv_nsec / 1000; - res = utimes(path, tv); - if (res == -1) - return -errno; + res = utimes(path, tv); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_create(const char *path, mode_t mode, struct fuse_file_info *fi) { - int fd; + int fd; - fd = open(path, fi->flags, mode); - if (fd == -1) - return -errno; + fd = open(path, fi->flags, mode); + if (fd == -1) + return -errno; - fi->fh = fd; - return 0; + fi->fh = fd; + return 0; } static int xmp_open(const char *path, struct fuse_file_info *fi) { - int fd; + int fd; - fd = open(path, fi->flags); - if (fd == -1) - return -errno; + fd = open(path, fi->flags); + if (fd == -1) + return -errno; - fi->fh = fd; - return 0; + fi->fh = fd; + return 0; } static int xmp_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int res; + int res; - (void) path; - res = pread(fi->fh, buf, size, offset); - if (res == -1) - res = -errno; + (void) path; + res = pread(fi->fh, buf, size, offset); + if (res == -1) + res = -errno; - return res; + return res; } static int xmp_write(const char *path, const char *buf, size_t size, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - int res; + int res; - (void) path; - res = pwrite(fi->fh, buf, size, offset); - if (res == -1) - res = -errno; + (void) path; + res = pwrite(fi->fh, buf, size, offset); + if (res == -1) + res = -errno; - return res; + return res; } static int xmp_statfs(const char *path, struct statvfs *stbuf) { - int res; + int res; - res = statvfs(path, stbuf); - if (res == -1) - return -errno; + res = statvfs(path, stbuf); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_flush(const char *path, struct fuse_file_info *fi) { - int res; + int res; - (void) path; - /* This is called from every close on an open file, so call the - close on the underlying filesystem. But since flush may be - called multiple times for an open file, this must not really - close the file. This is important if used on a network - filesystem like NFS which flush the data/metadata on close() */ - res = close(dup(fi->fh)); - if (res == -1) - return -errno; + (void) path; + /* This is called from every close on an open file, so call the + close on the underlying filesystem. But since flush may be + called multiple times for an open file, this must not really + close the file. This is important if used on a network + filesystem like NFS which flush the data/metadata on close() */ + res = close(dup(fi->fh)); + if (res == -1) + return -errno; - return 0; + return 0; } static int xmp_release(const char *path, struct fuse_file_info *fi) { - (void) path; - close(fi->fh); + (void) path; + close(fi->fh); - return 0; + return 0; } static int xmp_fsync(const char *path, int isdatasync, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int res; - (void) path; + int res; + (void) path; #ifndef HAVE_FDATASYNC - (void) isdatasync; + (void) isdatasync; #else - if (isdatasync) - res = fdatasync(fi->fh); - else + if (isdatasync) + res = fdatasync(fi->fh); + else #endif - res = fsync(fi->fh); - if (res == -1) - return -errno; + res = fsync(fi->fh); + if (res == -1) + return -errno; - return 0; + 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) + size_t size, int flags) { - int res = lsetxattr(path, name, value, size, flags); - if (res == -1) - return -errno; - return 0; + 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) + size_t size) { - int res = lgetxattr(path, name, value, size); - if (res == -1) - return -errno; - return res; + 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; + 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; + int res = lremovexattr(path, name); + if (res == -1) + return -errno; + return 0; } #endif /* HAVE_SETXATTR */ static int xmp_lock(const char *path, struct fuse_file_info *fi, int cmd, - struct flock *lock) + struct flock *lock) { - (void) path; + (void) path; - return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner, - sizeof(fi->lock_owner)); + return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner, + sizeof(fi->lock_owner)); } static struct fuse_operations xmp_oper = { - .getattr = xmp_getattr, - .fgetattr = xmp_fgetattr, - .access = xmp_access, - .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, - .ftruncate = xmp_ftruncate, - .utimens = xmp_utimens, - .create = xmp_create, - .open = xmp_open, - .read = xmp_read, - .write = xmp_write, - .statfs = xmp_statfs, - .flush = xmp_flush, - .release = xmp_release, - .fsync = xmp_fsync, + .getattr = xmp_getattr, + .fgetattr = xmp_fgetattr, + .access = xmp_access, + .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, + .ftruncate = xmp_ftruncate, + .utimens = xmp_utimens, + .create = xmp_create, + .open = xmp_open, + .read = xmp_read, + .write = xmp_write, + .statfs = xmp_statfs, + .flush = xmp_flush, + .release = xmp_release, + .fsync = xmp_fsync, #ifdef HAVE_SETXATTR - .setxattr = xmp_setxattr, - .getxattr = xmp_getxattr, - .listxattr = xmp_listxattr, - .removexattr= xmp_removexattr, + .setxattr = xmp_setxattr, + .getxattr = xmp_getxattr, + .listxattr = xmp_listxattr, + .removexattr = xmp_removexattr, #endif - .lock = xmp_lock, + .lock = xmp_lock, }; int main(int argc, char *argv[]) { - umask(0); - return fuse_main(argc, argv, &xmp_oper, NULL); + umask(0); + return fuse_main(argc, argv, &xmp_oper, NULL); } diff --git a/example/hello.c b/example/hello.c index 463e286..bcde80a 100644 --- a/example/hello.c +++ b/example/hello.c @@ -1,11 +1,11 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. - gcc -Wall `pkg-config fuse --cflags --libs` hello.c -o hello + gcc -Wall `pkg-config fuse --cflags --libs` hello.c -o hello */ #define FUSE_USE_VERSION 26 @@ -21,76 +21,76 @@ static const char *hello_path = "/hello"; static int hello_getattr(const char *path, struct stat *stbuf) { - int res = 0; - - memset(stbuf, 0, sizeof(struct stat)); - if (strcmp(path, "/") == 0) { - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 2; - } else if (strcmp(path, hello_path) == 0) { - stbuf->st_mode = S_IFREG | 0444; - stbuf->st_nlink = 1; - stbuf->st_size = strlen(hello_str); - } else - res = -ENOENT; - - return res; + int res = 0; + + memset(stbuf, 0, sizeof(struct stat)); + if (strcmp(path, "/") == 0) { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + } else if (strcmp(path, hello_path) == 0) { + stbuf->st_mode = S_IFREG | 0444; + stbuf->st_nlink = 1; + stbuf->st_size = strlen(hello_str); + } else + res = -ENOENT; + + return res; } static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - (void) offset; - (void) fi; + (void) offset; + (void) fi; - if (strcmp(path, "/") != 0) - return -ENOENT; + if (strcmp(path, "/") != 0) + return -ENOENT; - filler(buf, ".", NULL, 0); - filler(buf, "..", NULL, 0); - filler(buf, hello_path + 1, NULL, 0); + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + filler(buf, hello_path + 1, NULL, 0); - return 0; + return 0; } static int hello_open(const char *path, struct fuse_file_info *fi) { - if (strcmp(path, hello_path) != 0) - return -ENOENT; + if (strcmp(path, hello_path) != 0) + return -ENOENT; - if ((fi->flags & 3) != O_RDONLY) - return -EACCES; + if ((fi->flags & 3) != O_RDONLY) + return -EACCES; - return 0; + return 0; } static int hello_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - size_t len; - (void) fi; - if(strcmp(path, hello_path) != 0) - return -ENOENT; - - len = strlen(hello_str); - if (offset < len) { - if (offset + size > len) - size = len - offset; - memcpy(buf, hello_str + offset, size); - } else - size = 0; - - return size; + size_t len; + (void) fi; + if(strcmp(path, hello_path) != 0) + return -ENOENT; + + len = strlen(hello_str); + if (offset < len) { + if (offset + size > len) + size = len - offset; + memcpy(buf, hello_str + offset, size); + } else + size = 0; + + return size; } static struct fuse_operations hello_oper = { - .getattr = hello_getattr, - .readdir = hello_readdir, - .open = hello_open, - .read = hello_read, + .getattr = hello_getattr, + .readdir = hello_readdir, + .open = hello_open, + .read = hello_read, }; int main(int argc, char *argv[]) { - return fuse_main(argc, argv, &hello_oper, NULL); + return fuse_main(argc, argv, &hello_oper, NULL); } diff --git a/example/hello_ll.c b/example/hello_ll.c index 6ab6172..1d3a1a8 100644 --- a/example/hello_ll.c +++ b/example/hello_ll.c @@ -1,11 +1,11 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. - gcc -Wall `pkg-config fuse --cflags --libs` hello_ll.c -o hello_ll + gcc -Wall `pkg-config fuse --cflags --libs` hello_ll.c -o hello_ll */ #define FUSE_USE_VERSION 26 @@ -24,157 +24,158 @@ static const char *hello_name = "hello"; static int hello_stat(fuse_ino_t ino, struct stat *stbuf) { - stbuf->st_ino = ino; - switch (ino) { - case 1: - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 2; - break; - - case 2: - stbuf->st_mode = S_IFREG | 0444; - stbuf->st_nlink = 1; - stbuf->st_size = strlen(hello_str); - break; - - default: - return -1; - } - return 0; + stbuf->st_ino = ino; + switch (ino) { + case 1: + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + break; + + case 2: + stbuf->st_mode = S_IFREG | 0444; + stbuf->st_nlink = 1; + stbuf->st_size = strlen(hello_str); + break; + + default: + return -1; + } + return 0; } static void hello_ll_getattr(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - struct stat stbuf; + struct stat stbuf; - (void) fi; + (void) fi; - memset(&stbuf, 0, sizeof(stbuf)); - if (hello_stat(ino, &stbuf) == -1) - fuse_reply_err(req, ENOENT); - else - fuse_reply_attr(req, &stbuf, 1.0); + memset(&stbuf, 0, sizeof(stbuf)); + if (hello_stat(ino, &stbuf) == -1) + fuse_reply_err(req, ENOENT); + else + fuse_reply_attr(req, &stbuf, 1.0); } static void hello_ll_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) { - struct fuse_entry_param e; - - if (parent != 1 || strcmp(name, hello_name) != 0) - fuse_reply_err(req, ENOENT); - else { - memset(&e, 0, sizeof(e)); - e.ino = 2; - e.attr_timeout = 1.0; - e.entry_timeout = 1.0; - hello_stat(e.ino, &e.attr); - - fuse_reply_entry(req, &e); - } + struct fuse_entry_param e; + + if (parent != 1 || strcmp(name, hello_name) != 0) + fuse_reply_err(req, ENOENT); + else { + memset(&e, 0, sizeof(e)); + e.ino = 2; + e.attr_timeout = 1.0; + e.entry_timeout = 1.0; + hello_stat(e.ino, &e.attr); + + fuse_reply_entry(req, &e); + } } struct dirbuf { - char *p; - size_t size; + char *p; + size_t size; }; static void dirbuf_add(fuse_req_t req, struct dirbuf *b, const char *name, - fuse_ino_t ino) + fuse_ino_t ino) { - struct stat stbuf; - size_t oldsize = b->size; - b->size += fuse_add_direntry(req, NULL, 0, name, NULL, 0); - b->p = (char *) realloc(b->p, b->size); - memset(&stbuf, 0, sizeof(stbuf)); - stbuf.st_ino = ino; - fuse_add_direntry(req, b->p + oldsize, b->size - oldsize, name, &stbuf, - b->size); + struct stat stbuf; + size_t oldsize = b->size; + b->size += fuse_add_direntry(req, NULL, 0, name, NULL, 0); + b->p = (char *) realloc(b->p, b->size); + memset(&stbuf, 0, sizeof(stbuf)); + stbuf.st_ino = ino; + fuse_add_direntry(req, b->p + oldsize, b->size - oldsize, name, &stbuf, + b->size); } #define min(x, y) ((x) < (y) ? (x) : (y)) static int reply_buf_limited(fuse_req_t req, const char *buf, size_t bufsize, - off_t off, size_t maxsize) + off_t off, size_t maxsize) { - if (off < bufsize) - return fuse_reply_buf(req, buf + off, min(bufsize - off, maxsize)); - else - return fuse_reply_buf(req, NULL, 0); + if (off < bufsize) + return fuse_reply_buf(req, buf + off, + min(bufsize - off, maxsize)); + else + return fuse_reply_buf(req, NULL, 0); } static void hello_ll_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, - off_t off, struct fuse_file_info *fi) + off_t off, struct fuse_file_info *fi) { - (void) fi; - - if (ino != 1) - fuse_reply_err(req, ENOTDIR); - else { - struct dirbuf b; - - memset(&b, 0, sizeof(b)); - dirbuf_add(req, &b, ".", 1); - dirbuf_add(req, &b, "..", 1); - dirbuf_add(req, &b, hello_name, 2); - reply_buf_limited(req, b.p, b.size, off, size); - free(b.p); - } + (void) fi; + + if (ino != 1) + fuse_reply_err(req, ENOTDIR); + else { + struct dirbuf b; + + memset(&b, 0, sizeof(b)); + dirbuf_add(req, &b, ".", 1); + dirbuf_add(req, &b, "..", 1); + dirbuf_add(req, &b, hello_name, 2); + reply_buf_limited(req, b.p, b.size, off, size); + free(b.p); + } } static void hello_ll_open(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - if (ino != 2) - fuse_reply_err(req, EISDIR); - else if ((fi->flags & 3) != O_RDONLY) - fuse_reply_err(req, EACCES); - else - fuse_reply_open(req, fi); + if (ino != 2) + fuse_reply_err(req, EISDIR); + else if ((fi->flags & 3) != O_RDONLY) + fuse_reply_err(req, EACCES); + else + fuse_reply_open(req, fi); } static void hello_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size, - off_t off, struct fuse_file_info *fi) + off_t off, struct fuse_file_info *fi) { - (void) fi; + (void) fi; - assert(ino == 2); - reply_buf_limited(req, hello_str, strlen(hello_str), off, size); + assert(ino == 2); + reply_buf_limited(req, hello_str, strlen(hello_str), off, size); } static struct fuse_lowlevel_ops hello_ll_oper = { - .lookup = hello_ll_lookup, - .getattr = hello_ll_getattr, - .readdir = hello_ll_readdir, - .open = hello_ll_open, - .read = hello_ll_read, + .lookup = hello_ll_lookup, + .getattr = hello_ll_getattr, + .readdir = hello_ll_readdir, + .open = hello_ll_open, + .read = hello_ll_read, }; int main(int argc, char *argv[]) { - struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - struct fuse_chan *ch; - char *mountpoint; - int err = -1; - - if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 && - (ch = fuse_mount(mountpoint, &args)) != NULL) { - struct fuse_session *se; - - se = fuse_lowlevel_new(&args, &hello_ll_oper, sizeof(hello_ll_oper), - NULL); - if (se != NULL) { - if (fuse_set_signal_handlers(se) != -1) { - fuse_session_add_chan(se, ch); - err = fuse_session_loop(se); - fuse_remove_signal_handlers(se); - fuse_session_remove_chan(ch); - } - fuse_session_destroy(se); - } - fuse_unmount(mountpoint, ch); - } - fuse_opt_free_args(&args); - - return err ? 1 : 0; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + struct fuse_chan *ch; + char *mountpoint; + int err = -1; + + if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 && + (ch = fuse_mount(mountpoint, &args)) != NULL) { + struct fuse_session *se; + + se = fuse_lowlevel_new(&args, &hello_ll_oper, + sizeof(hello_ll_oper), NULL); + if (se != NULL) { + if (fuse_set_signal_handlers(se) != -1) { + fuse_session_add_chan(se, ch); + err = fuse_session_loop(se); + fuse_remove_signal_handlers(se); + fuse_session_remove_chan(ch); + } + fuse_session_destroy(se); + } + fuse_unmount(mountpoint, ch); + } + fuse_opt_free_args(&args); + + return err ? 1 : 0; } diff --git a/example/null.c b/example/null.c index 0793de6..a98226e 100644 --- a/example/null.c +++ b/example/null.c @@ -1,11 +1,11 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. - gcc -Wall `pkg-config fuse --cflags --libs` null.c -o null + gcc -Wall `pkg-config fuse --cflags --libs` null.c -o null */ #define FUSE_USE_VERSION 26 @@ -18,75 +18,75 @@ static int null_getattr(const char *path, struct stat *stbuf) { - if(strcmp(path, "/") != 0) - return -ENOENT; - - stbuf->st_mode = S_IFREG | 0644; - stbuf->st_nlink = 1; - stbuf->st_uid = getuid(); - stbuf->st_gid = getgid(); - stbuf->st_size = (1ULL << 32); /* 4G */ - stbuf->st_blocks = 0; - stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL); - - return 0; + if(strcmp(path, "/") != 0) + return -ENOENT; + + stbuf->st_mode = S_IFREG | 0644; + stbuf->st_nlink = 1; + stbuf->st_uid = getuid(); + stbuf->st_gid = getgid(); + stbuf->st_size = (1ULL << 32); /* 4G */ + stbuf->st_blocks = 0; + stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL); + + return 0; } static int null_truncate(const char *path, off_t size) { - (void) size; + (void) size; - if(strcmp(path, "/") != 0) - return -ENOENT; + if(strcmp(path, "/") != 0) + return -ENOENT; - return 0; + return 0; } static int null_open(const char *path, struct fuse_file_info *fi) { - (void) fi; + (void) fi; - if(strcmp(path, "/") != 0) - return -ENOENT; + if(strcmp(path, "/") != 0) + return -ENOENT; - return 0; + return 0; } static int null_read(const char *path, char *buf, size_t size, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - (void) buf; - (void) offset; - (void) fi; + (void) buf; + (void) offset; + (void) fi; - if(strcmp(path, "/") != 0) - return -ENOENT; + if(strcmp(path, "/") != 0) + return -ENOENT; - return size; + return size; } static int null_write(const char *path, const char *buf, size_t size, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { - (void) buf; - (void) offset; - (void) fi; + (void) buf; + (void) offset; + (void) fi; - if(strcmp(path, "/") != 0) - return -ENOENT; + if(strcmp(path, "/") != 0) + return -ENOENT; - return size; + return size; } static struct fuse_operations null_oper = { - .getattr = null_getattr, - .truncate = null_truncate, - .open = null_open, - .read = null_read, - .write = null_write, + .getattr = null_getattr, + .truncate = null_truncate, + .open = null_open, + .read = null_read, + .write = null_write, }; int main(int argc, char *argv[]) { - return fuse_main(argc, argv, &null_oper, NULL); + return fuse_main(argc, argv, &null_oper, NULL); } |