1 From 8929dda869d51b953c8f300864da62297db8a74e Mon Sep 17 00:00:00 2001
2 From: Li, Shaohua <shaohua.li@intel.com>
3 Date: Wed, 13 Aug 2008 17:26:01 +0800
4 Subject: [PATCH] fastboot: remove duplicate unpack_to_rootfs()
6 we check if initrd is initramfs first and then do real unpack. The
7 check isn't required, we can directly do unpack. If initrd isn't
8 initramfs, we can remove garbage. In my laptop, this saves 0.1s boot
9 time. This penalizes non-initramfs case, but now initramfs is mostly
12 Signed-off-by: Shaohua Li <shaohua.li@intel.com>
13 Acked-by: Arjan van de Ven <arjan@infradead.org>
14 Signed-off-by: Ingo Molnar <mingo@elte.hu>
16 init/initramfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++-----------
17 1 files changed, 56 insertions(+), 15 deletions(-)
19 diff --git a/init/initramfs.c b/init/initramfs.c
20 index 644fc01..da8d030 100644
21 --- a/init/initramfs.c
22 +++ b/init/initramfs.c
24 #include <linux/fcntl.h>
25 #include <linux/delay.h>
26 #include <linux/string.h>
27 +#include <linux/dirent.h>
28 #include <linux/syscalls.h>
30 static __initdata char *message;
31 @@ -121,8 +122,6 @@ static __initdata char *victim;
32 static __initdata unsigned count;
33 static __initdata loff_t this_header, next_header;
35 -static __initdata int dry_run;
37 static inline void __init eat(unsigned n)
40 @@ -183,10 +182,6 @@ static int __init do_header(void)
41 parse_header(collected);
42 next_header = this_header + N_ALIGN(name_len) + body_len;
43 next_header = (next_header + 3) & ~3;
45 - read_into(name_buf, N_ALIGN(name_len), GotName);
49 if (name_len <= 0 || name_len > PATH_MAX)
51 @@ -257,8 +252,6 @@ static int __init do_name(void)
57 clean_path(collected, mode);
59 int ml = maybe_link();
60 @@ -423,10 +416,9 @@ static void __init flush_window(void)
64 -static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
65 +static char * __init unpack_to_rootfs(char *buf, unsigned len)
68 - dry_run = check_only;
69 header_buf = kmalloc(110, GFP_KERNEL);
70 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
71 name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
72 @@ -520,10 +512,57 @@ skip:
76 +#define BUF_SIZE 1024
77 +static void __init clean_rootfs(void)
81 + struct linux_dirent64 *dirp;
84 + fd = sys_open("/", O_RDONLY, 0);
88 + buf = kzalloc(BUF_SIZE, GFP_KERNEL);
96 + count = sys_getdents64(fd, dirp, BUF_SIZE);
102 + ret = sys_newlstat(dirp->d_name, &st);
105 + if (S_ISDIR(st.st_mode))
106 + sys_rmdir(dirp->d_name);
108 + sys_unlink(dirp->d_name);
111 + count -= dirp->d_reclen;
112 + dirp = (void *)dirp + dirp->d_reclen;
115 + memset(buf, 0, BUF_SIZE);
116 + count = sys_getdents64(fd, dirp, BUF_SIZE);
123 static int __init populate_rootfs(void)
125 char *err = unpack_to_rootfs(__initramfs_start,
126 - __initramfs_end - __initramfs_start, 0);
127 + __initramfs_end - __initramfs_start);
131 @@ -531,13 +570,15 @@ static int __init populate_rootfs(void)
133 printk(KERN_INFO "checking if image is initramfs...");
134 err = unpack_to_rootfs((char *)initrd_start,
135 - initrd_end - initrd_start, 1);
136 + initrd_end - initrd_start);
139 - unpack_to_rootfs((char *)initrd_start,
140 - initrd_end - initrd_start, 0);
145 + unpack_to_rootfs(__initramfs_start,
146 + __initramfs_end - __initramfs_start);
148 printk("it isn't (%s); looks like an initrd\n", err);
149 fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);
150 @@ -550,7 +591,7 @@ static int __init populate_rootfs(void)
152 printk(KERN_INFO "Unpacking initramfs...");
153 err = unpack_to_rootfs((char *)initrd_start,
154 - initrd_end - initrd_start, 0);
155 + initrd_end - initrd_start);