On Sun, 6 Jan 2019 at 14:14, Joe Kickman <ad...@ya.ru> wrote: > > Hello. Sometimes while rescuing I see the situation of hanging PC. If the > hang happens at the moment of rewriting the log/map file - it gets size of 0 > :(. Luckily, the times that happened I had an almost recent backup copy. 40 > minutes of work was lost. As for a 3Tb drive - it is almost nothing, that > drive is being copied already for 3 days, now it is 90% done. > I propose to first rename the log, adding .bak at the end, flush file buffer > to disk (sync) and then write the new log file from memory to disk, thus > always having a recent backup. A similar mechanism is used by hddsuperclone, > and it was able to recover the log some times I have seen. > And 2 people wrote to me reporting the same problem. So I've got myself to > inform the whole community.
I haven't looked at how ddrescue writes the map file, but a better approach would probably be to write the new map file to a temporary file on the same filesystem, and then renaming it over the old one, eg: fd = open(“map.new”, O_WRONLY); write(fd, buf, bufsize); fsync(fd); close(fd); rename(“map.new”, “map”); This is atomic, and ensures that the map file will always be a complete and recent version. In this case there is no need for manual verification of the map file in case it looks valid but is possibly incomplete. This is a standard approach used to make sure a file is never in a corrupted/incomplete state. Regards, Ketil _______________________________________________ Bug-ddrescue mailing list Bug-ddrescue@gnu.org https://lists.gnu.org/mailman/listinfo/bug-ddrescue