hreinecke / sg3_utils

Deprecated git-svn mirror for sg3_utils

Home Page:http://sg.danny.cz/sg/sg3_utils.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sg_* commands can't to talk to write-protected disks

Gaelan opened this issue · comments

sg3_utils fails to communicate with a write-protected SCSI block device (i.e. one that sets the WP bit in its response to MODE SENSE):

$ sudo sg_luns /dev/sda
open error: /dev/sda: Read-only file system

Turning off the WP bit (and changing nothing else—I'm writing a target emulator, and it doesn't even implement WRITE yet) causes sg3_utils to work fine.

Not sure if this is a bug in sg3_utils or the kernel (or if I'm missing some way to make it work), but I'm opening it here first in hopes you all will know where the problem is.

$ sg_luns --version
version: 1.44 20200115

$ uname -a
Linux nixos 5.12.7 #1-NixOS SMP Wed May 26 10:59:15 UTC 2021 x86_64 GNU/Linux

The SCSI device in question is an experimental vhost-user-scsi implementation. It appears to the guest—running in QEMU—as a virtio-scsi device.

Well that is what pass-through devices are for. Either /dev/sg or /dev/bsg/<h:c:t:l> can be used in place of /dev/sda . The lsscsi utility can be used to see the mapping between /dev/sda and its pass-throughs ( I most often use 'lsscsi -gs'). Quite a few utilities have a --readonly option, but not sg_inq and sg_vpd, maybe they should.

Aha, /dev/bsg did it. I'd tried to find a passthrough device earlier, but I didn't have a /dev/sg, and lsscsi couldn't find it either. Didn't know about bsg. Thanks a ton!

BTW sg_luns has a --readonly option that should also work. Use --help or the man page to see available options. Many man pages include examples.