summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authornoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 00:48:07 +0000
committernoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 00:48:07 +0000
commit2f5df03a38f7c9cd7359cc64b09527dc007827eb (patch)
tree852d7ddcb43521e047c3ed27a0f80607da71c405 /native_client_sdk
parent3e72ed759ddc158877986c87cb8aeb7fb20a6fcb (diff)
downloadchromium_src-2f5df03a38f7c9cd7359cc64b09527dc007827eb.zip
chromium_src-2f5df03a38f7c9cd7359cc64b09527dc007827eb.tar.gz
chromium_src-2f5df03a38f7c9cd7359cc64b09527dc007827eb.tar.bz2
Additional cleanup
Additional cleanup/consolidation discovered as part of adding manifest files to the MountHttp. BUG=173525 Review URL: https://codereview.chromium.org/12166002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/inode_pool.h65
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/library.dsc1
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount.cc27
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount.h17
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc52
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_html5fs.cc8
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_http.cc28
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_mem.cc38
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_mem.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node.cc28
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node.h11
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.cc13
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.cc17
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.h8
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts/osstat.h5
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts_test/mount_html5fs_test.cc1
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc8
-rw-r--r--native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc7
21 files changed, 179 insertions, 175 deletions
diff --git a/native_client_sdk/src/libraries/nacl_mounts/inode_pool.h b/native_client_sdk/src/libraries/nacl_mounts/inode_pool.h
new file mode 100644
index 0000000..aabd8606
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_mounts/inode_pool.h
@@ -0,0 +1,65 @@
+/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef LIBRARIES_NACL_MOUNTS_INODE_POOL_H_
+#define LIBRARIES_NACL_MOUNTS_INODE_POOL_H_
+
+#include <stdlib.h>
+#include <vector>
+
+#include "nacl_mounts/osstat.h"
+#include "pthread.h"
+#include "utils/auto_lock.h"
+
+
+class INodePool {
+ public:
+ INodePool()
+ : max_nodes_(0),
+ num_nodes_(0) {
+ pthread_mutex_init(&lock_, NULL);
+ }
+ ~INodePool() {
+ pthread_mutex_destroy(&lock_);
+ }
+
+ ino_t Acquire() {
+ AutoLock lock(&lock_);
+ const int INO_CNT = 8;
+
+ // If we run out of INO numbers, then allocate 8 more
+ if (inos_.size() == 0) {
+ max_nodes_ += INO_CNT;
+ // Add eight more to the stack in reverse order, offset by 1
+ // since '0' refers to no INO.
+ for (int a = 0; a < INO_CNT; a++) {
+ inos_.push_back(max_nodes_ - a);
+ }
+ }
+
+ // Return the INO at the top of the stack.
+ int val = inos_.back();
+ inos_.pop_back();
+ num_nodes_++;
+ return val;
+ }
+
+ void Release(ino_t ino) {
+ AutoLock lock(&lock_);
+ inos_.push_back(ino);
+ num_nodes_--;
+ }
+
+ size_t size() const { return num_nodes_; }
+ size_t capacity() const { return max_nodes_; }
+
+ private:
+ size_t num_nodes_;
+ size_t max_nodes_;
+ std::vector<ino_t> inos_;
+ pthread_mutex_t lock_;
+};
+
+#endif // LIBRARIES_NACL_MOUNTS_INODE_POOL_H_
diff --git a/native_client_sdk/src/libraries/nacl_mounts/library.dsc b/native_client_sdk/src/libraries/nacl_mounts/library.dsc
index 0e76844..bf4e53f 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/library.dsc
+++ b/native_client_sdk/src/libraries/nacl_mounts/library.dsc
@@ -38,6 +38,7 @@
'HEADERS': [
{
'FILES': [
+ "inode_pool.h",
"kernel_handle.h",
"kernel_intercept.h",
"kernel_object.h",
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount.cc b/native_client_sdk/src/libraries/nacl_mounts/mount.cc
index 8c73594..07be9b396 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount.cc
@@ -21,8 +21,7 @@
#endif
Mount::Mount()
- : dev_(0),
- num_nodes_(0) {
+ : dev_(0) {
}
Mount::~Mount() {}
@@ -55,22 +54,12 @@ int Mount::OpenModeToPermission(int mode) {
return out;
}
-void Mount::OnNodeCreated() {
-#if defined(__native_client__)
- __sync_add_and_fetch(&num_nodes_, 1);
-#elif defined(WIN32)
- InterlockedIncrement(&num_nodes_);
-#else
-#error Implement atomic functions for this platform.
-#endif
-}
-void Mount::OnNodeDestroyed() {
-#if defined(__native_client__)
- __sync_sub_and_fetch(&num_nodes_, 1);
-#elif defined(WIN32)
- InterlockedDecrement(&num_nodes_);
-#else
-#error Implement atomic functions for this platform.
-#endif
+void Mount::OnNodeCreated(MountNode* node) {
+ node->stat_.st_ino = inode_pool_.Acquire();
+ node->stat_.st_dev = dev_;
}
+
+void Mount::OnNodeDestroyed(MountNode* node) {
+ if (node->stat_.st_ino) inode_pool_.Release(node->stat_.st_ino);
+} \ No newline at end of file
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount.h b/native_client_sdk/src/libraries/nacl_mounts/mount.h
index 108fa7b..e1da725 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount.h
@@ -8,6 +8,7 @@
#include <map>
#include <string>
+#include "nacl_mounts/inode_pool.h"
#include "nacl_mounts/mount_node.h"
#include "nacl_mounts/path.h"
#include "utils/macros.h"
@@ -42,9 +43,9 @@ class Mount : public RefObject {
void AcquireNode(MountNode* node);
void ReleaseNode(MountNode* node);
- // Open a node at |path|. The resulting MountNode is created with a ref
- // count of 1, and will be Closed when the last reference is released.
- virtual MountNode *Open(const Path& path, int mode) = 0;
+ // Open a node at |path| with the specified open flags. The resulting
+ // MountNode is created with a ref count of 1.
+ virtual MountNode *Open(const Path& path, int o_flags) = 0;
// Unlink, Mkdir, Rmdir will affect the both the RefCount
// and the nlink number in the stat object.
@@ -56,18 +57,14 @@ class Mount : public RefObject {
// Convert from R,W,R/W open flags to STAT permission flags
static int OpenModeToPermission(int mode);
- unsigned int num_nodes() const { return num_nodes_; }
-
- // Should only be called by MountNode when a new node is created with this
- // Mount as its parent.
- void OnNodeCreated();
- void OnNodeDestroyed();
+ void OnNodeCreated(MountNode* node) ;
+ void OnNodeDestroyed(MountNode* node);
protected:
// Device number for the mount.
int dev_;
- unsigned int num_nodes_;
PepperInterface* ppapi_; // Weak reference.
+ INodePool inode_pool_;
private:
// May only be called by the KernelProxy when the Kernel's
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc
index e4d3fbff..a85f8de 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc
@@ -31,7 +31,7 @@ void ReleaseAndNullNode(MountNode** node) {
class NullNode : public MountNode {
public:
- NullNode(Mount* mount, int ino, int dev);
+ explicit NullNode(Mount* mount);
virtual int Read(size_t offs, void* buf, size_t count);
virtual int Write(size_t offs, const void* buf, size_t count);
@@ -39,7 +39,7 @@ class NullNode : public MountNode {
class ConsoleNode : public NullNode {
public:
- ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level);
+ ConsoleNode(Mount* mount, PP_LogLevel level);
virtual int Write(size_t offs, const void* buf, size_t count);
@@ -50,7 +50,7 @@ private:
class TtyNode : public NullNode {
public:
- TtyNode(Mount* mount, int ino, int dev);
+ explicit TtyNode(Mount* mount);
virtual int Write(size_t offs, const void* buf, size_t count);
};
@@ -58,7 +58,7 @@ class TtyNode : public NullNode {
class ZeroNode : public MountNode {
public:
- ZeroNode(Mount* mount, int ino, int dev);
+ explicit ZeroNode(Mount* mount);
virtual int Read(size_t offs, void* buf, size_t count);
virtual int Write(size_t offs, const void* buf, size_t count);
@@ -66,7 +66,7 @@ class ZeroNode : public MountNode {
class UrandomNode : public MountNode {
public:
- UrandomNode(Mount* mount, int ino, int dev);
+ explicit UrandomNode(Mount* mount);
virtual int Read(size_t offs, void* buf, size_t count);
virtual int Write(size_t offs, const void* buf, size_t count);
@@ -78,8 +78,9 @@ class UrandomNode : public MountNode {
#endif
};
-NullNode::NullNode(Mount* mount, int ino, int dev)
- : MountNode(mount, ino, dev) {
+NullNode::NullNode(Mount* mount)
+ : MountNode(mount) {
+ stat_.st_mode = S_IFCHR;
}
int NullNode::Read(size_t offs, void* buf, size_t count) {
@@ -90,9 +91,10 @@ int NullNode::Write(size_t offs, const void* buf, size_t count) {
return count;
}
-ConsoleNode::ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level)
- : NullNode(mount, ino, dev),
+ConsoleNode::ConsoleNode(Mount* mount, PP_LogLevel level)
+ : NullNode(mount),
level_(level) {
+ stat_.st_mode = S_IFCHR;
}
int ConsoleNode::Write(size_t offs, const void* buf, size_t count) {
@@ -110,8 +112,8 @@ int ConsoleNode::Write(size_t offs, const void* buf, size_t count) {
}
-TtyNode::TtyNode(Mount* mount, int ino, int dev)
- : NullNode(mount, ino, dev) {
+TtyNode::TtyNode(Mount* mount)
+ : NullNode(mount) {
}
int TtyNode::Write(size_t offs, const void* buf, size_t count) {
@@ -129,8 +131,9 @@ int TtyNode::Write(size_t offs, const void* buf, size_t count) {
}
-ZeroNode::ZeroNode(Mount* mount, int ino, int dev)
- : MountNode(mount, ino, dev) {
+ZeroNode::ZeroNode(Mount* mount)
+ : MountNode(mount) {
+ stat_.st_mode = S_IFCHR;
}
int ZeroNode::Read(size_t offs, void* buf, size_t count) {
@@ -142,8 +145,9 @@ int ZeroNode::Write(size_t offs, const void* buf, size_t count) {
return count;
}
-UrandomNode::UrandomNode(Mount* mount, int ino, int dev)
- : MountNode(mount, ino, dev) {
+UrandomNode::UrandomNode(Mount* mount)
+ : MountNode(mount) {
+ stat_.st_mode = S_IFCHR;
#if defined(__native_client__)
size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1, &random_interface_,
sizeof(random_interface_));
@@ -243,24 +247,24 @@ bool MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
if (!Mount::Init(dev, args, ppapi))
return false;
- root_ = new MountNodeDir(this, 1, dev_);
- null_node_ = new NullNode(this, 2, dev_);
+ root_ = new MountNodeDir(this);
+ null_node_ = new NullNode(this);
root_->AddChild("/null", null_node_);
- zero_node_ = new ZeroNode(this, 3, dev_);
+ zero_node_ = new ZeroNode(this);
root_->AddChild("/zero", zero_node_);
- random_node_ = new UrandomNode(this, 4, dev_);
+ random_node_ = new UrandomNode(this);
root_->AddChild("/urandom", random_node_);
- console0_node_ = new ConsoleNode(this, 5, dev_, PP_LOGLEVEL_TIP);
+ console0_node_ = new ConsoleNode(this, PP_LOGLEVEL_TIP);
root_->AddChild("/console0", console0_node_);
- console1_node_ = new ConsoleNode(this, 6, dev_, PP_LOGLEVEL_LOG);
+ console1_node_ = new ConsoleNode(this, PP_LOGLEVEL_LOG);
root_->AddChild("/console1", console1_node_);
- console2_node_ = new ConsoleNode(this, 7, dev_, PP_LOGLEVEL_WARNING);
+ console2_node_ = new ConsoleNode(this, PP_LOGLEVEL_WARNING);
root_->AddChild("/console2", console2_node_);
- console3_node_ = new ConsoleNode(this, 8, dev_, PP_LOGLEVEL_ERROR);
+ console3_node_ = new ConsoleNode(this, PP_LOGLEVEL_ERROR);
root_->AddChild("/console3", console3_node_);
- tty_node_ = new TtyNode(this, 9, dev_);
+ tty_node_ = new TtyNode(this);
root_->AddChild("/tty", tty_node_);
return true;
}
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_html5fs.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_html5fs.cc
index 6c18d73..1eff4bc 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_html5fs.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_html5fs.cc
@@ -33,12 +33,8 @@ MountNode *MountHtml5Fs::Open(const Path& path, int mode) {
if (!fileref)
return NULL;
- // TODO(binji): Are these needed?
- const int ino = 0;
- const int USR_ID = 1;
- const int GRP_ID = 2;
- MountNodeHtml5Fs* node = new MountNodeHtml5Fs(this, ino, dev_, fileref);
- if (!node->Init(mode, USR_ID, GRP_ID)) {
+ MountNodeHtml5Fs* node = new MountNodeHtml5Fs(this, fileref);
+ if (!node->Init(mode)) {
node->Release();
return NULL;
}
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_http.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_http.cc
index f1c19b1..0bcdd27 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_http.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_http.cc
@@ -22,9 +22,6 @@
#define snprintf _snprintf
#endif
-static const int USR_ID = 1001;
-static const int GRP_ID = 1002;
-
typedef std::vector<char *> StringList_t;
static size_t SplitString(char *str, const char *delim, StringList_t* list) {
@@ -163,8 +160,7 @@ class MountNodeHttp : public MountNode {
virtual size_t GetSize();
protected:
- MountNodeHttp(Mount* mount, int ino, int dev, const std::string& url);
- virtual int Close();
+ MountNodeHttp(Mount* mount, const std::string& url);
private:
bool OpenUrl(const char* method,
@@ -363,17 +359,11 @@ size_t MountNodeHttp::GetSize() {
return stat_.st_size;
}
-MountNodeHttp::MountNodeHttp(Mount* mount, int ino, int dev,
- const std::string& url)
- : MountNode(mount, ino, dev),
+MountNodeHttp::MountNodeHttp(Mount* mount, const std::string& url)
+ : MountNode(mount),
url_(url) {
}
-
-int MountNodeHttp::Close() {
- return 0;
-}
-
bool MountNodeHttp::OpenUrl(const char* method,
StringMap_t* request_headers,
PP_Resource* out_loader,
@@ -471,8 +461,8 @@ MountNode *MountHttp::Open(const Path& path, int mode) {
path.Range(1, path.Size()) :
path.Join());
- MountNodeHttp* node = new MountNodeHttp(this, num_nodes_++, dev_, url);
- if (!node->Init(mode, USR_ID, GRP_ID) || (0 != node->GetStat(NULL))) {
+ MountNodeHttp* node = new MountNodeHttp(this, url);
+ if (!node->Init(mode) || (0 != node->GetStat(NULL))) {
node->Release();
return NULL;
}
@@ -600,8 +590,8 @@ MountNodeDir* MountHttp::FindOrCreateDir(const Path& path) {
}
// If the node does not exist, create it, and add it to the node cache
- MountNodeDir* node = new MountNodeDir(this, num_nodes_, dev_);
- node->Init(S_IREAD, USR_ID, GRP_ID);
+ MountNodeDir* node = new MountNodeDir(this);
+ node->Init(S_IREAD);
node_cache_[strpath] = node;
// If not the root node, find the parent node and add it to the parent
@@ -662,8 +652,8 @@ bool MountHttp::ParseManifest(char *text) {
path.Range(1, path.Size()) :
path.Join());
- MountNode* node = new MountNodeHttp(this, num_nodes_, dev_, url);
- node->Init(mode, USR_ID, GRP_ID);
+ MountNode* node = new MountNodeHttp(this, url);
+ node->Init(mode);
node->stat_.st_size = atoi(lenstr);
MountNodeDir* dir_node = FindOrCreateDir(path.Parent());
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_mem.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_mem.cc
index 3a81dd3..8a61dc0 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_mem.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_mem.cc
@@ -39,53 +39,23 @@ void MountMem::Destroy() {
}
MountNode* MountMem::AllocatePath(int mode) {
- ino_t ino = AllocateINO();
-
- MountNode *ptr = new MountNodeDir(this, ino, dev_);
- if (!ptr->Init(mode, USR_ID, GRP_ID)) {
+ MountNode *ptr = new MountNodeDir(this);
+ if (!ptr->Init(mode)) {
ptr->Release();
- FreeINO(ino);
return NULL;
}
return ptr;
}
MountNode* MountMem::AllocateData(int mode) {
- ino_t ino = AllocateINO();
-
- MountNode* ptr = new MountNodeMem(this, ino, dev_);
- //if (!ptr->Init(mode, getuid(), getgid())) {
- if (!ptr->Init(mode, USR_ID, GRP_ID)) {
+ MountNode* ptr = new MountNodeMem(this);
+ if (!ptr->Init(mode)) {
ptr->Release();
- FreeINO(ino);
return NULL;
}
return ptr;
}
-int MountMem::AllocateINO() {
- const int INO_CNT = 8;
-
- // If we run out of INO numbers, then allocate 8 more
- if (inos_.size() == 0) {
- max_ino_ += INO_CNT;
- // Add eight more to the stack in reverse order, offset by 1
- // since '0' refers to no INO.
- for (int a = 0; a < INO_CNT; a++) {
- inos_.push_back(max_ino_ - a);
- }
- }
-
- // Return the INO at the top of the stack.
- int val = inos_.back();
- inos_.pop_back();
- return val;
-}
-
-void MountMem::FreeINO(int ino) {
- inos_.push_back(ino);
-}
-
MountNode* MountMem::FindNode(const Path& path, int type) {
MountNode* node = root_;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_mem.h b/native_client_sdk/src/libraries/nacl_mounts/mount_mem.h
index e3cdec9..375e94e 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_mem.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_mem.h
@@ -31,8 +31,6 @@ class MountMem : public Mount {
virtual MountNode* FindNode(const Path& path, int type = 0);
public:
- typedef std::vector<ino_t> INOList_t;
-
virtual MountNode *Open(const Path& path, int mode);
virtual int Unlink(const Path& path);
virtual int Mkdir(const Path& path, int perm);
@@ -47,7 +45,6 @@ private:
int RemoveInternal(const Path& path, int remove_type);
MountNode* root_;
- INOList_t inos_;
size_t max_ino_;
friend class Mount;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_node.cc
index 5572ad4..f965b21 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node.cc
@@ -13,36 +13,32 @@
#include "nacl_mounts/mount.h"
#include "utils/auto_lock.h"
-MountNode::MountNode(Mount* mount, int ino, int dev)
+static const int USR_ID = 1001;
+static const int GRP_ID = 1002;
+
+MountNode::MountNode(Mount* mount)
: mount_(mount) {
memset(&stat_, 0, sizeof(stat_));
- stat_.st_ino = ino;
- stat_.st_dev = dev;
+ stat_.st_gid = GRP_ID;
+ stat_.st_uid = USR_ID;
// Mount should normally never be NULL, but may be null in tests.
if (mount_)
- mount_->OnNodeCreated();
+ mount_->OnNodeCreated(this);
}
MountNode::~MountNode() {
- if (mount_)
- mount_->OnNodeDestroyed();
}
-bool MountNode::Init(int mode, short uid, short gid) {
- stat_.st_mode = mode;
- stat_.st_gid = gid;
- stat_.st_uid = uid;
+bool MountNode::Init(int perm) {
+ stat_.st_mode |= perm;
return true;
}
void MountNode::Destroy() {
- Close();
-}
-
-int MountNode::Close() {
- FSync();
- return 0;
+ if (mount_) {
+ mount_->OnNodeDestroyed(this);
+ }
}
int MountNode::FSync() {
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node.h b/native_client_sdk/src/libraries/nacl_mounts/mount_node.h
index 0da2c32..c52e765 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node.h
@@ -16,16 +16,12 @@ class Mount;
class MountNode : public RefObject {
protected:
+ explicit MountNode(Mount* mount);
virtual ~MountNode();
- // This method is called by Destroy when the last reference to this
- // MountNode is released. Override this instead of Destroy, but do not call
- // it directly.
- virtual int Close();
-
protected:
- MountNode(Mount* mount, int ino, int dev);
- virtual bool Init(int mode, short uid, short gid);
+ // Initialize with node specific flags, in this case stat permissions.
+ virtual bool Init(int flags);
virtual void Destroy();
public:
@@ -68,6 +64,7 @@ protected:
struct stat stat_;
Mount* mount_;
+ friend class Mount;
friend class MountDev;
friend class MountHtml5Fs;
friend class MountHttp;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.cc
index 0d27cc3..230592c 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.cc
@@ -12,21 +12,16 @@
#include "utils/macros.h"
#include "utils/auto_lock.h"
-MountNodeDir::MountNodeDir(Mount* mount, int ino, int dev)
- : MountNode(mount, ino, dev),
+MountNodeDir::MountNodeDir(Mount* mount)
+ : MountNode(mount),
cache_(NULL) {
+ stat_.st_mode |= S_IFDIR;
}
MountNodeDir::~MountNodeDir() {
free(cache_);
}
-bool MountNodeDir::Init(int mode, short uid, short gid) {
- bool ok = MountNode::Init(mode, uid, gid);
- stat_.st_mode |= S_IFDIR;
- return ok;
-}
-
int MountNodeDir::Read(size_t offs, void *buf, size_t count) {
errno = EISDIR;
return -1;
@@ -69,7 +64,7 @@ int MountNodeDir::GetDents(size_t offs, struct dirent* pdir, size_t size) {
return size;
}
-int MountNodeDir:: AddChild(const std::string& name, MountNode* node) {
+int MountNodeDir::AddChild(const std::string& name, MountNode* node) {
AutoLock lock(&lock_);
if (name.empty()) {
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.h b/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.h
index 118ead2..4a32831 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_dir.h
@@ -19,9 +19,8 @@ class MountMem;
class MountNodeDir : public MountNode {
protected:
- MountNodeDir(Mount *mount, int ino, int dev);
+ explicit MountNodeDir(Mount* mnt);
virtual ~MountNodeDir();
- virtual bool Init(int mode, short uid, short gid);
public:
typedef std::map<std::string, MountNode*> MountNodeMap_t;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.cc
index 7652946..ba0ca73 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.cc
@@ -215,15 +215,14 @@ size_t MountNodeHtml5Fs::GetSize() {
return static_cast<size_t>(info.size);
}
-MountNodeHtml5Fs::MountNodeHtml5Fs(Mount* mount, int ino, int dev,
- PP_Resource fileref_resource)
- : MountNode(mount, ino, dev),
+MountNodeHtml5Fs::MountNodeHtml5Fs(Mount* mount, PP_Resource fileref_resource)
+ : MountNode(mount),
fileref_resource_(fileref_resource),
fileio_resource_(0) {
}
-bool MountNodeHtml5Fs::Init(int mode, short uid, short gid) {
- if (!MountNode::Init(Mount::OpenModeToPermission(mode), uid, gid))
+bool MountNodeHtml5Fs::Init(int perm) {
+ if (!MountNode::Init(Mount::OpenModeToPermission(perm)))
return false;
fileio_resource_= mount_->ppapi()->GetFileIoInterface()->Create(
@@ -232,7 +231,7 @@ bool MountNodeHtml5Fs::Init(int mode, short uid, short gid) {
return false;
int32_t open_result = mount_->ppapi()->GetFileIoInterface()->Open(
- fileio_resource_, fileref_resource_, ModeToOpenFlags(mode),
+ fileio_resource_, fileref_resource_, ModeToOpenFlags(perm),
PP_BlockUntilComplete());
if (open_result != PP_OK)
return false;
@@ -240,7 +239,9 @@ bool MountNodeHtml5Fs::Init(int mode, short uid, short gid) {
return true;
}
-int MountNodeHtml5Fs::Close() {
+void MountNodeHtml5Fs::Destroy() {
+ FSync();
+
if (fileio_resource_) {
mount_->ppapi()->GetFileIoInterface()->Close(fileio_resource_);
mount_->ppapi()->ReleaseResource(fileio_resource_);
@@ -249,5 +250,5 @@ int MountNodeHtml5Fs::Close() {
mount_->ppapi()->ReleaseResource(fileref_resource_);
fileio_resource_ = 0;
fileref_resource_ = 0;
- return 0;
+ MountNode::Destroy();
}
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.h b/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.h
index 8f2d15a..62a6d31 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_html5fs.h
@@ -25,9 +25,11 @@ class MountNodeHtml5Fs : public MountNode {
virtual size_t GetSize();
protected:
- MountNodeHtml5Fs(Mount* mount, int ino, int dev, PP_Resource fileref);
- virtual bool Init(int mode, short uid, short gid);
- virtual int Close();
+ MountNodeHtml5Fs(Mount* mount, PP_Resource fileref);
+
+ // Init with standard open flags
+ virtual bool Init(int o_mode);
+ virtual void Destroy();
private:
PP_Resource fileref_resource_;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.cc b/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.cc
index 07adb9d..7cb01b5 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.cc
@@ -13,22 +13,17 @@
#define BLOCK_SIZE (1 << 16)
#define BLOCK_MASK (BLOCK_SIZE - 1)
-MountNodeMem::MountNodeMem(Mount *mount, int ino, int dev)
- : MountNode(mount, ino, dev),
+MountNodeMem::MountNodeMem(Mount *mount)
+ : MountNode(mount),
data_(NULL),
capacity_(0) {
+ stat_.st_mode |= S_IFREG;
}
MountNodeMem::~MountNodeMem() {
free(data_);
}
-bool MountNodeMem::Init(int mode, short uid, short gid) {
- bool ok = MountNode::Init(mode, uid, gid);
- stat_.st_mode |= S_IFREG;
- return ok;
-}
-
int MountNodeMem::Read(size_t offs, void *buf, size_t count) {
AutoLock lock(&lock_);
if (count == 0) return 0;
diff --git a/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.h b/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.h
index e82a867..ded4cc3 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/mount_node_mem.h
@@ -9,11 +9,10 @@
class MountNodeMem : public MountNode {
public:
- MountNodeMem(Mount* mount, int ino, int dev);
+ explicit MountNodeMem(Mount* mount);
protected:
virtual ~MountNodeMem();
- virtual bool Init(int mode, short uid, short gid);
public:
// Normal read/write operations on a file
diff --git a/native_client_sdk/src/libraries/nacl_mounts/osstat.h b/native_client_sdk/src/libraries/nacl_mounts/osstat.h
index c11ea35..b02c2af 100644
--- a/native_client_sdk/src/libraries/nacl_mounts/osstat.h
+++ b/native_client_sdk/src/libraries/nacl_mounts/osstat.h
@@ -10,10 +10,13 @@
#if defined(WIN32)
#define S_IFCHR _S_IFCHR
#define S_IFDIR _S_IFDIR
-#define S_IFMT _S_IFMT
+#define S_IFIFO _S_IFIFO
#define S_IFREG _S_IFREG
+#define S_IFMT _S_IFMT
+
#define S_IREAD _S_IREAD
#define S_IWRITE _S_IWRITE
+#define S_IEXEC _S_IEXEC
#endif
#endif // LIBRARIES_NACL_MOUNTS_OSSTAT_H_
diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/mount_html5fs_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/mount_html5fs_test.cc
index 03b87e3..0125b6a 100644
--- a/native_client_sdk/src/libraries/nacl_mounts_test/mount_html5fs_test.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts_test/mount_html5fs_test.cc
@@ -161,6 +161,7 @@ void MountHtml5FsNodeTest::SetUp() {
EXPECT_CALL(*fileio_, Close(fileio_resource_));
EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_));
EXPECT_CALL(*ppapi_, ReleaseResource(fileio_resource_));
+ EXPECT_CALL(*fileio_, Flush(fileio_resource_, _));
node_ = mnt_->Open(Path(path_), O_CREAT | O_RDWR);
ASSERT_NE((MountNode*)NULL, node_);
diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc
index 76eb978..9342798 100644
--- a/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts_test/mount_node_test.cc
@@ -20,7 +20,7 @@ static int s_AllocNum = 0;
class MockMemory : public MountNodeMem {
public:
- MockMemory() : MountNodeMem(NULL, 0, 0) {
+ MockMemory() : MountNodeMem(NULL) {
s_AllocNum++;
}
@@ -29,7 +29,7 @@ class MockMemory : public MountNodeMem {
}
bool Init(int mode) {
- return MountNodeMem::Init(mode,0,0);
+ return MountNodeMem::Init(mode);
}
int AddChild(const std::string& name, MountNode *node) {
return MountNodeMem::AddChild(name, node);
@@ -49,7 +49,7 @@ class MockMemory : public MountNodeMem {
class MockDir : public MountNodeDir {
public:
- MockDir() : MountNodeDir(NULL, 0, 0) {
+ MockDir() : MountNodeDir(NULL) {
s_AllocNum++;
}
@@ -58,7 +58,7 @@ class MockDir : public MountNodeDir {
}
bool Init(int mode) {
- return MountNodeDir::Init(mode,0,0);
+ return MountNodeDir::Init(mode);
}
int AddChild(const std::string& name, MountNode *node) {
return MountNodeDir::AddChild(name, node);
diff --git a/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc b/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc
index cf89f4b..34c7ce6a 100644
--- a/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc
+++ b/native_client_sdk/src/libraries/nacl_mounts_test/mount_test.cc
@@ -24,6 +24,10 @@ class MountMemMock : public MountMem {
StringMap_t map;
Init(1, map, NULL);
};
+
+ int num_nodes() {
+ return (int) inode_pool_.size();
+ }
};
class MountDevMock : public MountDev {
@@ -32,6 +36,9 @@ class MountDevMock : public MountDev {
StringMap_t map;
Init(1, map, NULL);
}
+ int num_nodes() {
+ return (int) inode_pool_.size();
+ }
};
} // namespace