Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_mem.cc

Issue 15800004: [NaCl SDK] nacl_io: Added support for access() syscall. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes, implement httpfs, and write tests. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 #include "nacl_io/mount_mem.h" 5 #include "nacl_io/mount_mem.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <string> 9 #include <string>
10 #include <unistd.h>
10 11
11 #include "nacl_io/mount.h" 12 #include "nacl_io/mount.h"
12 #include "nacl_io/mount_node.h" 13 #include "nacl_io/mount_node.h"
13 #include "nacl_io/mount_node_dir.h" 14 #include "nacl_io/mount_node_dir.h"
14 #include "nacl_io/mount_node_mem.h" 15 #include "nacl_io/mount_node_mem.h"
15 #include "nacl_io/osstat.h" 16 #include "nacl_io/osstat.h"
16 #include "nacl_io/path.h" 17 #include "nacl_io/path.h"
17 #include "sdk_util/auto_lock.h" 18 #include "sdk_util/auto_lock.h"
18 #include "sdk_util/ref_object.h" 19 #include "sdk_util/ref_object.h"
19 20
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 // If a file is expected, but it's not a file, then fail. 71 // If a file is expected, but it's not a file, then fail.
71 if ((type & S_IFREG) && node->IsaDir()) 72 if ((type & S_IFREG) && node->IsaDir())
72 return EISDIR; 73 return EISDIR;
73 74
74 // We now have a valid object of the expected type, so return it. 75 // We now have a valid object of the expected type, so return it.
75 *out_node = node; 76 *out_node = node;
76 return 0; 77 return 0;
77 } 78 }
78 79
80 Error MountMem::Access(const Path& path, int a_mode) {
81 AutoLock lock(&lock_);
82 MountNode* node = NULL;
83 Error error = FindNode(path, 0, &node);
84
85 if (error)
86 return error;
87
88 int obj_mode = node->GetMode();
89 if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) ||
90 ((a_mode & W_OK) && !(obj_mode & S_IWRITE)) ||
91 ((a_mode & X_OK) && !(obj_mode & S_IEXEC))) {
binji 2013/06/19 16:46:28 no exec
Matt Giuca 2013/06/20 01:43:14 See comment on mount_html5fs. Also note that rega
binji 2013/06/20 16:07:21 OK
92 return EACCES;
93 }
94
95 return 0;
96 }
97
79 Error MountMem::Open(const Path& path, int mode, MountNode** out_node) { 98 Error MountMem::Open(const Path& path, int mode, MountNode** out_node) {
80 AutoLock lock(&lock_); 99 AutoLock lock(&lock_);
81 MountNode* node = NULL; 100 MountNode* node = NULL;
82 *out_node = NULL; 101 *out_node = NULL;
83 102
84 Error error = FindNode(path, 0, &node); 103 Error error = FindNode(path, 0, &node);
85 104
86 if (error) { 105 if (error) {
87 // If the node does not exist and we can't create it, fail 106 // If the node does not exist and we can't create it, fail
88 if ((mode & O_CREAT) == 0) 107 if ((mode & O_CREAT) == 0)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return ENOTDIR; 239 return ENOTDIR;
221 240
222 if (file_only && child->IsaDir()) 241 if (file_only && child->IsaDir())
223 return EISDIR; 242 return EISDIR;
224 243
225 if (remove_dir && child->ChildCount() > 0) 244 if (remove_dir && child->ChildCount() > 0)
226 return ENOTEMPTY; 245 return ENOTEMPTY;
227 246
228 return parent->RemoveChild(path.Basename()); 247 return parent->RemoveChild(path.Basename());
229 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698