| 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 11 matching lines...) Expand all Loading... |
| 22 FillDirInfo(GetDentsHelper* getdents, size_t num_bytes) | 22 FillDirInfo(GetDentsHelper* getdents, size_t num_bytes) |
| 23 : getdents(getdents), num_bytes(num_bytes), wrote_offset(false) {} | 23 : getdents(getdents), num_bytes(num_bytes), wrote_offset(false) {} |
| 24 | 24 |
| 25 GetDentsHelper* getdents; | 25 GetDentsHelper* getdents; |
| 26 size_t num_bytes; | 26 size_t num_bytes; |
| 27 bool wrote_offset; | 27 bool wrote_offset; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 FuseFs::FuseFs() : fuse_ops_(NULL), fuse_user_data_(NULL) {} | 32 FuseFs::FuseFs() : fuse_ops_(NULL), fuse_user_data_(NULL) { |
| 33 } |
| 33 | 34 |
| 34 Error FuseFs::Init(const FsInitArgs& args) { | 35 Error FuseFs::Init(const FsInitArgs& args) { |
| 35 Error error = Filesystem::Init(args); | 36 Error error = Filesystem::Init(args); |
| 36 if (error) | 37 if (error) |
| 37 return error; | 38 return error; |
| 38 | 39 |
| 39 fuse_ops_ = args.fuse_ops; | 40 fuse_ops_ = args.fuse_ops; |
| 40 if (fuse_ops_ == NULL) | 41 if (fuse_ops_ == NULL) |
| 41 return EINVAL; | 42 return EINVAL; |
| 42 | 43 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (result < 0) | 198 if (result < 0) |
| 198 return -result; | 199 return -result; |
| 199 | 200 |
| 200 return 0; | 201 return 0; |
| 201 } | 202 } |
| 202 | 203 |
| 203 FuseFsNode::FuseFsNode(Filesystem* filesystem, | 204 FuseFsNode::FuseFsNode(Filesystem* filesystem, |
| 204 struct fuse_operations* fuse_ops, | 205 struct fuse_operations* fuse_ops, |
| 205 struct fuse_file_info& info, | 206 struct fuse_file_info& info, |
| 206 const std::string& path) | 207 const std::string& path) |
| 207 : Node(filesystem), fuse_ops_(fuse_ops), info_(info), path_(path) {} | 208 : Node(filesystem), fuse_ops_(fuse_ops), info_(info), path_(path) { |
| 209 } |
| 208 | 210 |
| 209 bool FuseFsNode::CanOpen(int open_flags) { | 211 bool FuseFsNode::CanOpen(int open_flags) { |
| 210 struct stat statbuf; | 212 struct stat statbuf; |
| 211 Error error = GetStat(&statbuf); | 213 Error error = GetStat(&statbuf); |
| 212 if (error) | 214 if (error) |
| 213 return false; | 215 return false; |
| 214 | 216 |
| 215 // GetStat cached the mode in stat_.st_mode. Forward to Node::CanOpen, | 217 // GetStat cached the mode in stat_.st_mode. Forward to Node::CanOpen, |
| 216 // which will check this mode against open_flags. | 218 // which will check this mode against open_flags. |
| 217 return Node::CanOpen(open_flags); | 219 return Node::CanOpen(open_flags); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return error; | 266 return error; |
| 265 | 267 |
| 266 *out_size = stat_.st_size; | 268 *out_size = stat_.st_size; |
| 267 return 0; | 269 return 0; |
| 268 } | 270 } |
| 269 | 271 |
| 270 FileFuseFsNode::FileFuseFsNode(Filesystem* filesystem, | 272 FileFuseFsNode::FileFuseFsNode(Filesystem* filesystem, |
| 271 struct fuse_operations* fuse_ops, | 273 struct fuse_operations* fuse_ops, |
| 272 struct fuse_file_info& info, | 274 struct fuse_file_info& info, |
| 273 const std::string& path) | 275 const std::string& path) |
| 274 : FuseFsNode(filesystem, fuse_ops, info, path) {} | 276 : FuseFsNode(filesystem, fuse_ops, info, path) { |
| 277 } |
| 275 | 278 |
| 276 void FileFuseFsNode::Destroy() { | 279 void FileFuseFsNode::Destroy() { |
| 277 if (!fuse_ops_->release) | 280 if (!fuse_ops_->release) |
| 278 return; | 281 return; |
| 279 fuse_ops_->release(path_.c_str(), &info_); | 282 fuse_ops_->release(path_.c_str(), &info_); |
| 280 } | 283 } |
| 281 | 284 |
| 282 Error FileFuseFsNode::FSync() { | 285 Error FileFuseFsNode::FSync() { |
| 283 if (!fuse_ops_->fsync) | 286 if (!fuse_ops_->fsync) |
| 284 return ENOSYS; | 287 return ENOSYS; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // TODO(binji): What should we do if the user breaks this contract? Warn? | 343 // TODO(binji): What should we do if the user breaks this contract? Warn? |
| 341 // TODO(binji): support the direct_io flag | 344 // TODO(binji): support the direct_io flag |
| 342 *out_bytes = result; | 345 *out_bytes = result; |
| 343 return 0; | 346 return 0; |
| 344 } | 347 } |
| 345 | 348 |
| 346 DirFuseFsNode::DirFuseFsNode(Filesystem* filesystem, | 349 DirFuseFsNode::DirFuseFsNode(Filesystem* filesystem, |
| 347 struct fuse_operations* fuse_ops, | 350 struct fuse_operations* fuse_ops, |
| 348 struct fuse_file_info& info, | 351 struct fuse_file_info& info, |
| 349 const std::string& path) | 352 const std::string& path) |
| 350 : FuseFsNode(filesystem, fuse_ops, info, path) {} | 353 : FuseFsNode(filesystem, fuse_ops, info, path) { |
| 354 } |
| 351 | 355 |
| 352 void DirFuseFsNode::Destroy() { | 356 void DirFuseFsNode::Destroy() { |
| 353 if (!fuse_ops_->releasedir) | 357 if (!fuse_ops_->releasedir) |
| 354 return; | 358 return; |
| 355 fuse_ops_->releasedir(path_.c_str(), &info_); | 359 fuse_ops_->releasedir(path_.c_str(), &info_); |
| 356 } | 360 } |
| 357 | 361 |
| 358 Error DirFuseFsNode::FSync() { | 362 Error DirFuseFsNode::FSync() { |
| 359 if (!fuse_ops_->fsyncdir) | 363 if (!fuse_ops_->fsyncdir) |
| 360 return ENOSYS; | 364 return ENOSYS; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } else { | 446 } else { |
| 443 fill_info->getdents->AddDirent(ino, name, strlen(name)); | 447 fill_info->getdents->AddDirent(ino, name, strlen(name)); |
| 444 fill_info->num_bytes -= sizeof(dirent); | 448 fill_info->num_bytes -= sizeof(dirent); |
| 445 // According to the docs, we can never return 1 (buffer full) when the | 449 // According to the docs, we can never return 1 (buffer full) when the |
| 446 // offset is zero (the user is probably ignoring the result anyway). | 450 // offset is zero (the user is probably ignoring the result anyway). |
| 447 return 0; | 451 return 0; |
| 448 } | 452 } |
| 449 } | 453 } |
| 450 | 454 |
| 451 } // namespace nacl_io | 455 } // namespace nacl_io |
| OLD | NEW |