summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorbradnelson <bradnelson@google.com>2014-09-12 02:31:58 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-12 09:39:29 +0000
commit4af11334ed84a0280f0b0d2eedb2efd748f20b72 (patch)
treeab94f0904940158c4b748a3d88463c682d0f7b83 /native_client_sdk
parentd8a14b38c4934f78153ee74a0a6f621a84b6017e (diff)
downloadchromium_src-4af11334ed84a0280f0b0d2eedb2efd748f20b72.zip
chromium_src-4af11334ed84a0280f0b0d2eedb2efd748f20b72.tar.gz
chromium_src-4af11334ed84a0280f0b0d2eedb2efd748f20b72.tar.bz2
Plumbing though mode parameter to open, since fusefs can make use of it.
Hooking it up where it makes sense in other mounts. BUG=https://code.google.com/p/chromium/issues/detail?id=413397 TEST=None R=binji@chromium.org Review URL: https://codereview.chromium.org/565763002 Cr-Commit-Position: refs/heads/master@{#294561}
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.cc3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/filesystem.cc6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/filesystem.h14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.cc3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.cc3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc4
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_intercept.h2
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_object.cc6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_object.h2
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc16
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_proxy.h2
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_dummy.cc2
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h2
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc4
-rw-r--r--native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.cc5
-rw-r--r--native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.h3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/stream/stream_fs.cc3
-rw-r--r--native_client_sdk/src/libraries/nacl_io/stream/stream_fs.h3
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/event_test.cc12
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc21
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/jspipe_test.cc2
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/kernel_object_test.cc3
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc76
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc8
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/mock_fs.h1
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/mock_kernel_proxy.h2
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/tty_test.cc12
39 files changed, 166 insertions, 112 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.cc b/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.cc
index f29e411..108bdd2 100644
--- a/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.cc
@@ -240,7 +240,8 @@ Error FsNode::VIoctl(int request, va_list args) {
} // namespace
-Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error DevFs::OpenWithMode(const Path& path, int open_flags,
+ mode_t mode, ScopedNode* out_node) {
out_node->reset(NULL);
int error;
if (path.Part(1) == "fs") {
diff --git a/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.h b/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.h
index 9d20b6b..872f77e 100644
--- a/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/devfs/dev_fs.h
@@ -14,7 +14,8 @@ class Node;
class DevFs : public Filesystem {
public:
- virtual Error Open(const Path& path, int open_flags, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/filesystem.cc b/native_client_sdk/src/libraries/nacl_io/filesystem.cc
index feda1e7..2577a3a 100644
--- a/native_client_sdk/src/libraries/nacl_io/filesystem.cc
+++ b/native_client_sdk/src/libraries/nacl_io/filesystem.cc
@@ -39,6 +39,12 @@ Error Filesystem::Init(const FsInitArgs& args) {
void Filesystem::Destroy() {
}
+Error Filesystem::Open(const Path& path,
+ int open_flags,
+ ScopedNode* out_node) {
+ return OpenWithMode(path, open_flags, 0666, out_node);
+}
+
Error Filesystem::OpenResource(const Path& path, ScopedNode* out_node) {
out_node->reset(NULL);
LOG_TRACE("Can't open resource: %s", path.Join().c_str());
diff --git a/native_client_sdk/src/libraries/nacl_io/filesystem.h b/native_client_sdk/src/libraries/nacl_io/filesystem.h
index 8194100..862c527 100644
--- a/native_client_sdk/src/libraries/nacl_io/filesystem.h
+++ b/native_client_sdk/src/libraries/nacl_io/filesystem.h
@@ -62,12 +62,20 @@ class Filesystem : public sdk_util::RefObject {
// All paths in functions below are expected to containing a leading "/".
+ // Open a node at |path| with the specified open and modeflags. The resulting
+ // Node is created with a ref count of 1.
+ // Assumes that |out_node| is non-NULL.
+ virtual Error OpenWithMode(const Path& path,
+ int open_flags,
+ mode_t mode,
+ ScopedNode* out_node) = 0;
+
// Open a node at |path| with the specified open flags. The resulting
// Node is created with a ref count of 1.
// Assumes that |out_node| is non-NULL.
- virtual Error Open(const Path& path,
- int open_flags,
- ScopedNode* out_node) = 0;
+ Error Open(const Path& path,
+ int open_flags,
+ ScopedNode* out_node);
// OpenResource is only used to read files from the NaCl NMF file. No
// filesystem except PassthroughFs should implement it.
diff --git a/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc b/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc
index fe4c8ec..be3fe66 100644
--- a/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc
@@ -57,7 +57,8 @@ void FuseFs::Destroy() {
fuse_ops_->destroy(fuse_user_data_);
}
-Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error FuseFs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node) {
std::string path_str = path.Join();
const char* path_cstr = path_str.c_str();
int result = 0;
@@ -69,7 +70,6 @@ Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
if (open_flags & (O_CREAT | O_EXCL)) {
// According to the FUSE docs, open() is not called when O_CREAT or O_EXCL
// is passed.
- mode_t mode = S_IRALL | S_IWALL;
if (fuse_ops_->create) {
result = fuse_ops_->create(path_cstr, mode, &fi);
if (result < 0)
@@ -101,6 +101,8 @@ Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
*out_node = node;
return 0;
}
+ // Get mode.
+ mode = statbuf.st_mode & ~S_IFMT;
}
// Existing file.
@@ -129,6 +131,7 @@ Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
Error error = node->Init(open_flags);
if (error)
return error;
+ node->SetMode(mode);
*out_node = node;
return 0;
diff --git a/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.h b/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.h
index 1673b08..3ddc289 100644
--- a/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.h
@@ -21,7 +21,8 @@ class FuseFs : public Filesystem {
virtual void Destroy();
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
index 1cd8c37..c747733 100644
--- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
@@ -29,7 +29,8 @@ int64_t strtoull(const char* nptr, char** endptr, int base) {
} // namespace
-Error Html5Fs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node) {
out_node->reset(NULL);
Error error = BlockUntilFilesystemOpen();
if (error)
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h
index 40bc314..bf4c249 100644
--- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h
@@ -18,7 +18,8 @@ class Node;
class Html5Fs : public Filesystem {
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.cc b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.cc
index 74e7383..1950bb1 100644
--- a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.cc
@@ -41,7 +41,8 @@ std::string NormalizeHeaderKey(const std::string& s) {
return result;
}
-Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error HttpFs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node) {
out_node->reset(NULL);
ScopedNode node = FindExistingNode(path);
diff --git a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.h b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.h
index a5bca62..b481cc4 100644
--- a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs.h
@@ -18,7 +18,8 @@ class HttpFs : public Filesystem {
public:
typedef std::map<std::string, ScopedNode> NodeMap_t;
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.cc b/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.cc
index b0f18a5..26d2e14 100644
--- a/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.cc
@@ -391,7 +391,8 @@ PP_Var JsFs::WaitForResponse(RequestId request_id) {
}
}
-Error JsFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error JsFs::OpenWithMode(const Path& path, int open_flags, mode_t t,
+ ScopedNode* out_node) {
out_node->reset(NULL);
ScopedVar response(ppapi_);
if (!SendRequestAndWait(&response, "%s%s%d",
diff --git a/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.h b/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.h
index 901ac57..08b1e4c 100644
--- a/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/jsfs/js_fs.h
@@ -35,7 +35,8 @@ class JsFs : public Filesystem {
virtual void Destroy();
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
index 7d34517..218c76fc 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
@@ -221,9 +221,9 @@ int ki_umount(const char* path) {
return s_state.kp->umount(path);
}
-int ki_open(const char* path, int oflag) {
+int ki_open(const char* path, int oflag, mode_t mode) {
ON_NOSYS_RETURN(-1);
- return s_state.kp->open(path, oflag);
+ return s_state.kp->open(path, oflag, mode);
}
int ki_pipe(int pipefds[2]) {
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
index a9ad290..aad26842 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
@@ -85,7 +85,7 @@ int ki_mount(const char* source,
unsigned long mountflags,
const void* data);
int ki_umount(const char* path);
-int ki_open(const char* path, int oflag);
+int ki_open(const char* path, int oflag, mode_t mode);
int ki_pipe(int pipefds[2]);
ssize_t ki_read(int fd, void* buf, size_t nbyte);
ssize_t ki_write(int fd, const void* buf, size_t nbyte);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
index 853947f..c9f3f2ef 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
@@ -99,7 +99,7 @@ Error KernelObject::AcquireFsAndRelPath(const std::string& path,
// Given a path, acquire the associated filesystem and node, creating the
// node if needed based on the provided flags.
Error KernelObject::AcquireFsAndNode(const std::string& path,
- int oflags,
+ int oflags, mode_t mflags,
ScopedFilesystem* out_fs,
ScopedNode* out_node) {
Path rel_parts;
@@ -109,7 +109,7 @@ Error KernelObject::AcquireFsAndNode(const std::string& path,
if (error)
return error;
- error = (*out_fs)->Open(rel_parts, oflags, out_node);
+ error = (*out_fs)->OpenWithMode(rel_parts, oflags, mflags, out_node);
if (error)
return error;
@@ -143,7 +143,7 @@ Error KernelObject::SetCWD(const std::string& path) {
ScopedFilesystem fs;
ScopedNode node;
- Error error = AcquireFsAndNode(abs_path, O_RDONLY, &fs, &node);
+ Error error = AcquireFsAndNode(abs_path, O_RDONLY, 0, &fs, &node);
if (error)
return error;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.h b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
index 5563cf3..2f707e0 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
@@ -62,7 +62,7 @@ class KernelObject {
// specified by the |oflags|.
// Assumes |out_fs| and |out_node| are non-NULL.
Error AcquireFsAndNode(const std::string& path,
- int oflags,
+ int oflags, mode_t mflags,
ScopedFilesystem* out_fs,
ScopedNode* out_node);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
index 6d52caf..20d78f2 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -104,17 +104,17 @@ Error KernelProxy::Init(PepperInterface* ppapi) {
// Open the first three in order to get STDIN, STDOUT, STDERR
int fd;
- fd = open("/dev/stdin", O_RDONLY);
+ fd = open("/dev/stdin", O_RDONLY, 0);
assert(fd == 0);
if (fd < 0)
rtn = errno;
- fd = open("/dev/stdout", O_WRONLY);
+ fd = open("/dev/stdout", O_WRONLY, 0);
assert(fd == 1);
if (fd < 0)
rtn = errno;
- fd = open("/dev/stderr", O_WRONLY);
+ fd = open("/dev/stderr", O_WRONLY, 0);
assert(fd == 2);
if (fd < 0)
rtn = errno;
@@ -199,11 +199,11 @@ int KernelProxy::open_resource(const char* path) {
return AllocateFD(handle, path);
}
-int KernelProxy::open(const char* path, int open_flags) {
+int KernelProxy::open(const char* path, int open_flags, mode_t mode) {
ScopedFilesystem fs;
ScopedNode node;
- Error error = AcquireFsAndNode(path, open_flags, &fs, &node);
+ Error error = AcquireFsAndNode(path, open_flags, mode, &fs, &node);
if (error) {
errno = error;
return -1;
@@ -324,7 +324,7 @@ char* KernelProxy::getwd(char* buf) {
}
int KernelProxy::chmod(const char* path, mode_t mode) {
- int fd = KernelProxy::open(path, O_RDONLY);
+ int fd = KernelProxy::open(path, O_RDONLY, mode);
if (-1 == fd)
return -1;
@@ -388,7 +388,7 @@ int KernelProxy::rmdir(const char* path) {
}
int KernelProxy::stat(const char* path, struct stat* buf) {
- int fd = open(path, O_RDONLY);
+ int fd = open(path, O_RDONLY, 0);
if (-1 == fd)
return -1;
@@ -718,7 +718,7 @@ int KernelProxy::unlink(const char* path) {
}
int KernelProxy::truncate(const char* path, off_t len) {
- int fd = KernelProxy::open(path, O_WRONLY);
+ int fd = KernelProxy::open(path, O_WRONLY, 0);
if (-1 == fd)
return -1;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
index 046d922..0cfdbff 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
@@ -67,7 +67,7 @@ class KernelProxy : protected KernelObject {
virtual int open_resource(const char* file);
// KernelHandle and FD allocation and manipulation functions.
- virtual int open(const char* path, int open_flags);
+ virtual int open(const char* path, int open_flags, mode_t mode);
virtual int close(int fd);
virtual int dup(int fd);
virtual int dup2(int fd, int newfd);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc
index 271aa6e..7bdf4f9 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc
@@ -264,8 +264,8 @@ int WRAP(munmap)(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
- *newfd = ki_open(pathname, oflag);
+int WRAP(open)(const char* pathname, int oflag, mode_t mode, int* newfd) {
+ *newfd = ki_open(pathname, oflag, mode);
ERRNO_RTN(*newfd);
}
@@ -468,9 +468,9 @@ int _real_munmap(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) {
+int _real_open(const char* pathname, int oflag, mode_t mode, int* newfd) {
CHECK_REAL(open);
- return REAL(open)(pathname, oflag, cmode, newfd);
+ return REAL(open)(pathname, oflag, mode, newfd);
}
int _real_open_resource(const char* file, int* fd) {
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_dummy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_dummy.cc
index c384e3b..c4d0df8 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_dummy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_dummy.cc
@@ -48,7 +48,7 @@ int _real_munmap(void* addr, size_t length) {
return ENOSYS;
}
-int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) {
+int _real_open(const char* pathname, int oflag, mode_t mode, int* newfd) {
return ENOSYS;
}
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
index 0cc3e90..58fa1c1 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
@@ -272,8 +272,8 @@ int WRAP(munmap)(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
- *newfd = ki_open(pathname, oflag);
+int WRAP(open)(const char* pathname, int oflag, mode_t mode, int* newfd) {
+ *newfd = ki_open(pathname, oflag, mode);
RTN_ERRNO_IF(*newfd < 0);
return 0;
}
@@ -606,9 +606,9 @@ int _real_munmap(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) {
+int _real_open(const char* pathname, int oflag, mode_t mode, int* newfd) {
CHECK_REAL(open);
- return REAL(open)(pathname, oflag, cmode, newfd);
+ return REAL(open)(pathname, oflag, mode, newfd);
}
int _real_open_resource(const char* file, int* fd) {
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
index f560d3b..ebe8dd5 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
@@ -185,8 +185,8 @@ int WRAP(munmap)(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int WRAP(open)(const char* pathname, int oflag, mode_t cmode, int* newfd) {
- *newfd = ki_open(pathname, oflag);
+int WRAP(open)(const char* pathname, int oflag, mode_t mode, int* newfd) {
+ *newfd = ki_open(pathname, oflag, mode);
ERRNO_RTN(*newfd);
}
@@ -335,9 +335,9 @@ int _real_munmap(void* addr, size_t length) {
return REAL(munmap)(addr, length);
}
-int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd) {
+int _real_open(const char* pathname, int oflag, mode_t mode, int* newfd) {
CHECK_REAL(open);
- return REAL(open)(pathname, oflag, cmode, newfd);
+ return REAL(open)(pathname, oflag, mode, newfd);
}
int _real_open_resource(const char* file, int* fd) {
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
index 3dd9297..86b65e4 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
@@ -26,7 +26,7 @@ int _real_mmap(void** addr,
int fd,
int64_t offset);
int _real_munmap(void* addr, size_t length);
-int _real_open(const char* pathname, int oflag, mode_t cmode, int* newfd);
+int _real_open(const char* pathname, int oflag, mode_t mode, int* newfd);
int _real_open_resource(const char* file, int* fd);
int _real_read(int fd, void* buf, size_t count, size_t* nread);
int _real_rmdir(const char* pathname);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
index d617788..18c903d 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
@@ -129,9 +129,6 @@ int _mkdir(const char* path) {
}
int _open(const char* path, int oflag, ...) {
-#if 0
- // TODO(binji): ki_open should use the pmode parameter. When it does, this
- // will be necessary to add in.
va_list list;
int pmode = 0;
if (oflag & _O_CREAT) {
@@ -139,8 +136,7 @@ int _open(const char* path, int oflag, ...) {
pmode = va_arg(list, int);
va_end(list);
}
-#endif
- return ki_open(path, oflag);
+ return ki_open(path, oflag, (mode_t) pmode);
}
int _sopen(const char* path, int oflag, int shflag) {
diff --git a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc
index a159c32..111dc6f 100644
--- a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc
@@ -75,7 +75,8 @@ Error MemFs::FindNode(const Path& path, int type, ScopedNode* out_node) {
return 0;
}
-Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
+Error MemFs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node) {
out_node->reset(NULL);
ScopedNode node;
@@ -95,6 +96,7 @@ Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
error = node->Init(open_flags);
if (error)
return error;
+ node->SetMode(mode);
error = parent->AddChild(path.Basename(), node);
if (error)
diff --git a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.h b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.h
index 3438d79..51ccc06 100644
--- a/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.h
@@ -29,7 +29,8 @@ class MemFs : public Filesystem {
virtual Error FindNode(const Path& path, int type, ScopedNode* out_node);
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.cc b/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.cc
index 2858faf..abee3894 100644
--- a/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.cc
@@ -22,10 +22,11 @@ Error PassthroughFs::Init(const FsInitArgs& args) {
void PassthroughFs::Destroy() {
}
-Error PassthroughFs::Open(const Path& path, int mode, ScopedNode* out_node) {
+Error PassthroughFs::OpenWithMode(const Path& path, int open_flags,
+ mode_t mode, ScopedNode* out_node) {
out_node->reset(NULL);
int real_fd;
- int error = _real_open(path.Join().c_str(), mode, 0666, &real_fd);
+ int error = _real_open(path.Join().c_str(), open_flags, mode, &real_fd);
if (error)
return error;
diff --git a/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.h b/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.h
index baad6cd..8c7c86e 100644
--- a/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/passthroughfs/passthrough_fs.h
@@ -18,7 +18,8 @@ class PassthroughFs : public Filesystem {
virtual void Destroy();
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error OpenResource(const Path& path, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
diff --git a/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.cc b/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.cc
index a7d9184..703874f 100644
--- a/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.cc
@@ -84,7 +84,8 @@ StreamFs::~StreamFs() {
pthread_cond_destroy(&message_cond_);
}
-Error StreamFs::Open(const Path& path, int o_flags, ScopedNode* out_node) {
+Error StreamFs::OpenWithMode(const Path& path, int o_flags, mode_t mode,
+ ScopedNode* out_node) {
return EACCES;
}
diff --git a/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.h b/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.h
index ea136eb..d9f77c7 100644
--- a/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/stream/stream_fs.h
@@ -54,7 +54,8 @@ class StreamFs : public Filesystem {
// of a MountSocketWork object.
static PP_CompletionCallback GetRunCompletion(Work* work);
- virtual Error Open(const Path& path, int o_flags, ScopedNode* out_node);
+ virtual Error OpenWithMode(const Path& path, int o_flags, mode_t mode,
+ ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
virtual Error Rmdir(const Path& path);
diff --git a/native_client_sdk/src/tests/nacl_io_test/event_test.cc b/native_client_sdk/src/tests/nacl_io_test/event_test.cc
index b450f3c..8084df0 100644
--- a/native_client_sdk/src/tests/nacl_io_test/event_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/event_test.cc
@@ -273,8 +273,8 @@ TEST_F(SelectPollTest, PollMemPipe) {
int fds[2];
// Both FDs for regular files should be read/write but not exception.
- fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY);
- fds[1] = kp->open("/test.txt", O_RDONLY);
+ fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY, 0777);
+ fds[1] = kp->open("/test.txt", O_RDONLY, 0);
ASSERT_GT(fds[0], -1);
ASSERT_GT(fds[1], -1);
@@ -302,8 +302,8 @@ TEST_F(SelectPollTest, SelectMemPipe) {
int fds[2];
// Both FDs for regular files should be read/write but not exception.
- fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY);
- fds[1] = kp->open("/test.txt", O_RDONLY);
+ fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY, 0777);
+ fds[1] = kp->open("/test.txt", O_RDONLY, 0);
ASSERT_GT(fds[0], -1);
ASSERT_GT(fds[1], -1);
SetFDs(fds, 2);
@@ -344,8 +344,8 @@ TEST_F(SelectPollTest, SelectPartialFdset) {
int fds[2];
// Both FDs for regular files should be read/write but not exception.
- fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY);
- fds[1] = kp->open("/test.txt", O_RDONLY);
+ fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY, 0777);
+ fds[1] = kp->open("/test.txt", O_RDONLY, 0);
ASSERT_GT(fds[0], -1);
ASSERT_GT(fds[1], -1);
ASSERT_LT(fds[1], 8);
diff --git a/native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc b/native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc
index 962ca81..bf4b51d 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc
@@ -36,6 +36,7 @@ struct File {
typedef std::vector<File> Files;
Files g_files;
+mode_t last_create_mode = 0666;
bool IsValidPath(const char* path) {
if (path == NULL)
@@ -74,7 +75,7 @@ int testfs_getattr(const char* path, struct stat* stbuf) {
if (file == NULL)
return -ENOENT;
- stbuf->st_mode = S_IFREG | 0666;
+ stbuf->st_mode = S_IFREG | last_create_mode;
stbuf->st_size = file->data.size();
return 0;
}
@@ -95,7 +96,7 @@ int testfs_readdir(const char* path,
return 0;
}
-int testfs_create(const char* path, mode_t, struct fuse_file_info* fi) {
+int testfs_create(const char* path, mode_t mode, struct fuse_file_info* fi) {
if (!IsValidPath(path))
return -ENOENT;
@@ -108,6 +109,7 @@ int testfs_create(const char* path, mode_t, struct fuse_file_info* fi) {
file = &g_files.back();
file->name = &path[1]; // Skip initial /
}
+ last_create_mode = mode;
return 0;
}
@@ -232,6 +234,17 @@ TEST_F(FuseFsTest, OpenAndRead) {
ASSERT_STREQ("World!\n", buffer);
}
+TEST_F(FuseFsTest, CreateWithMode) {
+ ScopedNode node;
+ struct stat statbuf;
+
+ ASSERT_EQ(0, fs_.OpenWithMode(Path("/hello"),
+ O_RDWR | O_CREAT, 0723, &node));
+ EXPECT_EQ(0, node->GetStat(&statbuf));
+ EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT);
+ EXPECT_EQ(0723, statbuf.st_mode & ~S_IFMT);
+}
+
TEST_F(FuseFsTest, CreateAndWrite) {
ScopedNode node;
ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node));
@@ -341,14 +354,14 @@ void KernelProxyFuseTest::TearDown() {
TEST_F(KernelProxyFuseTest, Basic) {
// Write a file.
- int fd = ki_open("/hello", O_WRONLY | O_CREAT);
+ int fd = ki_open("/hello", O_WRONLY | O_CREAT, 0777);
ASSERT_GT(fd, -1);
ASSERT_EQ(sizeof(hello_world),
ki_write(fd, hello_world, sizeof(hello_world)));
EXPECT_EQ(0, ki_close(fd));
// Then read it back in.
- fd = ki_open("/hello", O_RDONLY);
+ fd = ki_open("/hello", O_RDONLY, 0);
ASSERT_GT(fd, -1);
char buffer[30];
diff --git a/native_client_sdk/src/tests/nacl_io_test/jspipe_test.cc b/native_client_sdk/src/tests/nacl_io_test/jspipe_test.cc
index 788d2b5..0a8e867 100644
--- a/native_client_sdk/src/tests/nacl_io_test/jspipe_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/jspipe_test.cc
@@ -434,7 +434,7 @@ TEST_F(JSPipeTest, JSPipeSelect) {
fd_set writefds;
fd_set errorfds;
- int pipe_fd = ki_open("/dev/jspipe1", O_RDONLY);
+ int pipe_fd = ki_open("/dev/jspipe1", O_RDONLY, 0);
ASSERT_GT(pipe_fd, 0) << "jspipe1 open failed: " << errno;
FD_ZERO(&readfds);
diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_object_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_object_test.cc
index 4350aae..e168d79 100644
--- a/native_client_sdk/src/tests/nacl_io_test/kernel_object_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/kernel_object_test.cc
@@ -32,7 +32,8 @@ class FilesystemForTesting : public Filesystem {
public:
Error Access(const Path& path, int a_mode) { return ENOSYS; }
- Error Open(const Path& path, int mode, ScopedNode* out_node) {
+ Error OpenWithMode(const Path& path, int open_flags,
+ mode_t mode, ScopedNode* out_node) {
out_node->reset(NULL);
return ENOSYS;
}
diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
index 4c0ab08..7009e0c 100644
--- a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
@@ -85,7 +85,7 @@ static int ki_fcntl_wrapper(int fd, int request, ...) {
* or the filesystem node but directly in the FD mapping.
*/
TEST_F(KernelProxyTest, Fcntl_GETFD) {
- int fd = ki_open("/test", O_RDWR | O_CREAT);
+ int fd = ki_open("/test", O_RDWR | O_CREAT, 0777);
ASSERT_NE(-1, fd);
// FD flags should start as zero.
@@ -116,7 +116,7 @@ TEST_F(KernelProxyTest, FileLeak) {
for (int file_num = 0; file_num < 4096; file_num++) {
sprintf(filename, "/foo%i.tmp", file_num++);
- int fd = ki_open(filename, O_WRONLY | O_CREAT);
+ int fd = ki_open(filename, O_WRONLY | O_CREAT, 0777);
ASSERT_GT(fd, -1);
ASSERT_EQ(1, root->ChildCount());
ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size));
@@ -232,7 +232,7 @@ TEST_F(KernelProxyTest, SignalSigwinch) {
TEST_F(KernelProxyTest, Rename) {
// Create a dummy file
- int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT);
+ int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT, 0777);
ASSERT_GT(file1, -1);
ASSERT_EQ(0, ki_close(file1));
@@ -293,27 +293,27 @@ TEST_F(KernelProxyTest, FDPathMapping) {
EXPECT_EQ(0, ki_mkdir("/example", S_IREAD | S_IWRITE));
ki_chdir("/foo");
- fd1 = ki_open("/example", O_RDONLY);
+ fd1 = ki_open("/example", O_RDONLY, 0);
EXPECT_NE(-1, fd1);
EXPECT_EQ(ki_fchdir(fd1), 0);
EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
EXPECT_STREQ("/example", text);
EXPECT_EQ(0, ki_chdir("/foo"));
- fd2 = ki_open("../example", O_RDONLY);
+ fd2 = ki_open("../example", O_RDONLY, 0);
EXPECT_NE(-1, fd2);
EXPECT_EQ(0, ki_fchdir(fd2));
EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
EXPECT_STREQ("/example", text);
EXPECT_EQ(0, ki_chdir("/foo"));
- fd3 = ki_open("../test", O_CREAT | O_RDWR);
+ fd3 = ki_open("../test", O_CREAT | O_RDWR, 0777);
EXPECT_NE(-1, fd3);
EXPECT_EQ(-1, ki_fchdir(fd3));
EXPECT_EQ(ENOTDIR, errno);
EXPECT_EQ(0, ki_chdir("/foo"));
- fd4 = ki_open("bar", O_RDONLY);
+ fd4 = ki_open("bar", O_RDONLY, 0);
EXPECT_EQ(0, ki_fchdir(fd4));
EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
EXPECT_STREQ("/foo/bar", text);
@@ -360,19 +360,19 @@ TEST_F(KernelProxyTest, MemMountIO) {
EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE));
// Fail to open "/foo/bar"
- EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY));
+ EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY, 0));
EXPECT_EQ(ENOENT, errno);
// Create bar "/foo/bar"
- fd1 = ki_open("/foo/bar", O_RDWR | O_CREAT);
+ fd1 = ki_open("/foo/bar", O_RDWR | O_CREAT, 0777);
ASSERT_NE(-1, fd1);
// Open (optionally create) bar "/foo/bar"
- fd2 = ki_open("/foo/bar", O_RDWR | O_CREAT);
+ fd2 = ki_open("/foo/bar", O_RDWR | O_CREAT, 0777);
ASSERT_NE(-1, fd2);
// Fail to exclusively create bar "/foo/bar"
- EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY | O_CREAT | O_EXCL));
+ EXPECT_EQ(-1, ki_open("/foo/bar", O_RDONLY | O_CREAT | O_EXCL, 0777));
EXPECT_EQ(EEXIST, errno);
// Write hello and world to same node with different descriptors
@@ -380,7 +380,7 @@ TEST_F(KernelProxyTest, MemMountIO) {
EXPECT_EQ(5, ki_write(fd2, "WORLD", 5));
EXPECT_EQ(5, ki_write(fd1, "HELLO", 5));
- fd3 = ki_open("/foo/bar", O_RDONLY);
+ fd3 = ki_open("/foo/bar", O_RDONLY, 0);
ASSERT_NE(-1, fd3);
len = ki_read(fd3, text, sizeof(text));
@@ -390,7 +390,7 @@ TEST_F(KernelProxyTest, MemMountIO) {
EXPECT_EQ(0, ki_close(fd1));
EXPECT_EQ(0, ki_close(fd2));
- fd1 = ki_open("/foo/bar", O_WRONLY | O_APPEND);
+ fd1 = ki_open("/foo/bar", O_WRONLY | O_APPEND, 0);
ASSERT_NE(-1, fd1);
EXPECT_EQ(5, ki_write(fd1, "WORLD", 5));
@@ -399,7 +399,7 @@ TEST_F(KernelProxyTest, MemMountIO) {
text[len] = 0;
EXPECT_STREQ("WORLD", text);
- fd2 = ki_open("/foo/bar", O_RDONLY);
+ fd2 = ki_open("/foo/bar", O_RDONLY, 0);
ASSERT_NE(-1, fd2);
len = ki_read(fd2, text, sizeof(text));
if (len > 0)
@@ -415,9 +415,9 @@ TEST_F(KernelProxyTest, MemMountFTruncate) {
// Open a file write only, write some text, then test that using a
// separate file descriptor pointing to it that it is correctly
// truncated at a specified number of bytes (2).
- fd1 = ki_open("/trunc", O_WRONLY | O_CREAT);
+ fd1 = ki_open("/trunc", O_WRONLY | O_CREAT, 0777);
ASSERT_NE(-1, fd1);
- fd2 = ki_open("/trunc", O_RDONLY);
+ fd2 = ki_open("/trunc", O_RDONLY, 0);
ASSERT_NE(-1, fd2);
EXPECT_EQ(5, ki_write(fd1, "HELLO", 5));
EXPECT_EQ(0, ki_ftruncate(fd1, 2));
@@ -435,20 +435,20 @@ TEST_F(KernelProxyTest, MemMountTruncate) {
// Open a file write only, write some text, then test that by
// referring to it by its path and truncating it we correctly truncate
// it at a specified number of bytes (2).
- fd1 = ki_open("/trunc", O_WRONLY | O_CREAT);
+ fd1 = ki_open("/trunc", O_WRONLY | O_CREAT, 0777);
ASSERT_NE(-1, fd1);
EXPECT_EQ(5, ki_write(fd1, "HELLO", 5));
EXPECT_EQ(0, ki_close(fd1));
EXPECT_EQ(0, ki_truncate("/trunc", 2));
// Verify the text is only 2 bytes long with new file descriptor.
- fd1 = ki_open("/trunc", O_RDONLY);
+ fd1 = ki_open("/trunc", O_RDONLY, 0);
ASSERT_NE(-1, fd1);
EXPECT_EQ(2, ki_read(fd1, text, sizeof(text)));
EXPECT_EQ(0, ki_close(fd1));
}
TEST_F(KernelProxyTest, MemMountLseek) {
- int fd = ki_open("/foo", O_CREAT | O_RDWR);
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
ASSERT_GT(fd, -1);
ASSERT_EQ(9, ki_write(fd, "Some text", 9));
@@ -468,7 +468,7 @@ TEST_F(KernelProxyTest, MemMountLseek) {
}
TEST_F(KernelProxyTest, CloseTwice) {
- int fd = ki_open("/foo", O_CREAT | O_RDWR);
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
ASSERT_GT(fd, -1);
EXPECT_EQ(9, ki_write(fd, "Some text", 9));
@@ -481,7 +481,7 @@ TEST_F(KernelProxyTest, CloseTwice) {
}
TEST_F(KernelProxyTest, MemMountDup) {
- int fd = ki_open("/foo", O_CREAT | O_RDWR);
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
ASSERT_GT(fd, -1);
int dup_fd = ki_dup(fd);
@@ -495,7 +495,7 @@ TEST_F(KernelProxyTest, MemMountDup) {
ASSERT_EQ(dup2_fd, ki_dup2(fd, dup2_fd));
ASSERT_EQ(9, ki_lseek(dup2_fd, 0, SEEK_CUR));
- int new_fd = ki_open("/bar", O_CREAT | O_RDWR);
+ int new_fd = ki_open("/bar", O_CREAT | O_RDWR, 0777);
ASSERT_EQ(fd, ki_dup2(new_fd, fd));
// fd, new_fd -> "/bar"
@@ -513,7 +513,7 @@ TEST_F(KernelProxyTest, MemMountDup) {
}
TEST_F(KernelProxyTest, Lstat) {
- int fd = ki_open("/foo", O_CREAT | O_RDWR);
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
ASSERT_GT(fd, -1);
ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE));
@@ -530,8 +530,17 @@ TEST_F(KernelProxyTest, Lstat) {
EXPECT_EQ(ENOENT, errno);
}
+TEST_F(KernelProxyTest, OpenWithMode) {
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723);
+ ASSERT_GT(fd, -1);
+
+ struct stat buf;
+ EXPECT_EQ(0, ki_lstat("/foo", &buf));
+ EXPECT_EQ(0723, buf.st_mode & ~S_IFMT);
+}
+
TEST_F(KernelProxyTest, UseAfterClose) {
- int fd = ki_open("/dummy", O_CREAT | O_WRONLY);
+ int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777);
ASSERT_GT(fd, -1);
EXPECT_EQ(5, ki_write(fd, "hello", 5));
EXPECT_EQ(0, ki_close(fd));
@@ -627,7 +636,7 @@ TEST_F(KernelProxyMountTest, MountAndIoctl) {
char path[100];
snprintf(path, 100, "dev/fs/%d", g_fs_dev);
- int fd = ki_open(path, O_RDONLY);
+ int fd = ki_open(path, O_RDONLY, 0);
ASSERT_GT(fd, -1);
EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef));
@@ -701,7 +710,8 @@ class KernelProxyMMapTest_Node : public Node {
class KernelProxyMMapTest_Filesystem : public Filesystem {
public:
- virtual Error Open(const Path& path, int mode, ScopedNode* out_node) {
+ virtual Error OpenWithMode(const Path& path, int open_flags,
+ mode_t mode, ScopedNode* out_node) {
out_node->reset(new KernelProxyMMapTest_Node(this));
return 0;
}
@@ -747,7 +757,7 @@ class KernelProxyMMapTest : public ::testing::Test {
TEST_F(KernelProxyMMapTest, MMap) {
ASSERT_EQ(0, ki_umount("/"));
ASSERT_EQ(0, ki_mount("", "/", "mmapfs", 0, NULL));
- int fd = ki_open("/file", O_RDWR | O_CREAT);
+ int fd = ki_open("/file", O_RDWR | O_CREAT, 0777);
ASSERT_NE(-1, fd);
void* addr1 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -829,8 +839,8 @@ class KernelProxyErrorTest : public ::testing::Test {
TEST_F(KernelProxyErrorTest, WriteError) {
ScopedRef<MockFs> mock_fs(fs());
ScopedRef<MockNode> mock_node(new MockNode(&*mock_fs));
- EXPECT_CALL(*mock_fs, Open(_, _, _))
- .WillOnce(DoAll(SetArgPointee<2>(mock_node), Return(0)));
+ EXPECT_CALL(*mock_fs, OpenWithMode(_, _, _, _))
+ .WillOnce(DoAll(SetArgPointee<3>(mock_node), Return(0)));
EXPECT_CALL(*mock_node, Write(_, _, _, _))
.WillOnce(DoAll(SetArgPointee<3>(0), // Wrote 0 bytes.
@@ -838,7 +848,7 @@ TEST_F(KernelProxyErrorTest, WriteError) {
EXPECT_CALL(*mock_node, Destroy()).Times(1);
- int fd = ki_open("/dummy", O_WRONLY);
+ int fd = ki_open("/dummy", O_WRONLY, 0);
EXPECT_NE(0, fd);
char buf[20];
@@ -851,8 +861,8 @@ TEST_F(KernelProxyErrorTest, WriteError) {
TEST_F(KernelProxyErrorTest, ReadError) {
ScopedRef<MockFs> mock_fs(fs());
ScopedRef<MockNode> mock_node(new MockNode(&*mock_fs));
- EXPECT_CALL(*mock_fs, Open(_, _, _))
- .WillOnce(DoAll(SetArgPointee<2>(mock_node), Return(0)));
+ EXPECT_CALL(*mock_fs, OpenWithMode(_, _, _, _))
+ .WillOnce(DoAll(SetArgPointee<3>(mock_node), Return(0)));
EXPECT_CALL(*mock_node, Read(_, _, _, _))
.WillOnce(DoAll(SetArgPointee<3>(0), // Read 0 bytes.
@@ -860,7 +870,7 @@ TEST_F(KernelProxyErrorTest, ReadError) {
EXPECT_CALL(*mock_node, Destroy()).Times(1);
- int fd = ki_open("/dummy", O_RDONLY);
+ int fd = ki_open("/dummy", O_RDONLY, 0);
EXPECT_NE(0, fd);
char buf[20];
diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc
index df2d994..79446ae 100644
--- a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc
@@ -127,7 +127,7 @@ class KernelWrapTest : public ::testing::Test {
errno = 0;
// Initializing the KernelProxy opens stdin/stdout/stderr.
- EXPECT_CALL(mock, open(_, _))
+ EXPECT_CALL(mock, open(_, _, _))
.WillOnce(Return(0))
.WillOnce(Return(1))
.WillOnce(Return(2));
@@ -450,12 +450,12 @@ TEST_F(KernelWrapTest, munmap) {
TEST_F(KernelWrapTest, open) {
// We pass O_RDONLY because we do not want an error in flags translation
- EXPECT_CALL(mock, open(kDummyConstChar, 0))
+ EXPECT_CALL(mock, open(kDummyConstChar, 0, 0))
.WillOnce(Return(kDummyInt2))
.WillOnce(Return(kDummyInt2));
- EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
- EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
+ EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0, 0));
+ EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0, 0));
}
TEST_F(KernelWrapTest, pipe) {
diff --git a/native_client_sdk/src/tests/nacl_io_test/mock_fs.h b/native_client_sdk/src/tests/nacl_io_test/mock_fs.h
index 8fe3b34..0ed0387 100644
--- a/native_client_sdk/src/tests/nacl_io_test/mock_fs.h
+++ b/native_client_sdk/src/tests/nacl_io_test/mock_fs.h
@@ -25,6 +25,7 @@ class MockFs : public nacl_io::Filesystem {
MOCK_METHOD0(Destroy, void());
MOCK_METHOD2(Access, Error(const Path&, int));
MOCK_METHOD3(Open, Error(const Path&, int, ScopedNode*));
+ MOCK_METHOD4(OpenWithMode, Error(const Path&, int, mode_t, ScopedNode*));
MOCK_METHOD2(OpenResource, Error(const Path&, ScopedNode*));
MOCK_METHOD1(Unlink, Error(const Path&));
MOCK_METHOD2(Mkdir, Error(const Path&, int));
diff --git a/native_client_sdk/src/tests/nacl_io_test/mock_kernel_proxy.h b/native_client_sdk/src/tests/nacl_io_test/mock_kernel_proxy.h
index 03059a9..04a37af 100644
--- a/native_client_sdk/src/tests/nacl_io_test/mock_kernel_proxy.h
+++ b/native_client_sdk/src/tests/nacl_io_test/mock_kernel_proxy.h
@@ -48,7 +48,7 @@ class MockKernelProxy : public nacl_io::KernelProxy {
MOCK_METHOD5(mount, int(const char*, const char*, const char*, unsigned long,
const void*));
MOCK_METHOD2(munmap, int(void*, size_t));
- MOCK_METHOD2(open, int(const char*, int));
+ MOCK_METHOD3(open, int(const char*, int, mode_t));
MOCK_METHOD1(pipe, int(int[2]));
MOCK_METHOD3(read, ssize_t(int, void*, size_t));
MOCK_METHOD3(readlink, int(const char*, char*, size_t count));
diff --git a/native_client_sdk/src/tests/nacl_io_test/tty_test.cc b/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
index b45fa80..7d129f9 100644
--- a/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
@@ -188,7 +188,7 @@ TEST_F(TtyTest, TtySelect) {
fd_set writefds;
fd_set errorfds;
- int tty_fd = ki_open("/dev/tty", O_RDONLY);
+ int tty_fd = ki_open("/dev/tty", O_RDONLY, 0);
ASSERT_GT(tty_fd, 0) << "tty open failed: " << errno;
FD_ZERO(&readfds);
@@ -231,7 +231,7 @@ TEST_F(TtyTest, TtySelect) {
}
TEST_F(TtyTest, TtyICANON) {
- int tty_fd = ki_open("/dev/tty", O_RDONLY);
+ int tty_fd = ki_open("/dev/tty", O_RDONLY, 0);
ASSERT_EQ(0, IsReadable(tty_fd));
@@ -264,7 +264,7 @@ static void sighandler(int sig) { g_received_signal = sig; }
TEST_F(TtyTest, WindowSize) {
// Get current window size
struct winsize old_winsize = {0};
- int tty_fd = ki_open("/dev/tty", O_RDONLY);
+ int tty_fd = ki_open("/dev/tty", O_RDONLY, 0);
ASSERT_EQ(0, ki_ioctl_wrapper(tty_fd, TIOCGWINSZ, &old_winsize));
// Install signal handler
@@ -312,7 +312,7 @@ static void* resize_thread_main(void* arg) {
TEST_F(TtyTest, ResizeDuringSelect) {
// Test that a window resize during a call
// to select(3) will cause it to fail with EINTR.
- int tty_fd = ki_open("/dev/tty", O_RDONLY);
+ int tty_fd = ki_open("/dev/tty", O_RDONLY, 0);
fd_set readfds;
fd_set errorfds;
@@ -347,7 +347,7 @@ static void* input_thread_main(void* arg) {
usleep(50 * 1000);
- int fd = ki_open("/dev/tty", O_RDONLY);
+ int fd = ki_open("/dev/tty", O_RDONLY, 0);
thiz->TtyWrite(fd, "test\n");
return NULL;
}
@@ -355,7 +355,7 @@ static void* input_thread_main(void* arg) {
TEST_F(TtyTest, InputDuringSelect) {
// Test that input which occurs while in select causes
// select to return.
- int tty_fd = ki_open("/dev/tty", O_RDONLY);
+ int tty_fd = ki_open("/dev/tty", O_RDONLY, 0);
fd_set readfds;
fd_set errorfds;