OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 #include "nacl_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 <unistd.h> |
| 10 |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "nacl_io/mount.h" | 13 #include "nacl_io/mount.h" |
12 #include "nacl_io/mount_node.h" | 14 #include "nacl_io/mount_node.h" |
13 #include "nacl_io/mount_node_dir.h" | 15 #include "nacl_io/mount_node_dir.h" |
14 #include "nacl_io/mount_node_mem.h" | 16 #include "nacl_io/mount_node_mem.h" |
15 #include "nacl_io/osstat.h" | 17 #include "nacl_io/osstat.h" |
16 #include "nacl_io/path.h" | 18 #include "nacl_io/path.h" |
17 #include "sdk_util/auto_lock.h" | 19 #include "sdk_util/auto_lock.h" |
18 #include "sdk_util/ref_object.h" | 20 #include "sdk_util/ref_object.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 71 |
70 // If a file is expected, but it's not a file, then fail. | 72 // If a file is expected, but it's not a file, then fail. |
71 if ((type & S_IFREG) && node->IsaDir()) | 73 if ((type & S_IFREG) && node->IsaDir()) |
72 return EISDIR; | 74 return EISDIR; |
73 | 75 |
74 // We now have a valid object of the expected type, so return it. | 76 // We now have a valid object of the expected type, so return it. |
75 *out_node = node; | 77 *out_node = node; |
76 return 0; | 78 return 0; |
77 } | 79 } |
78 | 80 |
| 81 Error MountMem::Access(const Path& path, int a_mode) { |
| 82 AutoLock lock(&lock_); |
| 83 MountNode* node = NULL; |
| 84 Error error = FindNode(path, 0, &node); |
| 85 |
| 86 if (error) |
| 87 return error; |
| 88 |
| 89 int obj_mode = node->GetMode(); |
| 90 if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) || |
| 91 ((a_mode & W_OK) && !(obj_mode & S_IWRITE)) || |
| 92 ((a_mode & X_OK) && !(obj_mode & S_IEXEC))) { |
| 93 return EACCES; |
| 94 } |
| 95 |
| 96 return 0; |
| 97 } |
| 98 |
79 Error MountMem::Open(const Path& path, int mode, MountNode** out_node) { | 99 Error MountMem::Open(const Path& path, int mode, MountNode** out_node) { |
80 AutoLock lock(&lock_); | 100 AutoLock lock(&lock_); |
81 MountNode* node = NULL; | 101 MountNode* node = NULL; |
82 *out_node = NULL; | 102 *out_node = NULL; |
83 | 103 |
84 Error error = FindNode(path, 0, &node); | 104 Error error = FindNode(path, 0, &node); |
85 | 105 |
86 if (error) { | 106 if (error) { |
87 // If the node does not exist and we can't create it, fail | 107 // If the node does not exist and we can't create it, fail |
88 if ((mode & O_CREAT) == 0) | 108 if ((mode & O_CREAT) == 0) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return ENOTDIR; | 240 return ENOTDIR; |
221 | 241 |
222 if (file_only && child->IsaDir()) | 242 if (file_only && child->IsaDir()) |
223 return EISDIR; | 243 return EISDIR; |
224 | 244 |
225 if (remove_dir && child->ChildCount() > 0) | 245 if (remove_dir && child->ChildCount() > 0) |
226 return ENOTEMPTY; | 246 return ENOTEMPTY; |
227 | 247 |
228 return parent->RemoveChild(path.Basename()); | 248 return parent->RemoveChild(path.Basename()); |
229 } | 249 } |
OLD | NEW |