ioctl
Yourself DirectlyAnd this 2013 Slackware thread is still the canonical source of this information.
Example usage:
#include <err.h> #include <fcntl.h> #include <linux/cdrom.h> #include <stdlib.h> #include <sysexits.h> #include <sys/ioctl.h> #include <unistd.h> int main(int argc, char **argv) { int cdrom; int drive_status; if (argc != 2) { errx(EX_USAGE, "Usage: tray_open device. For example: tray_open /dev/cdrom"); } if ((cdrom = open(argv[1], O_RDONLY | O_NONBLOCK)) == -1) { err(EX_NOINPUT, "Unable to open device %s", argv[1]); } if ((drive_status = ioctl(cdrom, CDROM_DRIVE_STATUS)) == -1) { err(EX_IOERR, "Cannot determine tray status of %s", argv[1]); } if (close(cdrom) == -1) { err(EX_IOERR, "Unable to close device %s", argv[1]); } exit(drive_status == CDS_TRAY_OPEN ? 0 : 1); }