public inbox for linux-next@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: linux-kbuild@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: linux-next@vger.kernel.org, ddiss@suse.de, nsc@kernel.org
Subject: [PATCH v3 2/8] gen_init_cpio: support -o <output_file> parameter
Date: Tue, 19 Aug 2025 13:05:45 +1000	[thread overview]
Message-ID: <20250819032607.28727-3-ddiss@suse.de> (raw)
In-Reply-To: <20250819032607.28727-1-ddiss@suse.de>

This is another preparatory change to allow for reflink-optimized
cpio archives with file data written / cloned via copy_file_range().
The output file is truncated prior to write, so that it maps to
usr/gen_initramfs.sh usage. It may make sense to offer an append option
in future, for easier archive concatenation.

Signed-off-by: David Disseldorp <ddiss@suse.de>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
---
 usr/gen_init_cpio.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 235bfc574e6b1..ea4b9b5fed014 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -110,7 +111,7 @@ static int cpio_trailer(void)
 	    push_pad(padlen(offset, 512)) < 0)
 		return -1;
 
-	return 0;
+	return fsync(outfd);
 }
 
 static int cpio_mkslink(const char *name, const char *target,
@@ -532,7 +533,7 @@ static int cpio_mkfile_line(const char *line)
 static void usage(const char *prog)
 {
 	fprintf(stderr, "Usage:\n"
-		"\t%s [-t <timestamp>] [-c] <cpio_list>\n"
+		"\t%s [-t <timestamp>] [-c] [-o <output_file>] <cpio_list>\n"
 		"\n"
 		"<cpio_list> is a file containing newline separated entries that\n"
 		"describe the files to be included in the initramfs archive:\n"
@@ -569,7 +570,8 @@ static void usage(const char *prog)
 		"as mtime for symlinks, directories, regular and special files.\n"
 		"The default is to use the current time for all files, but\n"
 		"preserve modification time for regular files.\n"
-		"-c: calculate and store 32-bit checksums for file data.\n",
+		"-c: calculate and store 32-bit checksums for file data.\n"
+		"<output_file>: write cpio to this file instead of stdout\n",
 		prog);
 }
 
@@ -611,7 +613,7 @@ int main (int argc, char *argv[])
 
 	default_mtime = time(NULL);
 	while (1) {
-		int opt = getopt(argc, argv, "t:ch");
+		int opt = getopt(argc, argv, "t:cho:");
 		char *invalid;
 
 		if (opt == -1)
@@ -630,6 +632,16 @@ int main (int argc, char *argv[])
 		case 'c':
 			do_csum = true;
 			break;
+		case 'o':
+			outfd = open(optarg,
+				     O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC,
+				     0600);
+			if (outfd < 0) {
+				fprintf(stderr, "failed to open %s\n", optarg);
+				usage(argv[0]);
+				exit(1);
+			}
+			break;
 		case 'h':
 		case '?':
 			usage(argv[0]);
-- 
2.43.0


  parent reply	other threads:[~2025-08-19  3:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-19  3:05 [PATCH v3 0/8] gen_init_cpio: add copy_file_range / reflink support David Disseldorp
2025-08-19  3:05 ` [PATCH v3 1/8] gen_init_cpio: write to fd instead of stdout stream David Disseldorp
2025-08-19  3:05 ` David Disseldorp [this message]
2025-08-19  3:05 ` [PATCH v3 3/8] gen_init_cpio: attempt copy_file_range for file data David Disseldorp
2025-08-19  3:05 ` [PATCH v3 4/8] gen_init_cpio: avoid duplicate strlen calls David Disseldorp
2025-08-19  3:05 ` [PATCH v3 5/8] gen_initramfs.sh: use gen_init_cpio -o parameter David Disseldorp
2025-08-19  3:05 ` [PATCH v3 6/8] docs: initramfs: file data alignment via name padding David Disseldorp
2025-08-19  3:05 ` [PATCH v3 7/8] gen_init_cpio: add -a <data_align> as reflink optimization David Disseldorp
2025-08-19  3:05 ` [PATCH v3 8/8] initramfs_test: add filename padding test case David Disseldorp
2025-08-19 20:16   ` kernel test robot
2025-08-20  1:13     ` David Disseldorp
2025-08-20 21:02       ` Nicolas Schier
2025-08-21  5:04         ` David Disseldorp
2025-08-21  5:40           ` Nicolas Schier
2025-08-21 19:09 ` [PATCH v3 0/8] gen_init_cpio: add copy_file_range / reflink support Nathan Chancellor

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=20250819032607.28727-3-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=nsc@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox