From 2b767016b3be028083f1a642ccf4651aea52dc53 Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 4 Sep 2013 13:31:06 +0100 Subject: [PATCH] Add barebones eject(1) --- Makefile | 1 + eject.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 eject.c diff --git a/Makefile b/Makefile index 2c2d716..24cd6f1 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ SRC = \ clear.c \ df.c \ dmesg.c \ + eject.c \ fallocate.c \ free.c \ halt.c \ diff --git a/eject.c b/eject.c new file mode 100644 index 0000000..9a090f0 --- /dev/null +++ b/eject.c @@ -0,0 +1,48 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include +#include +#include "util.h" + +enum { + CDROM_EJECT = 0x5309, + CDROM_CLOSE_TRAY = 0x5319, +}; + +static void +usage(void) +{ + eprintf("usage: %s [-t]\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int fd, out; + const char *cdrom = "/dev/sr0"; + int tflag = 0; + + ARGBEGIN { + case 't': + tflag = 1; + break; + default: + usage(); + } ARGEND; + + fd = open(cdrom, O_RDONLY | O_NONBLOCK); + if (fd < 0) + eprintf("open %s:", cdrom); + if (tflag) { + if (ioctl(fd, CDROM_CLOSE_TRAY, &out) < 0) + eprintf("ioctl:"); + } else { + if (ioctl(fd, CDROM_EJECT, &out) < 0) + eprintf("ioctl:"); + } + close(fd); + return 0; +}