Hello!

First of all, let me just say thank you for the excellent ddrescue;
I've used it to great success for many years.

Today I discovered a surprising behavior that seems (to me) to be a
bug: using `--domain-mapfile` omits trailing empty space in the
created outfile.

To demonstrate, I created a 1GiB (1,073,741,824 byte) ext4 partition,
copied some random data onto it, and unmounted it.

I then created a domain mapfile using partclone:

```
# partclone.ext4 --domain --source /dev/sdc1 --output partclone-domain-mapfile
```

Here is the head and tail of the resulting mapfile:

```
# Domain logfile created by partclone.ext4 v0.3.32
# Source: /dev/sdc1
# Offset: 0x00000000
# current_pos  current_status
0x40000000     ?
#      pos        size  status
0x00000000  0x010E1000  +
0x010E1000  0x06F1F000  ?
# ...
0x38000000  0x00041000  +
0x38041000  0x07FBF000  ?
```

As you can see, the status line's position is 0x40000000, and the last
data block listed is (0x38041000 + 0x07FBF000 = 0x40000000). That is,
the domain mapfile spans the entire 1GiB partition.

I then invoke ddrescue:

```
# ddrescue --domain-mapfile partclone-domain-mapfile /dev/sdc1 out.img out.log
```

My expectation here is that `out.img` will have an apparent size of
1GiB, but it's actually:

```
$ du --block-size=1 --apparent-size out.img
939790336 out.img
```

In other words, the last data block (position 0x38041000 =
939,790,336) is missing from the outfile.

Now, obviously that last data block is empty, but I'd still expect it
to be present in the outfile, the same as any other empty block.

This omission actually makes the resulting image unmountable:

```
# mount --mkdir -o loop,ro out.img mnt
mount: mnt: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error.
       dmesg(1) may have more information after failed mount system call.
```

If I "repair" the outfile using e.g. `truncate`, it mounts successfully:

```
$ truncate --size 1G out.img
# mount --mkdir -o loop,ro out.img mnt # succeeds
```

I can also get the expected output using `--extend-outfile`, e.g.:

```
# ddrescue --domain-mapfile partclone-domain-mapfile --extend-outfile
1GiB /dev/sdc1 out.img out.log
```

But that seems like an unnecessary workaround.

In summary, I'm surprised that the last data block is missing, even if
it is all zeros.

Is this the expected behavior?

Thanks,
Bret Quigley

Reply via email to