fs/hfsplus/unicode_test.c
Source file repositories/reference/linux-study-clean/fs/hfsplus/unicode_test.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hfsplus/unicode_test.c- Extension
.c- Size
- 47696 bytes
- Lines
- 1597
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/nls.hlinux/dcache.hlinux/stringhash.hhfsplus_fs.h
Detected Declarations
struct test_mock_string_envstruct test_mock_sbfunction free_mock_str_envfunction create_unistrfunction corrupt_unistrfunction hfsplus_strcasecmp_testfunction hfsplus_strcmp_testfunction hfsplus_unicode_edge_cases_testfunction hfsplus_unicode_boundary_testfunction free_mock_sbfunction test_uni2charfunction hfsplus_uni2asc_basic_testfunction hfsplus_uni2asc_special_chars_testfunction hfsplus_uni2asc_buffer_testfunction hfsplus_uni2asc_corrupted_testfunction hfsplus_uni2asc_edge_cases_testfunction test_char2unifunction check_unistr_contentfunction hfsplus_asc2uni_basic_testfunction hfsplus_asc2uni_special_chars_testfunction hfsplus_asc2uni_buffer_limits_testfunction hfsplus_asc2uni_edge_cases_testfunction hfsplus_asc2uni_decompose_testfunction setup_mock_dentryfunction create_qstrfunction hfsplus_hash_dentry_basic_testfunction hfsplus_hash_dentry_casefold_testfunction hfsplus_hash_dentry_special_chars_testfunction hfsplus_hash_dentry_decompose_testfunction hfsplus_hash_dentry_consistency_testfunction hfsplus_hash_dentry_edge_cases_testfunction hfsplus_compare_dentry_basic_testfunction hfsplus_compare_dentry_casefold_testfunction hfsplus_compare_dentry_special_chars_testfunction hfsplus_compare_dentry_length_testfunction hfsplus_compare_dentry_decompose_testfunction hfsplus_compare_dentry_edge_cases_testfunction hfsplus_compare_dentry_combined_flags_test
Annotated Snippet
struct test_mock_string_env {
struct hfsplus_unistr str1;
struct hfsplus_unistr str2;
char *buf;
u32 buf_size;
};
static struct test_mock_string_env *setup_mock_str_env(u32 buf_size)
{
struct test_mock_string_env *env;
env = kzalloc_obj(struct test_mock_string_env);
if (!env)
return NULL;
env->buf = kzalloc(buf_size, GFP_KERNEL);
if (!env->buf) {
kfree(env);
return NULL;
}
env->buf_size = buf_size;
return env;
}
static void free_mock_str_env(struct test_mock_string_env *env)
{
if (env->buf)
kfree(env->buf);
kfree(env);
}
/* Helper function to create hfsplus_unistr */
static void create_unistr(struct hfsplus_unistr *ustr, const char *ascii_str)
{
int len = strlen(ascii_str);
int i;
memset(ustr->unicode, 0, sizeof(ustr->unicode));
ustr->length = cpu_to_be16(len);
for (i = 0; i < len && i < HFSPLUS_MAX_STRLEN; i++)
ustr->unicode[i] = cpu_to_be16((u16)ascii_str[i]);
}
static void corrupt_unistr(struct hfsplus_unistr *ustr)
{
ustr->length = cpu_to_be16(U16_MAX);
}
/* Test hfsplus_strcasecmp function */
static void hfsplus_strcasecmp_test(struct kunit *test)
{
struct test_mock_string_env *mock_env;
mock_env = setup_mock_str_env(HFSPLUS_MAX_STRLEN + 1);
KUNIT_ASSERT_NOT_NULL(test, mock_env);
/* Test identical strings */
create_unistr(&mock_env->str1, "hello");
create_unistr(&mock_env->str2, "hello");
KUNIT_EXPECT_EQ(test, 0, hfsplus_strcasecmp(&mock_env->str1,
&mock_env->str2));
/* Test case insensitive comparison */
create_unistr(&mock_env->str1, "Hello");
create_unistr(&mock_env->str2, "hello");
KUNIT_EXPECT_EQ(test, 0, hfsplus_strcasecmp(&mock_env->str1,
&mock_env->str2));
create_unistr(&mock_env->str1, "HELLO");
create_unistr(&mock_env->str2, "hello");
KUNIT_EXPECT_EQ(test, 0, hfsplus_strcasecmp(&mock_env->str1,
&mock_env->str2));
/* Test different strings */
create_unistr(&mock_env->str1, "apple");
create_unistr(&mock_env->str2, "banana");
KUNIT_EXPECT_LT(test, hfsplus_strcasecmp(&mock_env->str1,
&mock_env->str2), 0);
create_unistr(&mock_env->str1, "zebra");
create_unistr(&mock_env->str2, "apple");
KUNIT_EXPECT_GT(test, hfsplus_strcasecmp(&mock_env->str1,
&mock_env->str2), 0);
/* Test different lengths */
create_unistr(&mock_env->str1, "test");
create_unistr(&mock_env->str2, "testing");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/nls.h`, `linux/dcache.h`, `linux/stringhash.h`, `hfsplus_fs.h`.
- Detected declarations: `struct test_mock_string_env`, `struct test_mock_sb`, `function free_mock_str_env`, `function create_unistr`, `function corrupt_unistr`, `function hfsplus_strcasecmp_test`, `function hfsplus_strcmp_test`, `function hfsplus_unicode_edge_cases_test`, `function hfsplus_unicode_boundary_test`, `function free_mock_sb`.
- 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.