]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs_proxy: implement ceph_readdir_r() 61537/head
authorXavi Hernandez <xhernandez@gmail.com>
Mon, 27 Jan 2025 11:07:58 +0000 (12:07 +0100)
committerXavi Hernandez <xhernandez@gmail.com>
Wed, 29 Jan 2025 11:12:48 +0000 (12:12 +0100)
Signed-off-by: Xavi Hernandez <xhernandez@gmail.com>
src/libcephfs_proxy/libcephfs_proxy.c

index 149fae123f76fc239a2421b743d4d4f5a85c6249..eca7e7bbbcbf38913a238407bcb362fc652f32a0 100644 (file)
@@ -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;
        }