Home | History | Annotate | Download | only in nacl_io
      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.
      4 
      5 #include "nacl_io/mount.h"
      6 
      7 #include <errno.h>
      8 #include <fcntl.h>
      9 #include <string>
     10 
     11 #include "nacl_io/mount_node.h"
     12 #include "nacl_io/mount_node_dir.h"
     13 #include "nacl_io/mount_node_mem.h"
     14 #include "nacl_io/osstat.h"
     15 #include "nacl_io/path.h"
     16 #include "sdk_util/auto_lock.h"
     17 #include "sdk_util/ref_object.h"
     18 
     19 #if defined(WIN32)
     20 #include <windows.h>
     21 #endif
     22 
     23 namespace nacl_io {
     24 
     25 Mount::Mount() : dev_(0) {}
     26 
     27 Mount::~Mount() {}
     28 
     29 Error Mount::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
     30   dev_ = dev;
     31   ppapi_ = ppapi;
     32   return 0;
     33 }
     34 
     35 void Mount::Destroy() {}
     36 
     37 Error Mount::OpenResource(const Path& path, ScopedMountNode* out_node) {
     38   out_node->reset(NULL);
     39   return EINVAL;
     40 }
     41 
     42 int Mount::OpenModeToPermission(int mode) {
     43   int out;
     44   switch (mode & 3) {
     45     case O_RDONLY:
     46       out = S_IREAD;
     47     case O_WRONLY:
     48       out = S_IWRITE;
     49     case O_RDWR:
     50       out = S_IREAD | S_IWRITE;
     51   }
     52   return out;
     53 }
     54 
     55 void Mount::OnNodeCreated(MountNode* node) {
     56   node->stat_.st_ino = inode_pool_.Acquire();
     57   node->stat_.st_dev = dev_;
     58 }
     59 
     60 void Mount::OnNodeDestroyed(MountNode* node) {
     61   if (node->stat_.st_ino)
     62     inode_pool_.Release(node->stat_.st_ino);
     63 }
     64 
     65 }  // namespace nacl_io
     66 
     67