Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc

Issue 605513002: [NaCl SDK] nacl_io: Replace allocated ino with hash of path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
index c747733231042d864218a51db54c9536ba8172d9..cf410fdc0bf9485aa7c04f376639a35b63ad46a3 100644
--- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
@@ -29,6 +29,37 @@ int64_t strtoull(const char* nptr, char** endptr, int base) {
} // namespace
+
+// Use a simple rotating hash to modify all bits.
+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.
+ const ino_t bits = (ino_t) (sizeof(ino_t) * 8);
+ ino_t out = (hash << 5) + (hash >> (ino_t) (bits - 5));
+ 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
+}
+
+static ino_t HashPath(const Path& path) {
+ ino_t hash = 0x12345678;
+ for (size_t segment = 0; segment < path.Size(); segment++) {
+ hash = HashChar(hash, '/');
+ const char *ptr = path.Part(segment).c_str();
+ 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
+ hash = HashChar(hash, *ptr++);
+ }
+ }
+ return hash;
+}
+
+// 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.
+// does not provide access to the real INO. Instead, since HTML5 does not
+// suport links, we assume that files are unique based on path to the base
+// of the mount.
+void Html5Fs::OnNodeCreated(Node* node) {
+ node->stat_.st_dev = dev_;
+}
+
+void Html5Fs::OnNodeDestroyed(Node* node) {}
+
+
Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
ScopedNode* out_node) {
out_node->reset(NULL);
@@ -43,6 +74,10 @@ Error Html5Fs::OpenWithMode(const Path& path, int open_flags, mode_t mode,
ScopedNode node(new Html5FsNode(this, fileref));
error = node->Init(open_flags);
+
+ // Set the INO based on the path
+ 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.
+
if (error)
return error;
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698