1 diff -uprN linux-2.6.23.orig/kernel/ksysfs.c linux-2.6.23/kernel/ksysfs.c
2 --- linux-2.6.23.orig/kernel/ksysfs.c 2007-10-09 15:31:38.000000000 -0500
3 +++ linux-2.6.23/kernel/ksysfs.c 2007-10-11 01:10:26.000000000 -0500
4 @@ -49,6 +49,165 @@ KERNEL_ATTR_RW(uevent_helper);
9 +#include <asm/setup.h>
11 +extern unsigned long kexec_boot_params;
13 +char kexec_cmdline[COMMAND_LINE_SIZE] = "";
16 +replace_cmdline_tag(void)
24 +/* TODO: check the return params */
25 + t = kmalloc(KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE, GFP_KERNEL);
26 + memset((void *)t, 0, KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE);
28 +/* TODO: validate that the boot params are ATAGS, in fact */
30 + copy = (struct tag *)t;
31 + real = (struct tag *)kexec_boot_params;
32 + rend = (struct tag *)(kexec_boot_params + KEXEC_BOOT_PARAMS_SIZE);
33 + while ((real->hdr.size) && (real < rend)) {
34 + if (real->hdr.tag != ATAG_CMDLINE) {
35 + memcpy((void *)copy, (void *)real, real->hdr.size * 4);
36 + copy = tag_next(copy);
38 + real = tag_next(real);
41 +/* TODO: validate that we have enough space in the buffer */
43 + i = strlen(kexec_cmdline);
45 + copy->hdr.tag = ATAG_CMDLINE;
46 + copy->hdr.size = (sizeof(struct tag_header) + i + 1 + 4) >> 2;
47 + strcpy(copy->u.cmdline.cmdline, kexec_cmdline);
48 + copy = tag_next(copy);
51 + copy->hdr.tag = ATAG_NONE; /* Empty tag ends list */
52 + copy->hdr.size = 0; /* zero length */
54 +/* TODO: validate that the temporary buffer isn't too full */
56 + memcpy((void *)kexec_boot_params, (void *)t, KEXEC_BOOT_PARAMS_SIZE);
58 + kfree(t); /* Don't forget to free the big buffer we used */
61 +static ssize_t kexec_cmdline_show(struct kset *kset, char *page)
63 + return sprintf(page, "%s\n", kexec_cmdline);
66 +static ssize_t kexec_cmdline_store(struct kset *kset, const char *page,
69 + if ((count + 1) > COMMAND_LINE_SIZE)
70 + count = COMMAND_LINE_SIZE;
71 + memcpy(kexec_cmdline, page, count);
72 + kexec_cmdline[count] = '\0';
73 + if (count && (kexec_cmdline[count - 1] == '\n'))
74 + kexec_cmdline[count - 1] = '\0';
75 + replace_cmdline_tag();
78 +KERNEL_ATTR_RW(kexec_cmdline);
80 +static ssize_t kexec_boot_params_show(struct kset *kset, char *page)
83 + char buf[PAGE_SIZE];
86 + p = (unsigned long *)kexec_boot_params;
88 + /* if this doesn't look like atags, just print first few words */
89 + if (p[1] != ATAG_CORE)
90 + return sprintf(page, "0x%lx 0x%lx 0x%lx 0x%lx\n",
91 + p[0], p[1], p[2], p[3]);
93 + /* carefully walk the atag list, and print out the structure */
98 + /* watch out, core tag is permitted to be empty */
101 + "CORE flg=%ld pgsz=%ld rdev=0x%lx\n",
104 + sprintf(buf,"CORE\n");
107 + sprintf(buf,"MEM %ldM@0x%lx\n", p[2] / (1024 * 1024),
110 + case ATAG_VIDEOTEXT:
111 + sprintf(buf,"VIDEOTEXT sz=%ld\n", p[0]);
114 + sprintf(buf,"RAMDISK prmpt=%ld %ldK@0x%lx\n",
118 + sprintf(buf,"INITRD2 %ldK@0x%lx\n", p[3] / 1024, p[2]);
121 + sprintf(buf,"SERIAL high=0x%08lx low=0x%08lx\n",
124 + case ATAG_REVISION:
125 + sprintf(buf,"REVISION rev=%ld\n", p[2]);
127 + case ATAG_VIDEOLFB:
128 + sprintf(buf,"VIDEOLFB sz=%ld\n", p[0]);
131 + sprintf(buf,"CMD \"%s\"\n", (char *)&p[2]);
134 + sprintf(buf,"NONE\n");
138 + sprintf(buf,"-unknown- sz=%ld\n", p[0]);
142 + /* carefully add to page */
143 + if ((strlen(buf) + strlen(page)) < PAGE_SIZE) {
149 + /* stop when we encounter a header length of 0 */
153 + /* go to the next tag */
156 + /* stop if we walked off the end of the buffer */
157 + if (p > (unsigned long *)(kexec_boot_params +
158 + KEXEC_BOOT_PARAMS_SIZE))
161 + } while (keep_doing);
163 + return (strlen(page));
165 +KERNEL_ATTR_RO(kexec_boot_params);
167 static ssize_t kexec_loaded_show(struct kset *kset, char *page)
169 return sprintf(page, "%d\n", !!kexec_image);
170 @@ -95,6 +254,8 @@ static struct attribute * kernel_attrs[]
172 &kexec_loaded_attr.attr,
173 &kexec_crash_loaded_attr.attr,
174 + &kexec_cmdline_attr.attr,
175 + &kexec_boot_params_attr.attr,