| 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/html5fs/html5_fs.h" | 5 #include "nacl_io/html5fs/html5_fs.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 #include <ppapi/c/pp_completion_callback.h> | 14 #include <ppapi/c/pp_completion_callback.h> |
| 15 #include <ppapi/c/pp_errors.h> | 15 #include <ppapi/c/pp_errors.h> |
| 16 | 16 |
| 17 #include "nacl_io/hash.h" |
| 17 #include "nacl_io/html5fs/html5_fs_node.h" | 18 #include "nacl_io/html5fs/html5_fs_node.h" |
| 18 #include "sdk_util/auto_lock.h" | 19 #include "sdk_util/auto_lock.h" |
| 19 | 20 |
| 20 namespace nacl_io { | 21 namespace nacl_io { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 #if defined(WIN32) | 25 #if defined(WIN32) |
| 25 int64_t strtoull(const char* nptr, char** endptr, int base) { | 26 int64_t strtoull(const char* nptr, char** endptr, int base) { |
| 26 return _strtoui64(nptr, endptr, base); | 27 return _strtoui64(nptr, endptr, base); |
| 27 } | 28 } |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 // Continuing DJB2a hash | |
| 33 ino_t Html5Fs::HashPathSegment(ino_t hash, const char *str, size_t len) { | |
| 34 // First add the path seperator | |
| 35 hash = (hash * static_cast<ino_t>(33)) ^ '/'; | |
| 36 while (len--) { | |
| 37 hash = (hash * static_cast<ino_t>(33)) ^ *str++; | |
| 38 } | |
| 39 return hash; | |
| 40 } | |
| 41 | |
| 42 ino_t Html5Fs::HashPath(const Path& path) { | |
| 43 // Prime the DJB2a hash | |
| 44 ino_t hash = 5381; | |
| 45 | |
| 46 // Apply a running DJB2a to each part of the path | |
| 47 for (size_t segment = 0; segment < path.Size(); segment++) { | |
| 48 const std::string& part = path.Part(segment); | |
| 49 hash = HashPathSegment(hash, part.c_str(), part.length()); | |
| 50 } | |
| 51 return hash; | |
| 52 } | |
| 53 | |
| 54 | |
| 55 // For HTML5, the INO should be the one used by the system, however PPAPI | 33 // For HTML5, the INO should be the one used by the system, however PPAPI |
| 56 // does not provide access to the real INO. Instead, since HTML5 does not | 34 // does not provide access to the real INO. Instead, since HTML5 does not |
| 57 // suport links, we assume that files are unique based on path to the base | 35 // suport links, we assume that files are unique based on path to the base |
| 58 // of the mount. | 36 // of the mount. |
| 59 void Html5Fs::OnNodeCreated(Node* node) { | 37 void Html5Fs::OnNodeCreated(Node* node) { |
| 60 node->stat_.st_dev = dev_; | 38 node->stat_.st_dev = dev_; |
| 61 } | 39 } |
| 62 | 40 |
| 63 void Html5Fs::OnNodeDestroyed(Node* node) {} | 41 void Html5Fs::OnNodeDestroyed(Node* node) {} |
| 64 | 42 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 316 } |
| 339 | 317 |
| 340 void Html5Fs::FilesystemOpenCallback(int32_t result) { | 318 void Html5Fs::FilesystemOpenCallback(int32_t result) { |
| 341 AUTO_LOCK(filesysem_open_lock_); | 319 AUTO_LOCK(filesysem_open_lock_); |
| 342 filesystem_open_has_result_ = true; | 320 filesystem_open_has_result_ = true; |
| 343 filesystem_open_error_ = PPERROR_TO_ERRNO(result); | 321 filesystem_open_error_ = PPERROR_TO_ERRNO(result); |
| 344 pthread_cond_signal(&filesystem_open_cond_); | 322 pthread_cond_signal(&filesystem_open_cond_); |
| 345 } | 323 } |
| 346 | 324 |
| 347 } // namespace nacl_io | 325 } // namespace nacl_io |
| OLD | NEW |