summaryrefslogtreecommitdiffstats
path: root/api/examples
diff options
context:
space:
mode:
authorAnand Avati <avati@redhat.com>2013-04-14 02:58:34 -0700
committerVijay Bellur <vbellur@redhat.com>2013-04-19 04:41:35 -0700
commita1db18cf7a6cde96f2e5b920ffbbf88e72a21fd4 (patch)
tree0c0ee87231c345b7619bf97c1bdc13eaafa6b83a /api/examples
parent1fc9b98a4eb6eda8db30940a8bb07d206e2fa049 (diff)
gfapi: support for chdir() and family
Add support for chdir, fchdir, getcwd, realpath equivalents in GFAPI. These are required for the Samba VFS plugin. Change-Id: I91d2db9146994403c98961c489c7640c51d5add2 BUG: 953694 Signed-off-by: Anand Avati <avati@redhat.com> Reviewed-on: http://review.gluster.org/4853 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'api/examples')
-rw-r--r--api/examples/glfsxmp.c81
1 files changed, 79 insertions, 2 deletions
diff --git a/api/examples/glfsxmp.c b/api/examples/glfsxmp.c
index b359cc7444c..644793a4b1a 100644
--- a/api/examples/glfsxmp.c
+++ b/api/examples/glfsxmp.c
@@ -60,6 +60,81 @@ test_xattr (glfs_t *fs)
int
+test_chdir (glfs_t *fs)
+{
+ int ret = -1;
+ ino_t ino = 0;
+ struct stat st;
+ char *topdir = "/topdir";
+ char *linkdir = "/linkdir";
+ char *subdir = "./subdir";
+ char *respath = NULL;
+ char pathbuf[4096];
+
+ ret = glfs_mkdir (fs, topdir, 0755);
+ if (ret) {
+ fprintf (stderr, "mkdir(%s): %s\n", topdir, strerror (errno));
+ return -1;
+ }
+
+ respath = glfs_getcwd (fs, pathbuf, 4096);
+ fprintf (stdout, "getcwd() = %s\n", respath);
+
+ ret = glfs_symlink (fs, topdir, linkdir);
+ if (ret) {
+ fprintf (stderr, "symlink(%s, %s): %s\n", topdir, linkdir, strerror (errno));
+ return -1;
+ }
+
+ ret = glfs_chdir (fs, linkdir);
+ if (ret) {
+ fprintf (stderr, "chdir(%s): %s\n", linkdir, strerror (errno));
+ return -1;
+ }
+
+ respath = glfs_getcwd (fs, pathbuf, 4096);
+ fprintf (stdout, "getcwd() = %s\n", respath);
+
+ respath = glfs_realpath (fs, subdir, pathbuf);
+ if (respath) {
+ fprintf (stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, respath);
+ return -1;
+ }
+
+ ret = glfs_mkdir (fs, subdir, 0755);
+ if (ret) {
+ fprintf (stderr, "mkdir(%s): %s\n", subdir, strerror (errno));
+ return -1;
+ }
+
+ respath = glfs_realpath (fs, subdir, pathbuf);
+ if (!respath) {
+ fprintf (stderr, "realpath(%s): %s\n", subdir, strerror (errno));
+ } else {
+ fprintf (stdout, "realpath(%s) = %s\n", subdir, respath);
+ }
+
+ ret = glfs_chdir (fs, subdir);
+ if (ret) {
+ fprintf (stderr, "chdir(%s): %s\n", subdir, strerror (errno));
+ return -1;
+ }
+
+ respath = glfs_getcwd (fs, pathbuf, 4096);
+ fprintf (stdout, "getcwd() = %s\n", respath);
+
+ respath = glfs_realpath (fs, "/linkdir/subdir", pathbuf);
+ if (!respath) {
+ fprintf (stderr, "realpath(/linkdir/subdir): %s\n", strerror (errno));
+ } else {
+ fprintf (stdout, "realpath(/linkdir/subdir) = %s\n", respath);
+ }
+
+ return 0;
+}
+
+
+int
main (int argc, char *argv[])
{
glfs_t *fs = NULL;
@@ -73,7 +148,7 @@ main (int argc, char *argv[])
char *filename = "/filename2";
- fs = glfs_new ("iops");
+ fs = glfs_new ("fsync");
if (!fs) {
fprintf (stderr, "glfs_new: returned NULL\n");
return 1;
@@ -93,7 +168,7 @@ main (int argc, char *argv[])
sleep (2);
- fs2 = glfs_new ("iops");
+ fs2 = glfs_new ("fsync");
if (!fs2) {
fprintf (stderr, "glfs_new: returned NULL\n");
return 1;
@@ -161,6 +236,8 @@ main (int argc, char *argv[])
test_xattr (fs);
+ test_chdir (fs);
+
// done
glfs_fini (fs);