X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=init%2Finitramfs.c;h=f81cfa40a719858a003ab50448f3d0925005d5ff;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=d0ce3884bc9df69b78431902698826519337bc08;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/init/initramfs.c b/init/initramfs.c index d0ce3884b..f81cfa40a 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -26,10 +26,12 @@ static void __init free(void *where) /* link hash */ -static struct hash { +#define N_ALIGN(len) ((((len) + 1) & ~3) + 2) + +static __initdata struct hash { int ino, minor, major; struct hash *next; - char *name; + char name[N_ALIGN(PATH_MAX)]; } *head[32]; static inline int hash(int major, int minor, int ino) @@ -57,7 +59,7 @@ static char __init *find_link(int major, int minor, int ino, char *name) q->ino = ino; q->minor = minor; q->major = major; - q->name = name; + strcpy(q->name, name); q->next = NULL; *p = q; return NULL; @@ -133,8 +135,6 @@ static inline void eat(unsigned n) count -= n; } -#define N_ALIGN(len) ((((len) + 1) & ~3) + 2) - static __initdata char *collected; static __initdata int remains; static __initdata char *collect; @@ -169,7 +169,7 @@ static int __init do_collect(void) memcpy(collect, victim, n); eat(n); collect += n; - if (remains -= n) + if ((remains -= n) != 0) return 1; state = next_state; return 0; @@ -207,7 +207,7 @@ static int __init do_header(void) static int __init do_skip(void) { - if (this_header + count <= next_header) { + if (this_header + count < next_header) { eat(count); return 1; } else { @@ -241,10 +241,9 @@ static __initdata int wfd; static int __init do_name(void) { state = SkipIt; - next_state = Start; + next_state = Reset; if (strcmp(collected, "TRAILER!!!") == 0) { free_hash(); - next_state = Reset; return 0; } if (dry_run) @@ -295,7 +294,7 @@ static int __init do_symlink(void) sys_symlink(collected + N_ALIGN(name_len), collected); sys_lchown(collected, uid, gid); state = SkipIt; - next_state = Start; + next_state = Reset; return 0; } @@ -331,6 +330,10 @@ static void __init flush_buffer(char *buf, unsigned len) buf += written; len -= written; state = Start; + } else if (c == 0) { + buf += written; + len -= written; + state = Reset; } else error("junk in compressed archive"); } @@ -372,11 +375,12 @@ static long bytes_out; #define Tracecv(c,x) #define STATIC static +#define INIT __init -static void flush_window(void); -static void error(char *m); -static void gzip_mark(void **); -static void gzip_release(void **); +static void __init flush_window(void); +static void __init error(char *m); +static void __init gzip_mark(void **); +static void __init gzip_release(void **); #include "../lib/inflate.c" @@ -409,7 +413,7 @@ static void __init flush_window(void) outcnt = 0; } -char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) +static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) { int written; dry_run = check_only; @@ -445,8 +449,7 @@ char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) bytes_out = 0; crc = (ulg)0xffffffffL; /* shift register contents */ makecrc(); - if (gunzip()) - message = "ungzip failed"; + gunzip(); if (state != Reset) error("junk in gzipped archive"); this_header = saved_offset + inptr; @@ -460,19 +463,50 @@ char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) return message; } -extern char __initramfs_start, __initramfs_end; +extern char __initramfs_start[], __initramfs_end[]; #ifdef CONFIG_BLK_DEV_INITRD #include +#include + +static void __init free_initrd(void) +{ +#ifdef CONFIG_KEXEC + unsigned long crashk_start = (unsigned long)__va(crashk_res.start); + unsigned long crashk_end = (unsigned long)__va(crashk_res.end); + + /* + * If the initrd region is overlapped with crashkernel reserved region, + * free only memory that is not part of crashkernel region. + */ + if (initrd_start < crashk_end && initrd_end > crashk_start) { + /* + * Initialize initrd memory region since the kexec boot does + * not do. + */ + memset((void *)initrd_start, 0, initrd_end - initrd_start); + if (initrd_start < crashk_start) + free_initrd_mem(initrd_start, crashk_start); + if (initrd_end > crashk_end) + free_initrd_mem(crashk_end, initrd_end); + } else +#endif + free_initrd_mem(initrd_start, initrd_end); + + initrd_start = 0; + initrd_end = 0; +} + #endif void __init populate_rootfs(void) { - char *err = unpack_to_rootfs(&__initramfs_start, - &__initramfs_end - &__initramfs_start, 0); + char *err = unpack_to_rootfs(__initramfs_start, + __initramfs_end - __initramfs_start, 0); if (err) panic(err); #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start) { +#ifdef CONFIG_BLK_DEV_RAM int fd; printk(KERN_INFO "checking if image is initramfs..."); err = unpack_to_rootfs((char *)initrd_start, @@ -481,17 +515,26 @@ void __init populate_rootfs(void) printk(" it is\n"); unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start, 0); - free_initrd_mem(initrd_start, initrd_end); + free_initrd(); return; } printk("it isn't (%s); looks like an initrd\n", err); - fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 700); + fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700); if (fd >= 0) { sys_write(fd, (char *)initrd_start, initrd_end - initrd_start); sys_close(fd); - free_initrd_mem(initrd_start, initrd_end); + free_initrd(); } +#else + printk(KERN_INFO "Unpacking initramfs..."); + err = unpack_to_rootfs((char *)initrd_start, + initrd_end - initrd_start, 0); + if (err) + panic(err); + printk(" done\n"); + free_initrd(); +#endif } #endif }