usr/gen_init_cpio.c
Source file repositories/reference/linux-study-clean/usr/gen_init_cpio.c
File Facts
- System
- Linux kernel
- Corpus path
usr/gen_init_cpio.c- Extension
.c- Size
- 17489 bytes
- Lines
- 782
- Domain
- Support Tooling And Documentation
- Bucket
- usr
- 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
stdio.hstdlib.hstdint.hstdbool.hsys/types.hsys/stat.hstring.hunistd.htime.hfcntl.herrno.hctype.hlimits.h
Detected Declarations
struct file_handlerstruct generic_typeenum generic_typesfunction push_buffunction push_padfunction push_restfunction cpio_trailerfunction cpio_mkslinkfunction cpio_mkslink_linefunction cpio_mkgenericfunction cpio_mkgeneric_linefunction cpio_mkdir_linefunction cpio_mkpipe_linefunction cpio_mksock_linefunction cpio_mknodfunction cpio_mknod_linefunction cpio_mkfile_csumfunction cpio_mkfilefunction cpio_mkfile_linefunction usagefunction main
Annotated Snippet
struct file_handler {
const char *type;
int (*handler)(const char *line);
};
static int push_buf(const char *name, size_t name_len)
{
ssize_t len;
len = write(outfd, name, name_len);
if (len != name_len)
return -1;
offset += name_len;
return 0;
}
static int push_pad(size_t padlen)
{
ssize_t len = 0;
if (!padlen)
return 0;
if (padlen < sizeof(padding))
len = write(outfd, padding, padlen);
if (len != padlen)
return -1;
offset += padlen;
return 0;
}
static int push_rest(const char *name, size_t name_len)
{
ssize_t len;
len = write(outfd, name, name_len);
if (len != name_len)
return -1;
offset += name_len;
return push_pad(padlen(name_len + CPIO_HDR_LEN, 4));
}
static int cpio_trailer(void)
{
int len;
unsigned int namesize = sizeof(CPIO_TRAILER);
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
0, /* ino */
0, /* mode */
(long) 0, /* uid */
(long) 0, /* gid */
1, /* nlink */
(long) 0, /* mtime */
0, /* filesize */
0, /* major */
0, /* minor */
0, /* rmajor */
0, /* rminor */
namesize, /* namesize */
0); /* chksum */
offset += len;
if (len != CPIO_HDR_LEN ||
push_rest(CPIO_TRAILER, namesize) < 0 ||
push_pad(padlen(offset, 512)) < 0)
return -1;
if (fsync(outfd) < 0 && errno != EINVAL)
return -1;
return 0;
}
static int cpio_mkslink(const char *name, const char *target,
unsigned int mode, uid_t uid, gid_t gid)
{
int len;
unsigned int namesize, targetsize = strlen(target) + 1;
if (name[0] == '/')
name++;
namesize = strlen(name) + 1;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdint.h`, `stdbool.h`, `sys/types.h`, `sys/stat.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct file_handler`, `struct generic_type`, `enum generic_types`, `function push_buf`, `function push_pad`, `function push_rest`, `function cpio_trailer`, `function cpio_mkslink`, `function cpio_mkslink_line`, `function cpio_mkgeneric`.
- Atlas domain: Support Tooling And Documentation / usr.
- 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.