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: Apply mtime supplied by user to all file types

Currently gen_init_cpio -d <timestamp> is applied to symlinks,
directories and special files. These files are created by
gen_init_cpio from their description. Without <timestamp> 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:
> -d <date> 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 <date> 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 <date>, 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 <baptiste@arista.com>
Link: https://lore.kernel.org/lkml/20181025215133.20138-1-baptiste@arista.com/
Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Dmitry Safonov and committed by
Masahiro Yamada
f3b2306b 7beba04e

+21 -12
+21 -12
usr/gen_init_cpio.c
··· 27 27 static unsigned int offset; 28 28 static unsigned int ino = 721; 29 29 static time_t default_mtime; 30 + static bool do_file_mtime; 30 31 static bool do_csum = false; 31 32 32 33 struct file_handler { ··· 330 329 int file; 331 330 int retval; 332 331 int rc = -1; 332 + time_t mtime; 333 333 int namesize; 334 334 unsigned int i; 335 335 uint32_t csum = 0; ··· 349 347 goto error; 350 348 } 351 349 352 - if (buf.st_mtime > 0xffffffff) { 353 - fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n", 354 - location); 355 - buf.st_mtime = 0xffffffff; 356 - } 350 + if (do_file_mtime) { 351 + mtime = default_mtime; 352 + } else { 353 + mtime = buf.st_mtime; 354 + if (mtime > 0xffffffff) { 355 + fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n", 356 + location); 357 + mtime = 0xffffffff; 358 + } 357 359 358 - if (buf.st_mtime < 0) { 359 - fprintf(stderr, "%s: Timestamp negative, clipping.\n", 360 - location); 361 - buf.st_mtime = 0; 360 + if (mtime < 0) { 361 + fprintf(stderr, "%s: Timestamp negative, clipping.\n", 362 + location); 363 + mtime = 0; 364 + } 362 365 } 363 366 364 367 if (buf.st_size > 0xffffffff) { ··· 394 387 (long) uid, /* uid */ 395 388 (long) gid, /* gid */ 396 389 nlinks, /* nlink */ 397 - (long) buf.st_mtime, /* mtime */ 390 + (long) mtime, /* mtime */ 398 391 size, /* filesize */ 399 392 3, /* major */ 400 393 1, /* minor */ ··· 543 536 "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n" 544 537 "\n" 545 538 "<timestamp> is time in seconds since Epoch that will be used\n" 546 - "as mtime for symlinks, special files and directories. The default\n" 547 - "is to use the current time for these entries.\n" 539 + "as mtime for symlinks, directories, regular and special files.\n" 540 + "The default is to use the current time for all files, but\n" 541 + "preserve modification time for regular files.\n" 548 542 "-c: calculate and store 32-bit checksums for file data.\n", 549 543 prog); 550 544 } ··· 602 594 usage(argv[0]); 603 595 exit(1); 604 596 } 597 + do_file_mtime = true; 605 598 break; 606 599 case 'c': 607 600 do_csum = true;