tools/testing/selftests/filesystems/openat2/openat2_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/openat2/openat2_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/openat2/openat2_test.c- Extension
.c- Size
- 10750 bytes
- Lines
- 363
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hsched.hsys/stat.hsys/types.hsys/mount.hstdlib.hstdbool.hstring.hhelpers.hkselftest_harness.h
Detected Declarations
struct open_how_extstruct struct_teststruct flag_testfunction openat2function EXPECT_EQfunction EXPECT_EQfunction EXPECT_EQfunction EXPECT_EQfunction ASSERT_GE
Annotated Snippet
struct open_how_ext {
struct open_how inner;
uint32_t extra1;
char pad1[128];
uint32_t extra2;
char pad2[128];
uint32_t extra3;
};
struct struct_test {
const char *name;
struct open_how_ext arg;
size_t size;
int err;
};
struct flag_test {
const char *name;
struct open_how how;
int err;
};
FIXTURE(openat2) {};
FIXTURE_SETUP(openat2)
{
if (!openat2_supported)
SKIP(return, "openat2(2) not supported");
}
FIXTURE_TEARDOWN(openat2) {}
/*
* Verify that the struct size and misalignment handling for openat2(2) is
* correct, including that is_zeroed_user() works.
*/
TEST_F(openat2, struct_argument_sizes)
{
int misalignments[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 17, 87 };
struct struct_test tests[] = {
/* Normal struct. */
{ .name = "normal struct",
.arg.inner.flags = O_RDONLY,
.size = sizeof(struct open_how) },
/* Bigger struct, with zeroed out end. */
{ .name = "bigger struct (zeroed out)",
.arg.inner.flags = O_RDONLY,
.size = sizeof(struct open_how_ext) },
/* TODO: Once expanded, check zero-padding. */
/* Smaller than version-0 struct. */
{ .name = "zero-sized 'struct'",
.arg.inner.flags = O_RDONLY, .size = 0, .err = -EINVAL },
{ .name = "smaller-than-v0 struct",
.arg.inner.flags = O_RDONLY,
.size = OPEN_HOW_SIZE_VER0 - 1, .err = -EINVAL },
/* Bigger struct, with non-zero trailing bytes. */
{ .name = "bigger struct (non-zero data in first 'future field')",
.arg.inner.flags = O_RDONLY, .arg.extra1 = 0xdeadbeef,
.size = sizeof(struct open_how_ext), .err = -E2BIG },
{ .name = "bigger struct (non-zero data in middle of 'future fields')",
.arg.inner.flags = O_RDONLY, .arg.extra2 = 0xfeedcafe,
.size = sizeof(struct open_how_ext), .err = -E2BIG },
{ .name = "bigger struct (non-zero data at end of 'future fields')",
.arg.inner.flags = O_RDONLY, .arg.extra3 = 0xabad1dea,
.size = sizeof(struct open_how_ext), .err = -E2BIG },
};
for (int i = 0; i < ARRAY_SIZE(tests); i++) {
struct struct_test *test = &tests[i];
struct open_how_ext how_ext = test->arg;
for (int j = 0; j < ARRAY_SIZE(misalignments); j++) {
int fd, misalign = misalignments[j];
void *copy = NULL, *how_copy = &how_ext;
char *fdpath = NULL;
if (misalign) {
/*
* Explicitly misalign the structure copying it with the given
* (mis)alignment offset. The other data is set to be non-zero to
* make sure that non-zero bytes outside the struct aren't checked
*
* This is effectively to check that is_zeroed_user() works.
*/
copy = malloc(misalign + sizeof(how_ext));
how_copy = copy + misalign;
memset(copy, 0xff, misalign);
Annotation
- Immediate include surface: `fcntl.h`, `sched.h`, `sys/stat.h`, `sys/types.h`, `sys/mount.h`, `stdlib.h`, `stdbool.h`, `string.h`.
- Detected declarations: `struct open_how_ext`, `struct struct_test`, `struct flag_test`, `function openat2`, `function EXPECT_EQ`, `function EXPECT_EQ`, `function EXPECT_EQ`, `function EXPECT_EQ`, `function ASSERT_GE`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.