]> git.proxmox.com Git - qemu-server.git/blobdiff - vmtar.c
bump version to 2.0-72
[qemu-server.git] / vmtar.c
diff --git a/vmtar.c b/vmtar.c
index f94aee60d898e244f52ed4918a66f511a980c261..29160b8208dd0b14eec828853fe0e85e405fa774 100644 (file)
--- a/vmtar.c
+++ b/vmtar.c
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2007-2009 Proxmox Server Solutions GmbH
+    Copyright (C) 2007-2012 Proxmox Server Solutions GmbH
 
     Copyright: vzdump is under GNU GPL, the GNU General Public License.
 
@@ -402,7 +402,7 @@ dump_sparse_file (int fd, struct writebuffer *wbuf, struct sp_array *ma)
 
     while (bytes_left > 0) {
       size_t bufsize = (bytes_left > BLOCKSIZE) ? BLOCKSIZE : bytes_left;
-      size_t bytes_read;
+      ssize_t bytes_read;
 
       char *blkbuf = buffer_block (wbuf);
       if ((bytes_read = full_read (fd, blkbuf, bufsize)) < 0) {
@@ -429,19 +429,24 @@ int
 main (int argc, char **argv)
 {
   struct sigaction sa;
+  int sparse = 0;
 
   while (1) {
     int option_index = 0;
     static struct option long_options[] = {
+      {"sparse", 0, 0, 's'},
       {"output", 1, 0, 'o'},
       {0, 0, 0, 0}
     };
 
-    char c = getopt_long (argc, argv, "o:", long_options, &option_index);
+    char c = getopt_long (argc, argv, "so:", long_options, &option_index);
     if (c == -1)
       break;
 
     switch (c) {
+    case 's':
+      sparse = 1;
+      break;
     case 'o':
       outname = optarg;
       break;
@@ -525,9 +530,20 @@ main (int argc, char **argv)
     time_t ctime = fs.st_mtime;
 
     struct sp_array *ma = sparray_new();
-    if (!scan_sparse_file (fd, ma)) {
-      fprintf (stderr, "scanning '%s' failed\n", source); 
-      exit (-1);
+    if (sparse && !S_ISBLK(fs.st_mode)) {
+      if (!scan_sparse_file (fd, ma)) {
+       fprintf (stderr, "scanning '%s' failed\n", source); 
+       exit (-1);
+      }
+    } else {
+      off_t file_size = lseek(fd, 0, SEEK_END);
+      if (file_size < 0) {
+       fprintf (stderr, "unable to get file size of '%s'\n", source); 
+       exit (-1);
+      }
+      sparray_add (ma, 0, file_size);
+      ma->real_size = file_size;
+      ma->effective_size = file_size;
     }
 
     dump_header (wbuf, archivename, ctime, ma);