pax_global_header00006660000000000000000000000064134071551360014517gustar00rootroot0000000000000052 comment=3c737e7c897d0cb09236d78d24c8d5aaf218e990 AUTHORS000066400000000000000000000001421340715513600121300ustar00rootroot00000000000000Kristof Koehler Peter Schlaile COPYING000066400000000000000000000431311340715513600121200ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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; either version 2 of the License, or (at your option) any later version. 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 Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ChangeLog000066400000000000000000000020701340715513600126340ustar00rootroot000000000000000.9.8 FEATURE: Option to perform a USB bus reset after every failed read attempt. 0.9.7 -- ignore - had a bug --- 0.9.6 BUGFIX: Prevent failure and possible loss of recoverable data from drives with 2^31 or more blocks. (Bugreport and patch by Thomas Arnold) Added utilies myrescue-stat and myrescue-bitmap2ppm to analyse the block bitmap Added option -T to avoid blocks, that took long to read. Random-jumping-mode now uses pseudorandom permutation to check each block exactly once. 0.9.5 -- skipped -- 0.9.4 Added options -F to skip around known bad regions and -G to concentrate around known good regions. Added option -J to randomly jump around. 0.9.3 Fixed error handling of short reads Added -A option to abort on first error 0.9.2 Added -R option to reverse reading direction thanks to Holger Ohmacht Added -f option to skip failed blocks Synced german and english manpages 0.9.1 Added german translation of manpage; thanks to Holger Ohmacht Enhanced english manpage 0.9.0 First beta release INSTALL000066400000000000000000000004701340715513600121150ustar00rootroot00000000000000Installation procedure ====================== ... is currently in a rather poor state. - Compile the binary * Change to the src directory * Type make - Install the binary * Copy the myrescue binary to the destination location, most probably /bin oder /sbin - Install the manpage That's all folks. README000066400000000000000000000003611340715513600117430ustar00rootroot00000000000000myrescue is a program to rescue the still-readable data from a damaged harddisk. It is similiar in purpose to dd_rescue, but it tries to quickly get out of damaged areas to first handle the not yet damaged part of the disk and return later. TODO000066400000000000000000000001571340715513600115560ustar00rootroot00000000000000Open Tasks ========== - ./configure && make && make install - Portability - Binary packages for distributions doc/000077500000000000000000000000001340715513600116305ustar00rootroot00000000000000doc/myrescue-bitmap2ppm.1000066400000000000000000000044651340715513600156300ustar00rootroot00000000000000.TH myrescue-bitmap2ppm "2" "February 2018" "myrescue 0.9.6" .SH NAME myrescue-bitmap2ppm \- Visualisation of the block bitmap for myrescue .SH SYNOPSIS .B myrescue-bitmap2ppm .I bitmap-file width [ rows width ] ... .SH DESCRIPTION myrescue-stat reads a block bitmap from myrescue(1) and generates a visualisation of each blocks condition. .PP The image is written to stdout in PPM(5) format. You can pipe the output into one of the netpbm converters or into ImageMagick(1) to convert it to a more common format like PNG. .PP Sucessfully copied blocks are shown as green pixels. Yellow-green-ish pixels indicate blocks that could be copied, but it took unusually long, indicating that this area might be near-failing. Yellow blocks have been tried once, but could not be read, red blocks could not be read on multiple attempts. Black pixels indicate blocks that have not yet been handled. .PP The pixels are arranged left-to right, with the first block in the upper left pixel. The width of the image must be specified on the command line - just pick any value. .PP In case of partially defective discs you might start by having myrescue do a random jump-around scan (option .BR -J ) and continually check the visualized block bitmap. If you are lucky, you might begin to see some structure in the image. If these structures somehow run diagonally, you can adjust the width until you get vertical stripes of defective areas. What this means depends on the internal layout of the disc, but it could be defective heads, platters, sectors, cracks, a factory workers hair, ... .PP Usually internally discs have different zones, so after a few (hundred?) rows you might see the vertical structures bend off. To adjust the image, you can tell the tool to switch to a different width after a certain number of rows. Repeat this until you identified all zones. The last width will be used up to the end of the bitmap. .PP The resulting image will have the maximum width necessary to accomodate all zones. Zones with shorter widths will be padded on the right with blue pixels. .PP You can now use this information to manually fine-tune the myrescue calls to concentrate on areas with higher probability of rescue. .SH AUTHORS Kristof Koehler .SH SEE ALSO .B myrescue(1), ppm(5), ImageMagick(1) .PP http://myrescue.sourceforge.net/ doc/myrescue-stat.1000066400000000000000000000014421340715513600145200ustar00rootroot00000000000000.TH myrescue-stat "2" "February 2018" "myrescue 0.9.6" .SH NAME myrescue-stat \- Block bitmap statistics for myrescue .SH SYNOPSIS .B myrescue-stat .IR bitmap-file .SH DESCRIPTION myrescue-stat reads a block bitmap from myrescue(1) and prints the number and percentage of blocks for the different conditions. .PP Possible conditions are: .TP 0 = Block has not yet been handled. .TP 1 = Block was successfully copied. .TP 2 = Block was successfully copied, but took a long time to read. (This usually indicates that the block is almost dead.) .TP Negative values = Attempts to read the block have so far failed. The absolute value indicate the number of failed read attempts. .SH AUTHORS Kristof Koehler .SH SEE ALSO .B myrescue(1) .PP http://myrescue.sourceforge.net/ doc/myrescue.1000066400000000000000000000204611340715513600135510ustar00rootroot00000000000000.TH myrescue "2" "February 2018" "myrescue 0.9.6" .SH NAME myrescue \- Harddisc Rescue .SH SYNOPSIS .B myrescue .RB [ -b .IR block-size ] .RB [ -B .IR bitmap-file ] .RB [ -A ] .RB [ -S ] .RB [ -r .IR retry-count ] .RB [ -f .IR skip-failed ] .RB [ -s .IR start-block ] .RB [ -e .IR end-block ] .RB [ -R ] .RB [ -G .IR good-range ] .RB [ -F .IR failed-range ] .RB [ -T ] .RB [ -J .IR jump-after-blocks ] .RB [ -U .IR usb-device-file ] .I input-file .I output-file .SH DESCRIPTION myrescue is a program to rescue the still-readable data from a damaged harddisk. It is similiar in purpose to dd_rescue, but it can be run in multiple passes and has options to avoid damaged areas to first handle the not yet damaged part of the disk. .PP The program tries to copy the device blockwise to a file and keeps a table ("block bitmap") noting whether a block has been successfully copied, not yet handled or has had errors. This block bitmap is used in successive passes to only read the not yet rescued blocks. .PP The program has a special skip mode to handle read errors. Usually harddisk surface defects cover more than just one block and continuous reading in defect areas can damage the surface, the heads and (by permanent recalibration) the drive mechanics. If this happens, the chances of rescuing the remaining undamaged data drop dramatically. So in skip mode, myrescue tries to get out of damaged areas quickly by exponentially increasing the stepsize. The skipped blocks are marked as unhandled in the block bitmap and can be retried later. .PP As another alternative, the program can jump around on the disc, trying random blocks to first get an overview of the damage. In case of regular defects (e.g. an entire failed head) this can be used to determine the physical disc structure and to avoid these regions in the first run. .PP Also there are options to avoid getting close to already recognized defects or stay in the proximity of good regions. .PP Finally, the program has an option to multiply try to read a block before considering it damaged. .SH NOTE .B This tools is no replacement for a professional data recovery service! If you do have the latter option, don't even think of using .BR myrescue , as it may further damage your disk. This tool is provided only for the case that you are absolutely desperate and definitely cannot afford a professional data recovery and know what you are doing. .PP Data recovery - whether professional or DIY - is always careful detective work. Damaged drives deteriorate rapidly and behave nondeterministically, you may not get a second chance once you made a mistake. So you have to be fully aware of what you're doing and understand precisely what's happening. If you are unsure it's probably best to stop right now and ask a linux guru for assistance. .PP In any case do not expect too much. While complete restores have been witnessed, you should not take them for granted. A better attitude is to consider your data lost and be glad for any survivors that turn up. .PP The usual GPL disclaimer applies. Especially the NON-WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. Don't blame (or sue) me if it fails to recover or further damages your data. .PP And a final word you probably don't want to hear in this situation: For the future consider a routinely backup to avoid a "next time". .SH OPTIONS .TP .BI -b " block-size" The size of the blocks (in bytes). Set this to your harddiscs error detection/correction unit size. Usually this is 4096, which happens to be the default. .TP .BI -B " bitmap-file" The file containing the status table of all blocks. Nice (or frightening...) to view with hexdump. 01 means OK; 02 means that the block was OK, but took a long time to read; 00 means not yet done; negative values mean the number of failed read attempts. If not given, defaults to .IB output-file .bitmap .TP .B -A Abort when encountering errors. .TP .B -S Activate skip mode: When encountering errors increase the stepsize exponentially until a readable block is found. .TP .BI -f " skip-failed" Skip blocks that have already had .I skip-failed failures. Useful to avoid scratching the same block over and over again. .TP .BI -r " retry-count" The number of times to read a block before it is declared bad for this run. (You can still retry it on the next run.) Default: 1 .TP .BI -s " start-block" The number of the block to start with. Default: 0 .TP .BI -e " end-block" The number of the block, where reading stops (not included!). Default: size of .I input-file divided by .IR block-size . .TP .B -R Reverse reading direction, i.e. from .I end-block (excluded) to .I start-block .TP .BI -G " good-range" Only try to read blocks within .I good-range blocks from an already successfully read block. .TP .BI -F " failed-range" Extends -f to also skip any block within .I failed-range blocks of a block to be skipped as specified by -f. .TP .B -T Also avoid blocks, that were successfully read, but took an unusually long time to read. In case of growing defects, these blocks can mark the boundaries of defective regions. This options makes -A, -S and -F treat such blocks as defective. .TP .BI -J " jump-after-blocks" Randomly jump across the disc after reading .I jump-after-blocks blocks in both directions. This might be useful to scan discs with scattered defects. In jump mode -S causes myrescue to jump to a new block upon the first failed sector or upon hitting a sector to be skipped as specified by -f, -G or -F. .TP .BI -U " usb-device-file" (Linux-specific feature) Perform a bus reset for the specified .I usb-device-file after every failed read attempt. Certain faulty SD cards will disappear completely from the bus after a read error occurs and the USB reader has to be reset completely in order to continue. .TP .BR -h ", " -? Display usage information. .SH RECOMMENDED PROCEDURE NOTE: In data recovery every case needs special consideration and a specific approach - mindlessly running procedures is a bad idea. So consider the following an example, keep a close eye on the process and be prepared to stop and reconsider if anything unusual happens. And once again: If you are feeling unsure, stop and ask someone experienced for assistance. .IP \(bu Make sure you have sufficient disk space for twice the whole partition (complete partition size, not just the used amount of data) plus some space for the block bitmap (1 byte per block). Of course this should NOT be on the damaged disc. .IP \(bu Determine the hardware block size (CRC/ECC unit) of your harddisk. This may be found out from hdparm, some entries in /proc/ide/hd? or on the web. I have not yet checked whether this is possible with an ioctl. If you have, please let me know. .IP \(bu Start a skip mode run with one retry per block to first copy the undamaged area. .IP \(bu Start a normal run with one retry per block to copy the remaining skipped blocks. You may try to use -f 1 to skip the damaged blocks from the first run. .IP \(bu Repeat until the number of errors seems to have converged. Try waiting a couple of hours between the retries. .IP \(bu Repeat this with higher retry counts and wait for convergence. .IP \(bu .B Make a copy of the rescued data and run fsck on it. The copy is important! Running fsck is risky if blocks containing filesystem structures (superblocks, directories, inodes, journal, ...) are missing. Sometimes the well-meant attempt to correct the filesystem can damage the image file, so always work on a copy. .IP \(bu Mount the filesystem (if copied to a file: via loopback) and check your data. If directory information has been destroyed, fsck moves unidentifiable file fragments to lost+found, so you should also check this location. .PP It may help to try reading non-defect areas in between to allow the drive to recalibrate. .PP The developers are glad to hear about your experiences. Please post them to the .B Experiences forum on the Sourceforge Project page. Thank you! .SH KNOWN BUGS The handling of the .I bitmap-file currently relies on the filesystem semantics, that when .BR lseek (2) ing beyond the end of file and then writing, the space in between is filled with zero-bytes. .PP The block bitmap maxes out after 127 failed read attempts. .SH AUTHORS Kristof Koehler , Peter Schlaile .SH SEE ALSO .BR dd (1), .BR dd_rescue "(no manpage?)" .PP http://www.google.de/search?q=data+recovery .PP http://myrescue.sourceforge.net/ doc/myrescue.de.1000066400000000000000000000246771340715513600141550ustar00rootroot00000000000000.TH MYRESCUE "8" "Juni 2008" "myrescue 0.9.6" "User Commands" .SH NAME myrescue \- Festplattenrettungstool .SH SYNOPSIS .B myrescue .RB [ -b .IR block-size ] .RB [ -B .IR bitmap-file ] .RB [ -A ] .RB [ -S ] .RB [ -r .IR retry-count ] .RB [ -f .IR skip-failed ] .RB [ -s .IR start-block ] .RB [ -e .IR end-block ] .RB [ -R ] .RB [ -G .IR good-range ] .RB [ -F .RB [ -T ] .IR failed-range ] .RB [ -J .IR jump-after-blocks ] .RB [ -U .IR usb-device-file ] .I input-file .I output-file .SH BESCHREIBUNG myrescue ist kleines Tool, um von beschaedigten Festplatten die noch lesbaren Daten zu sichern. Es hat eine aehnliche Funktion wie dd_rescue, jedoch kann es in mehreren Durchlaeufen aufgerufen werden und versucht zuerst, die unversehrten Daten zu retten. .PP Das Programm versucht, das Medium Block fuer Block in eine Datei auf einer .IB anderen (!) Festplatte zu kopieren, wobei eine Tabelle erstellt ("Blockbitmap") wird, in der die erfolgreich gelesenen bzw. fehlerhaften Bloecke festgehalten werden. Diese Blockbitmap kann dann fuer weitere Aufrufe wiederverwendet werden, so dass nur die bisher nicht kopierten Bloecke gelesen werden. .PP Zudem besitzt MyRescue einen speziellen Modus, um Lesefehler zu behandeln: Normalerweise sind bei einem Festplattenschaden viele Bloecke betroffen und damit defekt bzw. zerstoert. Versuchte man nun, diese Bloecke weiterhin zu lesen, so leidet die Plattenoberflaeche, die Lesekoepfe und auch die Mechanik darunter. Die Chancen fuer die Rettung der restlichen unbeschaedigten Bereiche sinken dramatisch. .PP Im Skip-Modus versucht MyRescue, so schnell wie moeglich aus dem defekten Bereich herauszukommen. Die uebersprungenen Bloecke werden in der Blockbitmap markiert. Hat man nun die noch lesbaren Daten gesichert, kann man dann weitere Leseversuche starten. .PP Weiterhin kann MyRescue zufaellig Bloecke ausprobieren. Damit erhaelt man einen ersten Ueberblick ueber Ausmass und Struktur der Schaeden. Bei regelmaessigen Schaeden (z.B. Ausfall eines ganzen Lesekopfs) kann man so die physikalische Struktur der Platte herausfinden und die beschaedigten Bereiche beim ersten Durchlauf umgehen. .PP Um die Festplatte weiter zu schonen, kann das Programm aufgefordert werden, die Umgebung bereits bekannter Defekte zu meiden oder zunaechst nur in der Naehe intakter Bereiche zu arbeiten. .PP Abschliessend besitzt das Programm eine Option, um mehrfache Leseversuche auf defekte Bloecke zu starten, bevor sie als zerstoert eingetragen werden. .SH HINWEIS .B DIESES TOOL IST KEIN (!) ERSATZ FUER PROFESSIONELLE DATENRETTUNG DURCH .B DARAUF SPEZIALISIERTE FIRMEN. .PP Haben Sie also die Moeglichkeit, eine solche Firma kostenguenstig (da solche Dienstleistungen sehr kostspielig sind) zu engagieren, dann sollten sie nicht einmal daran denken, MyRescue einzusetzen, da es zur weiteren Beschaedigung der Festplatte fuehren kann. MyRescue ist nur fuer ganz Verzweifelte, die sich eine professionelle Datenrettung auf keinen Fall leisten koennen und fuer diejenigen, die ganz genau wissen, was sie tun. .PP Datenrettung - egal ob professionell oder in Heimarbeit - ist sorgfaeltige Detektivarbeit. Der Zustand von beschaedigten Platten kann sich schnell verschlechtern und sie reagieren nicht mehr deterministisch. Hat man erst einmal einen Fehler gemacht, bekommt man meistens keine zweite Chance. Deswegen muss man sich genau bewusst sein, was man tut und genau verstehen, was gerade mit der Platte passiert. Wenn Sie sich unsicher fuehlen, sollten Sie jetzt aufhoeren und einen Linux-Experten um Unterstuetzung bitten. .PP Man sollte nicht zuviel erwarten. Den Autoren sind zwar schon komplette Restaurierungen gelungen, aber davon sollte man nicht ausgehen. Sehen Sie die Daten und Festplatte vorerst als zerstoert an. (Und freuen sich ueber alle ueberlebenden Dateien, die doch noch auftauchen.) .PP Es gilt der uebliche GPL-Haftungsausschluss. .B INSBESONDERE SEI DARAUF HINGEWIESEN, DAS DER AUTOR KEINERLEI HAFTUNG .B FUER MISLUNGENE RETTUNGSVERSUCHE ODER ZERSTOERTE FESTPLATTEN UEBERNIMMT! .PP Und abschliessend, auch wenn Sie das jetzt vermutlich am wenigsten hoeren wollen: Machen Sie in Zukunft regelmaessige Datensicherungen, um ein "naechstes Mal" in Sachen Datenrettung zu vermeiden. .SH OPTIONS .TP .BI -b " block-size" Die Groesse der Sektoren (fuer die Fehlererkennung) der Festplatte. Meistens sind das 4096 Bytes, was zufaellig der Defaultwert ist. .TP .BI -B " bitmap-file" Gibt den Namen der Bitmap-Datei an, die die Status aller Bloecke beinhaltet. Wenn man die Datei mittels hexdump anschaut, so steht der Wert 01 fuer korrekt gelesene Sektoren, 02 fuer solche, die erst nach laengerer Zeit gelesen werden konnten und 00 fuer noch nicht bearbeitete. Negative Werte geben die Anzahl fehlgeschlagener Leseversuche an. Gibt man keine Dateinamen an, so wird der Name .IB output-file .bitmap verwendet. .TP .B -A Wenn ein fehlerhafter Block entdeckt wird, wird der Kopiervorgang abgebrochen. .TP .B -S Aktiviert den Skip-Modus: Wenn ein fehlerhafter Block entdeckt wird, so erhoeht sich die Schrittweite exponentiell, bis wieder ein lesbarer Block gefunden wird. .TP .BI -f " skip-failed" Bloecke ueberspringen, die schon .I skip-failed mal nicht gelesen werden konnten. Damit kann vermieden werden, dass der Lesekopf immer wieder ueber den gleichen Sektor kratzt. .TP .BI -r " retry-count" Gibt die Anzahl der Leseversuche an, bis ein Block als defekt eingetragen wird. Voreinstellung ist 1 .TP .BI -s " start-block" Die Nummer des Startblocks, bei dem angefangen werden soll. Voreinstellung ist 0 .TP .BI -e " end-block" Die Nummer des Endblocks, bis zu dem gelesen werden soll (wobei dieser nicht eingeschlossen ist). Voreinstellung ist: Groesse von .I input-file dividiert durch die .IR block-size . .TP .B -R Rueckwaerts lesen, d.h. von .I end-block (nicht eingeschlossen) bis .I start-block .TP .BI -G " good-range" Es werden nur Bloecke gelesen, die hoechstens .I good-range Bloecke von einem schon erfolgreich gelesenen Block entfernt liegen. .TP .BI -F " failed-range" Erweitert die Wirkung von -f: Es werden auch Bloecke uebersprungen, die bis zu .I failed-range Bloecke von einem laut -f zu ueberspringenden Block entfernt liegen. .TP .B -T Vermeide Bloecke, die zwar erfolgreich gelesen werden konnten, bei denen dies aber ungewoehnlich lange gedauert hat. Diese Bloecke zeigen meist die Randbereiche von langsam sterbenden Plattenbereichen an. Diese Option sorgt dafuer, dass diese Bloecke fuer die Optionen bei -A, -S und -F wie defekte Bloecke behandelt werden. .TP .BI -J " jump-after-blocks" Jeweils nachdem .I jump-after-blocks Bloecke in beide Richtungen gelesen wurden, wird zufaellig zu einem anderen Block gesprungen. Sinnvoll, um Platten mit verstreuten Defektbereichen zunaechst zu scannen. In diesem Modus bewirkt -S das Weiterspringen beim ersten Defekt oder beim Antreffen eines Blocks, der laut -f, -G or -F zu ueberspringen ist. .TP .BI -U " usb-device-file" (Linux spezifisch) Nach jedem Lesefehler das per .I usb-device-file spezifizierte Gerät zuruecksetzen. Manche kaputte SD-Karte verschwindet nach einem Lesefehler komplett vom Bus. Der USB-Leser muss daher komplett zurueckgesetzt werden, um ueberhaupt weitermachen zu koennen. .IP Weitere Hintergrund-Infos: https://www.idioten-notschlachten.de/blog/2011/11/13/kennen-sie-asmi/ .TP .BR -h ", " -? Zeigt die Online-Hilfe an. .SH EMPFOHLENE VORGEHENSWEISE .PP Bevor man sich die Prozedur der Datenrettung antuen moechte ;-), sollte man folgendes ueberdenken: .IP \(bu Bei der Datenrettung ist jeder Fall einzigartig und benoetigt eine spezifische Herangehensweise. Das sture Befolgen von Vorgehensweisen ist ein dumme Idee. Betrachten Sie das folgende nur als Beispiel, beobachten Sie den Vorgang genau und schreiten sie ein, wenn etwas ungewoehnliches passiert. Und noch einmal: Wenn Sie sich unsicher sind, hoeren Sie sofort auf und ziehen einen Experten zu Rate. .IP \(bu Der ganze Vorgang ist sehr langwierig (u. Umstaenden mehrere Stunden oder gar Tage!) und aeusserst nervenaufreibend... .IP \(bu Man braucht genuegend freien Speicherplatz, und zwar mindestens die doppelte Mediengroesse (nicht nur der belegte Platz!) plus eine Blockbitmap mit je einem Byte pro Block. (Z.B. bei einer 4 GB Partition mehr als8 GB freien Speicher). Es sollte offensichtlich sein, dass die Daten NICHT auf der beschaedigten Platte gesichert werden. .IP .PP Nun gut, hat man sich dazu entschieden, so geht man wie folgt vor: .IP \(bu Bestimmen Sie die Hardware(!)-Blockgroesse ihrer Festplatte (meistens 4096 Bytes). Dies kann mittels dem Befehl hdparm oder ueber die Webseiten des Herstellers Ihrer Festplatte geschehen. Wer weiss, wie man das direkt aus MyRescue hinbekommt, moege es mich wissen lassen. .IP \(bu Starten Sie einen Durchlauf mit skip-modus und einem Leseversuch pro Block, um zuerst die noch lesbaren Daten zu sichern. .IP \(bu Starten Sie einen weiteren Durchlauf ohne skip-modus. .IP \(bu Wiederholen Sie diesen Vorgang, bis sich die Fehlerzahl nicht mehr aendert. Man sollte aufgrund der mechanischen Erwaermung der inneren Festplattenteile zwischen den Durchlaeufen immer ein bis zwei Stunden warten. .IP \(bu Wiederholen Sie das ganze mit einer hoeheren Zahl an Leseversuchen. .IP \(bu .B Erstellen Sie eine Kopie der geretteten Daten und fuehren Sie ggfs. den Befehl fsck darauf aus. Die Kopie ist wichtig! Wenn Dateisystemstrukturen beschaedigt wurden, koennen die Reparaturversuche von fsck die gerade geretteten Daten zerstoeren. Arbeiten Sie also ab jetzt immer mit einer Kopie der Image-Datei. .IP \(bu Mounten Sie das Dateisystem (falls in eine Datei kopiert: mittels loopback). Falls die Verzeichnisstrukturen zerstoert wurden, finden sich die noch zuzuordnenden Dateifragmente im Verzeichnis lost+found .PP Es hilft vielleicht, wenn man waehrend des Lesens von defekten Bloecken der Festplatte Zeit gibt, sich zu rekalibrieren. .PP Die Programmierer freuen sich (vor allem wenn alles glatt geht) von Ihnen und Ihren Erfahrungen hoeren, insbesondere im .B Experiences -Forum auf der Sourceforge Project Seite. Vielen Dank! .SH BEKANNTE FEHLER Das Handling der .I bitmap-file verlaesst sich darauf, dass bei .BR lseek (2) hinter das Dateiende der Bereich bis dahin mit Nullen aufgefuellt wird. .PP Die Blockbitmap zaehlt hoechstens 127 Lesefehler. .SH AUTOREN Kristof Koehler , Peter Schlaile .SH UEBERSETZUNG Holger Ohmacht Kristof Koehler .SH ANDERE TOOLS .BR dd (1), .BR dd_rescue "(no manpage?)" .PP http://www.google.de/search?q=data+recovery .PP http://myrescue.sourceforge.net/ src/000077500000000000000000000000001340715513600116525ustar00rootroot00000000000000src/Makefile000066400000000000000000000002511340715513600133100ustar00rootroot00000000000000CFLAGS = -Wall all: myrescue myrescue-stat myrescue-bitmap2ppm myrescue: myrescue.c permute.c myrescue-stat: myrescue-stat.c myrescue-bitmap2ppm: myrescue-bitmap2ppm.c src/myrescue-bitmap2ppm.c000066400000000000000000000066261340715513600157350ustar00rootroot00000000000000/* Convert myrescue block bitmap to an image Copyright (C) 2007 Kristof Koehler (kristofk at users.sourceforge.net) 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; either version 2 of the License, or (at your option) any later version. 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 __USE_LARGEFILE64 1 #define _LARGEFILE_SOURCE 1 #define _LARGEFILE64_SOURCE 1 #include #include #include #include int main(int argc, char** argv) { char *bitmap_name; int fd; int arg; unsigned long long width = 0; unsigned long long height = 0; unsigned long long size; unsigned long long size_remain; char *buf_bit; char *buf_rgb; unsigned long long w, h, x, y; int i, n; if ( argc < 3 ) { fprintf(stderr,"usage: bitmap2ppm ...\n"); exit(-1); } bitmap_name = argv[1]; fd = open64(bitmap_name, O_RDONLY); if ( fd < 0 ) { perror ( "bitmap open failed" ) ; exit(-1) ; } size = lseek64(fd, 0, SEEK_END) ; if (size < 0) { perror("filesize"); exit(-1); } if ( lseek64(fd, 0, SEEK_SET) < 0 ) { perror("seek"); exit(-1); } size_remain = size; for ( arg = 2; (size_remain > 0) && (arg < argc); arg +=2 ) { w = atoi(argv[arg]); if ( width < w ) width = w; h = (size_remain + (w-1)) / w; if ( arg+1 < argc ) { y = atoi(argv[arg+1]); if ( y < h ) h = y; } height += h; size_remain -= w*h; } fprintf(stdout,"P6\n%llu %llu\n255\n", width, height); fflush(stdout); buf_bit = malloc(width); if ( ! buf_bit ) { fprintf(stderr,"malloc failed\n"); exit(-1); } buf_rgb = malloc(3*width); if ( ! buf_rgb ) { fprintf(stderr,"malloc failed\n"); exit(-1); } size_remain = size; for ( arg = 2; (size_remain > 0) && (arg < argc); arg +=2 ) { w = atoi(argv[arg]); h = (size_remain + (w-1)) / w; if ( arg+1 < argc ) { y = atoi(argv[arg+1]); if ( y < h ) h = y; } for ( y = 0; y < h; y++ ) { n = 0; while ( (n < w) && (i = read(fd, buf_bit, w)) > 0 ) n += i; if ( i < 0 ) { perror("read failed"); exit(-1); } for ( x = 0; x < width; x++ ) { if ( x >= n ) { buf_rgb[3*x+0] = 0; buf_rgb[3*x+1] = 0; buf_rgb[3*x+2] = 128; } else if ( buf_bit[x] == 1 ) { buf_rgb[3*x+0] = 0; buf_rgb[3*x+1] = 128; buf_rgb[3*x+2] = 0; } else if ( buf_bit[x] == 2 ) { buf_rgb[3*x+0] = 128; buf_rgb[3*x+1] = 255; buf_rgb[3*x+2] = 0; } else if ( buf_bit[x] == 0 ) { buf_rgb[3*x+0] = 0; buf_rgb[3*x+1] = 0; buf_rgb[3*x+2] = 0; } else if ( buf_bit[x] == -1 ) { buf_rgb[3*x+0] = 255; buf_rgb[3*x+1] = 255; buf_rgb[3*x+2] = 0; } else { buf_rgb[3*x+0] = 255; buf_rgb[3*x+1] = 0; buf_rgb[3*x+2] = 0; } } write(1, buf_rgb, 3*width); } size_remain -= w*h; } close(fd); free(buf_bit); free(buf_rgb); return 0 ; } src/myrescue-stat.c000066400000000000000000000036051340715513600146270ustar00rootroot00000000000000/* Statistics dumper for myrescue Copyright (C) 2007 Kristof Koehler (kristofk at users.sourceforge.net) 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; either version 2 of the License, or (at your option) any later version. 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 __USE_LARGEFILE64 1 #define _LARGEFILE_SOURCE 1 #define _LARGEFILE64_SOURCE 1 #include #include #include #include #define BUFFER_SIZE 4096 int main(int argc, char** argv) { char *bitmap_name; int bitmap_fd; unsigned long long count[256]; unsigned long long total = 0; unsigned char buffer[BUFFER_SIZE]; int i, n; unsigned long long ull; if ( argc != 2 ) { fprintf(stderr,"usage: myrescue-stat \n"); exit(-1); } bitmap_name = argv[1]; bitmap_fd = open64(bitmap_name, O_RDONLY); if ( bitmap_fd < 0 ) { perror ( "bitmap open failed" ) ; exit(-1) ; } for ( i = 0; i < 256; i++ ) count[i] = 0; while ( (n = read(bitmap_fd, &buffer, BUFFER_SIZE)) > 0 ) { for ( i = 0; i < n; i++ ) count[buffer[i]]++; total += n; } if ( n < 0 ) { perror ( "bitmap read failed" ); exit(-1); } close(bitmap_fd); for ( i = -127; i < 128; i++ ) { ull = count[(unsigned char)i]; if ( ull > 0 ) fprintf ( stdout, "%d: %llu (%.2f%%)\n", i, ull, 100.0 * ull / total ); } return 0 ; } src/myrescue.c000066400000000000000000000372621340715513600136640ustar00rootroot00000000000000/* myrescue Harddisc Rescue Tool Copyright (C) 2002 Kristof Koehler (kristofk at users.sourceforge.net) Peter Schlaile (schlaile at users.sourceforge.net) 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; either version 2 of the License, or (at your option) any later version. 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 __USE_LARGEFILE64 1 #define _LARGEFILE_SOURCE 1 #define _LARGEFILE64_SOURCE 1 #define HAVE_USBRESET 1 #include #include #include #include #include #include #include #include #include #include #include #include #include "permute.h" #define LONG_TIME 3 #define SLEEP_AFTER_USBRESET 5 #if HAVE_USBRESET #include #include int usbreset(const char* usb_dev_file) { int fd; int rc; printf("Resetting USB device %s\n", usb_dev_file); fd = open(usb_dev_file, O_WRONLY); if (fd < 0) { perror("Error opening usb device file"); return 1; } rc = ioctl(fd, USBDEVFS_RESET, 0); if (rc < 0) { perror("Error in usb reset ioctl"); close(fd); return 1; } close(fd); printf("Reset successful\n"); sleep(SLEEP_AFTER_USBRESET); return 0; } #endif int sig_abort = 0; void handle_sig ( int dummy ) { sig_abort = 1; } long long filesize ( int fd ) { long long rval = lseek64(fd, 0, SEEK_END) ; if (rval < 0) { perror("filesize"); exit(-1); } return rval; } int peek_map(int bitmap_fd, long block) { char c = 0; if (lseek64(bitmap_fd, block, SEEK_SET) < 0) { perror("peek_map lseek64"); exit(-1); } if (read(bitmap_fd, &c, 1) < 0) { perror("peek_map read"); exit(-1); } return c; } void poke_map(int bitmap_fd, long block, char val) { if (lseek64(bitmap_fd, block, SEEK_SET) < 0) { perror("poke_map lseek64"); exit(-1); } if (write(bitmap_fd, &val, 1) != 1) { perror("poke_map write"); exit(-1); } } int copy_block( int src_fd, int dst_fd, long block_num, int block_size, unsigned char * buffer ) { long long filepos ; ssize_t src_count ; ssize_t dst_count ; filepos = block_num; filepos *= block_size; if (lseek64(src_fd, filepos, SEEK_SET) < 0) { perror("lseek64 src_fd"); return errno; } if (lseek64(dst_fd, filepos, SEEK_SET) < 0) { perror("lseek64 dst_fd"); return errno; } src_count = read(src_fd, buffer, block_size); if (src_count != block_size) { if (src_count == -1) { perror("src read failed"); return errno; } else { fprintf(stderr,"short read: %ld of %d\n", src_count, block_size); return -1; } } dst_count = write(dst_fd, buffer, block_size); if (dst_count != block_size) { if (dst_count == -1) { perror("dst write failed"); return errno; } else { fprintf(stderr,"short write: %ld of %d\n", dst_count, block_size); return -1; } } return 0; } int try_block ( int src_fd, int dst_fd, long block_num, int block_size, int retry_count, char * usb_dev_file, unsigned char * buffer ) { int r ; for ( r = 0 ; r < retry_count && ! sig_abort ; r++ ) { if ( copy_block ( src_fd, dst_fd, block_num, block_size, buffer ) == 0 ) return 1 ; #if HAVE_USBRESET if (usb_dev_file) usbreset(usb_dev_file); #endif } return 0 ; } int check_block ( int bitmap_fd, long block_num, int good_range, int failed_range, int skip_fail, int long_as_bad, long start, long end ) { int range = (good_range > failed_range) ? good_range : failed_range; int found_good = 0; long b; for ( b = block_num - range; b <= block_num + range; b++ ) { if ( (b < start) || (b >= end) ) continue; char st = peek_map(bitmap_fd,b); if ( (failed_range > 0) && (abs(block_num-b) <= failed_range) && ((-st >= skip_fail) || (long_as_bad && st == 2)) ) return 0; if ( (good_range > 0) && (abs(block_num-b) <= good_range) && ((st > 0) && (!long_as_bad || st != 2)) ) found_good = 1; } return good_range > 0 ? found_good : 1; } void print_status ( long block, long start_block, long end_block, long ok_count, long bad_count, long done_count ) { fprintf ( stderr, "\rblock %09ld (%09ld-%09ld, %.2f%%) " "ok %09ld bad %09ld ", block, start_block, end_block, (100.0*done_count)/(end_block-start_block), ok_count, bad_count ) ; } void do_copy ( int src_fd, int dst_fd, int bitmap_fd, int block_size, long start_block, long end_block, int retry_count, int abort_error, int skip, int skip_fail, int reverse, int good_range, int failed_range, int long_as_bad, char * usb_dev_file, unsigned char * buffer ) { long block_step = 1; long block ; long ok_count = 0 ; long bad_count = 0 ; char block_state ; int forward = !reverse; time_t before, after; int long_time; for ( block = forward ? start_block : (end_block-1) ; (forward ? (block < end_block) : (block >= start_block)) && ! sig_abort ; block += forward ? block_step : -block_step ) { block_state = peek_map ( bitmap_fd, block ) ; if ( (block_state <= 0) && ( (skip_fail == 0) || (-block_state < skip_fail) ) && check_block ( bitmap_fd, block, good_range, failed_range, skip_fail, long_as_bad, start_block, end_block ) ) { print_status ( block, start_block, end_block, ok_count, bad_count, forward ? block-start_block : end_block-1-block ); time(&before); if ( try_block ( src_fd, dst_fd, block, block_size, retry_count, usb_dev_file, buffer ) ) { time(&after); long_time = (after - before >= LONG_TIME); ++ok_count ; poke_map(bitmap_fd, block, long_time ? 2 : 1); if ( long_time && long_as_bad ) { if (abort_error) break; if (skip) block_step *= 2; } else { block_step = 1; } } else { ++bad_count; if ( block_state > -127 ) block_state -= 1; poke_map(bitmap_fd, block, block_state); if (abort_error) break; if (skip) block_step *= 2; } } else { if ( block % 1000 == 0 ) { print_status ( block, start_block, end_block, ok_count, bad_count, forward ? block-start_block : end_block-1-block ); } block_step = 1 ; } } if ( sig_abort ) fprintf ( stderr, "\nABORTED " ); else print_status ( forward ? end_block : start_block, start_block, end_block, ok_count, bad_count, end_block-start_block ) ; fprintf ( stderr, "\n" ) ; } int do_jump_run ( int src_fd, int dst_fd, int bitmap_fd, int block_size, long start_block, long end_block, int retry_count, int abort_error, int skip, int skip_fail, int jump, int good_range, int failed_range, int long_as_bad, char *usb_dev_file, long block, long orig_block, int jump_count, int jump_step, long *ok_count, long *bad_count, unsigned char * buffer ) { char block_state ; time_t before, after; int long_time; for ( ; jump_count-- > 0 && !sig_abort ; block += jump_step ) { if ( block >= end_block ) break; if ( block < start_block ) break; block_state = peek_map ( bitmap_fd, block ) ; if ( block_state > 0 ) continue; if ( ((skip_fail > 0) && (-block_state >= skip_fail)) || (!check_block ( bitmap_fd, block, good_range, failed_range, skip_fail, long_as_bad, start_block, end_block )) ) { if (skip || abort_error) return 0; else continue; } print_status ( block, start_block, end_block, *ok_count, *bad_count, orig_block-start_block ) ; time(&before); if ( try_block ( src_fd, dst_fd, block, block_size, retry_count, usb_dev_file, buffer ) ) { time(&after); long_time = (after - before >= LONG_TIME); ++(*ok_count); poke_map(bitmap_fd, block, long_time ? 2 : 1); if ( long_as_bad && long_time ) { if (skip || abort_error) return 0; } } else { ++(*bad_count); if ( block_state > -127 ) block_state -= 1; poke_map(bitmap_fd, block, block_state); if (skip || abort_error) return 0; } } return 1; } void do_jump ( int src_fd, int dst_fd, int bitmap_fd, int block_size, long start_block, long end_block, int retry_count, int abort_error, int skip, int skip_fail, int jump, int good_range, int failed_range, int long_as_bad, char * usb_dev_file, unsigned char * buffer ) { long orig_block, block ; long ok_count = 0 ; long bad_count = 0 ; permute_info *pi; srandom(getpid() ^ time(NULL)); pi = permute_init(997,16); for ( orig_block = start_block; orig_block < end_block && !sig_abort; orig_block++ ) { block = permute ( orig_block-start_block, end_block-start_block, pi ) + start_block; if ( orig_block % 1000 == 0 ) print_status ( block, start_block, end_block, ok_count, bad_count, orig_block-start_block ); if ( ! do_jump_run(src_fd, dst_fd, bitmap_fd, block_size, start_block, end_block, retry_count, abort_error, skip, skip_fail, jump, good_range, failed_range, long_as_bad, usb_dev_file, block, orig_block, jump, +1, &ok_count, &bad_count, buffer) ) if ( abort_error ) break; if ( ! do_jump_run(src_fd, dst_fd, bitmap_fd, block_size, start_block, end_block, retry_count, abort_error, skip, skip_fail, jump, good_range, failed_range, long_as_bad, usb_dev_file, block-1, orig_block, jump-1, -1, &ok_count, &bad_count, buffer) ) if ( abort_error ) break; } permute_free(pi); if ( sig_abort ) fprintf ( stderr, "\nABORTED " ); else print_status ( end_block, start_block, end_block, ok_count, bad_count, end_block-start_block ) ; fprintf(stderr,"\n"); } const char * usage = "myrescue [] \n" "options:\n" "-b block size in bytes, default: 4096\n" "-B bitmap-file, default: .bitmap\n" "-A abort on error\n" "-S skip errors (exponential-step)\n" "-f skip blocks with or more failures\n" "-r try up to reads per block, default: 1\n" "-s start block number, default: 0\n" "-e end block number (excl.), default: size of \n" "-G only read blocks around good ones\n" "-F skip blocks around failed ones\n" "-J randomly jump after reading a few sectors\n" "-T make -A, -S and -F avoid blocks that took long to read\n" "-R reverse copy direction\n" "-U USB device reset after read error\n" " (something like /dev/bus/usb/XXX/XXX !)\n" "-h, -? usage information\n" ; int main(int argc, char** argv) { char *src_name ; char *dst_name ; char *bitmap_name = NULL ; char bitmap_suffix[] = ".bitmap" ; int block_size = 4096 ; int abort_error = 0 ; int skip = 0 ; int skip_fail = 0 ; int retry_count = 1 ; long start_block = 0 ; long end_block = -1 ; int reverse = 0 ; int jump = 0 ; int good_range = 0 ; int failed_range = 0 ; int long_as_bad = 0 ; char* usb_dev_file = NULL; long long block_count ; int dst_fd ; int src_fd ; int bitmap_fd ; unsigned char* buffer ; int optc ; /* options */ while ( (optc = getopt ( argc, argv, "b:B:ASf:r:s:e:J:G:U:F:TRh?" ) ) != -1 ) { switch ( optc ) { case 'b' : block_size = atol(optarg); if (block_size <= 0) { fprintf(stderr, "invalid block-size: %s\n", optarg); exit(-1); } break ; case 'B' : bitmap_name = optarg; break ; case 'A' : abort_error = 1 ; break ; case 'S' : skip = 1 ; break ; case 'f' : skip_fail = atol(optarg); if (skip_fail <= 0) { fprintf(stderr, "invalid skip-failed level: %s\n", optarg); exit(-1); } break ; case 'r' : retry_count = atol(optarg); if (retry_count <= 0) { fprintf(stderr, "invalid retry-count: %s\n", optarg); exit(-1); } break ; case 's' : start_block = atol(optarg); if (start_block <= 0) { fprintf(stderr, "invalid start_block: %s\n", optarg); exit(-1); } break ; case 'e' : end_block = atol(optarg); if (end_block <= 0) { fprintf(stderr, "invalid end_block: %s\n", optarg); exit(-1); } break ; case 'J' : jump = atol(optarg); if (jump <= 0) { fprintf(stderr, "invalid jump value: %s\n", optarg); exit(-1); } break ; case 'G' : good_range = atol(optarg); if (good_range <= 0) { fprintf(stderr, "invalid good range value: %s\n", optarg); exit(-1); } break ; case 'F' : failed_range = atol(optarg); if (failed_range <= 0) { fprintf(stderr, "invalid failed range value: %s\n", optarg); exit(-1); } break ; case 'T' : long_as_bad = 1 ; break ; case 'R' : reverse = 1 ; break ; case 'U': #if HAVE_USBRESET usb_dev_file = optarg; #else fprintf(stderr, "usb reset not compiled in\n"); exit(-1); #endif break ; default : fprintf ( stderr, "%s", usage ) ; exit(-1) ; } } if (optind != argc - 2) { fprintf ( stderr, "%s", usage ) ; exit(-1) ; } /* buffer */ buffer = malloc ( block_size ) ; if ( buffer == NULL ) { fprintf ( stderr, "malloc (%d) failed\n", block_size ) ; exit(-1) ; } /* filenames */ src_name = argv[optind] ; dst_name = argv[optind+1] ; if ( bitmap_name == NULL ) { bitmap_name = malloc ( strlen(dst_name) + strlen(bitmap_suffix) + 1 ) ; if ( bitmap_name == NULL ) { fprintf ( stderr, "malloc failed\n" ) ; exit(-1) ; } strcpy ( bitmap_name, dst_name ) ; strcat ( bitmap_name, bitmap_suffix ) ; } /* open files */ src_fd = open64(src_name, O_RDONLY); if ( src_fd < 0 ) { perror ( "source open failed" ) ; exit(-1) ; } dst_fd = open64(dst_name, O_RDWR | O_CREAT, 0600); if ( dst_fd < 0 ) { perror ( "destination open failed" ) ; exit(-1) ; } bitmap_fd = open64(bitmap_name, O_RDWR | O_CREAT, 0600); if ( bitmap_fd < 0 ) { perror ( "bitmap open failed" ) ; exit(-1) ; } /* maximum block */ block_count = filesize(src_fd) ; block_count /= block_size ; if ( end_block == -1 ) { end_block = block_count ; } #ifdef CHECK_END_BLOCK if ( end_block > block_count ) { fprintf ( stderr, "end_block(%ld) > block_count(%Ld)\n" "end_block clipped\n", end_block, block_count ) ; end_block = block_count ; } #endif if ( start_block >= end_block ) { fprintf ( stderr, "start_block(%ld) >= end_block(%ld)\n", start_block, end_block ) ; exit(-1) ; } /* start the real job */ signal(SIGINT, handle_sig); if ( jump == 0 ) do_copy ( src_fd, dst_fd, bitmap_fd, block_size, start_block, end_block, retry_count, abort_error, skip, skip_fail, reverse, good_range, failed_range, long_as_bad, usb_dev_file, buffer ) ; else do_jump ( src_fd, dst_fd, bitmap_fd, block_size, start_block, end_block, retry_count, abort_error, skip, skip_fail, jump, good_range, failed_range, long_as_bad, usb_dev_file, buffer ); return 0 ; } src/permute.c000066400000000000000000000065711340715513600135100ustar00rootroot00000000000000/* permutation to "randomly" jump around the on disc Copyright (C) 2007 Kristof Koehler (kristofk at users.sourceforge.net) 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; either version 2 of the License, or (at your option) any later version. 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 FIXME: describe the algorithm here */ #include "permute.h" #include #include typedef struct permute_info_offsettbl_ permute_info_offsettbl; struct permute_info_offsettbl_ { permute_info_offsettbl* next; unsigned long long N; unsigned long long Off[]; }; struct permute_info_ { unsigned long long D; unsigned int rounds; unsigned long long **T; permute_info_offsettbl *Off; }; unsigned long long permute_once(unsigned long long i, unsigned long long N, permute_info *pi); permute_info* permute_init(unsigned long long D, unsigned int rounds) { unsigned long long i, j, r; unsigned long long t; permute_info* pi = malloc(sizeof(permute_info)); pi->D = D; pi->rounds = rounds; pi->T = malloc(sizeof(unsigned long long *) * (pi->D+1)); for ( i = 2; i <= pi->D; i++ ) { pi->T[i] = malloc(sizeof(unsigned long long)*i); for ( j = 0; j < i; j++ ) pi->T[i][j] = j; for ( j = 0; j < i; j++ ) { r = j + rand() * (i-j) / RAND_MAX; t = pi->T[i][j]; pi->T[i][j] = pi->T[i][r]; pi->T[i][r] = t; } } pi->Off = NULL; return pi; } void permute_free(permute_info *pi) { unsigned int i; permute_info_offsettbl* po, *npo; for ( i = 2; i <= pi->D; i++ ) free(pi->T[i]); free(pi->T); po = pi->Off; while ( po ) { npo = po->next; free(po); po = npo; } free(pi); } unsigned long long permute_getoffset(unsigned long long m, unsigned long long N, permute_info *pi) { permute_info_offsettbl* po; unsigned long long i, d, off; assert(m < pi->D); po = pi->Off; while ( po ) { if ( po->N == N ) break; po = po->next; } if ( ! po ) { po = malloc(sizeof(permute_info_offsettbl) + sizeof(unsigned long long) * pi->D); po->next = pi->Off; pi->Off = po; po->N = N; off = 0; for ( i = 0; i < pi->D; i++ ) { d = permute_once(i,pi->D,pi); po->Off[d] = off; off += N/pi->D; if ( d < N % pi->D ) off++; } } return po->Off[m]; } unsigned long long permute_once(unsigned long long i, unsigned long long N, permute_info *pi) { assert(i < N); if ( N == 1 ) { return 0; } else if ( N <= pi->D ) { return pi->T[N][i]; } else { unsigned long long m = i % pi->D; unsigned long long d = i / pi->D; unsigned long long w = N / pi->D + ( m < N % pi->D ? 1 : 0 ); return permute_getoffset(m,N,pi) + permute_once((d+m)%w,w,pi); } } unsigned long long permute(unsigned long long i, unsigned long long N, permute_info *pi) { unsigned int r; for ( r = 0; r < pi->rounds; r++ ) i = permute_once(i,N,pi); return i; } src/permute.h000066400000000000000000000034471340715513600135140ustar00rootroot00000000000000/* permutation to "randomly" jump around the on disc Copyright (C) 2007 Kristof Koehler (kristofk at users.sourceforge.net) 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; either version 2 of the License, or (at your option) any later version. 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 WARNING: This algorithm is basically a weekend hack and only intended for the purpose of randomizing disc access. It definitely produces a permutation, but I have not checked that the output is sufficiently random or that the selection of the permutation is unbiased. In fact, I'm even quite sure, that it only generates a subset of all possible permutations. So keep it away from applications that depend on the quality of the randomness or the unbiased permutation selection. This includes in particular areas like statistics, simulation and cryptography. */ #ifndef __PERMUTE_H__INCLUDED__ #define __PERMUTE_H__INCLUDED__ typedef struct permute_info_ permute_info; permute_info* permute_init(unsigned long long D, unsigned int rounds); void permute_free(permute_info *pi); unsigned long long permute(unsigned long long i, unsigned long long N, permute_info *pi); #endif /* __PERMUTE_H__INCLUDED__ */