init/initramfs_test.c
Source file repositories/reference/linux-study-clean/init/initramfs_test.c
File Facts
- System
- Linux kernel
- Corpus path
init/initramfs_test.c- Extension
.c- Size
- 16376 bytes
- Lines
- 586
- Domain
- Core OS
- Bucket
- Boot And Init
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/fcntl.hlinux/file.hlinux/fs.hlinux/init.hlinux/init_syscalls.hlinux/initrd.hlinux/stringify.hlinux/timekeeping.hinitramfs_internal.h
Detected Declarations
struct initramfs_test_cpiostruct test_fname_padstruct test_fname_path_maxstruct initramfs_test_bufsfunction parse_headerfunction initramfs_test_extractfunction filp_openfunction initramfs_test_datafunction initramfs_test_csumfunction initramfs_test_hardlinkfunction initramfs_test_manyfunction initramfs_test_fname_padfunction initramfs_test_fname_path_maxfunction initramfs_test_hdr_hexfunction initramfs_test_init
Annotated Snippet
struct initramfs_test_cpio {
char *magic;
unsigned int ino;
unsigned int mode;
unsigned int uid;
unsigned int gid;
unsigned int nlink;
unsigned int mtime;
unsigned int filesize;
unsigned int devmajor;
unsigned int devminor;
unsigned int rdevmajor;
unsigned int rdevminor;
unsigned int namesize;
unsigned int csum;
char *fname;
char *data;
};
/* regular newc header format */
#define CPIO_HDR_FMT "%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%s"
/*
* Bogus newc header with "0x" prefixes on the uid, gid, and namesize values.
* parse_header()/simple_str[n]toul() accepted this, contrary to the initramfs
* specification. hex2bin() now fails.
*/
#define CPIO_HDR_OX_INJECT \
"%s%08x%08x0x%06x0X%06x%08x%08x%08x%08x%08x%08x%08x0x%06x%08x%s"
static size_t fill_cpio(struct initramfs_test_cpio *cs, size_t csz,
bool inject_ox, char *out)
{
int i;
size_t off = 0;
for (i = 0; i < csz; i++) {
char *pos = &out[off];
struct initramfs_test_cpio *c = &cs[i];
size_t thislen;
/* +1 to account for nulterm */
thislen = sprintf(pos,
inject_ox ? CPIO_HDR_OX_INJECT : CPIO_HDR_FMT,
c->magic, c->ino, c->mode, c->uid, c->gid, c->nlink,
c->mtime, c->filesize, c->devmajor, c->devminor,
c->rdevmajor, c->rdevminor, c->namesize, c->csum,
c->fname) + 1;
pr_debug("packing (%zu): %.*s\n", thislen, (int)thislen, pos);
if (thislen != CPIO_HDRLEN + c->namesize)
pr_debug("padded to: %u\n", CPIO_HDRLEN + c->namesize);
off += CPIO_HDRLEN + c->namesize;
while (off & 3)
out[off++] = '\0';
memcpy(&out[off], c->data, c->filesize);
off += c->filesize;
while (off & 3)
out[off++] = '\0';
}
return off;
}
static void __init initramfs_test_extract(struct kunit *test)
{
char *err, *cpio_srcbuf;
size_t len;
struct timespec64 ts_before, ts_after;
struct kstat st = {};
struct initramfs_test_cpio c[] = { {
.magic = "070701",
.ino = 1,
.mode = S_IFREG | 0777,
.uid = 12,
.gid = 34,
.nlink = 1,
.mtime = 56,
.filesize = 0,
.devmajor = 0,
.devminor = 1,
.rdevmajor = 0,
.rdevminor = 0,
.namesize = sizeof("initramfs_test_extract"),
.csum = 0,
.fname = "initramfs_test_extract",
}, {
.magic = "070701",
.ino = 2,
.mode = S_IFDIR | 0777,
Annotation
- Immediate include surface: `kunit/test.h`, `linux/fcntl.h`, `linux/file.h`, `linux/fs.h`, `linux/init.h`, `linux/init_syscalls.h`, `linux/initrd.h`, `linux/stringify.h`.
- Detected declarations: `struct initramfs_test_cpio`, `struct test_fname_pad`, `struct test_fname_path_max`, `struct initramfs_test_bufs`, `function parse_header`, `function initramfs_test_extract`, `function filp_open`, `function initramfs_test_data`, `function initramfs_test_csum`, `function initramfs_test_hardlink`.
- Atlas domain: Core OS / Boot And Init.
- 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.