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/fusefs/fuse_fs.h" | 5 #include "nacl_io/fusefs/fuse_fs.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 return ENOSYS; | 83 return ENOSYS; |
84 } | 84 } |
85 } else { | 85 } else { |
86 // First determine if this is a regular file or a directory. | 86 // First determine if this is a regular file or a directory. |
87 if (fuse_ops_->getattr) { | 87 if (fuse_ops_->getattr) { |
88 struct stat statbuf; | 88 struct stat statbuf; |
89 result = fuse_ops_->getattr(path_cstr, &statbuf); | 89 result = fuse_ops_->getattr(path_cstr, &statbuf); |
90 if (result < 0) | 90 if (result < 0) |
91 return -result; | 91 return -result; |
92 | 92 |
93 if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { | 93 if (S_ISDIR(statbuf.st_mode)) { |
94 // This is a directory. Don't try to open, just create a new node with | 94 // This is a directory. Don't try to open, just create a new node with |
95 // this path. | 95 // this path. |
96 ScopedNode node(new DirFuseFsNode(this, fuse_ops_, fi, path_cstr)); | 96 ScopedNode node(new DirFuseFsNode(this, fuse_ops_, fi, path_cstr)); |
97 Error error = node->Init(open_flags); | 97 Error error = node->Init(open_flags); |
98 if (error) | 98 if (error) |
99 return error; | 99 return error; |
100 | 100 |
101 *out_node = node; | 101 *out_node = node; |
102 return 0; | 102 return 0; |
103 } | 103 } |
104 // Get mode. | 104 // Get mode. |
105 mode = statbuf.st_mode & ~S_IFMT; | 105 mode = statbuf.st_mode & 0777; |
bradn
2014/10/20 17:17:34
So we're explicitly excluding things like suid?
| |
106 } | 106 } |
107 | 107 |
108 // Existing file. | 108 // Existing file. |
109 if (open_flags & O_TRUNC) { | 109 if (open_flags & O_TRUNC) { |
110 // According to the FUSE docs, O_TRUNC does two calls: first truncate() | 110 // According to the FUSE docs, O_TRUNC does two calls: first truncate() |
111 // then open(). | 111 // then open(). |
112 if (!fuse_ops_->truncate) { | 112 if (!fuse_ops_->truncate) { |
113 LOG_TRACE("fuse_ops_->truncate is NULL."); | 113 LOG_TRACE("fuse_ops_->truncate is NULL."); |
114 return ENOSYS; | 114 return ENOSYS; |
115 } | 115 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 if (error) | 182 if (error) |
183 return error; | 183 return error; |
184 | 184 |
185 struct stat statbuf; | 185 struct stat statbuf; |
186 error = node->GetStat(&statbuf); | 186 error = node->GetStat(&statbuf); |
187 if (error) | 187 if (error) |
188 return error; | 188 return error; |
189 | 189 |
190 node.reset(); | 190 node.reset(); |
191 | 191 |
192 if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { | 192 if (S_ISDIR(statbuf.st_mode)) { |
193 return Rmdir(path); | 193 return Rmdir(path); |
194 } else { | 194 } else { |
195 return Unlink(path); | 195 return Unlink(path); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 Error FuseFs::Rename(const Path& path, const Path& newpath) { | 199 Error FuseFs::Rename(const Path& path, const Path& newpath) { |
200 if (!fuse_ops_->rename) { | 200 if (!fuse_ops_->rename) { |
201 LOG_TRACE("fuse_ops_->rename is NULL."); | 201 LOG_TRACE("fuse_ops_->rename is NULL."); |
202 return ENOSYS; | 202 return ENOSYS; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 } else { | 490 } else { |
491 fill_info->getdents->AddDirent(ino, name, strlen(name)); | 491 fill_info->getdents->AddDirent(ino, name, strlen(name)); |
492 fill_info->num_bytes -= sizeof(dirent); | 492 fill_info->num_bytes -= sizeof(dirent); |
493 // According to the docs, we can never return 1 (buffer full) when the | 493 // According to the docs, we can never return 1 (buffer full) when the |
494 // offset is zero (the user is probably ignoring the result anyway). | 494 // offset is zero (the user is probably ignoring the result anyway). |
495 return 0; | 495 return 0; |
496 } | 496 } |
497 } | 497 } |
498 | 498 |
499 } // namespace nacl_io | 499 } // namespace nacl_io |
OLD | NEW |