Chromium Code Reviews| 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 | |
| 33 // Use a simple rotating hash to modify all bits. | |
| 34 static inline ino_t HashChar(ino_t hash, char c) { | |
|
binji
2014/09/25 15:01:17
I'd add these to the anonymous namespace above rat
noelallen1
2014/09/25 18:10:08
Done.
| |
| 35 const ino_t bits = (ino_t) (sizeof(ino_t) * 8); | |
| 36 ino_t out = (hash << 5) + (hash >> (ino_t) (bits - 5)); | |
| 37 return out ^ c; | |
|
Sam Clegg
2014/09/25 19:12:09
Is this is well known hash function? Perhaps at a
noelallen1
2014/09/25 21:01:38
I actually went ahead and changed this to a well k
| |
| 38 } | |
| 39 | |
| 40 static ino_t HashPath(const Path& path) { | |
| 41 ino_t hash = 0x12345678; | |
| 42 for (size_t segment = 0; segment < path.Size(); segment++) { | |
| 43 hash = HashChar(hash, '/'); | |
| 44 const char *ptr = path.Part(segment).c_str(); | |
| 45 while (ptr) { | |
|
binji
2014/09/25 15:01:17
while (*ptr)
noelallen1
2014/09/25 18:10:08
Interesting, why didn't our current tests catch th
| |
| 46 hash = HashChar(hash, *ptr++); | |
| 47 } | |
| 48 } | |
| 49 return hash; | |
| 50 } | |
| 51 | |
| 52 // For HTML5, the INO should be the one used by the system, however PPAPI | |
|
binji
2014/09/25 15:01:17
It is not clear from the comment that you are over
noelallen1
2014/09/25 18:10:08
Done.
| |
| 53 // does not provide access to the real INO. Instead, since HTML5 does not | |
| 54 // suport links, we assume that files are unique based on path to the base | |
| 55 // of the mount. | |
| 56 void Html5Fs::OnNodeCreated(Node* node) { | |
| 57 node->stat_.st_dev = dev_; | |
| 58 } | |
| 59 | |
| 60 void Html5Fs::OnNodeDestroyed(Node* node) {} | |
| 61 | |
| 62 | |
| 32 Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode, | 63 Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode, |
| 33 ScopedNode* out_node) { | 64 ScopedNode* out_node) { |
| 34 out_node->reset(NULL); | 65 out_node->reset(NULL); |
| 35 Error error = BlockUntilFilesystemOpen(); | 66 Error error = BlockUntilFilesystemOpen(); |
| 36 if (error) | 67 if (error) |
| 37 return error; | 68 return error; |
| 38 | 69 |
| 39 PP_Resource fileref = file_ref_iface_->Create( | 70 PP_Resource fileref = file_ref_iface_->Create( |
| 40 filesystem_resource_, GetFullPath(path).Join().c_str()); | 71 filesystem_resource_, GetFullPath(path).Join().c_str()); |
| 41 if (!fileref) | 72 if (!fileref) |
| 42 return ENOENT; | 73 return ENOENT; |
| 43 | 74 |
| 44 ScopedNode node(new Html5FsNode(this, fileref)); | 75 ScopedNode node(new Html5FsNode(this, fileref)); |
| 45 error = node->Init(open_flags); | 76 error = node->Init(open_flags); |
| 77 | |
| 78 // Set the INO based on the path | |
| 79 node->stat_.st_ino = HashPath(path); | |
|
binji
2014/09/25 15:01:17
This will fix GetStat, but GetDents is also return
noelallen1
2014/09/25 18:10:08
Done.
| |
| 80 | |
| 46 if (error) | 81 if (error) |
| 47 return error; | 82 return error; |
| 48 | 83 |
| 49 *out_node = node; | 84 *out_node = node; |
| 50 return 0; | 85 return 0; |
| 51 } | 86 } |
| 52 | 87 |
| 53 Path Html5Fs::GetFullPath(const Path& path) { | 88 Path Html5Fs::GetFullPath(const Path& path) { |
| 54 Path full_path(path); | 89 Path full_path(path); |
| 55 full_path.Prepend(prefix_); | 90 full_path.Prepend(prefix_); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 } | 327 } |
| 293 | 328 |
| 294 void Html5Fs::FilesystemOpenCallback(int32_t result) { | 329 void Html5Fs::FilesystemOpenCallback(int32_t result) { |
| 295 AUTO_LOCK(filesysem_open_lock_); | 330 AUTO_LOCK(filesysem_open_lock_); |
| 296 filesystem_open_has_result_ = true; | 331 filesystem_open_has_result_ = true; |
| 297 filesystem_open_error_ = PPErrorToErrno(result); | 332 filesystem_open_error_ = PPErrorToErrno(result); |
| 298 pthread_cond_signal(&filesystem_open_cond_); | 333 pthread_cond_signal(&filesystem_open_cond_); |
| 299 } | 334 } |
| 300 | 335 |
| 301 } // namespace nacl_io | 336 } // namespace nacl_io |
| OLD | NEW |