Blame SOURCES/cpio-2.11-reproducible.patch

dd3c47
From d249aaececed97d8ed78508ddec27fc73112601f Mon Sep 17 00:00:00 2001
dd3c47
From: Sergey Poznyakoff <gray@gnu.org.ua>
dd3c47
Date: Mon, 1 Dec 2014 15:02:38 +0200
dd3c47
Subject: [PATCH 1/2] New options to create device and inode-independent
dd3c47
 archives.
dd3c47
dd3c47
* src/util.c (inode_val): New member trans_inode
dd3c47
(find_inode_val): New function.
dd3c47
(find_inode_file): Rewrite using the above.
dd3c47
(add_inode): Initialize the trans_inode member
dd3c47
depending on the value of renumber_inodes_option.
dd3c47
(get_inode_and_dev): New function.
dd3c47
(stat_to_cpio): Use get_inode_and_dev.
dd3c47
(arf_stores_inode_p): New function.
dd3c47
* src/extern.h (renumber_inodes_option)
dd3c47
(ignore_devno_option): New externs.
dd3c47
* src/global.c (renumber_inodes_option)
dd3c47
(ignore_devno_option): New variables.
dd3c47
* src/main.c: Add new options.
dd3c47
dd3c47
* NEWS: Document changes.
dd3c47
* doc/cpio.1: Document new options.
dd3c47
* doc/cpio.texi: Likewise.
dd3c47
---
dd3c47
 NEWS          | 14 +++++++++++
dd3c47
 doc/cpio.texi | 12 +++++++++
dd3c47
 src/extern.h  |  8 ++++--
dd3c47
 src/global.c  |  3 +++
dd3c47
 src/main.c    | 34 +++++++++++++++++++++++--
dd3c47
 src/util.c    | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
dd3c47
 6 files changed, 138 insertions(+), 14 deletions(-)
dd3c47
dd3c47
diff --git a/NEWS b/NEWS
dd3c47
index 1b068ba..c112d70 100644
dd3c47
--- a/NEWS
dd3c47
+++ b/NEWS
dd3c47
@@ -5,6 +5,20 @@ See the end of file for copying conditions.
dd3c47
 
dd3c47
 Please send cpio bug reports to <bug-cpio@gnu.org>.
dd3c47
 
dd3c47
+Downstream backports from newer versions
dd3c47
+* New options for copy-out mode:
dd3c47
+
dd3c47
+** --ignore-devno
dd3c47
+Store 0 in the device number fields, instead of the actual device
dd3c47
+number.
dd3c47
+
dd3c47
+** --renumber-inodes
dd3c47
+Renumber inodes when storing them in the archive.
dd3c47
+
dd3c47
+** --device-independent or --reproducible
dd3c47
+Create reproducible archives.  This is equivalent to 
dd3c47
+--ignore-devno --renumber-inodes.
dd3c47
+
dd3c47
 Version 2.11 - Sergey Poznyakoff, 2010-03-10
dd3c47
 
dd3c47
 * Fix mt build.
dd3c47
diff --git a/doc/cpio.texi b/doc/cpio.texi
dd3c47
index 1af808a..c9b62ee 100644
dd3c47
--- a/doc/cpio.texi
dd3c47
+++ b/doc/cpio.texi
dd3c47
@@ -342,6 +342,11 @@ Set the I/O block size to @var{io-size} bytes.
dd3c47
 @itemx --make-directories
dd3c47
 Create leading directories where needed.
dd3c47
 
dd3c47
+@item --device-independent
dd3c47
+@itemx --reproducible
dd3c47
+Create reproducible archives.  This is equivalent to
dd3c47
+@option{--ignore-devno --renumber-inodes}.
dd3c47
+
dd3c47
 @item -E @var{file}
dd3c47
 @itemx --pattern-file=@var{file}
dd3c47
 Read additional patterns specifying filenames to extract or list from
dd3c47
@@ -419,6 +424,10 @@ of the remote host.  The hostname can be preceded by a username and an @samp{@@}
dd3c47
 access the remote tape drive as that user, if you have permission to do
