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
3 // found in the LICENSE file.
5 #include "nacl_io/passthroughfs/passthrough_fs.h"
9 #include "nacl_io/kernel_handle.h"
10 #include "nacl_io/kernel_wrap_real.h"
14 class PassthroughFsNode : public Node {
16 explicit PassthroughFsNode(Filesystem* filesystem, int real_fd)
17 : Node(filesystem), real_fd_(real_fd) {}
20 virtual Error Init(int flags) { return 0; }
22 virtual void Destroy() {
24 _real_close(real_fd_);
29 // Normal read/write operations on a file
30 virtual Error Read(const HandleAttr& attr,
37 int err = _real_lseek(real_fd_, attr.offs, 0, &new_offset);
42 err = _real_read(real_fd_, buf, count, &nread);
46 *out_bytes = static_cast<int>(nread);
50 virtual Error Write(const HandleAttr& attr,
57 int err = _real_lseek(real_fd_, attr.offs, 0, &new_offset);
62 err = _real_write(real_fd_, buf, count, &nwrote);
66 *out_bytes = static_cast<int>(nwrote);
70 virtual Error FTruncate(off_t size) {
71 // TODO(binji): what to do here?
75 virtual Error GetDents(size_t offs,
80 int err = _real_getdents(real_fd_, pdir, count, &nread);
86 virtual Error GetStat(struct stat* stat) {
87 int err = _real_fstat(real_fd_, stat);
93 virtual Error Isatty() {
95 // isatty is not yet hooked up to the IRT interface under glibc.
99 int err = _real_isatty(real_fd_, &result);
106 Error MMap(void* addr,
113 int err = _real_mmap(out_addr, length, prot, flags, real_fd_, offset);
120 friend class PassthroughFs;
125 PassthroughFs::PassthroughFs() {}
127 Error PassthroughFs::Init(const FsInitArgs& args) {
128 return Filesystem::Init(args);
131 void PassthroughFs::Destroy() {}
133 Error PassthroughFs::Access(const Path& path, int a_mode) {
134 // There is no underlying 'access' syscall in NaCl. It just returns ENOSYS.
138 Error PassthroughFs::Open(const Path& path, int mode, ScopedNode* out_node) {
139 out_node->reset(NULL);
141 int error = _real_open(path.Join().c_str(), mode, 0666, &real_fd);
145 out_node->reset(new PassthroughFsNode(this, real_fd));
149 Error PassthroughFs::OpenResource(const Path& path, ScopedNode* out_node) {
151 out_node->reset(NULL);
152 int error = _real_open_resource(path.Join().c_str(), &real_fd);
156 out_node->reset(new PassthroughFsNode(this, real_fd));
160 Error PassthroughFs::Unlink(const Path& path) {
161 // Not implemented by NaCl.
165 Error PassthroughFs::Mkdir(const Path& path, int perm) {
166 return _real_mkdir(path.Join().c_str(), perm);
169 Error PassthroughFs::Rmdir(const Path& path) {
170 return _real_rmdir(path.Join().c_str());
173 Error PassthroughFs::Remove(const Path& path) {
174 // Not implemented by NaCl.
178 Error PassthroughFs::Rename(const Path& path, const Path& newpath) {
179 // Not implemented by NaCl.
183 } // namespace nacl_io