1 Index: linux-2.6.23.17/kernel/ksysfs.c
2 ===================================================================
3 --- linux-2.6.23.17.orig/kernel/ksysfs.c
4 +++ linux-2.6.23.17/kernel/ksysfs.c
5 @@ -49,6 +49,165 @@ KERNEL_ATTR_RW(uevent_helper);
10 +#include <asm/setup.h>
12 +extern unsigned long kexec_boot_params;
14 +char kexec_cmdline[COMMAND_LINE_SIZE] = "";
17 +replace_cmdline_tag(void)
25 +/* TODO: check the return params */
26 + t = kmalloc(KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE, GFP_KERNEL);
27 + memset((void *)t, 0, KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE);
29 +/* TODO: validate that the boot params are ATAGS, in fact */
31 + copy = (struct tag *)t;
32 + real = (struct tag *)kexec_boot_params;
33 + rend = (struct tag *)(kexec_boot_params + KEXEC_BOOT_PARAMS_SIZE);
34 + while ((real->hdr.size) && (real < rend)) {
35 + if (real->hdr.tag != ATAG_CMDLINE) {
36 + memcpy((void *)copy, (void *)real, real->hdr.size * 4);
37 + copy = tag_next(copy);
39 + real = tag_next(real);
42 +/* TODO: validate that we have enough space in the buffer */
44 + i = strlen(kexec_cmdline);
46 + copy->hdr.tag = ATAG_CMDLINE;
47 + copy->hdr.size = (sizeof(struct tag_header) + i + 1 + 4) >> 2;
48 + strcpy(copy->u.cmdline.cmdline, kexec_cmdline);
49 + copy = tag_next(copy);
52 + copy->hdr.tag = ATAG_NONE; /* Empty tag ends list */
53 + copy->hdr.size = 0; /* zero length */
55 +/* TODO: validate that the temporary buffer isn't too full */
57 + memcpy((void *)kexec_boot_params, (void *)t, KEXEC_BOOT_PARAMS_SIZE);
59 + kfree(t); /* Don't forget to free the big buffer we used */
62 +static ssize_t kexec_cmdline_show(struct kset *kset, char *page)
64 + return sprintf(page, "%s\n", kexec_cmdline);
67 +static ssize_t kexec_cmdline_store(struct kset *kset, const char *page,
70 + if ((count + 1) > COMMAND_LINE_SIZE)
71 + count = COMMAND_LINE_SIZE;
72 + memcpy(kexec_cmdline, page, count);
73 + kexec_cmdline[count] = '\0';
74 + if (count && (kexec_cmdline[count - 1] == '\n'))
75 + kexec_cmdline[count - 1] = '\0';
76 + replace_cmdline_tag();
79 +KERNEL_ATTR_RW(kexec_cmdline);
81 +static ssize_t kexec_boot_params_show(struct kset *kset, char *page)
84 + char buf[PAGE_SIZE];
87 + p = (unsigned long *)kexec_boot_params;
89 + /* if this doesn't look like atags, just print first few words */
90 + if (p[1] != ATAG_CORE)
91 + return sprintf(page, "0x%lx 0x%lx 0x%lx 0x%lx\n",
92 + p[0], p[1], p[2], p[3]);
94 + /* carefully walk the atag list, and print out the structure */
99 + /* watch out, core tag is permitted to be empty */
102 + "CORE flg=%ld pgsz=%ld rdev=0x%lx\n",
105 + sprintf(buf,"CORE\n");
108 + sprintf(buf,"MEM %ldM@0x%lx\n", p[2] / (1024 * 1024),
111 + case ATAG_VIDEOTEXT:
112 + sprintf(buf,"VIDEOTEXT sz=%ld\n", p[0]);
115 + sprintf(buf,"RAMDISK prmpt=%ld %ldK@0x%lx\n",
119 + sprintf(buf,"INITRD2 %ldK@0x%lx\n", p[3] / 1024, p[2]);
122 + sprintf(buf,"SERIAL high=0x%08lx low=0x%08lx\n",
125 + case ATAG_REVISION:
126 + sprintf(buf,"REVISION rev=%ld\n", p[2]);
128 + case ATAG_VIDEOLFB:
129 + sprintf(buf,"VIDEOLFB sz=%ld\n", p[0]);
132 + sprintf(buf,"CMD \"%s\"\n", (char *)&p[2]);
135 + sprintf(buf,"NONE\n");
139 + sprintf(buf,"-unknown- sz=%ld\n", p[0]);
143 + /* carefully add to page */
144 + if ((strlen(buf) + strlen(page)) < PAGE_SIZE) {
150 + /* stop when we encounter a header length of 0 */
154 + /* go to the next tag */
157 + /* stop if we walked off the end of the buffer */
158 + if (p > (unsigned long *)(kexec_boot_params +
159 + KEXEC_BOOT_PARAMS_SIZE))
162 + } while (keep_doing);
164 + return (strlen(page));
166 +KERNEL_ATTR_RO(kexec_boot_params);
168 static ssize_t kexec_loaded_show(struct kset *kset, char *page)
170 return sprintf(page, "%d\n", !!kexec_image);
171 @@ -95,6 +254,8 @@ static struct attribute * kernel_attrs[]
173 &kexec_loaded_attr.attr,
174 &kexec_crash_loaded_attr.attr,
175 + &kexec_cmdline_attr.attr,
176 + &kexec_boot_params_attr.attr,