dd3c47
 so (typically an entry in that user's @file{~/.rhosts} file).
dd3c47
 
dd3c47
+@item --ignore-devno
dd3c47
+Store 0 in the device number field of each archive member, instead of
dd3c47
+the actual device number.
dd3c47
+
dd3c47
 @item -k
dd3c47
 Ignored; for compatibility with other versions of cpio.
dd3c47
 
dd3c47
@@ -486,6 +495,9 @@ Do not print the number of blocks copied.
dd3c47
 @itemx --rename
dd3c47
 Interactively rename files.
dd3c47
 
dd3c47
+@item --renumber-inodes
dd3c47
+Renumber inodes when storing them in the archive.
dd3c47
+
dd3c47
 @item -R @var{owner}
dd3c47
 @itemx --owner @var{owner}
dd3c47
 
dd3c47
diff --git a/src/extern.h b/src/extern.h
dd3c47
index 4f94d40..f3a6c47 100644
dd3c47
--- a/src/extern.h
dd3c47
+++ b/src/extern.h
dd3c47
@@ -56,6 +56,8 @@ extern int only_verify_crc_flag;
dd3c47
 extern int no_abs_paths_flag;
dd3c47
 extern unsigned int warn_option;
dd3c47
 extern mode_t newdir_umask;
dd3c47
+extern int renumber_inodes_option;
dd3c47
+extern int ignore_devno_option;
dd3c47
 
dd3c47
 /* Values for warn_option */
dd3c47
 #define CPIO_WARN_NONE     0
dd3c47
@@ -171,8 +173,8 @@ void create_all_directories (char *name);
dd3c47
 void prepare_append (int out_file_des);
dd3c47
 char *find_inode_file (ino_t node_num,
dd3c47
 		       unsigned long major_num, unsigned long minor_num);
dd3c47
-void add_inode (ino_t node_num, char *file_name,
dd3c47
-	        unsigned long major_num, unsigned long minor_num);
dd3c47
+struct inode_val *add_inode (ino_t node_num, char *file_name,
dd3c47
+			     unsigned long major_num, unsigned long minor_num);
dd3c47
 int open_archive (char *file);
dd3c47
 void tape_offline (int tape_des);
dd3c47
 void get_next_reel (int tape_des);
dd3c47
@@ -217,3 +219,5 @@ void delay_set_stat (char const *file_name, struct stat *st,
dd3c47
 int repair_delayed_set_stat (struct cpio_file_stat *file_hdr);
dd3c47
 void apply_delayed_set_stat (void);
dd3c47
      
dd3c47
+int arf_stores_inode_p (enum archive_format arf);
dd3c47
+
dd3c47
diff --git a/src/global.c b/src/global.c
dd3c47
index cff9720..fb074fb 100644
dd3c47
--- a/src/global.c
dd3c47
+++ b/src/global.c
dd3c47
@@ -193,3 +193,6 @@ int (*xstat) ();
dd3c47
 
dd3c47
 /* Which copy operation to perform. (-i, -o, -p) */
dd3c47
 void (*copy_function) () = 0;
dd3c47
+
dd3c47
+int renumber_inodes_option;
dd3c47
+int ignore_devno_option;
dd3c47
diff --git a/src/main.c b/src/main.c
dd3c47
index 9b9bf74..6945c7d 100644
dd3c47
--- a/src/main.c
dd3c47
+++ b/src/main.c
dd3c47
@@ -57,7 +57,10 @@ enum cpio_options {
dd3c47
   FORCE_LOCAL_OPTION,            
dd3c47
   DEBUG_OPTION,                  
dd3c47
   BLOCK_SIZE_OPTION,             
dd3c47
-  TO_STDOUT_OPTION
dd3c47
+  TO_STDOUT_OPTION,
dd3c47
+  RENUMBER_INODES_OPTION,
dd3c47
+  IGNORE_DEVNO_OPTION,
dd3c47
+  DEVICE_INDEPENDENT_OPTION
dd3c47
 };
dd3c47
 
dd3c47
 const char *program_authors[] =
dd3c47
@@ -175,6 +178,13 @@ static struct argp_option options[] = {
dd3c47
    N_("Append to an existing archive."), GRID+1 },
dd3c47
   {NULL, 'O', N_("[[USER@]HOST:]FILE-NAME"), 0,
dd3c47
    N_("Archive filename to use instead of standard output. Optional USER and HOST specify the user and host names in case of a remote archive"), GRID+1 },
dd3c47
+  {"renumber-inodes", RENUMBER_INODES_OPTION, NULL, 0,
dd3c47
+   N_("Renumber inodes") },
dd3c47
+  {"ignore-devno", IGNORE_DEVNO_OPTION, NULL, 0,
dd3c47
+   N_("Don't store device numbers") },
dd3c47
+  {"device-independent", DEVICE_INDEPENDENT_OPTION, NULL, 0,
dd3c47
+   N_("Create device-independent (reproducible) archives") },
dd3c47
+  {"reproducible", 0, NULL, OPTION_ALIAS },
dd3c47
 #undef GRID
dd3c47
   
dd3c47
   /* ********** */
dd3c47
@@ -432,7 +442,19 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
dd3c47
 	error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
dd3c47
       copy_function = process_copy_pass;
dd3c47
       break;
dd3c47
-	  
dd3c47
+
dd3c47
+    case IGNORE_DEVNO_OPTION:
dd3c47
+      ignore_devno_option = 1;
dd3c47
+      break;
dd3c47
+      
dd3c47
+    case RENUMBER_INODES_OPTION:
dd3c47
+      renumber_inodes_option = 1;
dd3c47
+      break;
dd3c47
+
dd3c47
+    case DEVICE_INDEPENDENT_OPTION:
dd3c47
+      ignore_devno_option = renumber_inodes_option = 1;
dd3c47
+      break;
dd3c47
+      
dd3c47
     case RSH_COMMAND_OPTION:
dd3c47
       rsh_command_option = arg;
dd3c47
       break;
dd3c47
@@ -575,6 +597,8 @@ process_args (int argc, char *argv[])
dd3c47
       CHECK_USAGE(xstat != lstat, "--dereference", "--extract");
dd3c47
       CHECK_USAGE(append_flag, "--append", "--extract");
dd3c47
       CHECK_USAGE(output_archive_name, "-O", "--extract");
dd3c47
+      CHECK_USAGE (renumber_inodes_option, "--renumber-inodes", "--extract");
dd3c47
+      CHECK_USAGE (ignore_devno_option, "--ignore-devno", "--extract");
dd3c47
       if (to_stdout_option)
dd3c47
 	{
dd3c47
 	  CHECK_USAGE(create_dir_flag, "--make-directories", "--to-stdout");
dd3c47
@@ -630,6 +654,9 @@ process_args (int argc, char *argv[])
dd3c47
 	archive_format = arf_binary;
dd3c47
       if (output_archive_name)
dd3c47
 	archive_name = output_archive_name;
dd3c47
+
dd3c47
+      if (!arf_stores_inode_p (archive_format))
dd3c47
+	renumber_inodes_option = ignore_devno_option = 0;
dd3c47
     }
dd3c47
   else
dd3c47
     {
dd3c47
@@ -655,6 +682,9 @@ process_args (int argc, char *argv[])
dd3c47
       CHECK_USAGE(no_abs_paths_flag, "--absolute-pathnames",
dd3c47
 		  "--pass-through");
dd3c47
       CHECK_USAGE(to_stdout_option, "--to-stdout", "--pass-through");
dd3c47
+      CHECK_USAGE (renumber_inodes_option, "--renumber-inodes",
dd3c47
+		   "--pass-through");
dd3c47
+      CHECK_USAGE (ignore_devno_option, "--ignore-devno", "--pass-through");
dd3c47
       
dd3c47
       directory_name = argv[index];
dd3c47
     }
dd3c47
diff --git a/src/util.c b/src/util.c
dd3c47
index 2a821c7..ce45842 100644
dd3c47
--- a/src/util.c
dd3c47
+++ b/src/util.c
dd3c47
@@ -689,6 +689,7 @@ struct inode_val
dd3c47
   ino_t inode;
dd3c47
   unsigned long major_num;
dd3c47
   unsigned long minor_num;
dd3c47
+  ino_t trans_inode;
dd3c47
   char *file_name;
dd3c47
 };
dd3c47
 
dd3c47
@@ -712,8 +713,8 @@ inode_val_compare (const void *val1, const void *val2)
dd3c47
          && ival1->minor_num == ival2->minor_num;
dd3c47
 }
