-
Notifications
You must be signed in to change notification settings - Fork 108
Use hash func to boost file creation and lookup #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include <linux/dcache.h> | ||
| #include <linux/types.h> | ||
| #include "simplefs.h" | ||
|
|
||
| uint32_t simplefs_hash(struct dentry *dentry) | ||
| { | ||
| const char *str = dentry->d_name.name; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unkeyed FNV-1a is vulnerable to HashDoS. FNV-1a is deterministic and trivially reversible. Attackers can craft filenames that all collide, forcing O(n) linear scans on every directory operation. Consider using the kernel's
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on our previous discussion I believe we should stick with this approach to ensure consistency across reboots. |
||
| uint64_t h = 0xcbf29ce484222325ULL; | ||
| while (*str) { | ||
| h ^= (unsigned char) (*str++); | ||
| h *= 0x100000001b3ULL; | ||
| } | ||
| /* Fold high 32 bits into low 32 bits to mix the full 64-bit result */ | ||
| return (uint32_t) (h ^ (h >> 32)); | ||
| } | ||
RoyWFHuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.