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
3 // found in the LICENSE file.
5 #include "nacl_io/mount_passthrough.h"
9 #include "nacl_io/kernel_handle.h"
10 #include "nacl_io/kernel_wrap_real.h"
14 class MountNodePassthrough : public MountNode {
16 explicit MountNodePassthrough(Mount* mount, int real_fd)
17 : MountNode(mount), 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 Error MMap(void* addr,
100 int err = _real_mmap(out_addr, length, prot, flags, real_fd_, offset);
107 friend class MountPassthrough;
112 MountPassthrough::MountPassthrough() {}
114 Error MountPassthrough::Init(int dev,
116 PepperInterface* ppapi) {
117 return Mount::Init(dev, args, ppapi);
120 void MountPassthrough::Destroy() {}
122 Error MountPassthrough::Access(const Path& path, int a_mode) {
123 // There is no underlying 'access' syscall in NaCl. It just returns ENOSYS.
127 Error MountPassthrough::Open(const Path& path,
129 ScopedMountNode* out_node) {
130 out_node->reset(NULL);
132 int error = _real_open(path.Join().c_str(), mode, 0666, &real_fd);
136 out_node->reset(new MountNodePassthrough(this, real_fd));
140 Error MountPassthrough::OpenResource(const Path& path,
141 ScopedMountNode* out_node) {
143 out_node->reset(NULL);
144 int error = _real_open_resource(path.Join().c_str(), &real_fd);
148 out_node->reset(new MountNodePassthrough(this, real_fd));
152 Error MountPassthrough::Unlink(const Path& path) {
153 // Not implemented by NaCl.
157 Error MountPassthrough::Mkdir(const Path& path, int perm) {
158 return _real_mkdir(path.Join().c_str(), perm);
161 Error MountPassthrough::Rmdir(const Path& path) {
162 return _real_rmdir(path.Join().c_str());
165 Error MountPassthrough::Remove(const Path& path) {
166 // Not implemented by NaCl.
170 } // namespace nacl_io