tools/testing/selftests/filesystems/openat2/helpers.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/openat2/helpers.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/openat2/helpers.h- Extension
.h- Size
- 2874 bytes
- Lines
- 136
- 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
stdint.hstdbool.herrno.hlimits.hlinux/types.hlinux/unistd.hlinux/openat2.hkselftest_harness.h
Detected Declarations
function needs_openat2function raw_openat2function sys_openat2function sys_openatfunction sys_renameat2function touchatfunction fdequalfunction __detect_openat2_supported
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Author: Aleksa Sarai <cyphar@cyphar.com>
* Copyright (C) 2018-2019 SUSE LLC.
* Copyright (C) 2026 Amutable GmbH
*/
#ifndef __RESOLVEAT_H__
#define __RESOLVEAT_H__
#define _GNU_SOURCE
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <limits.h>
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/openat2.h>
#include "kselftest_harness.h"
#define BUILD_BUG_ON(e) ((void)(sizeof(struct { int:(-!!(e)); })))
#define OPEN_HOW_SIZE_VER0 24 /* sizeof first published struct */
#define OPEN_HOW_SIZE_LATEST OPEN_HOW_SIZE_VER0
__maybe_unused
static bool needs_openat2(const struct open_how *how)
{
return how->resolve != 0;
}
__maybe_unused
static int raw_openat2(int dfd, const char *path, void *how, size_t size)
{
int ret = syscall(__NR_openat2, dfd, path, how, size);
return ret >= 0 ? ret : -errno;
}
__maybe_unused
static int sys_openat2(int dfd, const char *path, struct open_how *how)
{
return raw_openat2(dfd, path, how, sizeof(*how));
}
__maybe_unused
static int sys_openat(int dfd, const char *path, struct open_how *how)
{
int ret = openat(dfd, path, how->flags, how->mode);
return ret >= 0 ? ret : -errno;
}
__maybe_unused
static int sys_renameat2(int olddirfd, const char *oldpath,
int newdirfd, const char *newpath, unsigned int flags)
{
int ret = syscall(__NR_renameat2, olddirfd, oldpath,
newdirfd, newpath, flags);
return ret >= 0 ? ret : -errno;
}
__maybe_unused
static int touchat(int dfd, const char *path)
{
int fd = openat(dfd, path, O_CREAT, 0700);
if (fd >= 0)
close(fd);
return fd;
}
__maybe_unused
static char *fdreadlink(struct __test_metadata *_metadata, int fd)
{
char *target, *tmp;
ASSERT_GT(asprintf(&tmp, "/proc/self/fd/%d", fd), 0);
target = malloc(PATH_MAX);
ASSERT_NE(target, NULL);
memset(target, 0, PATH_MAX);
ASSERT_GT(readlink(tmp, target, PATH_MAX), 0);
free(tmp);
return target;
}
Annotation
- Immediate include surface: `stdint.h`, `stdbool.h`, `errno.h`, `limits.h`, `linux/types.h`, `linux/unistd.h`, `linux/openat2.h`, `kselftest_harness.h`.
- Detected declarations: `function needs_openat2`, `function raw_openat2`, `function sys_openat2`, `function sys_openat`, `function sys_renameat2`, `function touchat`, `function fdequal`, `function __detect_openat2_supported`.
- 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.