[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <661c31aa-2648-d189-d92b-84fc342b25dd@infradead.org>
Date: Fri, 15 Jan 2021 19:10:50 -0800
From: Randy Dunlap <rdunlap@...radead.org>
To: Michael Katzmann <vk2bea@...il.com>, linux-kernel@...r.kernel.org,
linux-scsi <linux-scsi@...r.kernel.org>
Subject: Re: Changing sd device from read only to read/write fails in 5.10
(BLKROSET)
[adding linux-scsi mailing list:
Does linux-usb need to added also?]
On 1/15/21 7:03 PM, Michael Katzmann wrote:
> I have USB devices that have a write enable/write protect feature.
> A vendor specific SCSI command write enables a write protected drive.
> In kernels prior to 5.10 I have been able to write-enable the drive
> (by sending the vendor specific command to the SCSI generic device)
> and then change the read only state of the sd block device by clearing
> the read only state with BLKROSET.
>
> This code used to work to tell the kernel that the device is
> read/write (once enabled at the SCSI level). As of kernel 5.10 it does
> not.
>
> --------------------------
>
> // other routine opens SCSI generic device
> // like /dev/sg1 and sends vendor specific commands to change
> // device from read only to read/write.
> // The bit in the SCSI Mode Sense is read to confirm device is R/W
>
> int readOnly = 0;
> DeviceFD = open( /dev/sdb, O_RDONLY );
> // Clear the RO flag in the block device
> rtn0 = ioctl( DeviceFD, BLKROSET, &readOnly );
> // This re-reads the device so the OS knows that it is now write-enabled
> rtn1 = ioctl( DeviceFD, BLKRRPART, 0 );
> close( DeviceFD );
> // not sure this is necessary
> chmod( /dev/sdb, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
>
> if( (DeviceFD = open( /dev/sdb, O_RDWR )) == ERROR ) {
> printf("success\n"); // <== use to work (open R/W)
> } else {
> printf("failure"); // <== now fails under kernel 5.10
> }
> close( DeviceFD );
>
> --------------------------
>
> Can anyone tell me if the setting of the R/W state of the block device
> has changed or if the method of signaling to the system that the write
> state has changed is different in 5.10?
>
--
~Randy
You can't do anything without having to do something else first.
-- Belefant's Law
Powered by blists - more mailing lists