| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/dir_node.h" | 5 #include "nacl_io/dir_node.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "nacl_io/log.h" |
| 10 #include "nacl_io/osdirent.h" | 11 #include "nacl_io/osdirent.h" |
| 11 #include "nacl_io/osstat.h" | 12 #include "nacl_io/osstat.h" |
| 12 #include "sdk_util/auto_lock.h" | 13 #include "sdk_util/auto_lock.h" |
| 13 #include "sdk_util/macros.h" | 14 #include "sdk_util/macros.h" |
| 14 | 15 |
| 15 namespace nacl_io { | 16 namespace nacl_io { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // TODO(binji): For now, just use a dummy value for the parent ino. | 20 // TODO(binji): For now, just use a dummy value for the parent ino. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 for (NodeMap_t::iterator it = map_.begin(); it != map_.end(); ++it) { | 34 for (NodeMap_t::iterator it = map_.begin(); it != map_.end(); ++it) { |
| 34 it->second->Unlink(); | 35 it->second->Unlink(); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 Error DirNode::Read(const HandleAttr& attr, | 39 Error DirNode::Read(const HandleAttr& attr, |
| 39 void* buf, | 40 void* buf, |
| 40 size_t count, | 41 size_t count, |
| 41 int* out_bytes) { | 42 int* out_bytes) { |
| 42 *out_bytes = 0; | 43 *out_bytes = 0; |
| 44 LOG_TRACE("Can't read a directory."); |
| 43 return EISDIR; | 45 return EISDIR; |
| 44 } | 46 } |
| 45 | 47 |
| 46 Error DirNode::FTruncate(off_t size) { | 48 Error DirNode::FTruncate(off_t size) { |
| 49 LOG_TRACE("Can't truncate a directory."); |
| 47 return EISDIR; | 50 return EISDIR; |
| 48 } | 51 } |
| 49 | 52 |
| 50 Error DirNode::Write(const HandleAttr& attr, | 53 Error DirNode::Write(const HandleAttr& attr, |
| 51 const void* buf, | 54 const void* buf, |
| 52 size_t count, | 55 size_t count, |
| 53 int* out_bytes) { | 56 int* out_bytes) { |
| 54 *out_bytes = 0; | 57 *out_bytes = 0; |
| 58 LOG_TRACE("Can't write to a directory."); |
| 55 return EISDIR; | 59 return EISDIR; |
| 56 } | 60 } |
| 57 | 61 |
| 58 Error DirNode::GetDents(size_t offs, | 62 Error DirNode::GetDents(size_t offs, |
| 59 dirent* pdir, | 63 dirent* pdir, |
| 60 size_t size, | 64 size_t size, |
| 61 int* out_bytes) { | 65 int* out_bytes) { |
| 62 AUTO_LOCK(node_lock_); | 66 AUTO_LOCK(node_lock_); |
| 63 BuildCache_Locked(); | 67 BuildCache_Locked(); |
| 64 return cache_.GetDents(offs, pdir, size, out_bytes); | 68 return cache_.GetDents(offs, pdir, size, out_bytes); |
| 65 } | 69 } |
| 66 | 70 |
| 67 Error DirNode::AddChild(const std::string& name, const ScopedNode& node) { | 71 Error DirNode::AddChild(const std::string& name, const ScopedNode& node) { |
| 68 AUTO_LOCK(node_lock_); | 72 AUTO_LOCK(node_lock_); |
| 69 | 73 |
| 70 if (name.empty()) | 74 if (name.empty()) { |
| 75 LOG_ERROR("Can't add child with no name."); |
| 71 return ENOENT; | 76 return ENOENT; |
| 77 } |
| 72 | 78 |
| 73 if (name.length() >= MEMBER_SIZE(dirent, d_name)) | 79 if (name.length() >= MEMBER_SIZE(dirent, d_name)) { |
| 80 LOG_ERROR("Child name is too long: %d >= %d", |
| 81 name.length(), |
| 82 MEMBER_SIZE(dirent, d_name)); |
| 74 return ENAMETOOLONG; | 83 return ENAMETOOLONG; |
| 84 } |
| 75 | 85 |
| 76 NodeMap_t::iterator it = map_.find(name); | 86 NodeMap_t::iterator it = map_.find(name); |
| 77 if (it != map_.end()) | 87 if (it != map_.end()) { |
| 88 LOG_TRACE("Can't add child \"%s\", it already exists.", name); |
| 78 return EEXIST; | 89 return EEXIST; |
| 90 } |
| 79 | 91 |
| 80 node->Link(); | 92 node->Link(); |
| 81 map_[name] = node; | 93 map_[name] = node; |
| 82 ClearCache_Locked(); | 94 ClearCache_Locked(); |
| 83 return 0; | 95 return 0; |
| 84 } | 96 } |
| 85 | 97 |
| 86 Error DirNode::RemoveChild(const std::string& name) { | 98 Error DirNode::RemoveChild(const std::string& name) { |
| 87 AUTO_LOCK(node_lock_); | 99 AUTO_LOCK(node_lock_); |
| 88 NodeMap_t::iterator it = map_.find(name); | 100 NodeMap_t::iterator it = map_.find(name); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 137 |
| 126 cache_built_ = true; | 138 cache_built_ = true; |
| 127 } | 139 } |
| 128 | 140 |
| 129 void DirNode::ClearCache_Locked() { | 141 void DirNode::ClearCache_Locked() { |
| 130 cache_built_ = false; | 142 cache_built_ = false; |
| 131 cache_.Reset(); | 143 cache_.Reset(); |
| 132 } | 144 } |
| 133 | 145 |
| 134 } // namespace nacl_io | 146 } // namespace nacl_io |
| OLD | NEW |