Re: Changing sd device from read only to read/write fails in 5.10 (BLKROSET)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux