]> 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 8a9ab147c7cd25504e9ed844516bb11a1c27b0c9..29160b8208dd0b14eec828853fe0e85e405fa774 100644 (file)
--- a/vmtar.c
+++ b/vmtar.c
@@ -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) {
@@ -530,16 +530,20 @@ main (int argc, char **argv)
     time_t ctime = fs.st_mtime;
 
     struct sp_array *ma = sparray_new();
-    if (sparse) {
-           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 = fs.st_size;
-           sparray_add (ma, 0, file_size);
-           ma->real_size = file_size;
-           ma->effective_size = file_size;
+      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);