Blame SOURCES/tar-1.26-large-sparse-file-listing.patch

b77676
From 77cef4ee39ee083838e5cf2137b0f344b49afb6a Mon Sep 17 00:00:00 2001
b77676
From: Pavel Raiskup <praiskup@redhat.com>
b77676
Date: Tue, 29 Jan 2013 10:39:30 +0100
b77676
Subject: [PATCH 1/4] Fix bug in sparse file listing
b77676
b77676
List posix archives containing sparse files >8GB correctly and do not fail.
b77676
This fixes also bug in format of listing for sparse files >8GB - now the
b77676
real size is printed instead of the effective one (this is not strictly
b77676
posix format related).
b77676
b77676
* src/list.c: Remove redundant assignment.
b77676
* src/tar.h: Add new 'real_size' and 'real_size_set' fields in
b77676
  tar_stat_info struct.
b77676
* src/xheader.c: Correctly handle (especially sparse) file sizes directly in
b77676
  xheader_decode().
b77676
---
b77676
 src/list.c    |  1 -
b77676
 src/tar.h     |  4 ++++
b77676
 src/xheader.c | 15 ++++++++++++++-
b77676
 3 files changed, 18 insertions(+), 2 deletions(-)
b77676
b77676
diff --git a/src/list.c b/src/list.c
b77676
index dd501a9..6db36d1 100644
b77676
--- a/src/list.c
b77676
+++ b/src/list.c
b77676
@@ -670,7 +670,6 @@ decode_header (union block *header, struct tar_stat_info *stat_info,
b77676
 	}
b77676
     }
b77676
 
b77676
-  stat_info->archive_file_size = stat_info->stat.st_size;
b77676
   xheader_decode (stat_info);
b77676
 
b77676
   if (sparse_member_p (stat_info))
b77676
diff --git a/src/tar.h b/src/tar.h
b77676
index b181e58..690c146 100644
b77676
--- a/src/tar.h
b77676
+++ b/src/tar.h
b77676
@@ -327,6 +327,10 @@ struct tar_stat_info
b77676
   size_t sparse_map_size;   /* Size of the sparse map */
b77676
   struct sp_array *sparse_map;
b77676
 
b77676
+  off_t real_size;          /* The real size of sparse file */
b77676
+  int   real_size_set;      /* True when GNU.sparse.realsize is set in
b77676
+			       archived file */
b77676
+
b77676
   size_t xattr_map_size;   /* Size of the xattr map */
b77676
   struct xattr_array *xattr_map;
b77676
 
b77676
diff --git a/src/xheader.c b/src/xheader.c
b77676
index be793d4..708aece 100644
b77676
--- a/src/xheader.c
b77676
+++ b/src/xheader.c
b77676
@@ -764,6 +764,16 @@ xheader_decode (struct tar_stat_info *st)
b77676
 	continue;
b77676
     }
b77676
   run_override_list (keyword_override_list, st);
b77676
+
b77676
+  /* The archived (effective) file size is always set directly in tar header
b77676
+     field, possibly overridden by "size" extended header - in both cases,
b77676
+     result is now decoded in st->stat.st_size */
b77676
+  st->archive_file_size = st->stat.st_size;
b77676
+
b77676
+  /* The real file size (given by stat()) may be redefined for sparse
b77676
+     files in "GNU.sparse.realsize" extended header */
b77676
+  if (st->real_size_set)
b77676
+    st->stat.st_size = st->real_size;
b77676
 }
b77676
 
b77676
 static void
b77676
@@ -1438,7 +1435,10 @@ sparse_size_decoder (struct tar_stat_info *st,
b77676
 {
b77676
   uintmax_t u;
b77676
   if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword))
b77676
-    st->stat.st_size = u;
b77676
+    {
b77676
+      st->real_size_set = 1;
b77676
+      st->real_size = u;
b77676
+    }
b77676
 }
b77676
 
b77676
 static void
b77676
-- 
b77676
2.13.5
b77676
b77676
b77676
From 198d4621b2a367986c71cd2489c1465ec3be89dc Mon Sep 17 00:00:00 2001
b77676
From: Sergey Poznyakoff <gray@gnu.org>
b77676
Date: Fri, 7 Nov 2014 11:47:44 +0200
b77676
Subject: [PATCH 2/4] Add testcase for the previous commit.
b77676
b77676
* tests/sparse05.at: New file.
b77676
* tests/Makefile.am: Add sparse05.at
b77676
* tests/testsuite.at: Include sparse05.at
b77676
---
b77676
 tests/Makefile.am  |  1 +
