tools/testing/selftests/filesystems/utils.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/utils.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/utils.h- Extension
.h- Size
- 1103 bytes
- Lines
- 52
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
Dependency Surface
errno.hlinux/types.hsched.hsignal.hstdbool.hstdio.hstdlib.hstring.hsyscall.hsys/capability.hsys/fsuid.hsys/types.hunistd.h
Detected Declarations
function switch_userns
Annotated Snippet
#ifndef __IDMAP_UTILS_H
#define __IDMAP_UTILS_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <errno.h>
#include <linux/types.h>
#include <sched.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
#include <sys/capability.h>
#include <sys/fsuid.h>
#include <sys/types.h>
#include <unistd.h>
extern int get_userns_fd(unsigned long nsid, unsigned long hostid,
unsigned long range);
extern int caps_down(void);
extern int cap_down(cap_value_t down);
extern bool switch_ids(uid_t uid, gid_t gid);
extern int setup_userns(void);
extern int enter_userns(void);
static inline bool switch_userns(int fd, uid_t uid, gid_t gid, bool drop_caps)
{
if (setns(fd, CLONE_NEWUSER))
return false;
if (!switch_ids(uid, gid))
return false;
if (drop_caps && !caps_down())
return false;
return true;
}
extern int wait_for_pid(pid_t pid);
extern int write_file(const char *path, const char *val);
extern uint64_t get_unique_mnt_id(const char *path);
#endif /* __IDMAP_UTILS_H */
Annotation
- Immediate include surface: `errno.h`, `linux/types.h`, `sched.h`, `signal.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`.
- Detected declarations: `function switch_userns`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.