Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite
Date: Mon, 27 Jul 2020 18:07:43 +0200	[thread overview]
Message-ID: <20200727160744.329121-3-hch@lst.de> (raw)
In-Reply-To: <20200727160744.329121-1-hch@lst.de>

Pass a offset with the same scope as the file instead of ->f_pos.

Fixes: b63c1cd1c339 ("initramfs: switch initramfs unpacking to struct file based APIs")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 init/initramfs.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 50ec7e3c5389aa..584bc8fe88e77c 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -13,13 +13,14 @@
 #include <linux/memblock.h>
 #include <linux/namei.h>
 
-static ssize_t __init xwrite(struct file *file, const char *p, size_t count)
+static ssize_t __init xwrite(struct file *file, const char *p, size_t count,
+		loff_t *pos)
 {
 	ssize_t out = 0;
 
 	/* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
 	while (count) {
-		ssize_t rv = kernel_write(file, p, count, &file->f_pos);
+		ssize_t rv = kernel_write(file, p, count, pos);
 
 		if (rv < 0) {
 			if (rv == -EINTR || rv == -EAGAIN)
@@ -317,6 +318,7 @@ static int __init maybe_link(void)
 }
 
 static __initdata struct file *wfile;
+static __initdata loff_t wfile_pos;
 
 static int __init do_name(void)
 {
@@ -336,6 +338,7 @@ static int __init do_name(void)
 			wfile = filp_open(collected, openflags, mode);
 			if (IS_ERR(wfile))
 				return 0;
+			wfile_pos = 0;
 
 			vfs_fchown(wfile, uid, gid);
 			vfs_fchmod(wfile, mode);
@@ -365,7 +368,7 @@ static int __init do_copy(void)
 	if (byte_count >= body_len) {
 		struct timespec64 t[2] = { };
 
-		if (xwrite(wfile, victim, body_len) != body_len)
+		if (xwrite(wfile, victim, body_len, &wfile_pos) != body_len)
 			error("write error");
 
 		t[0].tv_sec = mtime;
@@ -377,7 +380,7 @@ static int __init do_copy(void)
 		state = SkipIt;
 		return 0;
 	} else {
-		if (xwrite(wfile, victim, byte_count) != byte_count)
+		if (xwrite(wfile, victim, byte_count, &wfile_pos) != byte_count)
 			error("write error");
 		body_len -= byte_count;
 		eat(byte_count);
@@ -580,6 +583,7 @@ static void __init populate_initrd_image(char *err)
 {
 	ssize_t written;
 	struct file *file;
+	loff_t pos = 0;
 
 	unpack_to_rootfs(__initramfs_start, __initramfs_size);
 
@@ -589,7 +593,8 @@ static void __init populate_initrd_image(char *err)
 	if (IS_ERR(file))
 		return;
 
-	written = xwrite(file, (char *)initrd_start, initrd_end - initrd_start);
+	written = xwrite(file, (char *)initrd_start, initrd_end - initrd_start,
+			&pos);
 	if (written != initrd_end - initrd_start)
 		pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
 		       written, initrd_end - initrd_start);
-- 
2.27.0


  parent reply	other threads:[~2020-07-27 16:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 16:07 fixes for: decruft the early init / initrd / initramfs code v2 Christoph Hellwig
2020-07-27 16:07 ` [PATCH 1/3] initramfs: remove clean_rootfs Christoph Hellwig
2020-07-27 16:07 ` Christoph Hellwig [this message]
2020-07-27 16:07 ` [PATCH 3/3] initd: pass a non-f_pos offset to kernel_read/kernel_write Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200727160744.329121-3-hch@lst.de \
    --to=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).