diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2005-11-16 13:00:24 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2005-11-16 13:00:24 +0000 |
commit | b3f9972a859e95cf836c0044c82fcf312afc566e (patch) | |
tree | 8eaad737402f56ae53f6ed57e2b0878830e652eb /example | |
parent | 666aea72dfafcf8e93d9c781d1d8d3e644bd6949 (diff) | |
download | android_external_fuse-b3f9972a859e95cf836c0044c82fcf312afc566e.tar.gz android_external_fuse-b3f9972a859e95cf836c0044c82fcf312afc566e.tar.bz2 android_external_fuse-b3f9972a859e95cf836c0044c82fcf312afc566e.zip |
merge FreeBSD stuff
Diffstat (limited to 'example')
-rw-r--r-- | example/fusexmp.c | 63 | ||||
-rw-r--r-- | example/fusexmp_fh.c | 63 |
2 files changed, 71 insertions, 55 deletions
diff --git a/example/fusexmp.c b/example/fusexmp.c index 5a2e9a0..26b2be2 100644 --- a/example/fusexmp.c +++ b/example/fusexmp.c @@ -29,7 +29,7 @@ static int xmp_getattr(const char *path, struct stat *stbuf) int res; res = lstat(path, stbuf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -40,7 +40,7 @@ static int xmp_access(const char *path, int mask) int res; res = access(path, mask); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -51,7 +51,7 @@ static int xmp_readlink(const char *path, char *buf, size_t size) int res; res = readlink(path, buf, size - 1); - if(res == -1) + if (res == -1) return -errno; buf[res] = '\0'; @@ -69,10 +69,10 @@ static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, (void) fi; dp = opendir(path); - if(dp == NULL) + if (dp == NULL) return -errno; - while((de = readdir(dp)) != NULL) { + while ((de = readdir(dp)) != NULL) { struct stat st; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; @@ -89,8 +89,17 @@ static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { int res; - res = mknod(path, mode, rdev); - if(res == -1) + /* 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; @@ -101,7 +110,7 @@ static int xmp_mkdir(const char *path, mode_t mode) int res; res = mkdir(path, mode); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -112,7 +121,7 @@ static int xmp_unlink(const char *path) int res; res = unlink(path); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -123,7 +132,7 @@ static int xmp_rmdir(const char *path) int res; res = rmdir(path); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -134,7 +143,7 @@ static int xmp_symlink(const char *from, const char *to) int res; res = symlink(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -145,7 +154,7 @@ static int xmp_rename(const char *from, const char *to) int res; res = rename(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -156,7 +165,7 @@ static int xmp_link(const char *from, const char *to) int res; res = link(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -167,7 +176,7 @@ static int xmp_chmod(const char *path, mode_t mode) int res; res = chmod(path, mode); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -178,7 +187,7 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid) int res; res = lchown(path, uid, gid); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -189,7 +198,7 @@ static int xmp_truncate(const char *path, off_t size) int res; res = truncate(path, size); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -200,7 +209,7 @@ static int xmp_utime(const char *path, struct utimbuf *buf) int res; res = utime(path, buf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -212,7 +221,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) int res; res = open(path, fi->flags); - if(res == -1) + if (res == -1) return -errno; close(res); @@ -227,11 +236,11 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset, (void) fi; fd = open(path, O_RDONLY); - if(fd == -1) + if (fd == -1) return -errno; res = pread(fd, buf, size, offset); - if(res == -1) + if (res == -1) res = -errno; close(fd); @@ -246,11 +255,11 @@ static int xmp_write(const char *path, const char *buf, size_t size, (void) fi; fd = open(path, O_WRONLY); - if(fd == -1) + if (fd == -1) return -errno; res = pwrite(fd, buf, size, offset); - if(res == -1) + if (res == -1) res = -errno; close(fd); @@ -262,7 +271,7 @@ static int xmp_statfs(const char *path, struct statvfs *stbuf) int res; res = statvfs(path, stbuf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -296,7 +305,7 @@ 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) + if (res == -1) return -errno; return 0; } @@ -305,7 +314,7 @@ 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) + if (res == -1) return -errno; return res; } @@ -313,7 +322,7 @@ static int xmp_getxattr(const char *path, const char *name, char *value, static int xmp_listxattr(const char *path, char *list, size_t size) { int res = llistxattr(path, list, size); - if(res == -1) + if (res == -1) return -errno; return res; } @@ -321,7 +330,7 @@ static int xmp_listxattr(const char *path, char *list, size_t size) static int xmp_removexattr(const char *path, const char *name) { int res = lremovexattr(path, name); - if(res == -1) + if (res == -1) return -errno; return 0; } diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c index 491e691..787f87c 100644 --- a/example/fusexmp_fh.c +++ b/example/fusexmp_fh.c @@ -26,7 +26,7 @@ static int xmp_getattr(const char *path, struct stat *stbuf) int res; res = lstat(path, stbuf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -40,7 +40,7 @@ static int xmp_fgetattr(const char *path, struct stat *stbuf, (void) path; res = fstat(fi->fh, stbuf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -51,7 +51,7 @@ static int xmp_access(const char *path, int mask) int res; res = access(path, mask); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -62,7 +62,7 @@ static int xmp_readlink(const char *path, char *buf, size_t size) int res; res = readlink(path, buf, size - 1); - if(res == -1) + if (res == -1) return -errno; buf[res] = '\0'; @@ -97,7 +97,7 @@ static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, 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)) + if (filler(buf, de->d_name, &st, telldir(dp))) break; } @@ -116,8 +116,11 @@ static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { int res; - res = mknod(path, mode, rdev); - if(res == -1) + if (S_ISFIFO(mode)) + res = mkfifo(path, mode); + else + res = mknod(path, mode, rdev); + if (res == -1) return -errno; return 0; @@ -128,7 +131,7 @@ static int xmp_mkdir(const char *path, mode_t mode) int res; res = mkdir(path, mode); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -139,7 +142,7 @@ static int xmp_unlink(const char *path) int res; res = unlink(path); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -150,7 +153,7 @@ static int xmp_rmdir(const char *path) int res; res = rmdir(path); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -161,7 +164,7 @@ static int xmp_symlink(const char *from, const char *to) int res; res = symlink(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -172,7 +175,7 @@ static int xmp_rename(const char *from, const char *to) int res; res = rename(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -183,7 +186,7 @@ static int xmp_link(const char *from, const char *to) int res; res = link(from, to); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -194,7 +197,7 @@ static int xmp_chmod(const char *path, mode_t mode) int res; res = chmod(path, mode); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -205,7 +208,7 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid) int res; res = lchown(path, uid, gid); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -216,7 +219,7 @@ static int xmp_truncate(const char *path, off_t size) int res; res = truncate(path, size); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -230,7 +233,7 @@ static int xmp_ftruncate(const char *path, off_t size, (void) path; res = ftruncate(fi->fh, size); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -241,7 +244,7 @@ static int xmp_utime(const char *path, struct utimbuf *buf) int res; res = utime(path, buf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -252,7 +255,7 @@ static int xmp_create(const char *path, mode_t mode, struct fuse_file_info *fi) int fd; fd = open(path, fi->flags, mode); - if(fd == -1) + if (fd == -1) return -errno; fi->fh = fd; @@ -264,7 +267,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) int fd; fd = open(path, fi->flags); - if(fd == -1) + if (fd == -1) return -errno; fi->fh = fd; @@ -278,7 +281,7 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset, (void) path; res = pread(fi->fh, buf, size, offset); - if(res == -1) + if (res == -1) res = -errno; return res; @@ -291,7 +294,7 @@ static int xmp_write(const char *path, const char *buf, size_t size, (void) path; res = pwrite(fi->fh, buf, size, offset); - if(res == -1) + if (res == -1) res = -errno; return res; @@ -302,7 +305,7 @@ static int xmp_statfs(const char *path, struct statvfs *stbuf) int res; res = statvfs(path, stbuf); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -322,11 +325,15 @@ static int xmp_fsync(const char *path, int isdatasync, int res; (void) path; +#ifndef HAVE_FDATASYNC + (void) isdatasync; +#else if (isdatasync) res = fdatasync(fi->fh); else +#endif res = fsync(fi->fh); - if(res == -1) + if (res == -1) return -errno; return 0; @@ -338,7 +345,7 @@ 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) + if (res == -1) return -errno; return 0; } @@ -347,7 +354,7 @@ 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) + if (res == -1) return -errno; return res; } @@ -355,7 +362,7 @@ static int xmp_getxattr(const char *path, const char *name, char *value, static int xmp_listxattr(const char *path, char *list, size_t size) { int res = llistxattr(path, list, size); - if(res == -1) + if (res == -1) return -errno; return res; } @@ -363,7 +370,7 @@ static int xmp_listxattr(const char *path, char *list, size_t size) static int xmp_removexattr(const char *path, const char *name) { int res = lremovexattr(path, name); - if(res == -1) + if (res == -1) return -errno; return 0; } |