From 7d81a11e661654394e116af52f0cab3d400ee2cf Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Sat, 21 Jan 2012 20:05:55 +0530 Subject: extras/test: add a test file to test 'f-fops'. mainly to test f*xattr(), fchown()/fchmod()/ftruncate() on fuse mounts. Change-Id: I59edbe172f307a2ba94f11c650ac0176fd35564f Signed-off-by: Amar Tumballi BUG: 766571 Reviewed-on: http://review.gluster.com/2692 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Vijay Bellur --- extras/test/test-ffop.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 extras/test/test-ffop.c (limited to 'extras/test/test-ffop.c') diff --git a/extras/test/test-ffop.c b/extras/test/test-ffop.c new file mode 100644 index 00000000000..2c47ab0045b --- /dev/null +++ b/extras/test/test-ffop.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + int ret = -1; + int fd = 0; + char *filename = NULL; + struct stat stbuf = {0,}; + + if (argc > 1) + filename = argv[1]; + + if (!filename) + filename = "temp-xattr-test-file"; + + fd = open (filename, O_RDWR|O_CREAT); + if (fd < 0) { + fd = 0; + fprintf (stderr, "open failed : %s\n", strerror (errno)); + goto out; + } + + ret = unlink (filename); + if (ret < 0) { + fprintf (stderr, "unlink failed : %s\n", strerror (errno)); + goto out; + } + + ret = ftruncate (fd, 0); + if (ret < 0) { + fprintf (stderr, "ftruncate failed : %s\n", strerror (errno)); + goto out; + } + + ret = fstat (fd, &stbuf); + if (ret < 0) { + fprintf (stderr, "fstat failed : %s\n", strerror (errno)); + goto out; + } + + ret = fchmod (fd, 0640); + if (ret < 0) { + fprintf (stderr, "fchmod failed : %s\n", strerror (errno)); + goto out; + } + + ret = fchown (fd, 10001, 10001); + if (ret < 0) { + fprintf (stderr, "fchown failed : %s\n", strerror (errno)); + goto out; + } + + ret = fsync (fd); + if (ret < 0) { + fprintf (stderr, "fsync failed : %s\n", strerror (errno)); + goto out; + } + + ret = fsetxattr (fd, "trusted.xattr-test", "working", 8, 0); + if (ret < 0) { + fprintf (stderr, "fsetxattr failed : %s\n", strerror (errno)); + goto out; + } + + ret = fdatasync (fd); + if (ret < 0) { + fprintf (stderr, "fdatasync failed : %s\n", strerror (errno)); + goto out; + } + + ret = flistxattr (fd, NULL, 0); + if (ret <= 0) { + ret = -1; + fprintf (stderr, "flistxattr failed : %s\n", strerror (errno)); + goto out; + } + + ret = fgetxattr (fd, "trusted.xattr-test", NULL, 0); + if (ret <= 0) { + ret = -1; + fprintf (stderr, "fgetxattr failed : %s\n", strerror (errno)); + goto out; + } + + ret = fremovexattr (fd, "trusted.xattr-test"); + if (ret < 0) { + fprintf (stderr, "fremovexattr failed : %s\n", strerror (errno)); + goto out; + } + + ret = 0; +out: + if (fd) + close (fd); + + return ret; +} -- cgit