| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 return 0; | 52 return 0; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void FuseFs::Destroy() { | 55 void FuseFs::Destroy() { |
| 56 if (fuse_ops_ && fuse_ops_->destroy) | 56 if (fuse_ops_ && fuse_ops_->destroy) |
| 57 fuse_ops_->destroy(fuse_user_data_); | 57 fuse_ops_->destroy(fuse_user_data_); |
| 58 } | 58 } |
| 59 | 59 |
| 60 Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { | 60 Error FuseFs::OpenWithMode(const Path& path, int open_flags, mode_t mode, |
| 61 ScopedNode* out_node) { |
| 61 std::string path_str = path.Join(); | 62 std::string path_str = path.Join(); |
| 62 const char* path_cstr = path_str.c_str(); | 63 const char* path_cstr = path_str.c_str(); |
| 63 int result = 0; | 64 int result = 0; |
| 64 | 65 |
| 65 struct fuse_file_info fi; | 66 struct fuse_file_info fi; |
| 66 memset(&fi, 0, sizeof(fi)); | 67 memset(&fi, 0, sizeof(fi)); |
| 67 fi.flags = open_flags; | 68 fi.flags = open_flags; |
| 68 | 69 |
| 69 if (open_flags & (O_CREAT | O_EXCL)) { | 70 if (open_flags & (O_CREAT | O_EXCL)) { |
| 70 // According to the FUSE docs, open() is not called when O_CREAT or O_EXCL | 71 // According to the FUSE docs, open() is not called when O_CREAT or O_EXCL |
| 71 // is passed. | 72 // is passed. |
| 72 mode_t mode = S_IRALL | S_IWALL; | |
| 73 if (fuse_ops_->create) { | 73 if (fuse_ops_->create) { |
| 74 result = fuse_ops_->create(path_cstr, mode, &fi); | 74 result = fuse_ops_->create(path_cstr, mode, &fi); |
| 75 if (result < 0) | 75 if (result < 0) |
| 76 return -result; | 76 return -result; |
| 77 } else if (fuse_ops_->mknod) { | 77 } else if (fuse_ops_->mknod) { |
| 78 result = fuse_ops_->mknod(path_cstr, mode, dev_); | 78 result = fuse_ops_->mknod(path_cstr, mode, dev_); |
| 79 if (result < 0) | 79 if (result < 0) |
| 80 return -result; | 80 return -result; |
| 81 } else { | 81 } else { |
| 82 LOG_TRACE("fuse_ops_->create and fuse_ops_->mknod are NULL."); | 82 LOG_TRACE("fuse_ops_->create and fuse_ops_->mknod are NULL."); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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. |
| 105 mode = statbuf.st_mode & ~S_IFMT; |
| 104 } | 106 } |
| 105 | 107 |
| 106 // Existing file. | 108 // Existing file. |
| 107 if (open_flags & O_TRUNC) { | 109 if (open_flags & O_TRUNC) { |
| 108 // 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() |
| 109 // then open(). | 111 // then open(). |
| 110 if (!fuse_ops_->truncate) { | 112 if (!fuse_ops_->truncate) { |
| 111 LOG_TRACE("fuse_ops_->truncate is NULL."); | 113 LOG_TRACE("fuse_ops_->truncate is NULL."); |
| 112 return ENOSYS; | 114 return ENOSYS; |
| 113 } | 115 } |
| 114 result = fuse_ops_->truncate(path_cstr, 0); | 116 result = fuse_ops_->truncate(path_cstr, 0); |
| 115 if (result < 0) | 117 if (result < 0) |
| 116 return -result; | 118 return -result; |
| 117 } | 119 } |
| 118 | 120 |
| 119 if (!fuse_ops_->open) { | 121 if (!fuse_ops_->open) { |
| 120 LOG_TRACE("fuse_ops_->open is NULL."); | 122 LOG_TRACE("fuse_ops_->open is NULL."); |
| 121 return ENOSYS; | 123 return ENOSYS; |
| 122 } | 124 } |
| 123 result = fuse_ops_->open(path_cstr, &fi); | 125 result = fuse_ops_->open(path_cstr, &fi); |
| 124 if (result < 0) | 126 if (result < 0) |
| 125 return -result; | 127 return -result; |
| 126 } | 128 } |
| 127 | 129 |
| 128 ScopedNode node(new FileFuseFsNode(this, fuse_ops_, fi, path_cstr)); | 130 ScopedNode node(new FileFuseFsNode(this, fuse_ops_, fi, path_cstr)); |
| 129 Error error = node->Init(open_flags); | 131 Error error = node->Init(open_flags); |
| 130 if (error) | 132 if (error) |
| 131 return error; | 133 return error; |
| 134 node->SetMode(mode); |
| 132 | 135 |
| 133 *out_node = node; | 136 *out_node = node; |
| 134 return 0; | 137 return 0; |
| 135 } | 138 } |
| 136 | 139 |
| 137 Error FuseFs::Unlink(const Path& path) { | 140 Error FuseFs::Unlink(const Path& path) { |
| 138 if (!fuse_ops_->unlink) { | 141 if (!fuse_ops_->unlink) { |
| 139 LOG_TRACE("fuse_ops_->unlink is NULL."); | 142 LOG_TRACE("fuse_ops_->unlink is NULL."); |
| 140 return ENOSYS; | 143 return ENOSYS; |
| 141 } | 144 } |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } else { | 462 } else { |
| 460 fill_info->getdents->AddDirent(ino, name, strlen(name)); | 463 fill_info->getdents->AddDirent(ino, name, strlen(name)); |
| 461 fill_info->num_bytes -= sizeof(dirent); | 464 fill_info->num_bytes -= sizeof(dirent); |
| 462 // According to the docs, we can never return 1 (buffer full) when the | 465 // According to the docs, we can never return 1 (buffer full) when the |
| 463 // offset is zero (the user is probably ignoring the result anyway). | 466 // offset is zero (the user is probably ignoring the result anyway). |
| 464 return 0; | 467 return 0; |
| 465 } | 468 } |
| 466 } | 469 } |
| 467 | 470 |
| 468 } // namespace nacl_io | 471 } // namespace nacl_io |
| OLD | NEW |