tools/testing/selftests/filesystems/utils.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/utils.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/utils.c- Extension
.c- Size
- 12844 bytes
- Lines
- 616
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hsys/types.hdirent.hgrp.hlinux/limits.hsched.hstdio.hstdlib.hsys/eventfd.hsys/fsuid.hsys/prctl.hsys/socket.hsys/stat.hsys/wait.hsys/xattr.hsys/mount.hkselftest.hwrappers.hutils.h
Detected Declarations
struct id_mapstruct liststruct userns_hierarchyfunction list_initfunction list_emptyfunction __list_addfunction list_add_tailfunction list_delfunction read_nointrfunction write_nointrfunction do_clonefunction get_userns_fd_cbfunction wait_for_pidfunction write_id_mappingfunction map_ids_from_idmapfunction list_for_eachfunction get_userns_fd_from_idmapfunction get_userns_fdfunction switch_idsfunction userns_fd_cbfunction create_userns_hierarchyfunction write_filefunction setup_usernsfunction enter_usernsfunction caps_downfunction cap_downfunction get_unique_mnt_id
Annotated Snippet
struct id_map {
idmap_type_t map_type;
__u32 nsid;
__u32 hostid;
__u32 range;
};
struct list {
void *elem;
struct list *next;
struct list *prev;
};
struct userns_hierarchy {
int fd_userns;
int fd_event;
unsigned int level;
struct list id_map;
};
static inline void list_init(struct list *list)
{
list->elem = NULL;
list->next = list->prev = list;
}
static inline int list_empty(const struct list *list)
{
return list == list->next;
}
static inline void __list_add(struct list *new, struct list *prev, struct list *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void list_add_tail(struct list *head, struct list *list)
{
__list_add(list, head->prev, head);
}
static inline void list_del(struct list *list)
{
struct list *next, *prev;
next = list->next;
prev = list->prev;
next->prev = prev;
prev->next = next;
}
static ssize_t read_nointr(int fd, void *buf, size_t count)
{
ssize_t ret;
do {
ret = read(fd, buf, count);
} while (ret < 0 && errno == EINTR);
return ret;
}
static ssize_t write_nointr(int fd, const void *buf, size_t count)
{
ssize_t ret;
do {
ret = write(fd, buf, count);
} while (ret < 0 && errno == EINTR);
return ret;
}
#define __STACK_SIZE (8 * 1024 * 1024)
static pid_t do_clone(int (*fn)(void *), void *arg, int flags)
{
void *stack;
stack = malloc(__STACK_SIZE);
if (!stack)
return -ENOMEM;
#ifdef __ia64__
return __clone2(fn, stack, __STACK_SIZE, flags | SIGCHLD, arg, NULL);
#else
return clone(fn, stack + __STACK_SIZE, flags | SIGCHLD, arg, NULL);
#endif
Annotation
- Immediate include surface: `fcntl.h`, `sys/types.h`, `dirent.h`, `grp.h`, `linux/limits.h`, `sched.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `struct id_map`, `struct list`, `struct userns_hierarchy`, `function list_init`, `function list_empty`, `function __list_add`, `function list_add_tail`, `function list_del`, `function read_nointr`, `function write_nointr`.
- 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.