Copying to usb flash drive corrupts files

Łukasz Sromek lukasz.sromek at gmail.com
Tue Feb 19 14:00:25 PST 2008


2008/2/19, Hans Petter Selasky <hselasky at c2i.net>:
> Hi,
>
> Is this some kind of phone ?

It's an old mp3 player.

>
> Have you tried to "fsck_msdosfs" the partition where the FAT filesystem
> resides ?

fsck indeed found some errors (Windows' scandisk didn't...), fixed
them, but it didn't help.

>
> Maybe you could do like this:
>
> dd if=/dev/urandom of=/tmp/myrandomfile bs=65536 count=64
>
> Then copy that file to the flash. "umount" and "mount". Then copy the file
> back to your disk again. After that you do a:
>
> cat /tmp/myrandomfile | hexdump > /tmp/myrandomfile.txt
>
> Then you compare the two .txt files using "diff".
>

I did hexdump -v (because "Without the -v option, any number of groups
of output lines, which would be identical to the immediately preceding
group of output lines (except for the input offsets), are replaced
with a line comprised of a single asterisk")

And files seem to be very different!

lukasz /tmp% diff /tmp/myrandomfile_usb.txt /tmp/myrandomfile.txt |wc -l
  201790

Diffs begin at byte 00ae000

lukasz /tmp% diff /tmp/myrandomfile_usb.txt /tmp/myrandomfile.txt |head
44545,45056c44545,45056
< 00ae000 88ce bdf4 ff09 2b2c abc1 0846 8fea 0ea9
< 00ae010 71ac d09c ac15 396f e802 79f6 19dd 1b53
< 00ae020 774f 610b c637 ab27 ec5b 5d84 a9e5 f8d6
< 00ae030 8e70 daae 0bb0 b303 3a7d 5f9f 754e 3c18
< 00ae040 3ec9 324d 9c5c ead3 6e9a e174 a05b eab2
< 00ae050 aa66 d6a6 f41c 5762 ff0d 5145 890e c495
< 00ae060 2b86 9ede 5cc1 cde5 4ee2 4ff6 2aab e528
< 00ae070 b09a 7fb2 7e74 6601 bc63 e5f0 f240 6362
< 00ae080 ee9c 7902 fcfb 3438 d1fd 10c6 6c1d cab9

lukasz /tmp% diff /tmp/myrandomfile_usb.txt /tmp/myrandomfile.txt  |
grep \> |head
> 00ae000 1e69 1cb8 fbcc d5f4 72c1 176f 0c70 b4b5
> 00ae010 ab99 a783 4c3c 53ab 2feb a027 8d2e a040
> 00ae020 4eb4 7d53 9590 0df4 d969 71b6 594f 9547
> 00ae030 a870 4321 8ec7 2b5f 698e 6373 61a0 55c2
> 00ae040 94f2 8705 87a7 e792 53e7 a022 b10d 734e
> 00ae050 c9ae 31b7 b913 bd27 d0cc 27a9 8049 134c
> 00ae060 e47c 02c5 6e49 854e 1f63 fe14 5b9c c028
> 00ae070 91a4 6cd3 98b8 cd6d 7366 03fe f54d 1a8a
> 00ae080 0bec 8c6f 44fc 477c e372 5aa9 a5f4 fe3c
> 00ae090 ec3a 830e 2820 ad62 858e 6edb ce39 d205

I guess you don't need whole diff output ;)

After a while I reformatted the drive and tried the same test... With
and without sync option:

lukasz /tmp% diff myrandomfile.txt myrandomfile_usb_sync.txt |wc -l
  491586
lukasz /tmp% diff myrandomfile.txt myrandomfile_usb_nosync.txt |wc -l
  522242


More information about the freebsd-usb mailing list