b77676
 tests/sparse05.at  | 46 ++++++++++++++++++++++++++++++++++++++++++++++
b77676
 tests/testsuite.at |  1 +
b77676
 3 files changed, 48 insertions(+)
b77676
 create mode 100644 tests/sparse05.at
b77676
b77676
diff --git a/tests/Makefile.am b/tests/Makefile.am
b77676
index 8e1ef8d..094b71c 100644
b77676
--- a/tests/Makefile.am
b77676
+++ b/tests/Makefile.am
b77676
@@ -171,6 +171,7 @@ TESTSUITE_AT = \
b77676
  sparse02.at\
b77676
  sparse03.at\
b77676
  sparse04.at\
b77676
+ sparse05.at\
b77676
  sparsemv.at\
b77676
  sparsemvp.at\
b77676
  spmvp00.at\
b77676
diff --git a/tests/sparse05.at b/tests/sparse05.at
b77676
new file mode 100644
b77676
index 0000000..72f3274
b77676
--- /dev/null
b77676
+++ b/tests/sparse05.at
b77676
@@ -0,0 +1,46 @@
b77676
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
b77676
+#
b77676
+# Test suite for GNU tar.
b77676
+# Copyright 2014 Free Software Foundation, Inc.
b77676
+
b77676
+# This file is part of GNU tar.
b77676
+
b77676
+# GNU tar is free software; you can redistribute it and/or modify
b77676
+# it under the terms of the GNU General Public License as published by
b77676
+# the Free Software Foundation; either version 3 of the License, or
b77676
+# (at your option) any later version.
b77676
+
b77676
+# GNU tar is distributed in the hope that it will be useful,
b77676
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b77676
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b77676
+# GNU General Public License for more details.
b77676
+
b77676
+# You should have received a copy of the GNU General Public License
b77676
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b77676
+
b77676
+AT_SETUP([listing sparse files bigger than 2^33 B])
b77676
+AT_KEYWORDS([sparse sparse05])
b77676
+
b77676
+# Description: If an archive in POSIX.1-2001 archive contained a sparse file
b77676
+# member whose real size (excluding zero blocks) is bigger than 2^33 bytes,
b77676
+# tar 1.28 would incorrectly list the real member size.
b77676
+# Reported by: Pavel Raiskup <praiskup@redhat.com>
b77676
+# References: <1359119879.15037.4.camel@raiskup>,
b77676
+#             http://lists.gnu.org/archive/html/bug-tar/2013-01/msg00001.html
b77676
+
b77676
+AT_TAR_CHECK([
b77676
+(echo 0 =2560
b77676
+for i in `seq 1 999`; do
b77676
+    echo 10M =2560
b77676
+done) | genfile --sparse --file BIGFILE --block-size 4K - || AT_SKIP_TEST
b77676
+tar -f - -c --sparse --posix BIGFILE | tar tvf - | awk '{ print $3, $(NF) }'
b77676
+],
b77676
+[0],
b77676
+[20961034240 BIGFILE
b77676
+],
b77676
+[],
b77676
+[],
b77676
+[],
b77676
+[pax])
b77676
+
b77676
+AT_CLEANUP
b77676
diff --git a/tests/testsuite.at b/tests/testsuite.at
b77676
index 3eb0eee..f7f00ee 100644
b77676
--- a/tests/testsuite.at
b77676
+++ b/tests/testsuite.at
b77676
@@ -308,6 +308,7 @@ m4_include([sparse01.at])
b77676
 m4_include([sparse02.at])
b77676
 m4_include([sparse03.at])
b77676
 m4_include([sparse04.at])
b77676
+m4_include([sparse05.at])
b77676
 m4_include([sparsemv.at])
b77676
 m4_include([spmvp00.at])
b77676
 m4_include([spmvp01.at])
b77676
-- 
b77676
2.13.5
b77676
b77676
b77676
From 8a795036f08bca508c3f3425f41c566562573e5f Mon Sep 17 00:00:00 2001
b77676
From: Sergey Poznyakoff <gray@gnu.org>
b77676
Date: Fri, 7 Nov 2014 11:37:33 +0200
b77676
Subject: [PATCH 3/4] genfile: improve sparse mode
b77676
b77676
Paxutils: 45af1632aa64a5ba1b108e248920e67c180e8485
b77676
b77676
* tests/genfile.c (generate_sparse_file): Handle '-' argument
b77676
(read from stdin);
b77676
If content strings starts with '=', treat it as fragment size and
b77676
use default pattern to fill it.
b77676
* doc/genfile.texi: Document changes to genfile.
b77676
---
b77676
 doc/genfile.texi | 31 +++++++++++++++-------
