fs/f2fs/hash.c
Source file repositories/reference/linux-study-clean/fs/f2fs/hash.c
File Facts
- System
- Linux kernel
- Corpus path
fs/f2fs/hash.c- Extension
.c- Size
- 3085 bytes
- Lines
- 138
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/fs.hlinux/f2fs_fs.hlinux/pagemap.hlinux/unicode.hf2fs.h
Detected Declarations
function Copyrightfunction str2hashbuffunction TEA_hash_namefunction f2fs_hash_filename
Annotated Snippet
if ((i % 4) == 3) {
*buf++ = val;
val = pad;
num--;
}
}
if (--num >= 0)
*buf++ = val;
while (--num >= 0)
*buf++ = pad;
}
static u32 TEA_hash_name(const u8 *p, size_t len)
{
__u32 in[8], buf[4];
/* Initialize the default seed for the hash checksum functions */
buf[0] = 0x67452301;
buf[1] = 0xefcdab89;
buf[2] = 0x98badcfe;
buf[3] = 0x10325476;
while (1) {
str2hashbuf(p, len, in, 4);
TEA_transform(buf, in);
p += 16;
if (len <= 16)
break;
len -= 16;
}
return buf[0] & ~F2FS_HASH_COL_BIT;
}
/*
* Compute @fname->hash. For all directories, @fname->disk_name must be set.
* For casefolded directories, @fname->usr_fname must be set, and also
* @fname->cf_name if the filename is valid Unicode and is not "." or "..".
*/
void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname)
{
const u8 *name = fname->disk_name.name;
size_t len = fname->disk_name.len;
WARN_ON_ONCE(!name);
if (name_is_dot_dotdot(name, len)) {
fname->hash = 0;
return;
}
#if IS_ENABLED(CONFIG_UNICODE)
if (IS_CASEFOLDED(dir)) {
/*
* If the casefolded name is provided, hash it instead of the
* on-disk name. If the casefolded name is *not* provided, that
* should only be because the name wasn't valid Unicode or was
* "." or "..", so fall back to treating the name as an opaque
* byte sequence. Note that to handle encrypted directories,
* the fallback must use usr_fname (plaintext) rather than
* disk_name (ciphertext).
*/
WARN_ON_ONCE(!fname->usr_fname->name);
if (fname->cf_name.name) {
name = fname->cf_name.name;
len = fname->cf_name.len;
} else {
name = fname->usr_fname->name;
len = fname->usr_fname->len;
}
if (IS_ENCRYPTED(dir)) {
struct qstr tmp = QSTR_INIT(name, len);
fname->hash =
cpu_to_le32(fscrypt_fname_siphash(dir, &tmp));
return;
}
}
#endif
fname->hash = cpu_to_le32(TEA_hash_name(name, len));
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/fs.h`, `linux/f2fs_fs.h`, `linux/pagemap.h`, `linux/unicode.h`, `f2fs.h`.
- Detected declarations: `function Copyright`, `function str2hashbuf`, `function TEA_hash_name`, `function f2fs_hash_filename`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.