| Index: native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
|
| diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
|
| index 7a33bfd684febb748d55304436c235fb1623a230..e8b4baf565728a7c7c89b138fd2eb0276c23a9de 100644
|
| --- a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
|
| +++ b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
|
| @@ -12,75 +12,74 @@
|
| #include "utils/macros.h"
|
| #include "utils/auto_lock.h"
|
|
|
| -MountNodeDir::MountNodeDir(Mount* mount)
|
| - : MountNode(mount),
|
| - cache_(NULL) {
|
| +MountNodeDir::MountNodeDir(Mount* mount) : MountNode(mount), cache_(NULL) {
|
| stat_.st_mode |= S_IFDIR;
|
| }
|
|
|
| -MountNodeDir::~MountNodeDir() {
|
| - free(cache_);
|
| -}
|
| +MountNodeDir::~MountNodeDir() { free(cache_); }
|
|
|
| -int MountNodeDir::Read(size_t offs, void *buf, size_t count) {
|
| - errno = EISDIR;
|
| - return -1;
|
| +Error MountNodeDir::Read(size_t offs, void* buf, size_t count, int* out_bytes) {
|
| + *out_bytes = 0;
|
| + return EISDIR;
|
| }
|
|
|
| -int MountNodeDir::FTruncate(off_t size) {
|
| - errno = EISDIR;
|
| - return -1;
|
| -}
|
| +Error MountNodeDir::FTruncate(off_t size) { return EISDIR; }
|
|
|
| -int MountNodeDir::Write(size_t offs, void *buf, size_t count) {
|
| - errno = EISDIR;
|
| - return -1;
|
| +Error MountNodeDir::Write(size_t offs,
|
| + void* buf,
|
| + size_t count,
|
| + int* out_bytes) {
|
| + *out_bytes = 0;
|
| + return EISDIR;
|
| }
|
|
|
| -int MountNodeDir::GetDents(size_t offs, struct dirent* pdir, size_t size) {
|
| +Error MountNodeDir::GetDents(size_t offs,
|
| + struct dirent* pdir,
|
| + size_t size,
|
| + int* out_bytes) {
|
| + *out_bytes = 0;
|
| +
|
| AutoLock lock(&lock_);
|
|
|
| // If the buffer pointer is invalid, fail
|
| - if (NULL == pdir) {
|
| - errno = EINVAL;
|
| - return -1;
|
| - }
|
| + if (NULL == pdir)
|
| + return EINVAL;
|
|
|
| // If the buffer is too small, fail
|
| - if (size < sizeof(struct dirent)) {
|
| - errno = EINVAL;
|
| - return -1;
|
| - }
|
| + if (size < sizeof(struct dirent))
|
| + return EINVAL;
|
|
|
| // Force size to a multiple of dirent
|
| size -= size % sizeof(struct dirent);
|
| size_t max = map_.size() * sizeof(struct dirent);
|
| - if (cache_ == NULL) BuildCache();
|
| + if (cache_ == NULL)
|
| + BuildCache();
|
|
|
| - if (offs >= max) return 0;
|
| - if (offs + size >= max) size = max - offs;
|
| + if (offs >= max) {
|
| + // OK, trying to read past the end.
|
| + return 0;
|
| + }
|
|
|
| - memcpy(pdir, ((char *) cache_) + offs, size);
|
| - return size;
|
| + if (offs + size >= max)
|
| + size = max - offs;
|
| +
|
| + memcpy(pdir, ((char*)cache_) + offs, size);
|
| + *out_bytes = size;
|
| + return 0;
|
| }
|
|
|
| -int MountNodeDir::AddChild(const std::string& name, MountNode* node) {
|
| +Error MountNodeDir::AddChild(const std::string& name, MountNode* node) {
|
| AutoLock lock(&lock_);
|
|
|
| - if (name.empty()) {
|
| - errno = ENOENT;
|
| - return -1;
|
| - }
|
| - if (name.length() >= MEMBER_SIZE(struct dirent, d_name)) {
|
| - errno = ENAMETOOLONG;
|
| - return -1;
|
| - }
|
| + if (name.empty())
|
| + return ENOENT;
|
| +
|
| + if (name.length() >= MEMBER_SIZE(struct dirent, d_name))
|
| + return ENAMETOOLONG;
|
|
|
| MountNodeMap_t::iterator it = map_.find(name);
|
| - if (it != map_.end()) {
|
| - errno = EEXIST;
|
| - return -1;
|
| - }
|
| + if (it != map_.end())
|
| + return EEXIST;
|
|
|
| node->Link();
|
| map_[name] = node;
|
| @@ -88,7 +87,7 @@ int MountNodeDir::AddChild(const std::string& name, MountNode* node) {
|
| return 0;
|
| }
|
|
|
| -int MountNodeDir::RemoveChild(const std::string& name) {
|
| +Error MountNodeDir::RemoveChild(const std::string& name) {
|
| AutoLock lock(&lock_);
|
| MountNodeMap_t::iterator it = map_.find(name);
|
| if (it != map_.end()) {
|
| @@ -97,18 +96,19 @@ int MountNodeDir::RemoveChild(const std::string& name) {
|
| ClearCache();
|
| return 0;
|
| }
|
| - errno = ENOENT;
|
| - return -1;
|
| + return ENOENT;
|
| }
|
|
|
| -MountNode* MountNodeDir::FindChild(const std::string& name) {
|
| +Error MountNodeDir::FindChild(const std::string& name, MountNode** out_node) {
|
| + *out_node = NULL;
|
| +
|
| AutoLock lock(&lock_);
|
| MountNodeMap_t::iterator it = map_.find(name);
|
| - if (it != map_.end()) {
|
| - return it->second;
|
| - }
|
| - errno = ENOENT;
|
| - return NULL;
|
| + if (it == map_.end())
|
| + return ENOENT;
|
| +
|
| + *out_node = it->second;
|
| + return 0;
|
| }
|
|
|
| int MountNodeDir::ChildCount() {
|
| @@ -123,7 +123,7 @@ void MountNodeDir::ClearCache() {
|
|
|
| void MountNodeDir::BuildCache() {
|
| if (map_.size()) {
|
| - cache_ = (struct dirent *) malloc(sizeof(struct dirent) * map_.size());
|
| + cache_ = (struct dirent*)malloc(sizeof(struct dirent) * map_.size());
|
| MountNodeMap_t::iterator it = map_.begin();
|
| for (size_t index = 0; it != map_.end(); it++, index++) {
|
| MountNode* node = it->second;
|
|
|