]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uclient: let's do getdents() too, while we're at it
authorSage Weil <sage@newdream.net>
Fri, 21 Aug 2009 20:27:31 +0000 (13:27 -0700)
committerSage Weil <sage@newdream.net>
Fri, 21 Aug 2009 20:27:31 +0000 (13:27 -0700)
src/client/Client.cc
src/client/Client.h
src/client/libceph.cc
src/client/libceph.h

index 7fbec190d083273a3ad7b8729505e87f41863215..4083ccb0e9e235ff73efcba9245b991e8bf1954c 100644 (file)
@@ -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++;
index 806497dc69f5602d99c6fa661fee00356e2474db..45ade973a439d2f09158549a5364106fb4dbb58d 100644 (file)
@@ -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);
index e9a07a2ba0cc4791d11d6bdcf5d40aaca8c935ed..5b24249f96a9fc5a5fc2ba384c1f09c47cc39986 100644 (file)
@@ -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);
index 8a749b2e767dd110cbcb0da3d655cd4b83b55f2d..bd010fbdc7ced17cd8937729f1047194ab8cfb30 100644 (file)
@@ -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);