Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/dir_node.cc

Issue 349703003: [NaCl SDK] Add some more logging to nacl_io. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux host build Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "nacl_io/osinttypes.h"
11 #include "nacl_io/osstat.h" 13 #include "nacl_io/osstat.h"
12 #include "sdk_util/auto_lock.h" 14 #include "sdk_util/auto_lock.h"
13 #include "sdk_util/macros.h" 15 #include "sdk_util/macros.h"
14 16
15 namespace nacl_io { 17 namespace nacl_io {
16 18
17 namespace { 19 namespace {
18 20
19 // TODO(binji): For now, just use a dummy value for the parent ino. 21 // TODO(binji): For now, just use a dummy value for the parent ino.
20 const ino_t kParentDirIno = -1; 22 const ino_t kParentDirIno = -1;
(...skipping 12 matching lines...) Expand all
33 for (NodeMap_t::iterator it = map_.begin(); it != map_.end(); ++it) { 35 for (NodeMap_t::iterator it = map_.begin(); it != map_.end(); ++it) {
34 it->second->Unlink(); 36 it->second->Unlink();
35 } 37 }
36 } 38 }
37 39
38 Error DirNode::Read(const HandleAttr& attr, 40 Error DirNode::Read(const HandleAttr& attr,
39 void* buf, 41 void* buf,
40 size_t count, 42 size_t count,
41 int* out_bytes) { 43 int* out_bytes) {
42 *out_bytes = 0; 44 *out_bytes = 0;
45 LOG_TRACE("Can't read a directory.");
43 return EISDIR; 46 return EISDIR;
44 } 47 }
45 48
46 Error DirNode::FTruncate(off_t size) { 49 Error DirNode::FTruncate(off_t size) {
50 LOG_TRACE("Can't truncate a directory.");
47 return EISDIR; 51 return EISDIR;
48 } 52 }
49 53
50 Error DirNode::Write(const HandleAttr& attr, 54 Error DirNode::Write(const HandleAttr& attr,
51 const void* buf, 55 const void* buf,
52 size_t count, 56 size_t count,
53 int* out_bytes) { 57 int* out_bytes) {
54 *out_bytes = 0; 58 *out_bytes = 0;
59 LOG_TRACE("Can't write to a directory.");
55 return EISDIR; 60 return EISDIR;
56 } 61 }
57 62
58 Error DirNode::GetDents(size_t offs, 63 Error DirNode::GetDents(size_t offs,
59 dirent* pdir, 64 dirent* pdir,
60 size_t size, 65 size_t size,
61 int* out_bytes) { 66 int* out_bytes) {
62 AUTO_LOCK(node_lock_); 67 AUTO_LOCK(node_lock_);
63 BuildCache_Locked(); 68 BuildCache_Locked();
64 return cache_.GetDents(offs, pdir, size, out_bytes); 69 return cache_.GetDents(offs, pdir, size, out_bytes);
65 } 70 }
66 71
67 Error DirNode::AddChild(const std::string& name, const ScopedNode& node) { 72 Error DirNode::AddChild(const std::string& name, const ScopedNode& node) {
68 AUTO_LOCK(node_lock_); 73 AUTO_LOCK(node_lock_);
69 74
70 if (name.empty()) 75 if (name.empty()) {
76 LOG_ERROR("Can't add child with no name.");
71 return ENOENT; 77 return ENOENT;
78 }
72 79
73 if (name.length() >= MEMBER_SIZE(dirent, d_name)) 80 if (name.length() >= MEMBER_SIZE(dirent, d_name)) {
81 LOG_ERROR("Child name is too long: %" PRIuS " >= %" PRIuS,
82 name.length(),
83 MEMBER_SIZE(dirent, d_name));
74 return ENAMETOOLONG; 84 return ENAMETOOLONG;
85 }
75 86
76 NodeMap_t::iterator it = map_.find(name); 87 NodeMap_t::iterator it = map_.find(name);
77 if (it != map_.end()) 88 if (it != map_.end()) {
89 LOG_TRACE("Can't add child \"%s\", it already exists.", name);
78 return EEXIST; 90 return EEXIST;
91 }
79 92
80 node->Link(); 93 node->Link();
81 map_[name] = node; 94 map_[name] = node;
82 ClearCache_Locked(); 95 ClearCache_Locked();
83 return 0; 96 return 0;
84 } 97 }
85 98
86 Error DirNode::RemoveChild(const std::string& name) { 99 Error DirNode::RemoveChild(const std::string& name) {
87 AUTO_LOCK(node_lock_); 100 AUTO_LOCK(node_lock_);
88 NodeMap_t::iterator it = map_.find(name); 101 NodeMap_t::iterator it = map_.find(name);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 138
126 cache_built_ = true; 139 cache_built_ = true;
127 } 140 }
128 141
129 void DirNode::ClearCache_Locked() { 142 void DirNode::ClearCache_Locked() {
130 cache_built_ = false; 143 cache_built_ = false;
131 cache_.Reset(); 144 cache_.Reset();
132 } 145 }
133 146
134 } // namespace nacl_io 147 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/devfs/tty_node.cc ('k') | native_client_sdk/src/libraries/nacl_io/filesystem.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698