mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									1400227773
								
							
						
					
					
						commit
						ae18b94099
					
				
					 1 changed files with 16 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue