Bryan O'Sullivan
2003-May-22 16:36 UTC
[klibc] [PATCH 2.5.69 3/3] Bandaids for gen_init_cpio and initramfs
Last patch for now. This gets gen_init_cpio into a state where it can pick up a "kinit" binary from usr and stuff it into the cpio archive as /sbin/init. This is obviously a crock, but it suffices for testing until something sane is done about integrating klibc into the kernel tree. The patch also adds a bit of instrumentation to initramfs.c, to try to help flush out bug 740. init/do_mounts.c | 2 +- init/initramfs.c | 18 +++++++----------- usr/Makefile | 2 +- usr/gen_init_cpio.c | 26 +++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 16 deletions(-) # This is a BitKeeper generated patch for the following project: # Project Name: Linux kernel tree # This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas: # ChangeSet 1.1234 -> 1.1236 # init/initramfs.c 1.6 -> 1.7 # init/do_mounts.c 1.50 -> 1.51 # usr/Makefile 1.6 -> 1.7 # usr/gen_init_cpio.c 1.3 -> 1.5 # # The following is the BitKeeper ChangeSet Log # -------------------------------------------- # 03/05/22 bos@serpentine.internal.keyresearch.com 1.1235 # Add /sbin/init to cpio archive. # -------------------------------------------- # 03/05/22 bos@serpentine.internal.keyresearch.com 1.1236 # More small fixes to get initramfs closer to working. # -------------------------------------------- # diff -Nru a/init/do_mounts.c b/init/do_mounts.c --- a/init/do_mounts.c Thu May 22 15:40:19 2003 +++ b/init/do_mounts.c Thu May 22 15:40:19 2003 @@ -123,7 +123,7 @@ int part; if (strncmp(name, "initramfs", 9) == 0 || strcmp(name, "/dev/nfs") == 0) { - ROOT_DEV = Root_InitRamFS; + res = Root_InitRamFS; goto nada; } diff -Nru a/init/initramfs.c b/init/initramfs.c --- a/init/initramfs.c Thu May 22 15:40:19 2003 +++ b/init/initramfs.c Thu May 22 15:40:19 2003 @@ -8,10 +8,7 @@ #include <linux/delay.h> #include <linux/string.h> -static void __init error(char *x) -{ - panic("populate_root: %s\n", x); -} +#define error(x...) panic("populate_root: " x) static void __init *malloc(int size) { @@ -63,7 +60,7 @@ } q = (struct hash *)malloc(sizeof(struct hash)); if (!q) - error("can't allocate link hash entry"); + error("can't allocate link hash entry\n"); q->ino = ino; q->minor = minor; q->major = major; @@ -223,7 +220,7 @@ while(count && *victim == '\0') eat(1); if (count && (this_header & 3)) - error("broken padding"); + error("broken padding\n"); return 1; } @@ -330,7 +327,7 @@ state = Start; continue; } else - error("junk in compressed archive"); + error("junk in compressed archive\n"); } } @@ -372,7 +369,6 @@ #define STATIC static static void flush_window(void); -static void error(char *m); static void gzip_mark(void **); static void gzip_release(void **); @@ -415,7 +411,7 @@ name_buf = malloc(N_ALIGN(PATH_MAX)); window = malloc(WSIZE); if (!window || !header_buf || !symlink_buf || !name_buf) - error("can't allocate buffers"); + error("can't allocate buffers\n"); state = Start; this_header = 0; while (len) { @@ -441,9 +437,9 @@ crc = (ulg)0xffffffffL; /* shift register contents */ makecrc(); if (gunzip()) - error("ungzip failed"); + error("ungzip failed\n"); if (state != Reset) - error("junk in gzipped archive"); + error("junk in gzipped archive: state %d\n", state); this_header = saved_offset + inptr; buf += inptr; len -= inptr; diff -Nru a/usr/Makefile b/usr/Makefile --- a/usr/Makefile Thu May 22 15:40:19 2003 +++ b/usr/Makefile Thu May 22 15:40:19 2003 @@ -20,7 +20,7 @@ # initramfs-y := $(obj)/root/hello quiet_cmd_cpio = CPIO $@ - cmd_cpio = ./$< > $@ + cmd_cpio = ./$< $(obj) > $@ $(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio $(initramfs-y) FORCE $(call if_changed,cpio) diff -Nru a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c --- a/usr/gen_init_cpio.c Thu May 22 15:40:19 2003 +++ b/usr/gen_init_cpio.c Thu May 22 15:40:19 2003 @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -138,8 +139,7 @@ push_rest(name); } -/* Not marked static to keep the compiler quiet, as no one uses this yet... */ -void cpio_mkfile(const char *filename, const char *location, +static void cpio_mkfile(const char *filename, const char *location, unsigned int mode, uid_t uid, gid_t gid) { char s[256]; @@ -201,7 +201,7 @@ free(filebuf); push_pad(); return; - + error_free: free(filebuf); error_close: @@ -212,9 +212,29 @@ int main (int argc, char *argv[]) { + struct stat st; + char *objdir; + char *kinit; + + if (argc != 2) { + fprintf(stderr, "usage: %s objdir\n", argv[0]); + exit(1); + } + + objdir = argv[1]; + cpio_mkdir("/dev", 0700, 0, 0); cpio_mknod("/dev/console", 0600, 0, 0, 'c', 5, 1); + cpio_mkdir("/proc", 0700, 0, 0); cpio_mkdir("/root", 0700, 0, 0); + cpio_mkdir("/sys", 0700, 0, 0); + cpio_mkdir("/sbin", 0700, 0, 0); + if (asprintf(&kinit, "%s/kinit", objdir) == -1) { + perror("asprintf"); + exit(1); + } + if (stat(kinit, &st) == 0) + cpio_mkfile(kinit, "/sbin/init", 0700, 0, 0); cpio_trailer(); exit(0);