| 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 |
| 11 #include <errno.h> | 11 #include <errno.h> |
| 12 #include <fcntl.h> | 12 #include <fcntl.h> |
| 13 #include <pthread.h> | 13 #include <pthread.h> |
| 14 #include <stdio.h> |
| 14 #include <string.h> | 15 #include <string.h> |
| 15 | 16 |
| 16 #include "nacl_io/devfs/jspipe_node.h" | 17 #include "nacl_io/devfs/jspipe_node.h" |
| 17 #include "nacl_io/devfs/tty_node.h" | 18 #include "nacl_io/devfs/tty_node.h" |
| 18 #include "nacl_io/dir_node.h" | 19 #include "nacl_io/dir_node.h" |
| 19 #include "nacl_io/kernel_wrap_real.h" | 20 #include "nacl_io/kernel_wrap_real.h" |
| 20 #include "nacl_io/node.h" | 21 #include "nacl_io/node.h" |
| 21 #include "nacl_io/osunistd.h" | 22 #include "nacl_io/osunistd.h" |
| 22 #include "nacl_io/pepper_interface.h" | 23 #include "nacl_io/pepper_interface.h" |
| 23 #include "sdk_util/auto_lock.h" | 24 #include "sdk_util/auto_lock.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 size_t count, | 105 size_t count, |
| 105 int* out_bytes); | 106 int* out_bytes); |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 #if defined(__native_client__) | 109 #if defined(__native_client__) |
| 109 nacl_irt_random random_interface_; | 110 nacl_irt_random random_interface_; |
| 110 bool interface_ok_; | 111 bool interface_ok_; |
| 111 #endif | 112 #endif |
| 112 }; | 113 }; |
| 113 | 114 |
| 115 class FsNode : public Node { |
| 116 public: |
| 117 FsNode(Filesystem* filesystem, Filesystem* other_fs); |
| 118 |
| 119 virtual Error VIoctl(int request, va_list args); |
| 120 |
| 121 private: |
| 122 // Don't addref the filesystem. We are relying on the fact that the |
| 123 // KernelObject will keep the filsystem around as long as we need it, and |
| 124 // this node will be destroyed when the filesystem is destroyed. |
| 125 Filesystem* other_fs_; |
| 126 }; |
| 127 |
| 114 RealNode::RealNode(Filesystem* filesystem, int fd) : Node(filesystem), fd_(fd) { | 128 RealNode::RealNode(Filesystem* filesystem, int fd) : Node(filesystem), fd_(fd) { |
| 115 SetType(S_IFCHR); | 129 SetType(S_IFCHR); |
| 116 } | 130 } |
| 117 | 131 |
| 118 Error RealNode::Read(const HandleAttr& attr, | 132 Error RealNode::Read(const HandleAttr& attr, |
| 119 void* buf, | 133 void* buf, |
| 120 size_t count, | 134 size_t count, |
| 121 int* out_bytes) { | 135 int* out_bytes) { |
| 122 *out_bytes = 0; | 136 *out_bytes = 0; |
| 123 | 137 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 268 } |
| 255 | 269 |
| 256 Error UrandomNode::Write(const HandleAttr& attr, | 270 Error UrandomNode::Write(const HandleAttr& attr, |
| 257 const void* buf, | 271 const void* buf, |
| 258 size_t count, | 272 size_t count, |
| 259 int* out_bytes) { | 273 int* out_bytes) { |
| 260 *out_bytes = count; | 274 *out_bytes = count; |
| 261 return 0; | 275 return 0; |
| 262 } | 276 } |
| 263 | 277 |
| 278 FsNode::FsNode(Filesystem* filesystem, Filesystem* other_fs) |
| 279 : Node(filesystem), other_fs_(other_fs) { |
| 280 } |
| 281 |
| 282 Error FsNode::VIoctl(int request, va_list args) { |
| 283 return other_fs_->Filesystem_VIoctl(request, args); |
| 284 } |
| 285 |
| 264 } // namespace | 286 } // namespace |
| 265 | 287 |
| 266 Error DevFs::Access(const Path& path, int a_mode) { | 288 Error DevFs::Access(const Path& path, int a_mode) { |
| 267 ScopedNode node; | 289 ScopedNode node; |
| 268 int error = root_->FindChild(path.Join(), &node); | 290 int error = root_->FindChild(path.Join(), &node); |
| 269 if (error) | 291 if (error) |
| 270 return error; | 292 return error; |
| 271 | 293 |
| 272 // Don't allow execute access. | 294 // Don't allow execute access. |
| 273 if (a_mode & X_OK) | 295 if (a_mode & X_OK) |
| 274 return EACCES; | 296 return EACCES; |
| 275 | 297 |
| 276 return 0; | 298 return 0; |
| 277 } | 299 } |
| 278 | 300 |
| 279 Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { | 301 Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { |
| 280 out_node->reset(NULL); | 302 out_node->reset(NULL); |
| 281 int error = root_->FindChild(path.Join(), out_node); | 303 int error; |
| 304 if (path.Part(1) == "fs") { |
| 305 if (path.Size() == 3) |
| 306 error = fs_dir_->FindChild(path.Part(2), out_node); |
| 307 else |
| 308 error = ENOENT; |
| 309 } else { |
| 310 error = root_->FindChild(path.Join(), out_node); |
| 311 } |
| 312 |
| 282 // Only return EACCES when trying to create a node that does not exist. | 313 // Only return EACCES when trying to create a node that does not exist. |
| 283 if ((error == ENOENT) && (open_flags & O_CREAT)) | 314 if ((error == ENOENT) && (open_flags & O_CREAT)) |
| 284 return EACCES; | 315 return EACCES; |
| 285 | 316 |
| 286 return error; | 317 return error; |
| 287 } | 318 } |
| 288 | 319 |
| 289 Error DevFs::Unlink(const Path& path) { return EPERM; } | 320 Error DevFs::Unlink(const Path& path) { return EPERM; } |
| 290 | 321 |
| 291 Error DevFs::Mkdir(const Path& path, int permissions) { return EPERM; } | 322 Error DevFs::Mkdir(const Path& path, int permissions) { return EPERM; } |
| 292 | 323 |
| 293 Error DevFs::Rmdir(const Path& path) { return EPERM; } | 324 Error DevFs::Rmdir(const Path& path) { return EPERM; } |
| 294 | 325 |
| 295 Error DevFs::Remove(const Path& path) { return EPERM; } | 326 Error DevFs::Remove(const Path& path) { return EPERM; } |
| 296 | 327 |
| 297 Error DevFs::Rename(const Path& path, const Path& newpath) { return EPERM; } | 328 Error DevFs::Rename(const Path& path, const Path& newpath) { return EPERM; } |
| 298 | 329 |
| 330 Error DevFs::CreateFsNode(Filesystem* other_fs) { |
| 331 int dev = other_fs->dev(); |
| 332 char path[32]; |
| 333 snprintf(path, 32, "%d", dev); |
| 334 ScopedNode new_node(new FsNode(this, other_fs)); |
| 335 return fs_dir_->AddChild(path, new_node); |
| 336 } |
| 337 |
| 338 Error DevFs::DestroyFsNode(Filesystem* other_fs) { |
| 339 int dev = other_fs->dev(); |
| 340 char path[32]; |
| 341 snprintf(path, 32, "%d", dev); |
| 342 return fs_dir_->RemoveChild(path); |
| 343 } |
| 344 |
| 345 |
| 299 DevFs::DevFs() {} | 346 DevFs::DevFs() {} |
| 300 | 347 |
| 301 #define INITIALIZE_DEV_NODE(path, klass) \ | 348 #define INITIALIZE_DEV_NODE(path, klass) \ |
| 302 new_node = ScopedNode(new klass(this)); \ | 349 new_node = ScopedNode(new klass(this)); \ |
| 303 error = root_->AddChild(path, new_node); \ | 350 error = root_->AddChild(path, new_node); \ |
| 304 if (error) \ | 351 if (error) \ |
| 305 return error; | 352 return error; |
| 306 | 353 |
| 307 #define INITIALIZE_DEV_NODE_1(path, klass, arg) \ | 354 #define INITIALIZE_DEV_NODE_1(path, klass, arg) \ |
| 308 new_node = ScopedNode(new klass(this, arg)); \ | 355 new_node = ScopedNode(new klass(this, arg)); \ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 329 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); | 376 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); |
| 330 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); | 377 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); |
| 331 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); | 378 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); |
| 332 INITIALIZE_DEV_NODE("/jspipe1", JSPipeNode); | 379 INITIALIZE_DEV_NODE("/jspipe1", JSPipeNode); |
| 333 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe1"); | 380 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe1"); |
| 334 INITIALIZE_DEV_NODE("/jspipe2", JSPipeNode); | 381 INITIALIZE_DEV_NODE("/jspipe2", JSPipeNode); |
| 335 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe2"); | 382 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe2"); |
| 336 INITIALIZE_DEV_NODE("/jspipe3", JSPipeNode); | 383 INITIALIZE_DEV_NODE("/jspipe3", JSPipeNode); |
| 337 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe3"); | 384 new_node->Ioctl(NACL_IOC_PIPE_SETNAME, "jspipe3"); |
| 338 | 385 |
| 386 // 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 |
| 388 // a mounted filesystem. |
| 389 INITIALIZE_DEV_NODE("/fs", DirNode); |
| 390 fs_dir_ = new_node; |
| 391 |
| 339 return 0; | 392 return 0; |
| 340 } | 393 } |
| 341 | 394 |
| 342 } // namespace nacl_io | 395 } // namespace nacl_io |
| OLD | NEW |