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
3 // found in the LICENSE file.
5 #include "nacl_io/passthroughfs/real_node.h"
10 #include "nacl_io/kernel_handle.h"
11 #include "nacl_io/kernel_wrap_real.h"
12 #include "nacl_io/log.h"
15 RealNode::RealNode(Filesystem* filesystem, int real_fd, bool close_on_destroy)
18 close_on_destroy_(close_on_destroy)
22 void RealNode::Destroy() {
23 if (close_on_destroy_)
24 _real_close(real_fd_);
28 // Normal read/write operations on a file
29 Error RealNode::Read(const HandleAttr& attr,
38 err = _real_lseek(real_fd_, attr.offs, SEEK_SET, &new_offset);
40 LOG_WARN("_real_lseek failed: %s\n", strerror(err));
46 err = _real_read(real_fd_, buf, count, &nread);
48 LOG_WARN("_real_read failed: %s\n", strerror(err));
52 *out_bytes = static_cast<int>(nread);
56 Error RealNode::Write(const HandleAttr& attr,
65 err = _real_lseek(real_fd_, attr.offs, SEEK_SET, &new_offset);
67 LOG_WARN("_real_lseek failed: %s\n", strerror(err));
73 err = _real_write(real_fd_, buf, count, &nwrote);
75 LOG_WARN("_real_write failed: %s\n", strerror(err));
79 *out_bytes = static_cast<int>(nwrote);
83 Error RealNode::FTruncate(off_t size) {
84 // TODO(binji): what to do here?
88 Error RealNode::GetDents(size_t offs,
93 int err = _real_getdents(real_fd_, pdir, count, &nread);
99 Error RealNode::GetStat(struct stat* stat) {
100 int err = _real_fstat(real_fd_, stat);
103 // On windows, fstat() of stdin/stdout/stderr returns all zeros
104 // for the permission bits. This can cause problems down the
105 // line. For example, CanOpen() will fail.
106 // TODO(sbc): Fix this within sel_ldr instead.
107 if (S_ISCHR(stat->st_mode) && (stat->st_mode & S_IRWXU) == 0)
108 stat->st_mode |= S_IRWXU;
112 Error RealNode::Isatty() {
114 // isatty is not yet hooked up to the IRT interface under glibc.
118 int err = _real_isatty(real_fd_, &result);
125 Error RealNode::MMap(void* addr,
132 int err = _real_mmap(out_addr, length, prot, flags, real_fd_, offset);