| 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 #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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 size_t writecnt; | 153 size_t writecnt; |
| 154 int err = _real_write(fd_, buf, count, &writecnt); | 154 int err = _real_write(fd_, buf, count, &writecnt); |
| 155 if (err) | 155 if (err) |
| 156 return err; | 156 return err; |
| 157 | 157 |
| 158 *out_bytes = static_cast<int>(writecnt); | 158 *out_bytes = static_cast<int>(writecnt); |
| 159 return 0; | 159 return 0; |
| 160 } | 160 } |
| 161 | 161 |
| 162 Error RealNode::GetStat(struct stat* stat) { return _real_fstat(fd_, stat); } | 162 Error RealNode::GetStat(struct stat* stat) { |
| 163 return _real_fstat(fd_, stat); |
| 164 } |
| 163 | 165 |
| 164 Error NullNode::Read(const HandleAttr& attr, | 166 Error NullNode::Read(const HandleAttr& attr, |
| 165 void* buf, | 167 void* buf, |
| 166 size_t count, | 168 size_t count, |
| 167 int* out_bytes) { | 169 int* out_bytes) { |
| 168 *out_bytes = 0; | 170 *out_bytes = 0; |
| 169 return 0; | 171 return 0; |
| 170 } | 172 } |
| 171 | 173 |
| 172 Error NullNode::Write(const HandleAttr& attr, | 174 Error NullNode::Write(const HandleAttr& attr, |
| 173 const void* buf, | 175 const void* buf, |
| 174 size_t count, | 176 size_t count, |
| 175 int* out_bytes) { | 177 int* out_bytes) { |
| 176 *out_bytes = count; | 178 *out_bytes = count; |
| 177 return 0; | 179 return 0; |
| 178 } | 180 } |
| 179 | 181 |
| 180 ConsoleNode::ConsoleNode(Filesystem* filesystem, PP_LogLevel level) | 182 ConsoleNode::ConsoleNode(Filesystem* filesystem, PP_LogLevel level) |
| 181 : CharNode(filesystem), level_(level) {} | 183 : CharNode(filesystem), level_(level) { |
| 184 } |
| 182 | 185 |
| 183 Error ConsoleNode::Write(const HandleAttr& attr, | 186 Error ConsoleNode::Write(const HandleAttr& attr, |
| 184 const void* buf, | 187 const void* buf, |
| 185 size_t count, | 188 size_t count, |
| 186 int* out_bytes) { | 189 int* out_bytes) { |
| 187 *out_bytes = 0; | 190 *out_bytes = 0; |
| 188 | 191 |
| 189 ConsoleInterface* con_intr = filesystem_->ppapi()->GetConsoleInterface(); | 192 ConsoleInterface* con_intr = filesystem_->ppapi()->GetConsoleInterface(); |
| 190 VarInterface* var_intr = filesystem_->ppapi()->GetVarInterface(); | 193 VarInterface* var_intr = filesystem_->ppapi()->GetVarInterface(); |
| 191 | 194 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 error = root_->FindChild(path.Join(), out_node); | 313 error = root_->FindChild(path.Join(), out_node); |
| 311 } | 314 } |
| 312 | 315 |
| 313 // Only return EACCES when trying to create a node that does not exist. | 316 // Only return EACCES when trying to create a node that does not exist. |
| 314 if ((error == ENOENT) && (open_flags & O_CREAT)) | 317 if ((error == ENOENT) && (open_flags & O_CREAT)) |
| 315 return EACCES; | 318 return EACCES; |
| 316 | 319 |
| 317 return error; | 320 return error; |
| 318 } | 321 } |
| 319 | 322 |
| 320 Error DevFs::Unlink(const Path& path) { return EPERM; } | 323 Error DevFs::Unlink(const Path& path) { |
| 324 return EPERM; |
| 325 } |
| 321 | 326 |
| 322 Error DevFs::Mkdir(const Path& path, int permissions) { return EPERM; } | 327 Error DevFs::Mkdir(const Path& path, int permissions) { |
| 328 return EPERM; |
| 329 } |
| 323 | 330 |
| 324 Error DevFs::Rmdir(const Path& path) { return EPERM; } | 331 Error DevFs::Rmdir(const Path& path) { |
| 332 return EPERM; |
| 333 } |
| 325 | 334 |
| 326 Error DevFs::Remove(const Path& path) { return EPERM; } | 335 Error DevFs::Remove(const Path& path) { |
| 336 return EPERM; |
| 337 } |
| 327 | 338 |
| 328 Error DevFs::Rename(const Path& path, const Path& newpath) { return EPERM; } | 339 Error DevFs::Rename(const Path& path, const Path& newpath) { |
| 340 return EPERM; |
| 341 } |
| 329 | 342 |
| 330 Error DevFs::CreateFsNode(Filesystem* other_fs) { | 343 Error DevFs::CreateFsNode(Filesystem* other_fs) { |
| 331 int dev = other_fs->dev(); | 344 int dev = other_fs->dev(); |
| 332 char path[32]; | 345 char path[32]; |
| 333 snprintf(path, 32, "%d", dev); | 346 snprintf(path, 32, "%d", dev); |
| 334 ScopedNode new_node(new FsNode(this, other_fs)); | 347 ScopedNode new_node(new FsNode(this, other_fs)); |
| 335 return fs_dir_->AddChild(path, new_node); | 348 return fs_dir_->AddChild(path, new_node); |
| 336 } | 349 } |
| 337 | 350 |
| 338 Error DevFs::DestroyFsNode(Filesystem* other_fs) { | 351 Error DevFs::DestroyFsNode(Filesystem* other_fs) { |
| 339 int dev = other_fs->dev(); | 352 int dev = other_fs->dev(); |
| 340 char path[32]; | 353 char path[32]; |
| 341 snprintf(path, 32, "%d", dev); | 354 snprintf(path, 32, "%d", dev); |
| 342 return fs_dir_->RemoveChild(path); | 355 return fs_dir_->RemoveChild(path); |
| 343 } | 356 } |
| 344 | 357 |
| 345 | 358 DevFs::DevFs() { |
| 346 DevFs::DevFs() {} | 359 } |
| 347 | 360 |
| 348 #define INITIALIZE_DEV_NODE(path, klass) \ | 361 #define INITIALIZE_DEV_NODE(path, klass) \ |
| 349 new_node = ScopedNode(new klass(this)); \ | 362 new_node = ScopedNode(new klass(this)); \ |
| 350 error = root_->AddChild(path, new_node); \ | 363 error = root_->AddChild(path, new_node); \ |
| 351 if (error) \ | 364 if (error) \ |
| 352 return error; | 365 return error; |
| 353 | 366 |
| 354 #define INITIALIZE_DEV_NODE_1(path, klass, arg) \ | 367 #define INITIALIZE_DEV_NODE_1(path, klass, arg) \ |
| 355 new_node = ScopedNode(new klass(this, arg)); \ | 368 new_node = ScopedNode(new klass(this, arg)); \ |
| 356 error = root_->AddChild(path, new_node); \ | 369 error = root_->AddChild(path, new_node); \ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 386 // Add a directory for "fs" nodes; they represent all currently-mounted | 399 // Add a directory for "fs" nodes; they represent all currently-mounted |
| 387 // filesystems. We can ioctl these nodes to make changes or provide input to | 400 // filesystems. We can ioctl these nodes to make changes or provide input to |
| 388 // a mounted filesystem. | 401 // a mounted filesystem. |
| 389 INITIALIZE_DEV_NODE("/fs", DirNode); | 402 INITIALIZE_DEV_NODE("/fs", DirNode); |
| 390 fs_dir_ = new_node; | 403 fs_dir_ = new_node; |
| 391 | 404 |
| 392 return 0; | 405 return 0; |
| 393 } | 406 } |
| 394 | 407 |
| 395 } // namespace nacl_io | 408 } // namespace nacl_io |
| OLD | NEW |