| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_mounts/mount.h" | 5 #include "nacl_mounts/mount.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "nacl_mounts/mount_node.h" | 11 #include "nacl_mounts/mount_node.h" |
| 12 #include "nacl_mounts/mount_node_dir.h" | 12 #include "nacl_mounts/mount_node_dir.h" |
| 13 #include "nacl_mounts/mount_node_mem.h" | 13 #include "nacl_mounts/mount_node_mem.h" |
| 14 #include "nacl_mounts/osstat.h" | 14 #include "nacl_mounts/osstat.h" |
| 15 #include "nacl_mounts/path.h" | 15 #include "nacl_mounts/path.h" |
| 16 #include "utils/auto_lock.h" | 16 #include "utils/auto_lock.h" |
| 17 #include "utils/ref_object.h" | 17 #include "utils/ref_object.h" |
| 18 | 18 |
| 19 #if defined(WIN32) | 19 #if defined(WIN32) |
| 20 #include <windows.h> | 20 #include <windows.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 Mount::Mount() | 23 Mount::Mount() |
| 24 : dev_(0), | 24 : dev_(0) { |
| 25 num_nodes_(0) { | |
| 26 } | 25 } |
| 27 | 26 |
| 28 Mount::~Mount() {} | 27 Mount::~Mount() {} |
| 29 | 28 |
| 30 bool Mount::Init(int dev, StringMap_t& args, PepperInterface* ppapi) { | 29 bool Mount::Init(int dev, StringMap_t& args, PepperInterface* ppapi) { |
| 31 dev_ = dev; | 30 dev_ = dev; |
| 32 ppapi_ = ppapi; | 31 ppapi_ = ppapi; |
| 33 return true; | 32 return true; |
| 34 } | 33 } |
| 35 | 34 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 int Mount::OpenModeToPermission(int mode) { | 47 int Mount::OpenModeToPermission(int mode) { |
| 49 int out; | 48 int out; |
| 50 switch (mode & 3) { | 49 switch (mode & 3) { |
| 51 case O_RDONLY: out = S_IREAD; | 50 case O_RDONLY: out = S_IREAD; |
| 52 case O_WRONLY: out = S_IWRITE; | 51 case O_WRONLY: out = S_IWRITE; |
| 53 case O_RDWR: out = S_IREAD | S_IWRITE; | 52 case O_RDWR: out = S_IREAD | S_IWRITE; |
| 54 } | 53 } |
| 55 return out; | 54 return out; |
| 56 } | 55 } |
| 57 | 56 |
| 58 void Mount::OnNodeCreated() { | 57 |
| 59 #if defined(__native_client__) | 58 void Mount::OnNodeCreated(MountNode* node) { |
| 60 __sync_add_and_fetch(&num_nodes_, 1); | 59 node->stat_.st_ino = inode_pool_.Acquire(); |
| 61 #elif defined(WIN32) | 60 node->stat_.st_dev = dev_; |
| 62 InterlockedIncrement(&num_nodes_); | |
| 63 #else | |
| 64 #error Implement atomic functions for this platform. | |
| 65 #endif | |
| 66 } | 61 } |
| 67 | 62 |
| 68 void Mount::OnNodeDestroyed() { | 63 void Mount::OnNodeDestroyed(MountNode* node) { |
| 69 #if defined(__native_client__) | 64 if (node->stat_.st_ino) inode_pool_.Release(node->stat_.st_ino); |
| 70 __sync_sub_and_fetch(&num_nodes_, 1); | 65 } |
| 71 #elif defined(WIN32) | |
| 72 InterlockedDecrement(&num_nodes_); | |
| 73 #else | |
| 74 #error Implement atomic functions for this platform. | |
| 75 #endif | |
| 76 } | |
| OLD | NEW |