Created
July 11, 2020 17:49
-
-
Save AXDOOMER/6b32907490e467e66cd2a9ce8e6d0fa2 to your computer and use it in GitHub Desktop.
ioctl, opens CD drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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