Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gen_init_cpio: support -o <output_file> parameter

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>
Link: https://lore.kernel.org/r/20250819032607.28727-3-ddiss@suse.de
Signed-off-by: Nathan Chancellor <nathan@kernel.org>

authored by

David Disseldorp and committed by
Nathan Chancellor
ae18b940 14002277

+16 -4
+16 -4
usr/gen_init_cpio.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 + #define _GNU_SOURCE 2 3 #include <stdio.h> 3 4 #include <stdlib.h> 4 5 #include <stdint.h> ··· 111 110 push_pad(padlen(offset, 512)) < 0) 112 111 return -1; 113 112 114 - return 0; 113 + return fsync(outfd); 115 114 } 116 115 117 116 static int cpio_mkslink(const char *name, const char *target, ··· 533 532 static void usage(const char *prog) 534 533 { 535 534 fprintf(stderr, "Usage:\n" 536 - "\t%s [-t <timestamp>] [-c] <cpio_list>\n" 535 + "\t%s [-t <timestamp>] [-c] [-o <output_file>] <cpio_list>\n" 537 536 "\n" 538 537 "<cpio_list> is a file containing newline separated entries that\n" 539 538 "describe the files to be included in the initramfs archive:\n" ··· 570 569 "as mtime for symlinks, directories, regular and special files.\n" 571 570 "The default is to use the current time for all files, but\n" 572 571 "preserve modification time for regular files.\n" 573 - "-c: calculate and store 32-bit checksums for file data.\n", 572 + "-c: calculate and store 32-bit checksums for file data.\n" 573 + "<output_file>: write cpio to this file instead of stdout\n", 574 574 prog); 575 575 } 576 576 ··· 613 611 614 612 default_mtime = time(NULL); 615 613 while (1) { 616 - int opt = getopt(argc, argv, "t:ch"); 614 + int opt = getopt(argc, argv, "t:cho:"); 617 615 char *invalid; 618 616 619 617 if (opt == -1) ··· 631 629 break; 632 630 case 'c': 633 631 do_csum = true; 632 + break; 633 + case 'o': 634 + outfd = open(optarg, 635 + O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC, 636 + 0600); 637 + if (outfd < 0) { 638 + fprintf(stderr, "failed to open %s\n", optarg); 639 + usage(argv[0]); 640 + exit(1); 641 + } 634 642 break; 635 643 case 'h': 636 644 case '?':