0

My flash disk is 16GB Kingston and this is part of the dmesg when mounted as /dev/sdc:

usb 2-3: new SuperSpeed USB device number 126 using xhci_hcd
usb 2-3: New USB device found, idVendor=0951, idProduct=1666
usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-3: Product: DataTraveler 3.0
usb 2-3: Manufacturer: Kingston
[sdc] 30277632 512-byte logical blocks: (15.5 GB/14.4 GiB)

There are as well devices /dev/sdc1 and /dev/sdc2 after plugging in the drive. I would like to create byte copy of the device. However when I run something as

dd if=/dev/sdc of=FLASH bs=512

then just small part is copied:

dd: error reading '/dev/sdc': Input/output error 
127456+0 records in
127456+0 records out 
65257472 bytes (65 MB, 62 MiB) copied, 13.0206 s, 5.0 MB/s

What is even stranger is that after that failed read there are the following messages in the dmesg

blk_update_request: I/O error, dev sdc, sector 127456
sd 7:0:0:0: [sdc] tag#0 FAILED Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
sd 7:0:0:0: [sdc] tag#0 CDB: Read(10) 28 00 00 01 f2 e0 00 01 00 00
usb 2-3: new SuperSpeed USB device number 127 using xhci_hcd
usb 2-3: New USB device found, idVendor=13fe, idProduct=5500
usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-3: Product: 2307 Boot ROM           
usb 2-3: Manufacturer: Phison                  
usb-storage 2-3:1.0: USB Mass Storage device detected
scsi host7: usb-storage 2-3:1.0
scsi 7:0:0:0: Direct-Access              2307 PRAM        1.00 PQ: 0 ANSI: 0 CCS
sd 7:0:0:0: Attached scsi generic sg3 type 0
sd 7:0:0:0: [sdc] Attached SCSI removable disk

So it seems that after fail to read, the device disappears and is somehow reconected by kernel module xhci_hcd. The problem is that when I reissue the command

dd if=/dev/sdc of=FLASH bs=512

then the result is

dd: failed to open '/dev/sdc': No medium found

The /dev/sdc is still in the device listing but the devices /dev/sdc1 and /dev/sdc2 disappears.

I decided to create the byte copy of the device by the following procedure. First I create empty file of the size of the device

dd if=/dev/zero of=FLASH bs=512 count=30277632

Then I create the following script

#!/bin/bash
#usage ./ddscript /dev/sdc blockoffset
dd bs=512 if=$1 of=FLASH seek=$2 skip=$2 conv=nocreat,notrunc,fdatasync iflag=direct,fullblock

After that script, from output I parse the number of bytes read, increase blockoffset and repeat until I reach 16GB. I would like to automate the process. Read block by dd, increase offset by the read data length or by constant when unsuccessful and repeat until end of block device.

The problem is, I need to physically disconnect and reconnect usb drive between these trials. I could not figure out how to reset the device to the state, where its again readable and its partitions appear without removing it from USB slot or restarting computer.

Of course it would be also beneficial, if I figured out why after read error device disappears and if I can somehow force kernel or xhci_hcd module to ignore read errors and not to destroy the device. If this behavior would be due to the hardware that power cycles after wrong read attempt, then I don't understand why the kernel would mount it then to some zombie state and not to the state that appears when I disconnect and connect the device again. From curiosity, I would like to see the place in kernel source, where the message "blk_update_request: I/O error, dev sdc, sector 127456" is triggered if this piece of code does not silently destroy/reset the device.

If successful, I will then post here the script to interactively read the content of disappearing device on read errors.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.