X-Git-Url: https://git.jankratochvil.net/?a=blobdiff_plain;f=badblock-guess.c;h=e7dacd238f5d766cd8df355bc153392da2eb61c6;hb=6b440e700542984772b723f222f2d6d3426210b9;hp=56ed478a24ca5f9bd19c97f03dd37271563e203d;hpb=a5691b6c368c0bf21c558eeacb7c233d7e6272ef;p=badblock-guess.git diff --git a/badblock-guess.c b/badblock-guess.c index 56ed478..e7dacd2 100644 --- a/badblock-guess.c +++ b/badblock-guess.c @@ -1,5 +1,23 @@ /* $Id$ */ +/* + * badblock-guess: Quickly recover most of the data from a damaged disk + * Copyright (C) 2002 Jan Kratochvil + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; exactly version 2 of the License required + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE @@ -256,6 +274,13 @@ ext2_loff_t gotext2_loff; exit(EXIT_FAILURE); } if (len!=(gotssize=write(dst_fd,buf,len))) { + /* see README/"Linux kernel flaw" */ + /* no "start==src_len-1" checking here, we may write larger blocks! */ + if (gotssize==((src_len&~1)-start)*BLOCK + /* -1 instead of 0 is given when no bytes were written */ + || (gotssize==-1 && start==src_len-1 && end==src_len)) + return; /* suppress error message */ + fprintf(stderr,"write(\"%s\",@%llu-@%llu=%llu=%lluB)=%lld: %m\n",dst_name, (unsigned long long)start, (unsigned long long)end, @@ -266,11 +291,29 @@ ext2_loff_t gotext2_loff; } } +static void range_zero(ext2_loff_t start,ext2_loff_t end) +{ +static const unsigned char buf_zero[BUF_ZERO_BLOCKS*BLOCK]; + + g_return_if_fail(startBUF_ZERO_BLOCKS ? start+BUF_ZERO_BLOCKS : end); + g_assert(mid>=start); + g_assert(mid<=end); + + write_dst(start,mid,buf_zero); + + start=mid; + } +} + static void process(ext2_loff_t start,ext2_loff_t end) { unsigned char block_buf[BLOCK]; ext2_loff_t bads; ext2_loff_t gotext2_loff; +ssize_t gotssize; g_return_if_fail(start=end) /* finished */ return; @@ -319,23 +371,6 @@ ext2_loff_t mid=(start+end)/2; } } -static void range_zero(ext2_loff_t start,ext2_loff_t end) -{ -static const unsigned char buf_zero[BUF_ZERO_BLOCKS*BLOCK]; - - g_return_if_fail(startBUF_ZERO_BLOCKS ? start+BUF_ZERO_BLOCKS : end); - g_assert(mid>=start); - g_assert(mid<=end); - - write_dst(start,mid,buf_zero); - - start=mid; - } -} - static void finish(void) { struct range *todo_linear=tree_linearize(todo_tree),*todol; @@ -390,7 +425,15 @@ int main(int argc,char **argv) setlinebuf(stderr); if (argc!=2 && argc!=3) { - fprintf(stderr,"Syntax: badblock-guess []\n"); + fprintf(stderr,"\ +badblock-guess, Copyright (C) 2002 Jan Kratochvil \n\ +$Id$\n\ +badblock-guess comes with ABSOLUTELY NO WARRANTY.\n\ +This is free software, and you are welcome to redistribute it\n\ +under certain conditions.\n\ +\n\ +Syntax: badblock-guess []\n\ +\n"); exit(EXIT_FAILURE); } if (-1==(src_fd=open64((src_name=argv[1]),O_RDONLY|O_BINARY))) {