| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/passthroughfs/real_node.h" | 5 #include "nacl_io/passthroughfs/real_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/kernel_handle.h" | 10 #include "nacl_io/kernel_handle.h" |
| 11 #include "nacl_io/kernel_wrap_real.h" | 11 #include "nacl_io/kernel_wrap_real.h" |
| 12 #include "nacl_io/log.h" | 12 #include "nacl_io/log.h" |
| 13 | 13 |
| 14 namespace nacl_io { | 14 namespace nacl_io { |
| 15 |
| 15 RealNode::RealNode(Filesystem* filesystem, int real_fd, bool close_on_destroy) | 16 RealNode::RealNode(Filesystem* filesystem, int real_fd, bool close_on_destroy) |
| 16 : Node(filesystem), | 17 : Node(filesystem), |
| 17 real_fd_(real_fd), | 18 real_fd_(real_fd), |
| 18 close_on_destroy_(close_on_destroy) | 19 close_on_destroy_(close_on_destroy) |
| 19 { | 20 { |
| 21 GetStat(&stat_); |
| 20 } | 22 } |
| 21 | 23 |
| 22 void RealNode::Destroy() { | 24 void RealNode::Destroy() { |
| 23 if (close_on_destroy_) | 25 if (close_on_destroy_) |
| 24 _real_close(real_fd_); | 26 _real_close(real_fd_); |
| 25 real_fd_ = -1; | 27 real_fd_ = -1; |
| 26 } | 28 } |
| 27 | 29 |
| 28 // Normal read/write operations on a file | 30 // Normal read/write operations on a file |
| 29 Error RealNode::Read(const HandleAttr& attr, | 31 Error RealNode::Read(const HandleAttr& attr, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 84 |
| 83 Error RealNode::FTruncate(off_t size) { | 85 Error RealNode::FTruncate(off_t size) { |
| 84 // TODO(binji): what to do here? | 86 // TODO(binji): what to do here? |
| 85 return ENOSYS; | 87 return ENOSYS; |
| 86 } | 88 } |
| 87 | 89 |
| 88 Error RealNode::GetDents(size_t offs, | 90 Error RealNode::GetDents(size_t offs, |
| 89 struct dirent* pdir, | 91 struct dirent* pdir, |
| 90 size_t count, | 92 size_t count, |
| 91 int* out_bytes) { | 93 int* out_bytes) { |
| 92 size_t nread; | 94 size_t out_bytes_as_size_t; |
| 93 int err = _real_getdents(real_fd_, pdir, count, &nread); | 95 Error rtn = _real_getdents(real_fd_, pdir, count, &out_bytes_as_size_t); |
| 94 if (err) | 96 if (rtn == 0) |
| 95 return err; | 97 *out_bytes = out_bytes_as_size_t; |
| 96 return nread; | 98 return rtn; |
| 97 } | 99 } |
| 98 | 100 |
| 101 #ifndef S_UNSUP |
| 102 #define S_UNSUP S_IFMT |
| 103 #endif |
| 104 |
| 99 Error RealNode::GetStat(struct stat* stat) { | 105 Error RealNode::GetStat(struct stat* stat) { |
| 100 int err = _real_fstat(real_fd_, stat); | 106 int err = _real_fstat(real_fd_, stat); |
| 101 if (err) | 107 if (err) |
| 102 return err; | 108 return err; |
| 103 // On windows, fstat() of stdin/stdout/stderr returns all zeros | 109 // On windows, fstat() of stdin/stdout/stderr (when they are represented |
| 104 // for the permission bits. This can cause problems down the | 110 // as char device or FIFO) returns all zeros for the mode bits. This can |
| 105 // line. For example, CanOpen() will fail. | 111 // cause problems down the line. For example, CanOpen() will fail. |
| 112 // We also have to check for S_UNSUP because S_IFIFO is currently not |
| 113 // reported by the windows sel_ldr. |
| 106 // TODO(sbc): Fix this within sel_ldr instead. | 114 // TODO(sbc): Fix this within sel_ldr instead. |
| 107 if (S_ISCHR(stat->st_mode) && (stat->st_mode & S_IRWXU) == 0) | 115 if ((stat->st_mode & S_IRWXU) == 0) { |
| 116 LOG_WARN("_real_fstat(%d) reported not access permissions: st_mode=O%o\n", |
| 117 real_fd_, stat->st_mode); |
| 118 } |
| 119 if ((S_ISCHR(stat->st_mode) |
| 120 || S_ISFIFO(stat->st_mode) |
| 121 || (stat->st_mode & S_IFMT) == S_UNSUP) && (stat->st_mode & S_IRWXU) == 0) |
| 108 stat->st_mode |= S_IRWXU; | 122 stat->st_mode |= S_IRWXU; |
| 109 return 0; | 123 return 0; |
| 110 } | 124 } |
| 111 | 125 |
| 112 Error RealNode::Isatty() { | 126 Error RealNode::Isatty() { |
| 113 #ifdef __GLIBC__ | 127 #ifdef __GLIBC__ |
| 114 // isatty is not yet hooked up to the IRT interface under glibc. | 128 // isatty is not yet hooked up to the IRT interface under glibc. |
| 115 return ENOTTY; | 129 return ENOTTY; |
| 116 #else | 130 #else |
| 117 int result = 0; | 131 int result = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 size_t offset, | 143 size_t offset, |
| 130 void** out_addr) { | 144 void** out_addr) { |
| 131 *out_addr = addr; | 145 *out_addr = addr; |
| 132 int err = _real_mmap(out_addr, length, prot, flags, real_fd_, offset); | 146 int err = _real_mmap(out_addr, length, prot, flags, real_fd_, offset); |
| 133 if (err) | 147 if (err) |
| 134 return err; | 148 return err; |
| 135 return 0; | 149 return 0; |
| 136 } | 150 } |
| 137 | 151 |
| 138 } | 152 } |
| OLD | NEW |