Commit bbadba6b authored by sbc's avatar sbc Committed by Commit bot

[NaCl SDK] nacl_io: Remove Node::Access method.

This is implemented generically in terms of GetStat().

Review URL: https://codereview.chromium.org/547053002

Cr-Commit-Position: refs/heads/master@{#294057}
parent d719be84
...@@ -240,21 +240,6 @@ Error FsNode::VIoctl(int request, va_list args) { ...@@ -240,21 +240,6 @@ Error FsNode::VIoctl(int request, va_list args) {
} // namespace } // namespace
Error DevFs::Access(const Path& path, int a_mode) {
ScopedNode node;
int error = root_->FindChild(path.Join(), &node);
if (error)
return error;
// Don't allow execute access.
if (a_mode & X_OK) {
LOG_TRACE("Executing devfs nodes is not allowed.");
return EACCES;
}
return 0;
}
Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
int error; int error;
......
...@@ -14,7 +14,6 @@ class Node; ...@@ -14,7 +14,6 @@ class Node;
class DevFs : public Filesystem { class DevFs : public Filesystem {
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int open_flags, ScopedNode* out_node); virtual Error Open(const Path& path, int open_flags, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions); virtual Error Mkdir(const Path& path, int permissions);
......
...@@ -62,10 +62,6 @@ class Filesystem : public sdk_util::RefObject { ...@@ -62,10 +62,6 @@ class Filesystem : public sdk_util::RefObject {
// All paths in functions below are expected to containing a leading "/". // All paths in functions below are expected to containing a leading "/".
// Test whether a file or directory at a given path can be accessed.
// Returns 0 on success, or an appropriate errno value on failure.
virtual Error Access(const Path& path, int a_mode) = 0;
// Open a node at |path| with the specified open flags. The resulting // Open a node at |path| with the specified open flags. The resulting
// Node is created with a ref count of 1. // Node is created with a ref count of 1.
// Assumes that |out_node| is non-NULL. // Assumes that |out_node| is non-NULL.
......
...@@ -57,19 +57,6 @@ void FuseFs::Destroy() { ...@@ -57,19 +57,6 @@ void FuseFs::Destroy() {
fuse_ops_->destroy(fuse_user_data_); fuse_ops_->destroy(fuse_user_data_);
} }
Error FuseFs::Access(const Path& path, int a_mode) {
if (!fuse_ops_->access) {
LOG_TRACE("fuse_ops_->access is NULL.");
return ENOSYS;
}
int result = fuse_ops_->access(path.Join().c_str(), a_mode);
if (result < 0)
return -result;
return 0;
}
Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
std::string path_str = path.Join(); std::string path_str = path.Join();
const char* path_cstr = path_str.c_str(); const char* path_cstr = path_str.c_str();
......
...@@ -21,7 +21,6 @@ class FuseFs : public Filesystem { ...@@ -21,7 +21,6 @@ class FuseFs : public Filesystem {
virtual void Destroy(); virtual void Destroy();
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm); virtual Error Mkdir(const Path& path, int perm);
......
...@@ -29,12 +29,6 @@ int64_t strtoull(const char* nptr, char** endptr, int base) { ...@@ -29,12 +29,6 @@ int64_t strtoull(const char* nptr, char** endptr, int base) {
} // namespace } // namespace
Error Html5Fs::Access(const Path& path, int a_mode) {
// a_mode is unused, since all files are readable, writable and executable.
ScopedNode node;
return Open(path, O_RDONLY, &node);
}
Error Html5Fs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error Html5Fs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
Error error = BlockUntilFilesystemOpen(); Error error = BlockUntilFilesystemOpen();
......
...@@ -18,7 +18,6 @@ class Node; ...@@ -18,7 +18,6 @@ class Node;
class Html5Fs : public Filesystem { class Html5Fs : public Filesystem {
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions); virtual Error Mkdir(const Path& path, int permissions);
......
...@@ -41,31 +41,6 @@ std::string NormalizeHeaderKey(const std::string& s) { ...@@ -41,31 +41,6 @@ std::string NormalizeHeaderKey(const std::string& s) {
return result; return result;
} }
Error HttpFs::Access(const Path& path, int a_mode) {
ScopedNode node = FindExistingNode(path);
if (node.get() == NULL) {
// If we can't find the node in the cache, fetch it
std::string url = MakeUrl(path);
node.reset(new HttpFsNode(this, url, cache_content_));
Error error = node->Init(0);
if (error)
return error;
error = node->GetStat(NULL);
if (error)
return error;
}
int obj_mode = node->GetMode();
if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) ||
((a_mode & W_OK) && !(obj_mode & S_IWRITE)) ||
((a_mode & X_OK) && !(obj_mode & S_IEXEC))) {
return EACCES;
}
return 0;
}
Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
......
...@@ -18,7 +18,6 @@ class HttpFs : public Filesystem { ...@@ -18,7 +18,6 @@ class HttpFs : public Filesystem {
public: public:
typedef std::map<std::string, ScopedNode> NodeMap_t; typedef std::map<std::string, ScopedNode> NodeMap_t;
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions); virtual Error Mkdir(const Path& path, int permissions);
......
...@@ -391,19 +391,6 @@ PP_Var JsFs::WaitForResponse(RequestId request_id) { ...@@ -391,19 +391,6 @@ PP_Var JsFs::WaitForResponse(RequestId request_id) {
} }
} }
Error JsFs::Access(const Path& path, int a_mode) {
ScopedVar response(ppapi_);
if (!SendRequestAndWait(&response, "%s%s%d",
"cmd", "access",
"path", path.Join().c_str(),
"amode", a_mode)) {
LOG_ERROR("Failed to send request.");
return EINVAL;
}
return ErrorFromResponse(response);
}
Error JsFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error JsFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
ScopedVar response(ppapi_); ScopedVar response(ppapi_);
......
...@@ -35,7 +35,6 @@ class JsFs : public Filesystem { ...@@ -35,7 +35,6 @@ class JsFs : public Filesystem {
virtual void Destroy(); virtual void Destroy();
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm); virtual Error Mkdir(const Path& path, int perm);
......
...@@ -843,20 +843,18 @@ int KernelProxy::fcntl(int fd, int request, va_list args) { ...@@ -843,20 +843,18 @@ int KernelProxy::fcntl(int fd, int request, va_list args) {
} }
int KernelProxy::access(const char* path, int amode) { int KernelProxy::access(const char* path, int amode) {
ScopedFilesystem fs; struct stat buf;
Path rel; int rtn = stat(path, &buf);
if (rtn != 0)
return rtn;
Error error = AcquireFsAndRelPath(path, &fs, &rel); if (((amode & R_OK) && !(buf.st_mode & S_IREAD)) ||
if (error) { ((amode & W_OK) && !(buf.st_mode & S_IWRITE)) ||
errno = error; ((amode & X_OK) && !(buf.st_mode & S_IEXEC))) {
errno = EACCES;
return -1; return -1;
} }
error = fs->Access(rel, amode);
if (error) {
errno = error;
return -1;
}
return 0; return 0;
} }
......
...@@ -75,23 +75,6 @@ Error MemFs::FindNode(const Path& path, int type, ScopedNode* out_node) { ...@@ -75,23 +75,6 @@ Error MemFs::FindNode(const Path& path, int type, ScopedNode* out_node) {
return 0; return 0;
} }
Error MemFs::Access(const Path& path, int a_mode) {
ScopedNode node;
Error error = FindNode(path, 0, &node);
if (error)
return error;
int obj_mode = node->GetMode();
if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) ||
((a_mode & W_OK) && !(obj_mode & S_IWRITE)) ||
((a_mode & X_OK) && !(obj_mode & S_IEXEC))) {
return EACCES;
}
return 0;
}
Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
ScopedNode node; ScopedNode node;
......
...@@ -29,7 +29,6 @@ class MemFs : public Filesystem { ...@@ -29,7 +29,6 @@ class MemFs : public Filesystem {
virtual Error FindNode(const Path& path, int type, ScopedNode* out_node); virtual Error FindNode(const Path& path, int type, ScopedNode* out_node);
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm); virtual Error Mkdir(const Path& path, int perm);
......
...@@ -22,11 +22,6 @@ Error PassthroughFs::Init(const FsInitArgs& args) { ...@@ -22,11 +22,6 @@ Error PassthroughFs::Init(const FsInitArgs& args) {
void PassthroughFs::Destroy() { void PassthroughFs::Destroy() {
} }
Error PassthroughFs::Access(const Path& path, int a_mode) {
// There is no underlying 'access' syscall in NaCl. It just returns ENOSYS.
return ENOSYS;
}
Error PassthroughFs::Open(const Path& path, int mode, ScopedNode* out_node) { Error PassthroughFs::Open(const Path& path, int mode, ScopedNode* out_node) {
out_node->reset(NULL); out_node->reset(NULL);
int real_fd; int real_fd;
......
...@@ -18,7 +18,6 @@ class PassthroughFs : public Filesystem { ...@@ -18,7 +18,6 @@ class PassthroughFs : public Filesystem {
virtual void Destroy(); virtual void Destroy();
public: public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node); virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error OpenResource(const Path& path, ScopedNode* out_node); virtual Error OpenResource(const Path& path, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
......
...@@ -84,10 +84,6 @@ StreamFs::~StreamFs() { ...@@ -84,10 +84,6 @@ StreamFs::~StreamFs() {
pthread_cond_destroy(&message_cond_); pthread_cond_destroy(&message_cond_);
} }
Error StreamFs::Access(const Path& path, int a_mode) {
return EACCES;
}
Error StreamFs::Open(const Path& path, int o_flags, ScopedNode* out_node) { Error StreamFs::Open(const Path& path, int o_flags, ScopedNode* out_node) {
return EACCES; return EACCES;
} }
......
...@@ -54,7 +54,6 @@ class StreamFs : public Filesystem { ...@@ -54,7 +54,6 @@ class StreamFs : public Filesystem {
// of a MountSocketWork object. // of a MountSocketWork object.
static PP_CompletionCallback GetRunCompletion(Work* work); static PP_CompletionCallback GetRunCompletion(Work* work);
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int o_flags, ScopedNode* out_node); virtual Error Open(const Path& path, int o_flags, ScopedNode* out_node);
virtual Error Unlink(const Path& path); virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions); virtual Error Mkdir(const Path& path, int permissions);
......
...@@ -20,6 +20,15 @@ class DevFsForTesting : public nacl_io::DevFs { ...@@ -20,6 +20,15 @@ class DevFsForTesting : public nacl_io::DevFs {
Init(args); Init(args);
} }
bool Exists(const char* filename) {
nacl_io::ScopedNode node;
if (Open(nacl_io::Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return (int)inode_pool_.size(); } int num_nodes() { return (int)inode_pool_.size(); }
}; };
......
...@@ -28,6 +28,15 @@ class MemFsForTesting : public MemFs { ...@@ -28,6 +28,15 @@ class MemFsForTesting : public MemFs {
EXPECT_EQ(0, Init(args)); EXPECT_EQ(0, Init(args));
} }
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return (int)inode_pool_.size(); } int num_nodes() { return (int)inode_pool_.size(); }
}; };
...@@ -42,13 +51,13 @@ TEST(FilesystemTest, Sanity) { ...@@ -42,13 +51,13 @@ TEST(FilesystemTest, Sanity) {
off_t result_size = 0; off_t result_size = 0;
int result_bytes = 0; int result_bytes = 0;
struct stat buf;
char buf1[1024]; char buf1[1024];
// A memory filesystem starts with one directory node: the root. // A memory filesystem starts with one directory node: the root.
EXPECT_EQ(1, fs.num_nodes()); EXPECT_EQ(1, fs.num_nodes());
// Fail to open non existent file // Fail to open non existent file
EXPECT_EQ(ENOENT, fs.Access(Path("/foo"), R_OK | W_OK));
EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDWR, &result_node)); EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDWR, &result_node));
EXPECT_EQ(NULL, result_node.get()); EXPECT_EQ(NULL, result_node.get());
EXPECT_EQ(1, fs.num_nodes()); EXPECT_EQ(1, fs.num_nodes());
...@@ -59,14 +68,16 @@ TEST(FilesystemTest, Sanity) { ...@@ -59,14 +68,16 @@ TEST(FilesystemTest, Sanity) {
// We now have a directory and a file. The file has a two references // We now have a directory and a file. The file has a two references
// one returned to the test, one for the name->inode map. // one returned to the test, one for the name->inode map.
EXPECT_EQ(2, fs.num_nodes()); ASSERT_EQ(2, fs.num_nodes());
EXPECT_EQ(2, file->RefCount()); ASSERT_EQ(2, file->RefCount());
EXPECT_EQ(0, fs.Access(Path("/foo"), R_OK | W_OK)); ASSERT_EQ(0, file->GetStat(&buf));
EXPECT_EQ(EACCES, fs.Access(Path("/foo"), X_OK)); ASSERT_EQ(0, buf.st_mode & S_IXUSR);
// All access should be allowed on the root directory. // All access should be allowed on the root directory.
EXPECT_EQ(0, fs.Access(Path("/"), R_OK | W_OK | X_OK)); EXPECT_EQ(0, fs.Open(Path("/"), O_RDONLY, &root));
// Open the root directory for write should fail. ASSERT_EQ(0, root->GetStat(&buf));
ASSERT_EQ(S_IRWXU, buf.st_mode & S_IRWXU);
// Opening a directory for write should fail.
EXPECT_EQ(EISDIR, fs.Open(Path("/"), O_RDWR, &root)); EXPECT_EQ(EISDIR, fs.Open(Path("/"), O_RDWR, &root));
EXPECT_EQ(2, fs.num_nodes()); EXPECT_EQ(2, fs.num_nodes());
...@@ -157,8 +168,7 @@ TEST(FilesystemTest, Sanity) { ...@@ -157,8 +168,7 @@ TEST(FilesystemTest, Sanity) {
EXPECT_EQ(1, fs.num_nodes()); EXPECT_EQ(1, fs.num_nodes());
// Verify the directory is gone // Verify the directory is gone
EXPECT_EQ(ENOENT, fs.Access(Path("/foo"), F_OK)); EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDONLY, &file));
EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDWR, &file));
EXPECT_EQ(NULL_NODE, file.get()); EXPECT_EQ(NULL_NODE, file.get());
} }
...@@ -213,25 +223,25 @@ TEST(FilesystemTest, MemFsRename) { ...@@ -213,25 +223,25 @@ TEST(FilesystemTest, MemFsRename) {
ScopedNode file; ScopedNode file;
ASSERT_EQ(0, fs.Open(Path("/dir1/file"), O_RDWR | O_CREAT | O_EXCL, &file)); ASSERT_EQ(0, fs.Open(Path("/dir1/file"), O_RDWR | O_CREAT | O_EXCL, &file));
ASSERT_EQ(0, fs.Access(Path("/dir1/file"), R_OK)); ASSERT_TRUE(fs.Exists("/dir1/file"));
ASSERT_EQ(4, fs.num_nodes()); ASSERT_EQ(4, fs.num_nodes());
// Move from one directory to another should ok // Move from one directory to another should ok
ASSERT_EQ(0, fs.Rename(Path("/dir1/file"), Path("/dir2/new_file"))); ASSERT_EQ(0, fs.Rename(Path("/dir1/file"), Path("/dir2/new_file")));
ASSERT_NE(0, fs.Access(Path("/dir1/file"), R_OK)); ASSERT_FALSE(fs.Exists("/dir1/file"));
ASSERT_EQ(0, fs.Access(Path("/dir2/new_file"), R_OK)); ASSERT_TRUE(fs.Exists("/dir2/new_file"));
ASSERT_EQ(4, fs.num_nodes()); ASSERT_EQ(4, fs.num_nodes());
// Move within the same directory // Move within the same directory
ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file"), Path("/dir2/new_file2"))); ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file"), Path("/dir2/new_file2")));
ASSERT_NE(0, fs.Access(Path("/dir2/new_file"), R_OK)); ASSERT_FALSE(fs.Exists("/dir2/new_file"));
ASSERT_EQ(0, fs.Access(Path("/dir2/new_file2"), R_OK)); ASSERT_TRUE(fs.Exists("/dir2/new_file2"));
ASSERT_EQ(4, fs.num_nodes()); ASSERT_EQ(4, fs.num_nodes());
// Move to another directory but without a filename // Move to another directory but without a filename
ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file2"), Path("/dir1"))); ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file2"), Path("/dir1")));
ASSERT_NE(0, fs.Access(Path("/dir2/new_file2"), R_OK)); ASSERT_FALSE(fs.Exists("/dir2/new_file2"));
ASSERT_EQ(0, fs.Access(Path("/dir1/new_file2"), R_OK)); ASSERT_TRUE(fs.Exists("/dir1/new_file2"));
ASSERT_EQ(4, fs.num_nodes()); ASSERT_EQ(4, fs.num_nodes());
} }
...@@ -244,8 +254,8 @@ TEST(FilesystemTest, MemFsRenameDir) { ...@@ -244,8 +254,8 @@ TEST(FilesystemTest, MemFsRenameDir) {
// Renaming one directory to another should work // Renaming one directory to another should work
ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2"))); ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2")));
ASSERT_NE(0, fs.Access(Path("/dir1"), R_OK)); ASSERT_FALSE(fs.Exists("/dir1"));
ASSERT_EQ(0, fs.Access(Path("/dir2"), R_OK)); ASSERT_TRUE(fs.Exists("/dir2"));
EXPECT_EQ(2, fs.num_nodes()); EXPECT_EQ(2, fs.num_nodes());
// Reset to initial state // Reset to initial state
...@@ -254,8 +264,8 @@ TEST(FilesystemTest, MemFsRenameDir) { ...@@ -254,8 +264,8 @@ TEST(FilesystemTest, MemFsRenameDir) {
// Renaming a directory to a new name within another // Renaming a directory to a new name within another
ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2/foo"))); ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2/foo")));
ASSERT_EQ(0, fs.Access(Path("/dir2"), R_OK)); ASSERT_TRUE(fs.Exists("/dir2"));
ASSERT_EQ(0, fs.Access(Path("/dir2/foo"), R_OK)); ASSERT_TRUE(fs.Exists("/dir2/foo"));
EXPECT_EQ(3, fs.num_nodes()); EXPECT_EQ(3, fs.num_nodes());
// Reset to initial state // Reset to initial state
...@@ -273,7 +283,7 @@ TEST(FilesystemTest, DevAccess) { ...@@ -273,7 +283,7 @@ TEST(FilesystemTest, DevAccess) {
FakePepperInterface pepper; FakePepperInterface pepper;
DevFsForTesting fs(&pepper); DevFsForTesting fs(&pepper);
ScopedNode invalid_node, valid_node; ScopedNode invalid_node, valid_node;
ASSERT_EQ(ENOENT, fs.Access(Path("/foo"), F_OK)); ASSERT_FALSE(fs.Exists("/foo"));
// Creating non-existent file should return EACCES // Creating non-existent file should return EACCES
ASSERT_EQ(EACCES, fs.Open(Path("/foo"), O_CREAT | O_RDWR, &invalid_node)); ASSERT_EQ(EACCES, fs.Open(Path("/foo"), O_CREAT | O_RDWR, &invalid_node));
...@@ -295,11 +305,12 @@ TEST(FilesystemTest, DevNull) { ...@@ -295,11 +305,12 @@ TEST(FilesystemTest, DevNull) {
DevFsForTesting fs(&pepper); DevFsForTesting fs(&pepper);
ScopedNode dev_null; ScopedNode dev_null;
int result_bytes = 0; int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/null"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/null"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/null"), O_RDWR, &dev_null)); ASSERT_EQ(0, fs.Open(Path("/null"), O_RDWR, &dev_null));
ASSERT_NE(NULL_NODE, dev_null.get()); ASSERT_NE(NULL_NODE, dev_null.get());
ASSERT_EQ(0, dev_null->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/null should write everything. // Writing to /dev/null should write everything.
const char msg[] = "Dummy test message."; const char msg[] = "Dummy test message.";
...@@ -319,11 +330,12 @@ TEST(FilesystemTest, DevZero) { ...@@ -319,11 +330,12 @@ TEST(FilesystemTest, DevZero) {
DevFsForTesting fs(&pepper); DevFsForTesting fs(&pepper);
ScopedNode dev_zero; ScopedNode dev_zero;
int result_bytes = 0; int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/zero"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/zero"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/zero"), O_RDWR, &dev_zero)); ASSERT_EQ(0, fs.Open(Path("/zero"), O_RDWR, &dev_zero));
ASSERT_NE(NULL_NODE, dev_zero.get()); ASSERT_NE(NULL_NODE, dev_zero.get());
ASSERT_EQ(0, dev_zero->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/zero should write everything. // Writing to /dev/zero should write everything.
HandleAttr attrs; HandleAttr attrs;
...@@ -350,11 +362,12 @@ TEST(FilesystemTest, DISABLED_DevUrandom) { ...@@ -350,11 +362,12 @@ TEST(FilesystemTest, DISABLED_DevUrandom) {
DevFsForTesting fs(&pepper); DevFsForTesting fs(&pepper);
ScopedNode dev_urandom; ScopedNode dev_urandom;
int result_bytes = 0; int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/urandom"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/urandom"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/urandom"), O_RDWR, &dev_urandom)); ASSERT_EQ(0, fs.Open(Path("/urandom"), O_RDWR, &dev_urandom));
ASSERT_NE(NULL_NODE, dev_urandom.get()); ASSERT_NE(NULL_NODE, dev_urandom.get());
ASSERT_EQ(0, dev_urandom->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/urandom should write everything. // Writing to /dev/urandom should write everything.
const char msg[] = "Dummy test message."; const char msg[] = "Dummy test message.";
......
...@@ -48,6 +48,15 @@ class Html5FsForTesting : public Html5Fs { ...@@ -48,6 +48,15 @@ class Html5FsForTesting : public Html5Fs {
Error error = Init(args); Error error = Init(args);
EXPECT_EQ(expected_error, error); EXPECT_EQ(expected_error, error);
} }
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
}; };
class Html5FsTest : public ::testing::Test { class Html5FsTest : public ::testing::Test {
...@@ -143,7 +152,7 @@ TEST_F(Html5FsTest, PassFilesystemResource) { ...@@ -143,7 +152,7 @@ TEST_F(Html5FsTest, PassFilesystemResource) {
ScopedRef<Html5FsForTesting> fs( ScopedRef<Html5FsForTesting> fs(
new Html5FsForTesting(map, &ppapi_)); new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK)); ASSERT_TRUE(fs->Exists("/foo"));
ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem); ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem);
} }
...@@ -156,18 +165,8 @@ TEST_F(Html5FsTest, MountSubtree) { ...@@ -156,18 +165,8 @@ TEST_F(Html5FsTest, MountSubtree) {
map["SOURCE"] = "/foo"; map["SOURCE"] = "/foo";
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/bar"), R_OK | W_OK | X_OK)); ASSERT_TRUE(fs->Exists("/bar"));
ASSERT_EQ(ENOENT, fs->Access(Path("/foo/bar"), F_OK)); ASSERT_FALSE(fs->Exists("/foo/bar"));
}
TEST_F(Html5FsTest, Access) {
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK));
ASSERT_EQ(ENOENT, fs->Access(Path("/bar"), F_OK));
} }
TEST_F(Html5FsTest, Mkdir) { TEST_F(Html5FsTest, Mkdir) {
...@@ -178,7 +177,7 @@ TEST_F(Html5FsTest, Mkdir) { ...@@ -178,7 +177,7 @@ TEST_F(Html5FsTest, Mkdir) {
EXPECT_EQ(EEXIST, fs->Mkdir(Path("/"), 0644)); EXPECT_EQ(EEXIST, fs->Mkdir(Path("/"), 0644));
Path path("/foo"); Path path("/foo");
ASSERT_EQ(ENOENT, fs->Access(path, F_OK)); ASSERT_FALSE(fs->Exists("/foo"));
ASSERT_EQ(0, fs->Mkdir(path, 0644)); ASSERT_EQ(0, fs->Mkdir(path, 0644));
struct stat stat; struct stat stat;
...@@ -189,15 +188,16 @@ TEST_F(Html5FsTest, Mkdir) { ...@@ -189,15 +188,16 @@ TEST_F(Html5FsTest, Mkdir) {
} }
TEST_F(Html5FsTest, Remove) { TEST_F(Html5FsTest, Remove) {
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); const char* kPath = "/foo";
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile(kPath, NULL));
StringMap_t map; StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo"); Path path(kPath);
ASSERT_EQ(0, fs->Access(path, F_OK)); ASSERT_TRUE(fs->Exists(kPath));
ASSERT_EQ(0, fs->Remove(path)); ASSERT_EQ(0, fs->Remove(path));
EXPECT_EQ(ENOENT, fs->Access(path, F_OK)); EXPECT_FALSE(fs->Exists(kPath));
} }
TEST_F(Html5FsTest, Unlink) { TEST_F(Html5FsTest, Unlink) {
...@@ -207,10 +207,12 @@ TEST_F(Html5FsTest, Unlink) { ...@@ -207,10 +207,12 @@ TEST_F(Html5FsTest, Unlink) {
StringMap_t map; StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_TRUE(fs->Exists("/dir"));
ASSERT_TRUE(fs->Exists("/file"));
ASSERT_EQ(0, fs->Unlink(Path("/file")));
ASSERT_EQ(EISDIR, fs->Unlink(Path("/dir"))); ASSERT_EQ(EISDIR, fs->Unlink(Path("/dir")));
EXPECT_EQ(0, fs->Unlink(Path("/file"))); EXPECT_FALSE(fs->Exists("/file"));
EXPECT_EQ(ENOENT, fs->Access(Path("/file"), F_OK)); EXPECT_TRUE(fs->Exists("/dir"));
EXPECT_EQ(0, fs->Access(Path("/dir"), F_OK));
} }
TEST_F(Html5FsTest, Rmdir) { TEST_F(Html5FsTest, Rmdir) {
...@@ -222,8 +224,8 @@ TEST_F(Html5FsTest, Rmdir) { ...@@ -222,8 +224,8 @@ TEST_F(Html5FsTest, Rmdir) {
ASSERT_EQ(ENOTDIR, fs->Rmdir(Path("/file"))); ASSERT_EQ(ENOTDIR, fs->Rmdir(Path("/file")));
EXPECT_EQ(0, fs->Rmdir(Path("/dir"))); EXPECT_EQ(0, fs->Rmdir(Path("/dir")));
EXPECT_EQ(ENOENT, fs->Access(Path("/dir"), F_OK)); EXPECT_FALSE(fs->Exists("/dir"));
EXPECT_EQ(0, fs->Access(Path("/file"), F_OK)); EXPECT_TRUE(fs->Exists("/file"));
} }
TEST_F(Html5FsTest, Rename) { TEST_F(Html5FsTest, Rename) {
...@@ -232,21 +234,19 @@ TEST_F(Html5FsTest, Rename) { ...@@ -232,21 +234,19 @@ TEST_F(Html5FsTest, Rename) {
StringMap_t map; StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo"); ASSERT_TRUE(fs->Exists("/foo"));
Path newpath("/bar"); ASSERT_EQ(0, fs->Rename(Path("/foo"), Path("/bar")));
ASSERT_EQ(0, fs->Access(path, F_OK)); EXPECT_FALSE(fs->Exists("/foo"));
ASSERT_EQ(0, fs->Rename(path, newpath)); EXPECT_TRUE(fs->Exists("/bar"));
EXPECT_EQ(ENOENT, fs->Access(path, F_OK));
EXPECT_EQ(0, fs->Access(newpath, F_OK));
} }
TEST_F(Html5FsTest, OpenForCreate) { TEST_F(Html5FsTest, OpenForCreate) {
StringMap_t map; StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo"); EXPECT_FALSE(fs->Exists("/foo"));
EXPECT_EQ(ENOENT, fs->Access(path, F_OK));
Path path("/foo");
ScopedNode node; ScopedNode node;
ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node)); ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node));
......
...@@ -78,15 +78,6 @@ class HttpFsLargeFileTest : public HttpFsTest { ...@@ -78,15 +78,6 @@ class HttpFsLargeFileTest : public HttpFsTest {
} // namespace } // namespace
TEST_P(HttpFsTest, Access) {
ASSERT_TRUE(ppapi_.server_template()->AddEntity("foo", "", NULL));
ASSERT_EQ(0, fs_.Access(Path("/foo"), R_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), X_OK));
ASSERT_EQ(ENOENT, fs_.Access(Path("/bar"), F_OK));
}
TEST_P(HttpFsTest, OpenAndCloseServerError) { TEST_P(HttpFsTest, OpenAndCloseServerError) {
EXPECT_TRUE(ppapi_.server_template()->AddError("file", 500)); EXPECT_TRUE(ppapi_.server_template()->AddError("file", 500));
...@@ -278,9 +269,9 @@ TEST(HttpFsDirTest, Root) { ...@@ -278,9 +269,9 @@ TEST(HttpFsDirTest, Root) {
ASSERT_TRUE(node->IsaDir()); ASSERT_TRUE(node->IsaDir());
// We have to r+w access to the root node // We have to r+w access to the root node
ASSERT_EQ(0, fs.Access(Path("/"), R_OK)); struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/"), X_OK)); ASSERT_EQ(0, node->GetStat(&buf));
ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK)); ASSERT_EQ(S_IXUSR | S_IRUSR, buf.st_mode & S_IRWXU);
} }
TEST(HttpFsDirTest, Mkdir) { TEST(HttpFsDirTest, Mkdir) {
...@@ -392,20 +383,17 @@ TEST(HttpFsBlobUrlTest, Basic) { ...@@ -392,20 +383,17 @@ TEST(HttpFsBlobUrlTest, Basic) {
HttpFsForTesting fs(args, &ppapi); HttpFsForTesting fs(args, &ppapi);
// Check access to root folder // Any other path than / should fail.
ASSERT_EQ(0, fs.Access(Path("/"), R_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/"), X_OK));
// Any other path will fail.
ScopedNode foo;
ASSERT_EQ(ENOENT, fs.Access(Path("/blah"), R_OK));
// Verify file size
ScopedNode node; ScopedNode node;
struct stat statbuf; ASSERT_EQ(ENOENT, fs.Open(Path("/blah"), R_OK, &node));
// Check access to blob file
ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node));
ASSERT_EQ(0, node->GetStat(&statbuf)); ASSERT_EQ(true, node->IsaFile());
ASSERT_EQ(0, node->GetStat(&statbuf));
ASSERT_EQ(strlen(kContent), statbuf.st_size); // Verify file size and permissions
struct stat buf;
ASSERT_EQ(0, node->GetStat(&buf));
ASSERT_EQ(S_IRUSR, buf.st_mode & S_IRWXU);
ASSERT_EQ(strlen(kContent), buf.st_size);
} }
...@@ -518,27 +518,6 @@ const int JsFsNodeTest::fd = 123; ...@@ -518,27 +518,6 @@ const int JsFsNodeTest::fd = 123;
} // namespace } // namespace
TEST_F(JsFsTest, Access) {
int a_mode = R_OK | W_OK | X_OK;
PP_Var expected;
ASSERT_EQ(true, CreateDict(&expected));
ASSERT_EQ(true, SetDictKeyValue(&expected, "id", 1));
ASSERT_EQ(true, SetDictKeyValue(&expected, "cmd", "access"));
ASSERT_EQ(true, SetDictKeyValue(&expected, "path", "/foo"));
ASSERT_EQ(true, SetDictKeyValue(&expected, "amode", a_mode));
PP_Var response;
ASSERT_EQ(true, CreateDict(&response));
ASSERT_EQ(true, SetDictKeyValue(&response, "id", 1));
ASSERT_EQ(true, SetDictKeyValue(&response, "error", 0));
Expect(expected, response);
StartJsThread();
EXPECT_EQ(0, fs_->Access(Path("/foo"), a_mode));
}
TEST_F(JsFsTest, Open) { TEST_F(JsFsTest, Open) {
PP_Var expected; PP_Var expected;
ASSERT_EQ(true, CreateDict(&expected)); ASSERT_EQ(true, CreateDict(&expected));
......
...@@ -122,10 +122,11 @@ class JSPipeNodeTest : public ::testing::Test { ...@@ -122,10 +122,11 @@ class JSPipeNodeTest : public ::testing::Test {
void SetUp() { void SetUp() {
name_ = "jspipe1"; name_ = "jspipe1";
ASSERT_EQ(0, fs_.Access(Path("/jspipe1"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/jspipe1"), X_OK));
ASSERT_EQ(0, fs_.Open(Path("/jspipe1"), O_RDWR, &pipe_dev_)); ASSERT_EQ(0, fs_.Open(Path("/jspipe1"), O_RDWR, &pipe_dev_));
ASSERT_NE(NULL_NODE, pipe_dev_.get()); ASSERT_NE(NULL_NODE, pipe_dev_.get());
struct stat buf;
ASSERT_EQ(0, pipe_dev_->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
} }
/** /**
......
...@@ -701,7 +701,6 @@ class KernelProxyMMapTest_Node : public Node { ...@@ -701,7 +701,6 @@ class KernelProxyMMapTest_Node : public Node {
class KernelProxyMMapTest_Filesystem : public Filesystem { class KernelProxyMMapTest_Filesystem : public Filesystem {
public: public:
virtual Error Access(const Path& path, int a_mode) { return 0; }
virtual Error Open(const Path& path, int mode, ScopedNode* out_node) { virtual Error Open(const Path& path, int mode, ScopedNode* out_node) {
out_node->reset(new KernelProxyMMapTest_Node(this)); out_node->reset(new KernelProxyMMapTest_Node(this));
return 0; return 0;
......
...@@ -36,6 +36,15 @@ class MemFsForTesting : public MemFs { ...@@ -36,6 +36,15 @@ class MemFsForTesting : public MemFs {
EXPECT_EQ(0, Init(args)); EXPECT_EQ(0, Init(args));
} }
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return inode_pool_.size(); } int num_nodes() { return inode_pool_.size(); }
}; };
......
...@@ -37,10 +37,11 @@ class TtyNodeTest : public ::testing::Test { ...@@ -37,10 +37,11 @@ class TtyNodeTest : public ::testing::Test {
TtyNodeTest() : fs_(&ppapi_) {} TtyNodeTest() : fs_(&ppapi_) {}
void SetUp() { void SetUp() {
ASSERT_EQ(0, fs_.Access(Path("/tty"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/tty"), X_OK));
ASSERT_EQ(0, fs_.Open(Path("/tty"), O_RDWR, &dev_tty_)); ASSERT_EQ(0, fs_.Open(Path("/tty"), O_RDWR, &dev_tty_));
ASSERT_NE(NULL_NODE, dev_tty_.get()); ASSERT_NE(NULL_NODE, dev_tty_.get());
struct stat buf;
ASSERT_EQ(0, dev_tty_->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
} }
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment