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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/memfs/mem_fs.cc

Issue 565763002: Plumbing though mode parameter to open, since fusefs can make use of it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years, 3 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 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
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;
99 node->SetMode(mode);
98 100
99 error = parent->AddChild(path.Basename(), node); 101 error = parent->AddChild(path.Basename(), node);
100 if (error) 102 if (error)
101 return error; 103 return error;
102 104
103 } else { 105 } else {
104 // Opening an existing file. 106 // Opening an existing file.
105 107
106 // Directories can only be opened read-only. 108 // Directories can only be opened read-only.
107 if (node->IsaDir() && (open_flags & 3) != O_RDONLY) 109 if (node->IsaDir() && (open_flags & 3) != O_RDONLY)
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (file_only && child->IsaDir()) 267 if (file_only && child->IsaDir())
266 return EISDIR; 268 return EISDIR;
267 269
268 if (remove_dir && child->ChildCount() > 0) 270 if (remove_dir && child->ChildCount() > 0)
269 return ENOTEMPTY; 271 return ENOTEMPTY;
270 272
271 return parent->RemoveChild(path.Basename()); 273 return parent->RemoveChild(path.Basename());
272 } 274 }
273 275
274 } // namespace nacl_io 276 } // namespace nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698