| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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 | 5 |
| 6 #include "nacl_io/mount_node_html5fs.h" | 6 #include "nacl_io/mount_node_html5fs.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <ppapi/c/pp_completion_callback.h> | 10 #include <ppapi/c/pp_completion_callback.h> |
| 11 #include <ppapi/c/pp_directory_entry.h> |
| 11 #include <ppapi/c/pp_errors.h> | 12 #include <ppapi/c/pp_errors.h> |
| 12 #include <ppapi/c/pp_file_info.h> | 13 #include <ppapi/c/pp_file_info.h> |
| 13 #include <ppapi/c/ppb_file_io.h> | 14 #include <ppapi/c/ppb_file_io.h> |
| 14 #include <string.h> | 15 #include <string.h> |
| 15 #include <vector> | 16 #include <vector> |
| 16 #include "nacl_io/mount.h" | 17 #include "nacl_io/mount.h" |
| 17 #include "nacl_io/osdirent.h" | 18 #include "nacl_io/osdirent.h" |
| 18 #include "nacl_io/pepper_interface.h" | 19 #include "nacl_io/pepper_interface.h" |
| 19 #include "utils/auto_lock.h" | 20 #include "utils/auto_lock.h" |
| 20 | 21 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 fileio_resource_, PP_BlockUntilComplete()); | 69 fileio_resource_, PP_BlockUntilComplete()); |
| 69 if (result != PP_OK) { | 70 if (result != PP_OK) { |
| 70 errno = PPErrorToErrno(result); | 71 errno = PPErrorToErrno(result); |
| 71 return -1; | 72 return -1; |
| 72 } | 73 } |
| 73 | 74 |
| 74 return 0; | 75 return 0; |
| 75 } | 76 } |
| 76 | 77 |
| 77 int MountNodeHtml5Fs::GetDents(size_t offs, struct dirent* pdir, size_t size) { | 78 int MountNodeHtml5Fs::GetDents(size_t offs, struct dirent* pdir, size_t size) { |
| 78 // The directory reader interface is a dev interface, if it doesn't exist, | |
| 79 // just fail. | |
| 80 if (!mount_->ppapi()->GetDirectoryReaderInterface()) { | |
| 81 errno = ENOSYS; | |
| 82 return -1; | |
| 83 } | |
| 84 | |
| 85 // If the buffer pointer is invalid, fail | 79 // If the buffer pointer is invalid, fail |
| 86 if (NULL == pdir) { | 80 if (NULL == pdir) { |
| 87 errno = EINVAL; | 81 errno = EINVAL; |
| 88 return -1; | 82 return -1; |
| 89 } | 83 } |
| 90 | 84 |
| 91 // If the buffer is too small, fail | 85 // If the buffer is too small, fail |
| 92 if (size < sizeof(struct dirent)) { | 86 if (size < sizeof(struct dirent)) { |
| 93 errno = EINVAL; | 87 errno = EINVAL; |
| 94 return -1; | 88 return -1; |
| 95 } | 89 } |
| 96 | 90 |
| 97 ScopedResource directory_reader( | |
| 98 mount_->ppapi(), | |
| 99 mount_->ppapi()->GetDirectoryReaderInterface()->Create( | |
| 100 fileref_resource_)); | |
| 101 if (!directory_reader.pp_resource()) { | |
| 102 errno = ENOSYS; | |
| 103 return -1; | |
| 104 } | |
| 105 | |
| 106 OutputBuffer output_buf = { NULL, 0 }; | 91 OutputBuffer output_buf = { NULL, 0 }; |
| 107 PP_ArrayOutput output = { &GetOutputBuffer, &output_buf }; | 92 PP_ArrayOutput output = { &GetOutputBuffer, &output_buf }; |
| 108 int32_t result = mount_->ppapi()->GetDirectoryReaderInterface()->ReadEntries( | 93 int32_t result = mount_->ppapi()->GetFileRefInterface()->ReadEntries( |
| 109 directory_reader.pp_resource(), output, | 94 fileref_resource_, output, PP_BlockUntilComplete()); |
| 110 PP_BlockUntilComplete()); | |
| 111 if (result != PP_OK) { | 95 if (result != PP_OK) { |
| 112 errno = PPErrorToErrno(result); | 96 errno = PPErrorToErrno(result); |
| 113 return -1; | 97 return -1; |
| 114 } | 98 } |
| 115 | 99 |
| 116 std::vector<struct dirent> dirents; | 100 std::vector<struct dirent> dirents; |
| 117 PP_DirectoryEntry_Dev* entries = | 101 PP_DirectoryEntry* entries = |
| 118 static_cast<PP_DirectoryEntry_Dev*>(output_buf.data); | 102 static_cast<PP_DirectoryEntry*>(output_buf.data); |
| 119 | 103 |
| 120 for (int i = 0; i < output_buf.element_count; ++i) { | 104 for (int i = 0; i < output_buf.element_count; ++i) { |
| 121 PP_Var file_name_var = mount_->ppapi()->GetFileRefInterface()->GetName( | 105 PP_Var file_name_var = mount_->ppapi()->GetFileRefInterface()->GetName( |
| 122 entries[i].file_ref); | 106 entries[i].file_ref); |
| 123 | 107 |
| 124 // Release the file reference. | 108 // Release the file reference. |
| 125 mount_->ppapi()->ReleaseResource(entries[i].file_ref); | 109 mount_->ppapi()->ReleaseResource(entries[i].file_ref); |
| 126 | 110 |
| 127 if (file_name_var.type != PP_VARTYPE_STRING) | 111 if (file_name_var.type != PP_VARTYPE_STRING) |
| 128 continue; | 112 continue; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (fileio_resource_) { | 253 if (fileio_resource_) { |
| 270 mount_->ppapi()->GetFileIoInterface()->Close(fileio_resource_); | 254 mount_->ppapi()->GetFileIoInterface()->Close(fileio_resource_); |
| 271 mount_->ppapi()->ReleaseResource(fileio_resource_); | 255 mount_->ppapi()->ReleaseResource(fileio_resource_); |
| 272 } | 256 } |
| 273 | 257 |
| 274 mount_->ppapi()->ReleaseResource(fileref_resource_); | 258 mount_->ppapi()->ReleaseResource(fileref_resource_); |
| 275 fileio_resource_ = 0; | 259 fileio_resource_ = 0; |
| 276 fileref_resource_ = 0; | 260 fileref_resource_ = 0; |
| 277 MountNode::Destroy(); | 261 MountNode::Destroy(); |
| 278 } | 262 } |
| OLD | NEW |