<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/usr/gen_init_cpio.c, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-10-07T16:53:05+00:00</updated>
<entry>
<title>gen_init_cpio: Ignore fsync() returning EINVAL on pipes</title>
<updated>2025-10-07T16:53:05+00:00</updated>
<author>
<name>Dmitry Safonov</name>
<email>dima@arista.com</email>
</author>
<published>2025-10-07T03:46:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=38492c5743f8b7213ca86f0cd72ea625af35d5ef'/>
<id>urn:sha1:38492c5743f8b7213ca86f0cd72ea625af35d5ef</id>
<content type='text'>
The reproducer:
echo | ./usr/gen_init_cpio /dev/stdin &gt; /dev/null

fsync() on a pipe fd returns -EINVAL, which makes gen_init_cpio fail.
Ignore -EINVAL from fsync().

Fixes: ae18b94099b0 ("gen_init_cpio: support -o &lt;output_file&gt; parameter")
Cc: David Disseldorp &lt;ddiss@suse.de&gt;
Cc: Nicolas Schier &lt;nsc@kernel.org&gt;
Signed-off-by: Dmitry Safonov &lt;dima@arista.com&gt;
Reviewed-by: David Disseldorp &lt;ddiss@suse.de&gt;
Link: https://patch.msgid.link/20251007-gen_init_cpio-pipe-v2-1-b098ab94b58a@arista.com
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: add -a &lt;data_align&gt; as reflink optimization</title>
<updated>2025-08-20T23:02:56+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2025-08-19T03:05:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5467e85508fd106443311eb7973ef588b4ef8bb6'/>
<id>urn:sha1:5467e85508fd106443311eb7973ef588b4ef8bb6</id>
<content type='text'>
As described in buffer-format.rst, the existing initramfs.c extraction
logic works fine if the cpio filename field is padded out with trailing
zeros, with a caveat that the padded namesize can't exceed PATH_MAX.

Add filename zero-padding logic to gen_init_cpio, which can be triggered
via the new -a &lt;data_align&gt; parameter. Performance and storage
utilization is improved for Btrfs and XFS workloads, as copy_file_range
can reflink the entire source file into a filesystem block-size aligned
destination offset within the cpio archive.

Btrfs benchmarks run on 6.15.8-1-default (Tumbleweed) x86_64 host:
  &gt; truncate --size=2G /tmp/backing.img
  &gt; /sbin/mkfs.btrfs /tmp/backing.img
  ...
  Sector size:        4096        (CPU page size: 4096)
  ...
  &gt; sudo mount /tmp/backing.img mnt
  &gt; sudo chown $USER mnt
  &gt; cd mnt
  mnt&gt; dd if=/dev/urandom of=foo bs=1M count=20 &amp;&amp; cat foo &gt;/dev/null
  ...
  mnt&gt; echo "file /foo foo 0755 0 0" &gt; list
  mnt&gt; perf stat -r 10 gen_init_cpio -o unaligned_btrfs list
  ...
            0.023496 +- 0.000472 seconds time elapsed  ( +-  2.01% )

  mnt&gt; perf stat -r 10 gen_init_cpio -o aligned_btrfs -a 4096 list
  ...
           0.0010010 +- 0.0000565 seconds time elapsed  ( +-  5.65% )

  mnt&gt; /sbin/xfs_io -c "fiemap -v" unaligned_btrfs
  unaligned_btrfs:
   EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
     0: [0..40967]:      695040..736007   40968   0x1
  mnt&gt; /sbin/xfs_io -c "fiemap -v" aligned_btrfs
  aligned_btrfs:
   EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
     0: [0..7]:          26768..26775         8   0x0
     1: [8..40967]:      269056..310015   40960 0x2000
     2: [40968..40975]:  26776..26783         8   0x1
  mnt&gt; /sbin/btrfs fi du unaligned_btrfs aligned_btrfs
       Total   Exclusive  Set shared  Filename
    20.00MiB    20.00MiB       0.00B  unaligned_btrfs
    20.01MiB     8.00KiB    20.00MiB  aligned_btrfs

XFS benchmarks run on same host:
  &gt; sudo umount mnt &amp;&amp; rm /tmp/backing.img
  &gt; truncate --size=2G /tmp/backing.img
  &gt; /sbin/mkfs.xfs /tmp/backing.img
  ...
           =                       reflink=1    ...
  data     =                       bsize=4096   blocks=524288, imaxpct=25
  ...
  &gt; sudo mount /tmp/backing.img mnt
  &gt; sudo chown $USER mnt
  &gt; cd mnt
  mnt&gt; dd if=/dev/urandom of=foo bs=1M count=20 &amp;&amp; cat foo &gt;/dev/null
  ...
  mnt&gt; echo "file /foo foo 0755 0 0" &gt; list
  mnt&gt; perf stat -r 10 gen_init_cpio -o unaligned_xfs list
  ...
            0.011069 +- 0.000469 seconds time elapsed  ( +-  4.24% )

  mnt&gt; perf stat -r 10 gen_init_cpio -o aligned_xfs -a 4096 list
  ...
            0.001273 +- 0.000288 seconds time elapsed  ( +- 22.60% )

  mnt&gt; /sbin/xfs_io -c "fiemap -v" unaligned_xfs
   unaligned_xfs:
   EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
     0: [0..40967]:      106176..147143   40968   0x0
     1: [40968..65023]:  147144..171199   24056 0x801
  mnt&gt; /sbin/xfs_io -c "fiemap -v" aligned_xfs
   aligned_xfs:
   EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
     0: [0..7]:          120..127             8   0x0
     1: [8..40967]:      192..41151       40960 0x2000
     2: [40968..40975]:  236728..236735       8   0x0
     3: [40976..106495]: 236736..302255   65520 0x801

