summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-08-21 22:27:31 +0200
committerSage Weil <sage@newdream.net>2009-08-21 22:27:31 +0200
commit2279e4354656f3171632c2a2343392c7118f8ff3 (patch)
tree3ff75e420f169309346f7b19adfb1141cc6bef6d
parentcrush: put temp arrays on the stack (diff)
downloadceph-2279e4354656f3171632c2a2343392c7118f8ff3.tar.xz
ceph-2279e4354656f3171632c2a2343392c7118f8ff3.zip
uclient: let's do getdents() too, while we're at it
-rw-r--r--src/client/Client.cc12
-rw-r--r--src/client/Client.h10
-rw-r--r--src/client/libceph.cc5
-rw-r--r--src/client/libceph.h1
4 files changed, 23 insertions, 5 deletions
diff --git a/src/client/Client.cc b/src/client/Client.cc
index 7fbec190d08..4083ccb0e9e 100644
--- a/src/client/Client.cc
+++ b/src/client/Client.cc
@@ -3644,9 +3644,9 @@ int Client::readdirplus_r(DIR *d, struct dirent *de, struct stat *st, int *stmas
assert(0);
}
-int Client::getdnames(DIR *d, char *buf, int buflen)
+int Client::_getdents(DIR *dir, char *buf, int buflen, bool fullent)
{
- DirResult *dirp = (DirResult*)d;
+ DirResult *dirp = (DirResult *)dir;
int ret = 0;
while (1) {
@@ -3675,13 +3675,17 @@ int Client::getdnames(DIR *d, char *buf, int buflen)
// is there room?
int dlen = ent[pos].d_name.length();
- const char *dname = ent[pos].d_name.c_str();
+ if (fullent)
+ dlen += sizeof(struct dirent);
if (ret + dlen + 1 > buflen) {
if (!ret)
return -ERANGE; // the buffer is too small for the first name!
return ret;
}
- memcpy(buf + ret, dname, dlen + 1);
+ if (fullent)
+ _readdir_fill_dirent((struct dirent *)(buf + ret), &ent[pos], dirp->offset);
+ else
+ memcpy(buf + ret, ent[pos].d_name.c_str(), dlen + 1);
ret += dlen + 1;
pos++;
diff --git a/src/client/Client.h b/src/client/Client.h
index 806497dc69f..45ade973a43 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -1112,7 +1112,15 @@ public:
int closedir(DIR *dirp);
int readdir_r(DIR *dirp, struct dirent *de);
int readdirplus_r(DIR *dirp, struct dirent *de, struct stat *st, int *stmask);
- int getdnames(DIR *dirp, char *buf, int buflen); // get a bunch of dentries at once
+
+ int _getdents(DIR *dirp, char *buf, int buflen, bool ful); // get a bunch of dentries at once
+ int getdents(DIR *dirp, char *buf, int buflen) {
+ return _getdents(dirp, buf, buflen, true);
+ }
+ int getdnames(DIR *dirp, char *buf, int buflen) {
+ return _getdents(dirp, buf, buflen, false);
+ }
+
void rewinddir(DIR *dirp);
loff_t telldir(DIR *dirp);
void seekdir(DIR *dirp, loff_t offset);
diff --git a/src/client/libceph.cc b/src/client/libceph.cc
index e9a07a2ba0c..5b24249f96a 100644
--- a/src/client/libceph.cc
+++ b/src/client/libceph.cc
@@ -117,6 +117,11 @@ extern "C" int ceph_readdirplus_r(DIR *dirp, struct dirent *de, struct stat *st,
return client->readdirplus_r(dirp, de, st, stmask);
}
+extern "C" int ceph_getdents(DIR *dirp, char *buf, int buflen)
+{
+ return client->getdents(dirp, buf, buflen);
+}
+
extern "C" int ceph_getdnames(DIR *dirp, char *buf, int buflen)
{
return client->getdnames(dirp, buf, buflen);
diff --git a/src/client/libceph.h b/src/client/libceph.h
index 8a749b2e767..bd010fbdc7c 100644
--- a/src/client/libceph.h
+++ b/src/client/libceph.h
@@ -31,6 +31,7 @@ int ceph_opendir(const char *name, DIR **dirpp);
int ceph_closedir(DIR *dirp);
int ceph_readdir_r(DIR *dirp, struct dirent *de);
int ceph_readdirplus_r(DIR *dirp, struct dirent *de, struct stat *st, int *stmask);
+int ceph_getdents(DIR *dirp, char *name, int buflen);
int ceph_getdnames(DIR *dirp, char *name, int buflen);
void ceph_rewinddir(DIR *dirp);
loff_t ceph_telldir(DIR *dirp);