gr.pos = 0;
int r = readdir_r_cb(dir, _readdir_getdent_cb, (void *)&gr);
- if (r < 0)
- return r;
-
- if (gr.pos == 0)
- return -ERANGE;
+ if (r < 0) { // some error
+ if (r == -1) { // buffer ran out of space
+ if (gr.pos) { // but we got some entries already!
+ return gr.pos;
+ } // or we need a larger buffer
+ return -ERANGE;
+ } else { // actual error, return it
+ return r;
+ }
+ }
return gr.pos;
}
int getdir(const char *relpath, list<string>& names); // get the whole dir at once.
+ /**
+ * Returns the length of the buffer that got filled in, or -errno.
+ * If it returns -ERANGE you just need to increase the size of the
+ * buffer and try again.
+ */
int _getdents(dir_result_t *dirp, char *buf, int buflen, bool ful); // get a bunch of dentries at once
int getdents(dir_result_t *dirp, char *buf, int buflen) {
return _getdents(dirp, buf, buflen, true);
int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
struct stat *st, int *stmask);
int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
+/**
+ * This returns the used buffer space on success, -ERANGE if the buffer
+ * is not large enough to hold a name, or -errno on other issues.
+ */
int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
loff_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);