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

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: Fix test 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
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..f364728b31015543c99da9e49352c9a0ad4204d6 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,41 @@ int64_t strtoull(const char* nptr, char** endptr, int base) {
} // namespace
+// Continuing DJB2a hash
+ino_t Html5Fs::HashPathSegment(ino_t hash, const char *str, size_t len) {
+ // First add the path seperator
+ hash = (hash * static_cast<ino_t>(33)) ^ '/';
+ while (len--) {
+ hash = (hash * static_cast<ino_t>(33)) ^ *str++;
+ }
+ return hash;
+}
+
+ino_t Html5Fs::HashPath(const Path& path) {
+ // Prime the DJB2a hash
+ ino_t hash = 5381;
+
+ // Apply a running DJB2a to each part of the path
+ for (size_t segment = 0; segment < path.Size(); segment++) {
+ const char *ptr = path.Part(segment).c_str();
+ size_t len = strlen(ptr);
binji 2014/09/25 21:52:04 OK, but you could just use path.Part(segment).leng
noelallen1 2014/09/25 22:39:55 Done.
+ hash = HashPathSegment(hash, ptr, len);
+ }
+ return hash;
+}
+
+
+// For HTML5, the INO should be the one used by the system, however PPAPI
+// 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 +78,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);
+
if (error)
return error;

Powered by Google App Engine
This is Rietveld 408576698