dd3c47
 
dd3c47
-char *
dd3c47
-find_inode_file (ino_t node_num, unsigned long major_num,
dd3c47
+static struct inode_val *
dd3c47
+find_inode_val (ino_t node_num, unsigned long major_num,
dd3c47
 		 unsigned long minor_num)
dd3c47
 {
dd3c47
   struct inode_val sample;
dd3c47
@@ -725,32 +726,78 @@ find_inode_file (ino_t node_num, unsigned long major_num,
dd3c47
   sample.inode = node_num;
dd3c47
   sample.major_num = major_num;
dd3c47
   sample.minor_num = minor_num;
dd3c47
-  ival = hash_lookup (hash_table, &sample);
dd3c47
+  return hash_lookup (hash_table, &sample);
dd3c47
+}
dd3c47
+
dd3c47
+char *
dd3c47
+find_inode_file (ino_t node_num, unsigned long major_num,
dd3c47
+		 unsigned long minor_num)
dd3c47
+{
dd3c47
+  struct inode_val *ival = find_inode_val (node_num, major_num, minor_num);
dd3c47
   return ival ? ival->file_name : NULL;
dd3c47
 }
dd3c47
 
dd3c47
 /* Associate FILE_NAME with the inode NODE_NUM.  (Insert into hash table.)  */
dd3c47
 
dd3c47
-void
dd3c47
+static ino_t next_inode;
dd3c47
+
dd3c47
+struct inode_val *
dd3c47
 add_inode (ino_t node_num, char *file_name, unsigned long major_num,
dd3c47
 	   unsigned long minor_num)
dd3c47
 {
dd3c47
   struct inode_val *temp;
dd3c47
-  struct inode_val *e;
dd3c47
+  struct inode_val *e = NULL;
dd3c47
   
dd3c47
   /* Create new inode record.  */
dd3c47
   temp = (struct inode_val *) xmalloc (sizeof (struct inode_val));
dd3c47
   temp->inode = node_num;
dd3c47
   temp->major_num = major_num;
dd3c47
   temp->minor_num = minor_num;
dd3c47
-  temp->file_name = xstrdup (file_name);
dd3c47
+  temp->file_name = file_name ? xstrdup (file_name) : NULL;
dd3c47
+
dd3c47
+  if (renumber_inodes_option)
dd3c47
+    temp->trans_inode = next_inode++;
dd3c47
+  else
dd3c47
+    temp->trans_inode = temp->inode;
dd3c47
 
dd3c47
   if (!((hash_table
dd3c47
 	 || (hash_table = hash_initialize (0, 0, inode_val_hasher,
dd3c47
 					   inode_val_compare, 0)))
dd3c47
 	&& (e = hash_insert (hash_table, temp))))
dd3c47
     xalloc_die ();
dd3c47
-  /* FIXME: e is not used */
dd3c47
+  return e;
dd3c47
+}
dd3c47
+
dd3c47
+static ino_t
dd3c47
+get_inode_and_dev (struct cpio_file_stat *hdr, struct stat *st)
dd3c47
+{
dd3c47
+  if (renumber_inodes_option)
dd3c47
+    {
dd3c47
+      if (st->st_nlink > 1)
dd3c47
+	{
dd3c47
+	  struct inode_val *ival = find_inode_val (st->st_ino,
dd3c47
+						   major (st->st_dev),
dd3c47
+						   minor (st->st_dev));
dd3c47
+	  if (!ival)
dd3c47
+	    ival = add_inode (st->st_ino, NULL,
dd3c47
+			      major (st->st_dev), minor (st->st_dev));
dd3c47
+	  hdr->c_ino = ival->trans_inode;
dd3c47
+	}
dd3c47
+      else
dd3c47
+	hdr->c_ino = next_inode++;
dd3c47
+    }
dd3c47
+  else
dd3c47
+    hdr->c_ino = st->st_ino;
dd3c47
+  if (ignore_devno_option)
dd3c47
+    {
dd3c47
+      hdr->c_dev_maj = 0;
dd3c47
+      hdr->c_dev_min = 0;
dd3c47
+    }
dd3c47
+  else
dd3c47
+    {
dd3c47
+      hdr->c_dev_maj = major (st->st_dev);
dd3c47
+      hdr->c_dev_min = minor (st->st_dev);
dd3c47
+    }
dd3c47
 }
dd3c47
 
dd3c47
 
dd3c47
@@ -1220,9 +1267,8 @@ sparse_write (int fildes, char *buf, unsigned int nbyte)
dd3c47
 void
dd3c47
 stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st)
dd3c47
 {
dd3c47
-  hdr->c_dev_maj = major (st->st_dev);
dd3c47
-  hdr->c_dev_min = minor (st->st_dev);
dd3c47
-  hdr->c_ino = st->st_ino;
dd3c47
+  get_inode_and_dev (hdr, st);
dd3c47
+
dd3c47
   /* For POSIX systems that don't define the S_IF macros,
dd3c47
      we can't assume that S_ISfoo means the standard Unix
dd3c47
      S_IFfoo bit(s) are set.  So do it manually, with a
dd3c47
@@ -1618,3 +1664,18 @@ cpio_create_dir (struct cpio_file_stat *file_hdr, int existing_dir)
dd3c47
   return 0;
dd3c47
 }
dd3c47
 
dd3c47
+/* Return true if the archive format ARF stores inode numbers */
dd3c47
+int
dd3c47
+arf_stores_inode_p (enum archive_format arf)
dd3c47
+{
dd3c47
+  switch (arf)
dd3c47
+    {
dd3c47
+    case arf_tar:
dd3c47
+    case arf_ustar:
dd3c47
+      return 0;
dd3c47
+
dd3c47
+    default:
dd3c47
+      break;
dd3c47
+    }
dd3c47
+  return 1;
dd3c47
+}
dd3c47
-- 
dd3c47
2.9.3
dd3c47
dd3c47
dd3c47
From 8d468d9c5134415b187dc5738a7fdaec17f87cf5 Mon Sep 17 00:00:00 2001
dd3c47
From: Pavel Raiskup <praiskup@redhat.com>
dd3c47
Date: Mon, 6 Feb 2017 08:43:18 +0100
dd3c47
Subject: [PATCH 2/2] build: lint warnings in --device-independent
dd3c47
dd3c47
Complements: 3945f9db44c935608caa5f0
dd3c47
dd3c47
* src/util.c (find_inode_val): Drop unused variable.
dd3c47
(get_inode_and_dev): Function doesn't return any value, drop the
dd3c47
return value in definition.
dd3c47
---
dd3c47
 src/util.c | 3 +--
dd3c47
 1 file changed, 1 insertion(+), 2 deletions(-)
dd3c47
dd3c47
diff --git a/src/util.c b/src/util.c
dd3c47
index ce45842..f3efc6c 100644
dd3c47
--- a/src/util.c
dd3c47
+++ b/src/util.c
dd3c47
@@ -718,7 +718,6 @@ find_inode_val (ino_t node_num, unsigned long major_num,
dd3c47
 		 unsigned long minor_num)
dd3c47
 {
dd3c47
   struct inode_val sample;
dd3c47
-  struct inode_val *ival;
dd3c47
   
dd3c47
   if (!hash_table)
dd3c47
     return NULL;
dd3c47
@@ -768,7 +767,7 @@ add_inode (ino_t node_num, char *file_name, unsigned long major_num,
dd3c47
   return e;
dd3c47
 }
dd3c47
 
dd3c47
-static ino_t
dd3c47
+static void
dd3c47
 get_inode_and_dev (struct cpio_file_stat *hdr, struct stat *st)
dd3c47
 {
dd3c47
   if (renumber_inodes_option)
dd3c47
-- 
dd3c47
2.9.3
dd3c47