lib/earlycpio.c
Source file repositories/reference/linux-study-clean/lib/earlycpio.c
File Facts
- System
- Linux kernel
- Corpus path
lib/earlycpio.c- Extension
.c- Size
- 3637 bytes
- Lines
- 142
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/earlycpio.hlinux/kernel.hlinux/string.h
Detected Declarations
enum cpio_fieldsfunction filename
Annotated Snippet
if (!*p) {
/* All cpio headers need to be 4-byte aligned */
p += 4;
len -= 4;
continue;
}
j = 6; /* The magic field is only 6 characters */
chp = ch;
for (i = C_NFIELDS; i; i--) {
v = 0;
while (j--) {
v <<= 4;
c = *p++;
x = c - '0';
if (x < 10) {
v += x;
continue;
}
x = (c | 0x20) - 'a';
if (x < 6) {
v += x + 10;
continue;
}
goto quit; /* Invalid hexadecimal */
}
*chp++ = v;
j = 8; /* All other fields are 8 characters */
}
if ((ch[C_MAGIC] - 0x070701) > 1)
goto quit; /* Invalid magic */
len -= cpio_header_len;
dptr = PTR_ALIGN(p + ch[C_NAMESIZE], 4);
nptr = PTR_ALIGN(dptr + ch[C_FILESIZE], 4);
if (nptr > p + len || dptr < p || nptr < dptr)
goto quit; /* Buffer overrun */
if ((ch[C_MODE] & 0170000) == 0100000 &&
ch[C_NAMESIZE] >= mypathsize &&
!memcmp(p, path, mypathsize)) {
if (nextoff)
*nextoff = (long)nptr - (long)data;
if (ch[C_NAMESIZE] - mypathsize >= MAX_CPIO_FILE_NAME) {
pr_warn(
"File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
p, MAX_CPIO_FILE_NAME);
}
strscpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
cd.data = (void *)dptr;
cd.size = ch[C_FILESIZE];
return cd; /* Found it! */
}
len -= (nptr - p);
p = nptr;
}
quit:
return cd;
}
Annotation
- Immediate include surface: `linux/earlycpio.h`, `linux/kernel.h`, `linux/string.h`.
- Detected declarations: `enum cpio_fields`, `function filename`.
- Atlas domain: Kernel Services / lib.
- 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.