diff options
| author | Raghavendra G <raghavendra@zresearch.com> | 2009-06-10 07:01:16 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-30 14:36:25 -0700 | 
| commit | 56ac05f7e74ed9dc1ce6748687109cc8723fe113 (patch) | |
| tree | 984bebb065c0263e9099e1a0f37dff5586116cb4 /libglusterfsclient | |
| parent | 344319ab62daccac38592df30417d706836afb74 (diff) | |
libglusterfsclient: implement glusterfs_readdir_r
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfsclient')
| -rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 55 | ||||
| -rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.h | 17 | 
2 files changed, 72 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 36189aaa1b9..49cb7b3c06f 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.  | 
