tools/testing/selftests/filesystems/anon_inode_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/anon_inode_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/anon_inode_test.c
Extension
.c
Size
1315 bytes
Lines
73
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#define __SANE_USERSPACE_TYPES__

#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>

#include "kselftest_harness.h"
#include "wrappers.h"

TEST(anon_inode_no_chown)
{
	int fd_context;

	fd_context = sys_fsopen("tmpfs", 0);
	ASSERT_GE(fd_context, 0);

	ASSERT_LT(fchown(fd_context, 1234, 5678), 0);
	ASSERT_EQ(errno, EOPNOTSUPP);

	EXPECT_EQ(close(fd_context), 0);
}

TEST(anon_inode_no_chmod)
{
	int fd_context;

	fd_context = sys_fsopen("tmpfs", 0);
	ASSERT_GE(fd_context, 0);

	ASSERT_LT(fchmod(fd_context, 0777), 0);
	ASSERT_EQ(errno, EOPNOTSUPP);

	EXPECT_EQ(close(fd_context), 0);
}

TEST(anon_inode_no_exec)
{
	int fd_context;

	fd_context = sys_fsopen("tmpfs", 0);
	ASSERT_GE(fd_context, 0);

	char *const empty_argv[] = {NULL};
	char *const empty_envp[] = {NULL};

	ASSERT_LT(execveat(fd_context, "", empty_argv, empty_envp, AT_EMPTY_PATH), 0);
	ASSERT_EQ(errno, EACCES);

	EXPECT_EQ(close(fd_context), 0);
}

TEST(anon_inode_no_open)
{
	int fd_context;

	fd_context = sys_fsopen("tmpfs", 0);
	ASSERT_GE(fd_context, 0);

	ASSERT_GE(dup2(fd_context, 500), 0);
	ASSERT_EQ(close(fd_context), 0);
	fd_context = 500;

	ASSERT_LT(open("/proc/self/fd/500", 0), 0);
	ASSERT_EQ(errno, ENXIO);

	EXPECT_EQ(close(fd_context), 0);
}

TEST_HARNESS_MAIN

Annotation

Implementation Notes