b77676
 tests/genfile.c  | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-------
b77676
 2 files changed, 91 insertions(+), 19 deletions(-)
b77676
b77676
diff --git a/doc/genfile.texi b/doc/genfile.texi
b77676
index b37e26e..b993b9b 100644
b77676
--- a/doc/genfile.texi
b77676
+++ b/doc/genfile.texi
b77676
@@ -124,9 +124,8 @@ the rest of the command line specifies a so-called @dfn{file map}.
b77676
 descriptors}. Each descriptor is composed of two values: a number,
b77676
 specifying fragment offset from the end of the previous fragment or,
b77676
 for the very first fragment, from the beginning of the file, and
b77676
-@dfn{contents string}, i.e., a string of characters, specifying the
b77676
-pattern to fill the fragment with. File offset can be suffixed with
b77676
-the following quantifiers:
b77676
+@dfn{contents string}, that specifies the pattern to fill the fragment
b77676
+with. File offset can be suffixed with the following quantifiers:
b77676
 
b77676
 @table @samp
b77676
 @item k
b77676
@@ -140,17 +139,29 @@ The number is expressed in megabytes.
b77676
 The number is expressed in gigabytes.
b77676
 @end table
b77676
 
b77676
-    For each letter in contents string @command{genfile} will generate
b77676
-a @dfn{block} of data, filled with this letter and will write it to
b77676
-the fragment. The size of block is given by @option{--block-size}
b77676
-option. It defaults to 512. Thus, if the string consists of @var{n}
b77676
-characters, the resulting file fragment will contain
b77676
-@code{@var{n}*@var{block-size}} of data. 
b77676
+    Contents string can be either a fragment size or a pattern.
b77676
+Fragment size is a decimal number, prefixed with an equals sign.  It
b77676
+can be suffixed with a quantifier, as discussed above.  If fragment
b77676
+size is given, the fragment of that size will be filled with the
b77676
+currently selected pattern (@pxref{Generate Mode, --pattern}) and
b77676
+written to the file.  
b77676
 
b77676
-    Last fragment descriptor can have only file offset part. In this
b77676
+    A pattern is a string of arbitrary ASCII characters.  For each
b77676
+of them, @command{genfile} will generate a @dfn{block} of data,
b77676
+filled with that character and will write it to the fragment. The size
b77676
+of block is given by @option{--block-size} option. It defaults to 512.
b77676
+Thus, if pattern consists of @var{n} characters, the resulting file
b77676
+fragment will contain @code{@var{n}*@var{block-size}} bytes of data.
b77676
+
b77676
+    The last fragment descriptor can have only file offset part. In this
b77676
 case @command{genfile} will create a hole at the end of the file up to
b77676
 the given offset.
b77676
 
b77676
+    A dash appearing as a fragment descriptor instructs
b77676
+@command{genfile} to read file map from the standard input.  Each line
b77676
+of input should consist of fragment offset and contents string,
b77676
+separated by any amount of whitespace.
b77676
+
b77676
     For example, consider the following invocation:
b77676
 
b77676
 @smallexample
b77676
diff --git a/tests/genfile.c b/tests/genfile.c
b77676
index fa480ef..d41336b 100644
b77676
--- a/tests/genfile.c
b77676
+++ b/tests/genfile.c
b77676
@@ -32,6 +32,7 @@
b77676
 #include <inttostr.h>
b77676
 #include <fcntl.h>
b77676
 #include <sys/stat.h>
b77676
+#include <c-ctype.h>
b77676
 #define obstack_chunk_alloc malloc
b77676
 #define obstack_chunk_free free
b77676
 #include <obstack.h>
b77676
@@ -506,6 +507,53 @@ mksparse (int fd, off_t displ, char *marks)
b77676
     }
b77676
 }
b77676
 
