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> |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace { | 22 namespace { |
23 | 23 |
24 #if defined(WIN32) | 24 #if defined(WIN32) |
25 int64_t strtoull(const char* nptr, char** endptr, int base) { | 25 int64_t strtoull(const char* nptr, char** endptr, int base) { |
26 return _strtoui64(nptr, endptr, base); | 26 return _strtoui64(nptr, endptr, base); |
27 } | 27 } |
28 #endif | 28 #endif |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
| 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 char *ptr = path.Part(segment).c_str(); |
| 49 size_t len = path.Part(segment).length(); |
| 50 hash = HashPathSegment(hash, ptr, len); |
| 51 } |
| 52 return hash; |
| 53 } |
| 54 |
| 55 |
| 56 // For HTML5, the INO should be the one used by the system, however PPAPI |
| 57 // does not provide access to the real INO. Instead, since HTML5 does not |
| 58 // suport links, we assume that files are unique based on path to the base |
| 59 // of the mount. |
| 60 void Html5Fs::OnNodeCreated(Node* node) { |
| 61 node->stat_.st_dev = dev_; |
| 62 } |
| 63 |
| 64 void Html5Fs::OnNodeDestroyed(Node* node) {} |
| 65 |
| 66 |
32 Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode, | 67 Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode, |
33 ScopedNode* out_node) { | 68 ScopedNode* out_node) { |
34 out_node->reset(NULL); | 69 out_node->reset(NULL); |
35 Error error = BlockUntilFilesystemOpen(); | 70 Error error = BlockUntilFilesystemOpen(); |
36 if (error) | 71 if (error) |
37 return error; | 72 return error; |
38 | 73 |
39 PP_Resource fileref = file_ref_iface_->Create( | 74 PP_Resource fileref = file_ref_iface_->Create( |
40 filesystem_resource_, GetFullPath(path).Join().c_str()); | 75 filesystem_resource_, GetFullPath(path).Join().c_str()); |
41 if (!fileref) | 76 if (!fileref) |
42 return ENOENT; | 77 return ENOENT; |
43 | 78 |
44 ScopedNode node(new Html5FsNode(this, fileref)); | 79 ScopedNode node(new Html5FsNode(this, fileref)); |
45 error = node->Init(open_flags); | 80 error = node->Init(open_flags); |
| 81 |
| 82 // Set the INO based on the path |
| 83 node->stat_.st_ino = HashPath(path); |
| 84 |
46 if (error) | 85 if (error) |
47 return error; | 86 return error; |
48 | 87 |
49 *out_node = node; | 88 *out_node = node; |
50 return 0; | 89 return 0; |
51 } | 90 } |
52 | 91 |
53 Path Html5Fs::GetFullPath(const Path& path) { | 92 Path Html5Fs::GetFullPath(const Path& path) { |
54 Path full_path(path); | 93 Path full_path(path); |
55 full_path.Prepend(prefix_); | 94 full_path.Prepend(prefix_); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 331 } |
293 | 332 |
294 void Html5Fs::FilesystemOpenCallback(int32_t result) { | 333 void Html5Fs::FilesystemOpenCallback(int32_t result) { |
295 AUTO_LOCK(filesysem_open_lock_); | 334 AUTO_LOCK(filesysem_open_lock_); |
296 filesystem_open_has_result_ = true; | 335 filesystem_open_has_result_ = true; |
297 filesystem_open_error_ = PPErrorToErrno(result); | 336 filesystem_open_error_ = PPErrorToErrno(result); |
298 pthread_cond_signal(&filesystem_open_cond_); | 337 pthread_cond_signal(&filesystem_open_cond_); |
299 } | 338 } |
300 | 339 |
301 } // namespace nacl_io | 340 } // namespace nacl_io |
OLD | NEW |