baruch / diskscan

Scan disk for bad or near failure sectors, performs disk diagnostics
GNU General Public License v3.0
108 stars 29 forks source link

Support old PATA/non-SCSI drives on Linux #36

Open ChristianTacke opened 9 years ago

ChristianTacke commented 9 years ago

Please consider supporting /dev/hd*devices too. Currently they emit this error:

E: Failed to issue ioctl to device errno=22: Invalid argument
E: Can't get block device size information for path /dev/hda: Invalid argument

strace has this failing ioctl:

ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[10]=[25, 00, 00, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=0, iovec_count=0, dxfer_len=512, timeout=600000, flags=0x2}) = -1 EINVAL (Invalid argument)

Maybe an alternative is what blockdev --getsize64 uses:

ioctl(3, BLKGETSIZE64, 20020396032)     = 0
baruch commented 9 years ago

I do not have a system with PATA devices (or even supports it) to be able to test and develop it. The ioctl with SCSI command would probably be the first barrier. The Linux SATA layer will translate that into the appropriate ATA commands but for PATA I don't think that's being done at all.

Can you use sg_read to read from your device? If not it will be a pain to support it. If yes, can you log the output of strace for sg_read so I can see what gets done?

ChristianTacke commented 9 years ago

Do you need special options to sg_read?

# strace sg_read if=/dev/hda bs=512 count=128
...
open("/dev/hda", O_RDONLY|O_LARGEFILE)  = 3
brk(0)                                  = 0xb786d000
brk(0xb789e000)                         = 0xb789e000
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 65536) = 65536
ChristianTacke commented 9 years ago

JFI: The SD-cardreader in my laptop (/dev/mmcblk0) has the exact same issue with the size ioctl, currently. And the sg_read looks also the same.

baruch commented 9 years ago

This method is going to be a lot less informative but I guess it would be better to have something rather than not being supported at all. I'll take a look at that shortly.

ChristianTacke commented 9 years ago

Note: sg_read if=/dev/sda bs=512 count=128 also uses plain read(). Should I use some special options to sg_read? Adding blk_sgio=1 makes sg_read use SG_IO ioctls on /dev/sda and fail on /dev/hda. Haven't yet tried that on my SD card reader.

baruch commented 8 years ago

The fact that blk_sgio fails is directly related to the fact that the disks are not handled through the SCSI layer and libata. They are handled by the old PATA layer and so would require a different interface to be sent raw commands. As these type of disks are no longer produced and will just die off I won't be spending much time writing code for that old layer. I may consider a patch if it comes my way.

I should however be able to get it tested with plain reads and let the underlying OS translate to the PATA commands. It should be good enough to get the latency information even if we don't get the low level error indicators when they exist.