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::Open(const Path& path, int open_flags, ScopedNode* out_node) { | 78 Error MemFs::OpenWithMode(const Path& path, int open_flags, mode_t mode, |
79 ScopedNode* out_node) { | |
79 out_node->reset(NULL); | 80 out_node->reset(NULL); |
80 ScopedNode node; | 81 ScopedNode node; |
81 | 82 |
82 Error error = FindNode(path, 0, &node); | 83 Error error = FindNode(path, 0, &node); |
83 if (error) { | 84 if (error) { |
84 // If the node does not exist and we can't create it, fail | 85 // If the node does not exist and we can't create it, fail |
85 if ((open_flags & O_CREAT) == 0) | 86 if ((open_flags & O_CREAT) == 0) |
86 return ENOENT; | 87 return ENOENT; |
87 | 88 |
88 // Now first find the parent directory to see if we can add it | 89 // Now first find the parent directory to see if we can add it |
89 ScopedNode parent; | 90 ScopedNode parent; |
90 error = FindNode(path.Parent(), S_IFDIR, &parent); | 91 error = FindNode(path.Parent(), S_IFDIR, &parent); |
91 if (error) | 92 if (error) |
92 return error; | 93 return error; |
93 | 94 |
94 node.reset(new MemFsNode(this)); | 95 node.reset(new MemFsNode(this)); |
95 error = node->Init(open_flags); | 96 error = node->Init(open_flags); |
96 if (error) | 97 if (error) |
97 return error; | 98 return error; |
98 | 99 |
Sam Clegg
2014/09/11 23:47:08
SetMode()?
bradn
2014/09/12 06:17:03
Done.
| |
99 error = parent->AddChild(path.Basename(), node); | 100 error = parent->AddChild(path.Basename(), node); |
100 if (error) | 101 if (error) |
101 return error; | 102 return error; |
102 | 103 |
103 } else { | 104 } else { |
104 // Opening an existing file. | 105 // Opening an existing file. |
105 | 106 |
106 // Directories can only be opened read-only. | 107 // Directories can only be opened read-only. |
107 if (node->IsaDir() && (open_flags & 3) != O_RDONLY) | 108 if (node->IsaDir() && (open_flags & 3) != O_RDONLY) |
108 return EISDIR; | 109 return EISDIR; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 if (file_only && child->IsaDir()) | 266 if (file_only && child->IsaDir()) |
266 return EISDIR; | 267 return EISDIR; |
267 | 268 |
268 if (remove_dir && child->ChildCount() > 0) | 269 if (remove_dir && child->ChildCount() > 0) |
269 return ENOTEMPTY; | 270 return ENOTEMPTY; |
270 | 271 |
271 return parent->RemoveChild(path.Basename()); | 272 return parent->RemoveChild(path.Basename()); |
272 } | 273 } |
273 | 274 |
274 } // namespace nacl_io | 275 } // namespace nacl_io |
OLD | NEW |