summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@zresearch.com>2009-06-10 07:01:16 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-11 07:29:00 -0700
commit75f555fd89d2bf3dbd5aceeb112b748f4a8966e3 (patch)
tree03cdcaff42c372436079ede6f0beaa1559e66bc6 /libglusterfsclient/src
parentac53b60bc29831cecfa7d5919278afc6c7053392 (diff)
libglusterfsclient: implement glusterfs_readdir_r
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfsclient/src')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c55
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.h17
2 files changed, 72 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 0e7f81b5360..11ee08d038c 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -3598,6 +3598,61 @@ libgf_client_readdir (libglusterfs_client_ctx_t *ctx, fd_t *fd,
return op_ret;
}
+
+int
+glusterfs_readdir_r (glusterfs_dir_t dirfd, struct dirent *entry,
+ struct dirent **result)
+{
+ int op_ret = -1;
+ libglusterfs_client_ctx_t *ctx = NULL;
+ off_t offset = 0;
+ libglusterfs_client_fd_ctx_t *fd_ctx = NULL;
+ struct dirent *dirp = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, entry, out);
+
+ fd_ctx = libgf_get_fd_ctx (dirfd);
+ if (!fd_ctx) {
+ errno = EBADF;
+ goto out;
+ }
+
+ pthread_mutex_lock (&fd_ctx->lock);
+ {
+ ctx = fd_ctx->ctx;
+ offset = fd_ctx->offset;
+ dirp = &fd_ctx->dirp;
+
+ memset (dirp, 0, sizeof (struct dirent));
+ op_ret = libgf_client_readdir (ctx, (fd_t *)dirfd, dirp,
+ &offset);
+ if (op_ret <= 0) {
+ if (result && (op_ret == 0)) {
+ *result = NULL;
+ } else if (op_ret < 0){
+ op_ret = errno;
+ }
+ goto unlock;
+ }
+
+ fd_ctx->offset = offset;
+
+ if (result) {
+ *result = memcpy (entry, dirp, sizeof (*entry));
+ } else {
+ memcpy (entry, dirp, sizeof (*entry));
+ }
+
+ op_ret = 0;
+ }
+unlock:
+ pthread_mutex_unlock (&fd_ctx->lock);
+
+out:
+ return op_ret;
+}
+
+
struct dirent *
glusterfs_readdir (glusterfs_dir_t dirfd)
{
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index e8b19f4bc51..7ce7288f897 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -635,6 +635,23 @@ glusterfs_readdir (glusterfs_dir_t dirfd);
+/* re-entrant version of glusterfs_readdir.
+ *
+ * @dirfd : The handle of directory to be read. This handle is the one
+ * returned by opendir.
+ * @entry : Pointer to storage to store a directory entry. The storage
+ * pointed to by entry shall be large enough for a dirent with
+ * an array of char d_name members containing at least
+ * {NAME_MAX}+1 elements.
+ * @result : Upon successful return, the pointer returned at *result shall
+ * have the same value as the argument entry. Upon reaching the
+ * end of the directory stream, this pointer shall have the
+ * value NULL.
+ */
+int
+glusterfs_readdir_r (glusterfs_dir_t dirfd, struct dirent *entry,
+ struct dirent **result);
+
/* Close a directory handle.
*
* @fd : The directory handle to be closed.