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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.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
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/devfs/jspipe_event_emitter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(WIN32) 5 #if defined(WIN32)
6 #define _CRT_RAND_S 6 #define _CRT_RAND_S
7 #endif 7 #endif
8 8
9 #include "nacl_io/devfs/dev_fs.h" 9 #include "nacl_io/devfs/dev_fs.h"
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ConsoleNode::ConsoleNode(Filesystem* filesystem, PP_LogLevel level) 182 ConsoleNode::ConsoleNode(Filesystem* filesystem, PP_LogLevel level)
183 : CharNode(filesystem), level_(level) { 183 : CharNode(filesystem), level_(level) {
184 } 184 }
185 185
186 Error ConsoleNode::Write(const HandleAttr& attr, 186 Error ConsoleNode::Write(const HandleAttr& attr,
187 const void* buf, 187 const void* buf,
188 size_t count, 188 size_t count,
189 int* out_bytes) { 189 int* out_bytes) {
190 *out_bytes = 0; 190 *out_bytes = 0;
191 191
192 ConsoleInterface* con_intr = filesystem_->ppapi()->GetConsoleInterface(); 192 ConsoleInterface* con_iface = filesystem_->ppapi()->GetConsoleInterface();
193 VarInterface* var_intr = filesystem_->ppapi()->GetVarInterface(); 193 VarInterface* var_iface = filesystem_->ppapi()->GetVarInterface();
194 194
195 if (!(var_intr && con_intr)) 195 if (!(var_iface && con_iface)) {
196 LOG_ERROR("Got NULL interface(s): %s%s",
197 con_iface ? "" : "Console ",
198 var_iface ? "" : "Var");
196 return ENOSYS; 199 return ENOSYS;
200 }
197 201
198 const char* var_data = static_cast<const char*>(buf); 202 const char* var_data = static_cast<const char*>(buf);
199 uint32_t len = static_cast<uint32_t>(count); 203 uint32_t len = static_cast<uint32_t>(count);
200 struct PP_Var val = var_intr->VarFromUtf8(var_data, len); 204 struct PP_Var val = var_iface->VarFromUtf8(var_data, len);
201 con_intr->Log(filesystem_->ppapi()->GetInstance(), level_, val); 205 con_iface->Log(filesystem_->ppapi()->GetInstance(), level_, val);
206 var_iface->Release(val);
202 207
203 *out_bytes = count; 208 *out_bytes = count;
204 return 0; 209 return 0;
205 } 210 }
206 211
207 ZeroNode::ZeroNode(Filesystem* filesystem) : Node(filesystem) { 212 ZeroNode::ZeroNode(Filesystem* filesystem) : Node(filesystem) {
208 SetType(S_IFCHR); 213 SetType(S_IFCHR);
209 } 214 }
210 215
211 Error ZeroNode::Read(const HandleAttr& attr, 216 Error ZeroNode::Read(const HandleAttr& attr,
(...skipping 22 matching lines...) Expand all
234 #endif 239 #endif
235 } 240 }
236 241
237 Error UrandomNode::Read(const HandleAttr& attr, 242 Error UrandomNode::Read(const HandleAttr& attr,
238 void* buf, 243 void* buf,
239 size_t count, 244 size_t count,
240 int* out_bytes) { 245 int* out_bytes) {
241 *out_bytes = 0; 246 *out_bytes = 0;
242 247
243 #if defined(__native_client__) 248 #if defined(__native_client__)
244 if (!interface_ok_) 249 if (!interface_ok_) {
250 LOG_ERROR("NACL_IRT_RANDOM_v0_1 interface not avaiable.");
245 return EBADF; 251 return EBADF;
252 }
246 253
247 size_t nread; 254 size_t nread;
248 int error = (*random_interface_.get_random_bytes)(buf, count, &nread); 255 int error = (*random_interface_.get_random_bytes)(buf, count, &nread);
249 if (error) 256 if (error)
250 return error; 257 return error;
251 #elif defined(WIN32) 258 #elif defined(WIN32)
252 char* out = static_cast<char*>(buf); 259 char* out = static_cast<char*>(buf);
253 size_t bytes_left = count; 260 size_t bytes_left = count;
254 while (bytes_left) { 261 while (bytes_left) {
255 unsigned int random_int; 262 unsigned int random_int;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 295
289 } // namespace 296 } // namespace
290 297
291 Error DevFs::Access(const Path& path, int a_mode) { 298 Error DevFs::Access(const Path& path, int a_mode) {
292 ScopedNode node; 299 ScopedNode node;
293 int error = root_->FindChild(path.Join(), &node); 300 int error = root_->FindChild(path.Join(), &node);
294 if (error) 301 if (error)
295 return error; 302 return error;
296 303
297 // Don't allow execute access. 304 // Don't allow execute access.
298 if (a_mode & X_OK) 305 if (a_mode & X_OK) {
306 LOG_TRACE("Executing devfs nodes is not allowed.");
299 return EACCES; 307 return EACCES;
308 }
300 309
301 return 0; 310 return 0;
302 } 311 }
303 312
304 Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { 313 Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
305 out_node->reset(NULL); 314 out_node->reset(NULL);
306 int error; 315 int error;
307 if (path.Part(1) == "fs") { 316 if (path.Part(1) == "fs") {
308 if (path.Size() == 3) 317 if (path.Size() == 3) {
309 error = fs_dir_->FindChild(path.Part(2), out_node); 318 error = fs_dir_->FindChild(path.Part(2), out_node);
310 else 319 } else {
320 LOG_TRACE("Bad devfs path: %s", path.Join().c_str());
311 error = ENOENT; 321 error = ENOENT;
322 }
312 } else { 323 } else {
313 error = root_->FindChild(path.Join(), out_node); 324 error = root_->FindChild(path.Join(), out_node);
314 } 325 }
315 326
316 // Only return EACCES when trying to create a node that does not exist. 327 // Only return EACCES when trying to create a node that does not exist.
317 if ((error == ENOENT) && (open_flags & O_CREAT)) 328 if ((error == ENOENT) && (open_flags & O_CREAT)) {
329 LOG_TRACE("Cannot create devfs node: %s", path.Join().c_str());
318 return EACCES; 330 return EACCES;
331 }
319 332
320 return error; 333 return error;
321 } 334 }
322 335
323 Error DevFs::Unlink(const Path& path) { 336 Error DevFs::Unlink(const Path& path) {
337 LOG_ERROR("unlink not supported.");
324 return EPERM; 338 return EPERM;
325 } 339 }
326 340
327 Error DevFs::Mkdir(const Path& path, int permissions) { 341 Error DevFs::Mkdir(const Path& path, int permissions) {
342 LOG_ERROR("mkdir not supported.");
328 return EPERM; 343 return EPERM;
329 } 344 }
330 345
331 Error DevFs::Rmdir(const Path& path) { 346 Error DevFs::Rmdir(const Path& path) {
347 LOG_ERROR("rmdir not supported.");
332 return EPERM; 348 return EPERM;
333 } 349 }
334 350
335 Error DevFs::Remove(const Path& path) { 351 Error DevFs::Remove(const Path& path) {
352 LOG_ERROR("remove not supported.");
336 return EPERM; 353 return EPERM;
337 } 354 }
338 355
339 Error DevFs::Rename(const Path& path, const Path& newpath) { 356 Error DevFs::Rename(const Path& path, const Path& newpath) {
357 LOG_ERROR("rename not supported.");
340 return EPERM; 358 return EPERM;
341 } 359 }
342 360
343 Error DevFs::CreateFsNode(Filesystem* other_fs) { 361 Error DevFs::CreateFsNode(Filesystem* other_fs) {
344 int dev = other_fs->dev(); 362 int dev = other_fs->dev();
345 char path[32]; 363 char path[32];
346 snprintf(path, 32, "%d", dev); 364 snprintf(path, 32, "%d", dev);
347 ScopedNode new_node(new FsNode(this, other_fs)); 365 ScopedNode new_node(new FsNode(this, other_fs));
348 return fs_dir_->AddChild(path, new_node); 366 return fs_dir_->AddChild(path, new_node);
349 } 367 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // Add a directory for "fs" nodes; they represent all currently-mounted 417 // Add a directory for "fs" nodes; they represent all currently-mounted
400 // filesystems. We can ioctl these nodes to make changes or provide input to 418 // filesystems. We can ioctl these nodes to make changes or provide input to
401 // a mounted filesystem. 419 // a mounted filesystem.
402 INITIALIZE_DEV_NODE("/fs", DirNode); 420 INITIALIZE_DEV_NODE("/fs", DirNode);
403 fs_dir_ = new_node; 421 fs_dir_ = new_node;
404 422
405 return 0; 423 return 0;
406 } 424 }
407 425
408 } // namespace nacl_io 426 } // namespace nacl_io
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/devfs/jspipe_event_emitter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698