b77676
+static int
b77676
+make_fragment (int fd, char *offstr, char *mapstr)
b77676
+{
b77676
+  int i;
b77676
+  off_t displ = get_size (offstr, 1);
b77676
+
b77676
+  file_length += displ;
b77676
+
b77676
+  if (!mapstr || !*mapstr)
b77676
+    {
b77676
+      mkhole (fd, displ);
b77676
+      return 1;
b77676
+    }
b77676
+  else if (*mapstr == '=')
b77676
+    {
b77676
+      off_t n = get_size (mapstr + 1, 1);
b77676
+
b77676
+      switch (pattern)
b77676
+	{
b77676
+	case DEFAULT_PATTERN:
b77676
+	  for (i = 0; i < block_size; i++)
b77676
+	    buffer[i] = i & 255;
b77676
+	  break;
b77676
+	  
b77676
+	case ZEROS_PATTERN:
b77676
+	  memset (buffer, 0, block_size);
b77676
+	  break;
b77676
+	}
b77676
+
b77676
+      if (lseek (fd, displ, SEEK_CUR) == -1)
b77676
+	error (EXIT_FAILURE, errno, "lseek");
b77676
+      
b77676
+      for (; n; n--)
b77676
+	{
b77676
+	  if (write (fd, buffer, block_size) != block_size)
b77676
+	    error (EXIT_FAILURE, errno, "write");
b77676
+	  file_length += block_size;
b77676
+	}
b77676
+    }
b77676
+  else
b77676
+    {
b77676
+      file_length += block_size * strlen (mapstr);
b77676
+      mksparse (fd, displ, mapstr);
b77676
+    }
b77676
+  return 0;
b77676
+}
b77676
+
b77676
 static void
b77676
 generate_sparse_file (int argc, char **argv)
b77676
 {
b77676
@@ -526,20 +574,33 @@ generate_sparse_file (int argc, char **argv)
b77676
 
b77676
   file_length = 0;
b77676
 
b77676
-  for (i = 0; i < argc; i += 2)
b77676
+  while (argc)
b77676
     {
b77676
-      off_t displ = get_size (argv[i], 1);
b77676
-      file_length += displ;
b77676
+      if (argv[0][0] == '-' && argv[0][1] == 0)
b77676
+	{
b77676
+	  char buf[256];
b77676
+	  while (fgets (buf, sizeof (buf), stdin))
b77676
+	    {
b77676
+	      size_t n = strlen (buf);
b77676
 
b77676
-      if (i == argc-1)
b77676
-	{
b77676
-	  mkhole (fd, displ);
b77676
-	  break;
b77676
+	      while (n > 0 && c_isspace (buf[n-1]))
b77676
+		buf[--n] = 0;
b77676
+	      
b77676
+	      n = strcspn (buf, " \t");
b77676
+	      buf[n++] = 0;
b77676
+	      while (buf[n] && c_isblank (buf[n]))
b77676
+		++n;
b77676
+	      make_fragment (fd, buf, buf + n);
b77676
+	    }
b77676
+	  ++argv;
b77676
+	  --argc;
b77676
 	}
b77676
       else
b77676
 	{
b77676
-	  file_length += block_size * strlen (argv[i+1]);
b77676
-	  mksparse (fd, displ, argv[i+1]);
b77676
+	  if (make_fragment (fd, argv[0], argv[1]))
b77676
+	    break;
b77676
+	  argc -= 2;
b77676
+	  argv += 2;
b77676
 	}
b77676
     }
b77676
 
b77676
-- 
b77676
2.13.5
b77676
b77676
b77676
From 29e35df407d6c7b1e1ff57f7ef2030a253132a8a Mon Sep 17 00:00:00 2001
b77676
From: Pavel Raiskup <praiskup@redhat.com>
b77676
Date: Fri, 4 Dec 2015 19:36:14 +0100
b77676
Subject: [PATCH 4/4] genfile: remove unused variable
b77676
b77676
paxutils: 58b8ac114790e2de7992db1a387ec14238783f39
b77676
b77676
* tests/genfile.c (generate_sparse_file): Remove unused 'i'.
b77676
---
b77676
 tests/genfile.c | 1 -
b77676
 1 file changed, 1 deletion(-)
b77676
b77676
diff --git a/tests/genfile.c b/tests/genfile.c
b77676
index d41336b..4699d21 100644
b77676
--- a/tests/genfile.c
b77676
+++ b/tests/genfile.c
b77676
@@ -557,7 +557,6 @@ make_fragment (int fd, char *offstr, char *mapstr)
b77676
 static void
b77676
 generate_sparse_file (int argc, char **argv)
b77676
 {
b77676
-  int i;
b77676
   int fd;
b77676
   int flags = O_CREAT | O_RDWR | O_BINARY;
b77676
 
b77676
-- 
b77676
2.13.5
b77676