]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
ea4c617ed9d47c4a6dfa4245a072157c978ea5a5
[thirdparty/openembedded/openembedded-core-contrib.git] /
1 From 24559ecf972ff482222f6fc152f15468d2380e2d 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()
5
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
10 widely used.
11
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>
15 ---
16 init/initramfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++-----------
17 1 files changed, 56 insertions(+), 15 deletions(-)
18
19 diff --git a/init/initramfs.c b/init/initramfs.c
20 index 4f5ba75..6b5c1dc 100644
21 --- a/init/initramfs.c
22 +++ b/init/initramfs.c
23 @@ -5,6 +5,7 @@
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>
29 #include <linux/utime.h>
30
31 @@ -166,8 +167,6 @@ static __initdata char *victim;
32 static __initdata unsigned count;
33 static __initdata loff_t this_header, next_header;
34
35 -static __initdata int dry_run;
36 -
37 static inline void __init eat(unsigned n)
38 {
39 victim += n;
40 @@ -229,10 +228,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;
44 - if (dry_run) {
45 - read_into(name_buf, N_ALIGN(name_len), GotName);
46 - return 0;
47 - }
48 state = SkipIt;
49 if (name_len <= 0 || name_len > PATH_MAX)
50 return 0;
51 @@ -303,8 +298,6 @@ static int __init do_name(void)
52 free_hash();
53 return 0;
54 }
55 - if (dry_run)
56 - return 0;
57 clean_path(collected, mode);
58 if (S_ISREG(mode)) {
59 int ml = maybe_link();
60 @@ -475,10 +468,9 @@ static void __init flush_window(void)
61 outcnt = 0;
62 }
63
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)
66 {
67 int written;
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 @@ -573,10 +565,57 @@ skip:
73 initrd_end = 0;
74 }
75
76 +#define BUF_SIZE 1024
77 +static void __init clean_rootfs(void)
78 +{
79 + int fd;
80 + void *buf;
81 + struct linux_dirent64 *dirp;
82 + int count;
83 +
84 + fd = sys_open("/", O_RDONLY, 0);
85 + WARN_ON(fd < 0);
86 + if (fd < 0)
87 + return;
88 + buf = kzalloc(BUF_SIZE, GFP_KERNEL);
89 + WARN_ON(!buf);
90 + if (!buf) {
91 + sys_close(fd);
92 + return;
93 + }
94 +
95 + dirp = buf;
96 + count = sys_getdents64(fd, dirp, BUF_SIZE);
97 + while (count > 0) {
98 + while (count > 0) {
99 + struct stat st;
100 + int ret;
101 +
102 + ret = sys_newlstat(dirp->d_name, &st);
103 + WARN_ON_ONCE(ret);
104 + if (!ret) {
105 + if (S_ISDIR(st.st_mode))
106 + sys_rmdir(dirp->d_name);
107 + else
108 + sys_unlink(dirp->d_name);
109 + }
110 +
111 + count -= dirp->d_reclen;
112 + dirp = (void *)dirp + dirp->d_reclen;
113 + }
114 + dirp = buf;
115 + memset(buf, 0, BUF_SIZE);
116 + count = sys_getdents64(fd, dirp, BUF_SIZE);
117 + }
118 +
119 + sys_close(fd);
120 + kfree(buf);
121 +}
122 +
123 static int __init populate_rootfs(void)
124 {
125 char *err = unpack_to_rootfs(__initramfs_start,
126 - __initramfs_end - __initramfs_start, 0);
127 + __initramfs_end - __initramfs_start);
128 if (err)
129 panic(err);
130 if (initrd_start) {
131 @@ -584,13 +623,15 @@ static int __init populate_rootfs(void)
132 int fd;
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);
137 if (!err) {
138 printk(" it is\n");
139 - unpack_to_rootfs((char *)initrd_start,
140 - initrd_end - initrd_start, 0);
141 free_initrd();
142 return 0;
143 + } else {
144 + clean_rootfs();
145 + unpack_to_rootfs(__initramfs_start,
146 + __initramfs_end - __initramfs_start);
147 }
148 printk("it isn't (%s); looks like an initrd\n", err);
149 fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);
150 @@ -603,7 +644,7 @@ static int __init populate_rootfs(void)
151 #else
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);
156 if (err)
157 panic(err);
158 printk(" done\n");
159 --
160 1.5.5.1
161