The alignment is best-effort; a stderr message is printed if alignment
can't be achieved due to PATH_MAX overrun, with fallback to non-padded
filename. This allows it to still be useful for opportunistic alignment,
e.g. on aarch64 Btrfs with 64K block-size. Alignment failure messages
provide an indicator that reordering of the cpio-manifest may be
beneficial.

Archive read performance for reflinked initramfs images may suffer due
to the effects of fragmentation, particularly on spinning disks. To
mitigate excessive fragmentation, files with lengths less than
data_align aren't padded.

Signed-off-by: David Disseldorp &lt;ddiss@suse.de&gt;
Reviewed-by: Nicolas Schier &lt;nsc@kernel.org&gt;
Link: https://lore.kernel.org/r/20250819032607.28727-8-ddiss@suse.de
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: avoid duplicate strlen calls</title>
<updated>2025-08-20T23:02:56+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2025-08-19T03:05:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=348ff9e3c1cf1a4124be1c94937dfc131bf6be29'/>
<id>urn:sha1:348ff9e3c1cf1a4124be1c94937dfc131bf6be29</id>
<content type='text'>
We determine the filename length for the cpio header, so shouldn't
recalculate it when writing out the filename.

Signed-off-by: David Disseldorp &lt;ddiss@suse.de&gt;
Reviewed-by: Nicolas Schier &lt;nsc@kernel.org&gt;
Link: https://lore.kernel.org/r/20250819032607.28727-5-ddiss@suse.de
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: attempt copy_file_range for file data</title>
<updated>2025-08-20T23:02:55+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2025-08-19T03:05:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=97169cd6d95b338f2dbf5d3154b7d2233fce7d8a'/>
<id>urn:sha1:97169cd6d95b338f2dbf5d3154b7d2233fce7d8a</id>
<content type='text'>
The copy_file_range syscall can improve copy performance by cloning
extents between cpio archive source and destination files.
Existing read / write based copy logic is retained for fallback in case
the copy_file_range syscall is unsupported or unavailable due to
cross-filesystem EXDEV, etc.

Clone or reflink, as opposed to copy, of source file extents into the
output cpio archive may (e.g. on Btrfs and XFS) require alignment of the
output to the filesystem block size. This could be achieved by inserting
padding entries into the cpio archive manifest.

Signed-off-by: David Disseldorp &lt;ddiss@suse.de&gt;
Reviewed-by: Nicolas Schier &lt;nsc@kernel.org&gt;
Link: https://lore.kernel.org/r/20250819032607.28727-4-ddiss@suse.de
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: support -o &lt;output_file&gt; parameter</title>
<updated>2025-08-20T23:02:55+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2025-08-19T03:05:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ae18b94099b04264b32e33b057114024bc72c993'/>
<id>urn:sha1:ae18b94099b04264b32e33b057114024bc72c993</id>
<content type='text'>
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 &lt;ddiss@suse.de&gt;
Reviewed-by: Nicolas Schier &lt;nsc@kernel.org&gt;
Link: https://lore.kernel.org/r/20250819032607.28727-3-ddiss@suse.de
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: write to fd instead of stdout stream</title>
<updated>2025-08-20T23:02:55+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2025-08-19T03:05:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1400227773201918f270dda48f20afcd613d9bc3'/>
<id>urn:sha1:1400227773201918f270dda48f20afcd613d9bc3</id>
<content type='text'>
In preparation for more efficient archiving using copy_file_range(),
switch from writing archive data to stdout to using STDOUT_FILENO and
I/O via write(), dprintf(), etc.
Basic I/O error handling is added to cover cases such as ENOSPC. Partial
writes are treated as errors.

