OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memfs/mem_fs.h" | 5 #include "nacl_io/memfs/mem_fs.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 // If a file is expected, but it's not a file, then fail. | 69 // If a file is expected, but it's not a file, then fail. |
70 if ((type & S_IFREG) && node->IsaDir()) | 70 if ((type & S_IFREG) && node->IsaDir()) |
71 return EISDIR; | 71 return EISDIR; |
72 | 72 |
73 // We now have a valid object of the expected type, so return it. | 73 // We now have a valid object of the expected type, so return it. |
74 *out_node = node; | 74 *out_node = node; |
75 return 0; | 75 return 0; |
76 } | 76 } |
77 | 77 |
78 Error MemFs::Access(const Path& path, int a_mode) { | |
79 ScopedNode node; | |
80 Error error = FindNode(path, 0, &node); | |
81 | |
82 if (error) | |
83 return error; | |
84 | |
85 int obj_mode = node->GetMode(); | |
86 if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) || | |
87 ((a_mode & W_OK) && !(obj_mode & S_IWRITE)) || | |
88 ((a_mode & X_OK) && !(obj_mode & S_IEXEC))) { | |
89 return EACCES; | |
90 } | |
91 | |
92 return 0; | |
93 } | |
94 | |
95 Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { | 78 Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { |
96 out_node->reset(NULL); | 79 out_node->reset(NULL); |
97 ScopedNode node; | 80 ScopedNode node; |
98 | 81 |
99 Error error = FindNode(path, 0, &node); | 82 Error error = FindNode(path, 0, &node); |
100 if (error) { | 83 if (error) { |
101 // If the node does not exist and we can't create it, fail | 84 // If the node does not exist and we can't create it, fail |
102 if ((open_flags & O_CREAT) == 0) | 85 if ((open_flags & O_CREAT) == 0) |
103 return ENOENT; | 86 return ENOENT; |
104 | 87 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (file_only && child->IsaDir()) | 265 if (file_only && child->IsaDir()) |
283 return EISDIR; | 266 return EISDIR; |
284 | 267 |
285 if (remove_dir && child->ChildCount() > 0) | 268 if (remove_dir && child->ChildCount() > 0) |
286 return ENOTEMPTY; | 269 return ENOTEMPTY; |
287 | 270 |
288 return parent->RemoveChild(path.Basename()); | 271 return parent->RemoveChild(path.Basename()); |
289 } | 272 } |
290 | 273 |
291 } // namespace nacl_io | 274 } // namespace nacl_io |
OLD | NEW |