bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] sparse file to /dev/null


From: Sergey Poznyakoff
Subject: Re: [Bug-tar] sparse file to /dev/null
Date: Sun, 24 Jul 2005 13:02:43 +0300

Peter Vrabec <address@hidden> wrote:

> $ tar cf x.tar --sparse --totals x
> Total bytes written: 10240 (10KiB, 75B/s)
> 
> but
> 
> $ tar cf /dev/null --sparse --totals x
> tar: x: Cannot seek to 0: Bad file descriptor
> Total bytes written: 21474846720 (21GiB, 4.1GiB/s)
> tar: Error exit delayed from previous errors
> 
> Because this bahavior cause some problem for Amanda.

I see at least two possible solutions. First one (see att. 1) will
minimize I/O operations when archiving sparse files to /dev/null, just
as tar does for the regular files. This will, however, produce incorrect
(higher) total estimate, since any sparse files will be processed as
usual ones.

The second solution (see att. 2) will produce precise total size at the
expense of execution time (sparse files will be scanned even when
archiving to /dev/null).

I'm equally comfortable with both solutions, though I am inclined to use
the latter. Which one will Amanda people prefer?

By the way, getsize_gnutar() in amanda/client-src/sendsize.c returns
long, which is not correct.

Regards,
Sergey

Index: src/create.c
===================================================================
RCS file: /cvsroot/tar/tar/src/create.c,v
retrieving revision 1.101
diff -p -u -r1.101 create.c
--- src/create.c        22 Jun 2005 06:24:39 -0000      1.101
+++ src/create.c        24 Jul 2005 09:33:08 -0000
@@ -1486,7 +1486,7 @@ dump_file0 (struct tar_stat_info *st, ch
          else
            fd = -1;
 
-         if (sparse_option && sparse_file_p (st))
+         if (fd != -1 && sparse_option && sparse_file_p (st))
            {
              status = sparse_dump_file (fd, st);
              if (status == dump_status_not_implemented)
Index: src/create.c
===================================================================
RCS file: /cvsroot/tar/tar/src/create.c,v
retrieving revision 1.101
diff -p -u -r1.101 create.c
--- src/create.c        22 Jun 2005 06:24:39 -0000      1.101
+++ src/create.c        24 Jul 2005 09:57:54 -0000
@@ -350,16 +350,20 @@ string_to_chars (char const *str, char *
 }
 
 
-/* A file is not dumpable if
+/* A file is considered dumpable if it is sparse and both --sparse and --totals
+   are specified.
+   Otherwise, it is dumpable unless any of the following conditions occur:
+   
    a) it is empty *and* world-readable, or
    b) current archive is /dev/null */
 
 bool
 file_dumpable_p (struct tar_stat_info *st)
 {
-  return !(dev_null_output
-          || (st->archive_file_size == 0
-              && (st->stat.st_mode & MODE_R) == MODE_R));
+  if (dev_null_output)
+    return totals_option && sparse_option && sparse_file_p (st);
+  return !(st->archive_file_size == 0
+          && (st->stat.st_mode & MODE_R) == MODE_R);
 }
 
 
@@ -1486,7 +1490,7 @@ dump_file0 (struct tar_stat_info *st, ch
          else
            fd = -1;
 
-         if (sparse_option && sparse_file_p (st))
+         if (fd != -1 && sparse_option && sparse_file_p (st))
            {
              status = sparse_dump_file (fd, st);
              if (status == dump_status_not_implemented)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]