sg_scsi_ioctl(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… sg_scsi_ioctl(9) β€” like, the kernel API manual, bestie

okay so this is a page from the Kernel API Manual (sg_scsi_ioctl(9), yes that's the whole title, we're being so official today ✨) and honestly? it's giving "legacy code that still lives in the group chat." let's get into it 🫢


✨ NAME ✨

sg_scsi_ioctl β€” handle deprecated SCSI_IOCTL_SEND_COMMAND ioctl

🌸 SYNOPSIS 🌸

int sg_scsi_ioctl (struct request_queue *q , bool open_for_write ,
       struct scsi_ioctl_command __user *sic );

πŸŽ€ ARGUMENTS πŸŽ€

  • q β€” the request queue you're sending your scsi commands down. that's the road, bestie, and your command is the car πŸ’…
  • open_for_write β€” literally just: is the file / block device opened for writing? yes or no, iconic question, we love a bool 🌈
  • sic β€” the userspace structure that describes the command you wanna perform. it's the what of the whole operation πŸ¦‹

πŸ”₯ DESCRIPTION πŸ”₯

so you send down the scsi command described by sic to the device below the request queue q. that's it. that's the whole vibe. no cap πŸ“¨

πŸ’€ NOTES πŸ’€ (please read these, i'm serious)

  • 🚨 this interface is deprecated β€” users should use the SG_IO interface instead, because that's a more flexible approach to performing SCSI commands on a device. don't be that person still using the old one, i'm begging πŸ™ˆ
  • the SCSI command length is determined by examining the 1st byte of the given command. there is no way to override this. like, none. don't ask, don't try, it's not happening πŸ’…
  • data transfers are limited to PAGE_SIZE. small plate energy, honestly πŸ“
  • the length (x + y) must be at least OMAX_SB_LEN bytes long so it can accommodate the sense buffer when an error occurs. the sense buffer is truncated to OMAX_SB_LEN (16) bytes so that old code will not be surprised 😭 like we're protecting the elders, we respect it
  • if a Unix error occurs (e.g. ENOMEM) then the user will receive a negative return and the Unix error code in 'errno'. if the SCSI command succeeds then 0 is returned. positive numbers returned are the compacted SCSI error codes (4 bytes in one int) where the lowest byte is the SCSI status. three different return flavours, she contains multitudes πŸ‘‘
fr fr, read the return value carefully β€” negative vs 0 vs positive is not a vibe, it's a whole meaning 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./drivers/scsi/scsi_ioctl.c ioctl_probe(9), scsi_set_medium_removal(9), scsi_cmd_allowed(9), scsi_ioctl(9), scsi_ioctl_block_when_processing_errors(9)

go read those, they're the rest of the friend group, iykyk 🌟


and that's the page, bestie 🧚 this lil slice of the Kernel API Manual lives in ./drivers/scsi and it's dated October 2026 β€” so yeah, that's the source, the version, and the date, all signed off with love πŸ’– slay, stay deprecated-free, and remember: use SG_IO 😘

πŸ“¦ where this page comes from