init/initramfs.c
Source file repositories/reference/linux-study-clean/init/initramfs.c
File Facts
- System
- Linux kernel
- Corpus path
init/initramfs.c- Extension
.c- Size
- 18751 bytes
- Lines
- 793
- Domain
- Core OS
- Bucket
- Boot And Init
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
linux/async.hlinux/delay.hlinux/dirent.hlinux/export.hlinux/fcntl.hlinux/file.hlinux/fs.hlinux/hex.hlinux/init.hlinux/init_syscalls.hlinux/kstrtox.hlinux/memblock.hlinux/mm.hlinux/namei.hlinux/overflow.hlinux/security.hlinux/slab.hlinux/string.hlinux/syscalls.hlinux/types.hlinux/umh.hlinux/utime.hasm/byteorder.hdo_mounts.hinitramfs_internal.hlinux/decompress/generic.hlinux/initrd.hlinux/kexec.h
Detected Declarations
struct dir_entryfunction xwritefunction errorfunction hashfunction free_hashfunction do_utimefunction do_utime_pathfunction dir_addfunction dir_utimefunction do_utimefunction parse_headerfunction eatfunction read_intofunction do_startfunction do_collectfunction do_headerfunction do_skipfunction do_resetfunction clean_pathfunction maybe_linkfunction do_namefunction S_ISFIFOfunction do_copyfunction do_symlinkfunction write_bufferfunction flush_bufferfunction unpack_to_rootfsfunction retain_initrd_paramfunction keepinitrd_setupfunction initramfs_async_setupfunction reserve_initrd_memfunction free_initrd_memfunction kexec_free_initrdfunction kexec_free_initrdfunction populate_initrd_imagefunction do_populate_rootfsfunction wait_for_initramfsfunction populate_rootfsexport wait_for_initramfs
Annotated Snippet
struct dir_entry {
struct list_head list;
time64_t mtime;
char name[];
};
static void __init dir_add(const char *name, size_t nlen, time64_t mtime)
{
struct dir_entry *de;
de = kmalloc_flex(*de, name, nlen);
if (!de)
panic_show_mem("can't allocate dir_entry buffer");
INIT_LIST_HEAD(&de->list);
strscpy(de->name, name, nlen);
de->mtime = mtime;
list_add(&de->list, &dir_list);
}
static void __init dir_utime(void)
{
struct dir_entry *de, *tmp;
list_for_each_entry_safe(de, tmp, &dir_list, list) {
list_del(&de->list);
do_utime(de->name, de->mtime);
kfree(de);
}
}
#else
static void __init do_utime(char *filename, time64_t mtime) {}
static void __init do_utime_path(const struct path *path, time64_t mtime) {}
static void __init dir_add(const char *name, size_t nlen, time64_t mtime) {}
static void __init dir_utime(void) {}
#endif
static __initdata time64_t mtime;
/* cpio header parsing */
static __initdata unsigned long ino, major, minor, nlink;
static __initdata umode_t mode;
static __initdata unsigned long body_len, name_len;
static __initdata uid_t uid;
static __initdata gid_t gid;
static __initdata unsigned rdev;
static __initdata u32 hdr_csum;
static int __init parse_header(char *s)
{
__be32 header[13];
int ret;
ret = hex2bin((u8 *)header, s + 6, sizeof(header));
if (ret) {
error("damaged header");
return ret;
}
ino = be32_to_cpu(header[0]);
mode = be32_to_cpu(header[1]);
uid = be32_to_cpu(header[2]);
gid = be32_to_cpu(header[3]);
nlink = be32_to_cpu(header[4]);
mtime = be32_to_cpu(header[5]); /* breaks in y2106 */
body_len = be32_to_cpu(header[6]);
major = be32_to_cpu(header[7]);
minor = be32_to_cpu(header[8]);
rdev = new_encode_dev(MKDEV(be32_to_cpu(header[9]), be32_to_cpu(header[10])));
name_len = be32_to_cpu(header[11]);
hdr_csum = be32_to_cpu(header[12]);
return 0;
}
/* Finite-state machine */
static __initdata enum state {
Start,
Collect,
GotHeader,
SkipIt,
GotName,
CopyFile,
GotSymlink,
Reset
} state, next_state;
static __initdata char *victim;
static unsigned long byte_count __initdata;
static __initdata loff_t this_header, next_header;
Annotation
- Immediate include surface: `linux/async.h`, `linux/delay.h`, `linux/dirent.h`, `linux/export.h`, `linux/fcntl.h`, `linux/file.h`, `linux/fs.h`, `linux/hex.h`.
- Detected declarations: `struct dir_entry`, `function xwrite`, `function error`, `function hash`, `function free_hash`, `function do_utime`, `function do_utime_path`, `function dir_add`, `function dir_utime`, `function do_utime`.
- Atlas domain: Core OS / Boot And Init.
- Implementation status: integration 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.