From 7b5cc9f652571004b6e9fff497192c0133d58037 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Mon, 27 Jan 2025 12:07:58 +0100 Subject: [PATCH] libcephfs_proxy: implement ceph_readdir_r() Signed-off-by: Xavi Hernandez --- src/libcephfs_proxy/libcephfs_proxy.c | 36 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/libcephfs_proxy/libcephfs_proxy.c b/src/libcephfs_proxy/libcephfs_proxy.c index 149fae123f7..eca7e7bbbcb 100644 --- a/src/libcephfs_proxy/libcephfs_proxy.c +++ b/src/libcephfs_proxy/libcephfs_proxy.c @@ -735,24 +735,48 @@ __public int ceph_mount(struct ceph_mount_info *cmount, const char *root) return CEPH_PROCESS(cmount, LIBCEPHFSD_OP_MOUNT, req, ans); } -__public struct dirent *ceph_readdir(struct ceph_mount_info *cmount, - struct ceph_dir_result *dirp) +/* The return value of this function has the same meaning as the original + * ceph_readdir_r(): + * + * Returned values: + * + * 1 if we got a dirent + * 0 for end of directory + * <0 for error + */ +__public int ceph_readdir_r(struct ceph_mount_info *cmount, + struct ceph_dir_result *dirp, struct dirent *de) { - static struct dirent de; int32_t err; CEPH_REQ(ceph_readdir, req, 0, ans, 1); req.dir = ptr_value(dirp); - CEPH_BUFF_ADD(ans, &de, sizeof(de)); + CEPH_BUFF_ADD(ans, de, sizeof(struct dirent)); err = CEPH_PROCESS(cmount, LIBCEPHFSD_OP_READDIR, req, ans); if (err < 0) { - errno = -err; - return NULL; + return err; } if (ans.eod) { + return 0; + } + + return 1; +} + +__public struct dirent *ceph_readdir(struct ceph_mount_info *cmount, + struct ceph_dir_result *dirp) +{ + static struct dirent de; + int res; + + res = ceph_readdir_r(cmount, dirp, &de); + if (res <= 0) { + if (res < 0) { + errno = -res; + } return NULL; } -- 2.39.5