mirror of
https://github.com/ceph/ceph
synced 2025-02-19 00:47:49 +00:00
uclient: let's do getdents() too, while we're at it
This commit is contained in:
parent
3ccb16483a
commit
2279e43546
@ -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++;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user