Re: [PATCH v2] initramfs: Support initrd that is bigger than 2GiB

From: Geert Uytterhoeven
Date: Mon Jun 23 2014 - 05:30:29 EST


On Sat, Jun 21, 2014 at 4:29 AM, Yinghai Lu <yinghai@xxxxxxxxxx> wrote:
> --- linux-2.6.orig/init/initramfs.c
> +++ linux-2.6/init/initramfs.c
> @@ -19,6 +19,26 @@
> #include <linux/syscalls.h>
> #include <linux/utime.h>
>
> +static long __init xwrite(unsigned int fd, char *p,
> + size_t count)

Shouldn't this return ssize_t instead of long?

> +{
> + ssize_t left = count;
> + long written;

ssize_t written

> +
> + /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
> + while (left > 0) {
> + written = sys_write(fd, p, left);
> +
> + if (written <= 0)
> + break;
> +
> + left -= written;
> + p += written;
> + }
> +
> + return (written < 0) ? written : count;
> +}
> +
> static __initdata char *message;
> static void __init error(char *x)
> {

> @@ -604,8 +624,13 @@ static int __init populate_rootfs(void)
> fd = sys_open("/initrd.image",
> O_WRONLY|O_CREAT, 0700);
> if (fd >= 0) {
> - sys_write(fd, (char *)initrd_start,
> - initrd_end - initrd_start);
> + long written = xwrite(fd, (char *)initrd_start,

ssize_t written

> + initrd_end - initrd_start);
> +
> + if (written != initrd_end - initrd_start)
> + pr_err("/initrd.image: incomplete write (%ld != %ld)\n",

"%zd", once written is ssize_t.

> + written, initrd_end - initrd_start);
> +
> sys_close(fd);
> free_initrd();
> }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/