summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-04-16 23:54:42 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-04-17 13:43:22 +0530
commiteb4d5f0074ab6430973188906a8083d26e24e790 (patch)
treea674cd615d02ec04f876b8bd7b6234768ee73397 /libglusterfsclient
parentf6ebe58492095a5d7ceb5762cb35defca945ab45 (diff)
libglusterfsclient: Add opendir API
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 68a5a7efddf..de9eed55f7f 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -3535,6 +3535,64 @@ out:
return op_ret;
}
+glusterfs_dir_t
+glusterfs_opendir (glusterfs_handle_t handle, const char *path)
+{
+ int op_ret = -1;
+ libglusterfs_client_ctx_t *ctx = handle;
+ loc_t loc = {0, };
+ fd_t *dirfd = NULL;
+ char *name = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, ctx, out);
+ GF_VALIDATE_ABSOLUTE_PATH_OR_GOTO (LIBGF_XL_NAME, path, out);
+
+ loc.path = strdup (path);
+ op_ret = libgf_client_path_lookup (&loc, ctx, 1);
+
+ if (op_ret == -1)
+ goto out;
+
+ name = strdup (path);
+ op_ret = libgf_client_loc_fill (&loc, ctx, 0, loc.parent->ino,
+ basename (name));
+ if (op_ret == -1) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ if (!S_ISDIR (loc.inode->st_mode)) {
+ errno = ENOTDIR;
+ op_ret = -1;
+ goto out;
+ }
+
+ dirfd = fd_create (loc.inode, 0);
+ op_ret = libgf_client_opendir (ctx, &loc, dirfd);
+
+ if (op_ret == -1) {
+ fd_unref (dirfd);
+ dirfd = NULL;
+ goto out;
+ }
+
+ if (libgf_get_fd_ctx (dirfd))
+ goto out;
+
+ if (!(libgf_alloc_fd_ctx (ctx, dirfd))) {
+ op_ret = -1;
+ errno = EINVAL;
+ fd_unref (dirfd);
+ dirfd = NULL;
+ }
+
+out:
+ if (name)
+ FREE (name);
+ libgf_client_loc_wipe (&loc);
+ return dirfd;
+}
+
static struct xlator_fops libgf_client_fops = {
};