Do partial transfer if destination device is shorter than the source
authorshort <>
Tue, 10 Jun 2003 22:15:54 +0000 (22:15 +0000)
committershort <>
Tue, 10 Jun 2003 22:15:54 +0000 (22:15 +0000)
badblock-guess.c

index e7dacd2..69103fd 100644 (file)
@@ -56,8 +56,8 @@ static void finish(void) G_GNUC_NORETURN;
 
 static int src_fd=-1,dst_fd=-1;
 static const char *src_name,*dst_name;
 
 static int src_fd=-1,dst_fd=-1;
 static const char *src_name,*dst_name;
-static ext2_loff_t src_len;    /* in blocks! */
-static blk_t src_lenblk;       /* ==src_len, just a different type */
+static ext2_loff_t src_len,dst_len;    /* in blocks! */
+static blk_t src_lenblk,dst_lenblk;    /* ==src_len,==dst_len, just a different type */
 
 static ext2_loff_t stat_lastread,stat_todo,stat_bads,stat_largest,stat_todo_hunks;
 
 
 static ext2_loff_t stat_lastread,stat_todo,stat_bads,stat_largest,stat_todo_hunks;
 
@@ -470,6 +470,23 @@ struct stat src_stat,dst_stat;
                fprintf(stderr,"\"%s\" length %llu <=0\n",src_name,(unsigned long long)src_len);
                exit(EXIT_FAILURE);
                }
                fprintf(stderr,"\"%s\" length %llu <=0\n",src_name,(unsigned long long)src_len);
                exit(EXIT_FAILURE);
                }
+       if (dst_fd!=-1) {
+               if (ext2fs_get_device_size(dst_name,BLOCK,&dst_lenblk)) {
+                       fprintf(stderr,"ext2fs_get_device_size(\"%s\",%d,...): %m\n",dst_name,BLOCK);
+                       exit(EXIT_FAILURE);
+                       }
+               dst_len=dst_lenblk;
+               if (dst_len<=0) {
+                       fprintf(stderr,"\"%s\" length %llu <=0\n",dst_name,(unsigned long long)dst_len);
+                       exit(EXIT_FAILURE);
+                       }
+               if (dst_len<src_len) {
+                       fprintf(stderr,"WARNING: Ignoring exceeding trailing data of \"%s\" from %llu up to its end %llu!\n",
+                                       src_name,(unsigned long long)dst_len,(unsigned long long)src_len);
+                       src_len=dst_len;
+                       src_lenblk=dst_lenblk;
+                       }
+               }
 
        node_memchunk=g_mem_chunk_new("node_memchunk",sizeof(struct range)/*atom_size*/,
                        0x1000 /*are_size: 64KB*/,G_ALLOC_AND_FREE);
 
        node_memchunk=g_mem_chunk_new("node_memchunk",sizeof(struct range)/*atom_size*/,
                        0x1000 /*are_size: 64KB*/,G_ALLOC_AND_FREE);