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_DEVICE is in read-only mode 😭
  • both of them 0 β†’ BLK_DEVICE is 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 β€” when 0 is given, the SWP bit in the Control mode page gets cleared (i.e. that bit is set to 0) using sdparm, and then blockdev is used to set BLK_DEVICE to read-write mode. when 1 is given, the SWP bit in the Control mode page gets set using sdparm, and blockdev is used to set BLK_DEVICE to 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 and BLK_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: when BLK_DEVICE is in read-only mode, Linux will not typically allow BLK_DEVICE to be opened read-write by sdparm. so the default action of this script is to use the sdparm --readonly option when --set 0 has been invoked. but it's possible that BLK_DEVICE could 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 --wr option makes sdparm open BLK_DEVICE read-write when --set 0 is 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 Β© 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 ⭐


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