SCSI_CH_SWP(8)
π SCSI_CH_SWP β bestie edition π
okay so this is scsi_ch_swp from the sdparm crew (it's a section 8 system admin page, iykyk), and it's literally here to change SCSI Software WRITE Protect and block device settings. no cap. π
β¨ NAME β¨
scsi_ch_swp β change SCSI Software WRITE Protect and block device settings π
π¦ SYNOPSIS π¦
scsi_ch_swp [--help] [--set 0|1] [--verbose] [--wr] BLK_DEVICE
πΈ DESCRIPTION πΈ
so this is a bash shell script, bestie, and what it does is try to read or change the Software Write Protect (SWP) bit in the SCSI Control mode page, and it does that using the sdparm utility. π«Ά
and like β if that change actually works, then it goes and uses the blockdev utility to change BLK_DEVICE's read-write or read-only setting in sympathy. iconic behaviour, honestly.
β οΈ heads up: this script is only available in Linux, because blockdev is Linux specific. periodt.
if changing the SWP bit is supported, then setting the SWP bit makes BLK_DEVICE read-only at the device (disk) itself. clearing the SWP bit makes BLK_DEVICE read-write, which is usually the default setting at device (disk) power up. β¨
and if you give it no options at all? it just prints out the current state of the SWP bit (using sdparm) together with blockdev's RO bit. so:
- both of them
1βBLK_DEVICEis in read-only mode π - both of them
0βBLK_DEVICEis in read-write mode π₯
π OPTIONS π
real talk: arguments to long options are mandatory for short options as well.
-h,--helpβ prints out the usage message, then exits. bye bestie π-s,--set 0|1β when0is given, the SWP bit in the Control mode page gets cleared (i.e. that bit is set to0) usingsdparm, and thenblockdevis used to setBLK_DEVICEto read-write mode. when1is given, the SWP bit in the Control mode page gets set usingsdparm, andblockdevis used to setBLK_DEVICEto read-only mode. the default (i.e. when you don't pass this option at all) is to just read the state of the SWP bit andBLK_DEVICE's read-only mode and print those values out. π-v,--verboseβ increases the level or verbosity. it's giving chatty β¨-w,--wrβ okay so here's the tea: whenBLK_DEVICEis in read-only mode, Linux will not typically allowBLK_DEVICEto be opened read-write bysdparm. so the default action of this script is to use thesdparm --readonlyoption when--set 0has been invoked. but it's possible thatBLK_DEVICEcould be a generic device (e.g./dev/sg3) which has a different interpretation of the read-only open flag and may fail. π for those rare cases, the--wroption makessdparmopenBLK_DEVICEread-write when--set 0is invoked. main character energy for real.
π EXIT STATUS π
the exit status of this script is 0 when it's successful. π otherwise the exit status is that of the sdparm or the blockdev utility, whichever is called last. see the sdparm(8) man page for more.
π AUTHORS π
Written by D. Gilbert π
π COPYRIGHT π
Copyright Β© 2013 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. π€ (that's the dramatic part, and yes it means what it says.)
β SEE ALSO β
sdparm(sdparm)blockdev(8)
and that's the whole vibe, bestie β this page is from sdparm-1.08, dated May 2013, and it's the SCSI_CH_SWP(8) manual page. slay, go protect some writes π
π¦π
π¦ where this page comes from
- arch rolling: sdparm 1.12-1 Β· BSD
- debian bookworm: sdparm 1.12-1 Β· BSD-3-Clause
- debian trixie: sdparm 1.12-2 Β· BSD-3-Clause
- epel 10: sdparm 1.12-9.el10_0 Β· BSD-2-Clause AND GPL-2.0-or-later AND BSD-4-Clause-UC
- epel 9: sdparm 1.12-2.el9 Β· BSD
- fedora 43: sdparm 1.12-12.fc43 Β· BSD-2-Clause AND GPL-2.0-or-later AND BSD-4-Clause-UC
- fedora 44: sdparm 1.12-13.fc44 Β· BSD-2-Clause AND GPL-2.0-or-later AND BSD-4-Clause-UC
- nixpkgs unstable: sdparm 1.12
- opensuse-leap 16.0: sdparm 1.12-160000.2.2 Β· BSD-2-Clause AND BSD-4-Clause
- opensuse-leap 16.0: sdparm 1.12-160000.2.2 Β· BSD-2-Clause AND BSD-4-Clause
- opensuse-leap 16.0: sdparm 1.12-160000.2.2 Β· BSD-2-Clause AND BSD-4-Clause
- opensuse-leap 16.0: sdparm 1.12-160000.2.2 Β· BSD-2-Clause AND BSD-4-Clause
- ubuntu jammy: sdparm 1.10-1
- ubuntu noble: sdparm 1.12-1 Β· BSD-3-Clause
- ubuntu questing: sdparm 1.12-2
- ubuntu resolute: sdparm 1.12-3 Β· BSD-3-Clause
- ubuntu stonking: sdparm 1.12-3 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms