1SCSI_CH_SWP(8) SDPARM SCSI_CH_SWP(8)
2
3
4
6 scsi_ch_swp - change SCSI Software WRITE Protect and block device set‐
7 tings
8
10 scsi_ch_swp [--help] [--set 0|1] [--verbose] [--wr] BLK_DEVICE
11
13 This bash shell script attempts to read or change the Software Write
14 Protect (SWP) bit in the SCSI Control mode page using the sdparm util‐
15 ity. If that change is successful then it uses the blockdev utility to
16 change BLK_DEVICE's read-write or read-only setting in sympathy. This
17 script is only available in Linux since the blockdev utility is Linux
18 specific.
19
20 If changing the SWP bit is supported, setting the SWP bit makes
21 BLK_DEVICE read-only at the device (disk) itself. Clearing the SWP bit
22 makes BLK_DEVICE read-write which is usually the default setting at
23 device (disk) power up.
24
25 If no options are given then the current state of the SWP bit is
26 printed out (using sdparm) together with blockdev's RO bit. If they are
27 both 1 then BLK_DEVICE is in read-only mode; if they are both 0 then
28 BLK_DEVICE is in read-write mode.
29
31 Arguments to long options are mandatory for short options as well.
32
33 -h, --help
34 print out the usage message then exit.
35
36 -s, --set 0|1
37 when 0 is given then the SWP bit in the Control mode page is
38 cleared (i.e. set that bit to 0) using sdparm; and blockdev is
39 used to set BLK_DEVICE to read-write mode. When 1 is given then
40 the SWP bit in the Control mode page is set using sdparm; and
41 blockdev is used to set BLK_DEVICE to read-only mode. The
42 default (i.e. when this option is not given) is to read the
43 state of the SWP bit and BLK_DEVICE's read-only mode and print
44 those values out.
45
46 -v, --verbose
47 increase level or verbosity.
48
49 -w, --wr
50 when the BLK_DEVICE is in read-only mode, Linux will not typi‐
51 cally allow BLK_DEVICE to be opened read-write by sdparm, so the
52 default action of this script is to use the sdparm --readonly
53 option when --set 0 has been invoked. It is possible that
54 BLK_DEVICE could be a generic device (e.g. /dev/sg3) which has a
55 different interpretation of the read-only open flag and may
56 fail. For such rare cases the --wr option makes sdparm open
57 BLK_DEVICE read-write when --set 0 is invoked.
58
60 The exit status of this script is 0 when it is successful. Otherwise
61 the exit status is that of the sdparm or the blockdev utility, which‐
62 ever is called last. See the sdparm(8) man page.
63
65 Written by D. Gilbert
66
68 Copyright © 2013 Douglas Gilbert
69 This software is distributed under a FreeBSD license. There is NO war‐
70 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
71 POSE.
72
74 sdparm(sdparm), blockdev(8)
75
76
77
78sdparm-1.08 May 2013 SCSI_CH_SWP(8)