linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gen_init_cpio: allow file mtime to be overridden
@ 2018-10-25 21:51 Baptiste Covolato
  0 siblings, 0 replies; only message in thread
From: Baptiste Covolato @ 2018-10-25 21:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: baptiste, kstewart, gregkh, tglx, pombredanne, yamada.masahiro,
	forney, andrzej.p

By default gen_init_cpio uses the current time as mtime for links,
special files and directories. We have the possibility to set this
timestamp to a fixed value using -t. However, this timestamp doesn't
apply to regular files. For those, the mtime returned by stat is used.

This commit introduces a '-a' option, which when used, will modify the
mtime of regular files to match the timestamp of special files,
directories, ...

v2: Fix typos in commit title/message

Signed-off-by: Baptiste Covolato <baptiste@arista.com>
---
 usr/gen_init_cpio.c       | 19 +++++++++++++++----
 usr/gen_initramfs_list.sh |  2 +-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 03b21189d58b..e2432ff31965 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -24,6 +24,7 @@
 static unsigned int offset;
 static unsigned int ino = 721;
 static time_t default_mtime;
+static int default_mtime_all;
 
 struct file_handler {
 	const char *type;
@@ -305,6 +306,7 @@ static int cpio_mkfile(const char *name, const char *location,
 	int rc = -1;
 	int namesize;
 	unsigned int i;
+	time_t mtime;
 
 	mode |= S_IFREG;
 
@@ -320,6 +322,10 @@ static int cpio_mkfile(const char *name, const char *location,
 		goto error;
 	}
 
+	mtime = buf.st_mtime;
+	if (default_mtime_all)
+		mtime = default_mtime;
+
 	filebuf = malloc(buf.st_size);
 	if (!filebuf) {
 		fprintf (stderr, "out of memory\n");
@@ -348,7 +354,7 @@ static int cpio_mkfile(const char *name, const char *location,
 			(long) uid,		/* uid */
 			(long) gid,		/* gid */
 			nlinks,			/* nlink */
-			(long) buf.st_mtime,	/* mtime */
+			(long) mtime,		/* mtime */
 			size,			/* filesize */
 			3,			/* major */
 			1,			/* minor */
@@ -452,7 +458,7 @@ static int cpio_mkfile_line(const char *line)
 static void usage(const char *prog)
 {
 	fprintf(stderr, "Usage:\n"
-		"\t%s [-t <timestamp>] <cpio_list>\n"
+		"\t%s [-t <timestamp>] [-a] <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"
@@ -487,7 +493,9 @@ static void usage(const char *prog)
 		"\n"
 		"<timestamp> is time in seconds since Epoch that will be used\n"
 		"as mtime for symlinks, special files and directories. The default\n"
-		"is to use the current time for these entries.\n",
+		"is to use the current time for these entries. If -a is specified,\n"
+		"the same mtime will be used for files, overriding their original\n"
+		"mtime.\n",
 		prog);
 }
 
@@ -529,12 +537,15 @@ int main (int argc, char *argv[])
 
 	default_mtime = time(NULL);
 	while (1) {
-		int opt = getopt(argc, argv, "t:h");
+		int opt = getopt(argc, argv, "t:ha");
 		char *invalid;
 
 		if (opt == -1)
 			break;
 		switch (opt) {
+		case 'a':
+			default_mtime_all = 1;
+			break;
 		case 't':
 			default_mtime = strtol(optarg, &invalid, 10);
 			if (!*optarg || *invalid) {
diff --git a/usr/gen_initramfs_list.sh b/usr/gen_initramfs_list.sh
index 0aad760fcd8c..1704e0638bcc 100755
--- a/usr/gen_initramfs_list.sh
+++ b/usr/gen_initramfs_list.sh
@@ -308,7 +308,7 @@ if [ ! -z ${output_file} ]; then
 		if test -n "$KBUILD_BUILD_TIMESTAMP"; then
 			timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
 			if test -n "$timestamp"; then
-				timestamp="-t $timestamp"
+				timestamp="-a -t $timestamp"
 			fi
 		fi
 		cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)"
-- 
2.19.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-25 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-25 21:51 [PATCH v2] gen_init_cpio: allow file mtime to be overridden Baptiste Covolato

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).