Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/mount_node.h" | 5 #include "nacl_io/mount_node.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <poll.h> | 9 #include <poll.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "nacl_io/kernel_wrap_real.h" | 16 #include "nacl_io/kernel_wrap_real.h" |
| 17 #include "nacl_io/mount.h" | 17 #include "nacl_io/mount.h" |
| 18 #include "nacl_io/osmman.h" | 18 #include "nacl_io/osmman.h" |
| 19 #include "sdk_util/auto_lock.h" | 19 #include "sdk_util/auto_lock.h" |
| 20 | 20 |
| 21 namespace nacl_io { | 21 namespace nacl_io { |
| 22 | 22 |
| 23 static const int USR_ID = 1001; | 23 static const int USR_ID = 1001; |
| 24 static const int GRP_ID = 1002; | 24 static const int GRP_ID = 1002; |
| 25 | 25 |
| 26 MountNode::MountNode(Mount* mount) : mount_(mount) { | 26 MountNode::MountNode(Mount* mount) : mount_(mount) { |
| 27 memset(&stat_, 0, sizeof(stat_)); | 27 memset(&stat_, 0, sizeof(stat_)); |
| 28 stat_.st_gid = GRP_ID; | 28 stat_.st_gid = GRP_ID; |
| 29 stat_.st_uid = USR_ID; | 29 stat_.st_uid = USR_ID; |
| 30 state_ = 0; | |
| 30 | 31 |
| 31 // Mount should normally never be NULL, but may be null in tests. | 32 // Mount should normally never be NULL, but may be null in tests. |
| 32 // If NULL, at least set the inode to a valid (nonzero) value. | 33 // If NULL, at least set the inode to a valid (nonzero) value. |
| 33 if (mount_) | 34 if (mount_) |
| 34 mount_->OnNodeCreated(this); | 35 mount_->OnNodeCreated(this); |
| 35 else | 36 else |
| 36 stat_.st_ino = 1; | 37 stat_.st_ino = 1; |
| 37 } | 38 } |
| 38 | 39 |
| 39 MountNode::~MountNode() {} | 40 MountNode::~MountNode() {} |
| 40 | 41 |
| 41 Error MountNode::Init(int perm) { | 42 Error MountNode::Init(int perm) { |
| 42 stat_.st_mode |= perm; | 43 stat_.st_mode |= perm; |
| 44 state_ |= perm & (O_NONBLOCK); | |
|
binji
2013/09/12 01:47:57
where is state_ used?
noelallen1
2013/09/12 23:19:03
Done.
| |
| 43 return 0; | 45 return 0; |
| 44 } | 46 } |
| 45 | 47 |
| 46 void MountNode::Destroy() { | 48 void MountNode::Destroy() { |
| 47 if (mount_) { | 49 if (mount_) { |
| 48 mount_->OnNodeDestroyed(this); | 50 mount_->OnNodeDestroyed(this); |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Declared in EventEmitter, default to regular files which always return | 54 EventEmitter* MountNode::GetEventEmitter() { return NULL; } |
| 53 // a ready of TRUE for read, write, or error. | 55 |
| 54 uint32_t MountNode::GetEventStatus() { | 56 uint32_t MountNode::GetEventStatus() { |
| 55 uint32_t val = POLLIN | POLLOUT | POLLERR; | 57 if (GetEventEmitter()) |
| 56 return val; | 58 return GetEventEmitter()->GetEventStatus(); |
| 59 | |
| 60 return POLLIN | POLLOUT; | |
| 57 } | 61 } |
| 58 | 62 |
| 59 | |
| 60 Error MountNode::FSync() { return 0; } | 63 Error MountNode::FSync() { return 0; } |
| 61 | 64 |
| 62 Error MountNode::FTruncate(off_t length) { return EINVAL; } | 65 Error MountNode::FTruncate(off_t length) { return EINVAL; } |
| 63 | 66 |
| 64 Error MountNode::GetDents(size_t offs, | 67 Error MountNode::GetDents(size_t offs, |
| 65 struct dirent* pdir, | 68 struct dirent* pdir, |
| 66 size_t count, | 69 size_t count, |
| 67 int* out_bytes) { | 70 int* out_bytes) { |
| 68 *out_bytes = 0; | 71 *out_bytes = 0; |
| 69 return ENOTDIR; | 72 return ENOTDIR; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } | 173 } |
| 171 | 174 |
| 172 int MountNode::ChildCount() { return 0; } | 175 int MountNode::ChildCount() { return 0; } |
| 173 | 176 |
| 174 void MountNode::Link() { stat_.st_nlink++; } | 177 void MountNode::Link() { stat_.st_nlink++; } |
| 175 | 178 |
| 176 void MountNode::Unlink() { stat_.st_nlink--; } | 179 void MountNode::Unlink() { stat_.st_nlink--; } |
| 177 | 180 |
| 178 } // namespace nacl_io | 181 } // namespace nacl_io |
| 179 | 182 |
| OLD | NEW |