Signed-off-by: David Disseldorp &lt;ddiss@suse.de&gt;
Reviewed-by: Nicolas Schier &lt;nsc@kernel.org&gt;
Link: https://lore.kernel.org/r/20250819032607.28727-2-ddiss@suse.de
Signed-off-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: Apply mtime supplied by user to all file types</title>
<updated>2023-12-29T13:25:21+00:00</updated>
<author>
<name>Dmitry Safonov</name>
<email>dima@arista.com</email>
</author>
<published>2023-12-20T00:33:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f3b2306bea33b3a86ad2df4dcfab53b629e1bc84'/>
<id>urn:sha1:f3b2306bea33b3a86ad2df4dcfab53b629e1bc84</id>
<content type='text'>
Currently gen_init_cpio -d &lt;timestamp&gt; is applied to symlinks,
directories and special files. These files are created by
gen_init_cpio from their description. Without &lt;timestamp&gt; option
current time(NULL) is used. And regular files that go in initramfs
are created before cpio generation, so their mtime(s) are preserved.

This is usually not an issue as reproducible builds should rebuild
everything in the distribution, including binaries, configs and whatever
other regular files may find their way into kernel's initramfs.

On the other hand, gen_initramfs.sh usage claims:
&gt;	-d &lt;date&gt;      Use date for all file mtime values

Ar Arista initramfs files are managed with version control system
that preserves mtime. Those are configs, boot parameters, init scripts,
version files, platform-specific files, probably some others, too.

While it's certainly possible to work this around by copying the file
into temp directory and adjusting mtime prior to gen_init_cpio call,
I don't see why it needs workarounds.

The intended user of -d &lt;date&gt; option is the one that needs to create
a reproducible build, see commit a8b8017c34fe ("initramfs: Use
KBUILD_BUILD_TIMESTAMP for generated entries"). If a user wants
the build reproduction, they use -d &lt;date&gt;, which can be set on all
types of files, without surprising exceptions and workarounds.
Let's KISS here and just apply the time that user specified
with -d option.

Based-on-a-patch-by: Baptiste Covolato &lt;baptiste@arista.com&gt;
Link: https://lore.kernel.org/lkml/20181025215133.20138-1-baptiste@arista.com/
Signed-off-by: Dmitry Safonov &lt;dima@arista.com&gt;
Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>initramfs: Check negative timestamp to prevent broken cpio archive</title>
<updated>2023-04-16T08:37:01+00:00</updated>
<author>
<name>Benjamin Gray</name>
<email>bgray@linux.ibm.com</email>
</author>
<published>2023-03-20T04:08:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5efb685bb3af112038af78a2cdf28f0ffdad45f5'/>
<id>urn:sha1:5efb685bb3af112038af78a2cdf28f0ffdad45f5</id>
<content type='text'>
Similar to commit 4c9d410f32b3 ("initramfs: Check timestamp to prevent
broken cpio archive"), except asserts that the timestamp is
non-negative. This can happen when the KBUILD_BUILD_TIMESTAMP is a value
before UNIX epoch, which may be set when making reproducible builds that
don't want to look like they use a valid date.

While support for dates before 1970 might not be supported, this is more
about preventing undetected CPIO corruption. The printf's use a minimum
length format specifier, and will happily make the field longer than 8
characters if they need to.

Signed-off-by: Benjamin Gray &lt;bgray@linux.ibm.com&gt;
Reviewed-by: Andrew Donnellan &lt;ajd@linux.ibm.com&gt;
Tested-by: Andrew Donnellan &lt;ajd@linux.ibm.com&gt;
Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
</entry>
<entry>
<title>usr/gen_init_cpio.c: remove unnecessary -1 values from int file</title>
<updated>2022-10-03T21:21:44+00:00</updated>
<author>
<name>Li zeming</name>
<email>zeming@nfschina.com</email>
</author>
<published>2022-09-19T01:44:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=462cd7724e2341472c9f9670ac88e250788d4c82'/>
<id>urn:sha1:462cd7724e2341472c9f9670ac88e250788d4c82</id>
<content type='text'>
The file variable is assigned first, it does not need to be initialized.

Link: https://lkml.kernel.org/r/20220919014406.3242-1-zeming@nfschina.com
Signed-off-by: Li zeming &lt;zeming@nfschina.com&gt;
Cc: Li zeming &lt;zeming@nfschina.com&gt;
Cc: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
Cc: Nicolas Schier &lt;nicolas@fjasle.eu&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>gen_init_cpio: support file checksum archiving</title>
<updated>2022-05-10T01:29:20+00:00</updated>
<author>
<name>David Disseldorp</name>
<email>ddiss@suse.de</email>
</author>
<published>2022-05-10T01:29:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ea8048719a0c46d95e6ab925bf0924e7198d9971'/>
<id>urn:sha1:ea8048719a0c46d95e6ab925bf0924e7198d9971</id>
<content type='text'>
Documentation/driver-api/early-userspace/buffer-format.rst includes the
specification for checksum-enabled cpio archives.  Implement support for
this format in gen_init_cpio via a new '-c' parameter.

Link: https://lkml.kernel.org/r/20220404093429.27570-6-ddiss@suse.de
Signed-off-by: David Disseldorp &lt;ddiss@suse.de&gt;
Suggested-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Cc: Martin Wilck &lt;mwilck@suse.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
</content>
</entry>
</feed>
