Skip to content

Instantly share code, notes, and snippets.

@AXDOOMER
Created July 11, 2020 17:49
Show Gist options
  • Save AXDOOMER/6b32907490e467e66cd2a9ce8e6d0fa2 to your computer and use it in GitHub Desktop.
Save AXDOOMER/6b32907490e467e66cd2a9ce8e6d0fa2 to your computer and use it in GitHub Desktop.
ioctl, opens CD drive
// https://manpages.courier-mta.org/htmlman2/ioctl.2.html
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
// Path to CD-ROM drive
char* dev = "/dev/dvd";
int fd = open(dev, O_RDONLY | O_NONBLOCK);
if (fd == -1) {
printf("Failed to open '%s'\n", dev);
exit(1);
}
printf("fd: %d\n", fd);
// Eject the CD-ROM tray
ioctl(fd, CDROMEJECT);
sleep(2);
// Close the CD-ROM tray
ioctl(fd, CDROMCLOSETRAY);
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment