Add barebones eject(1)

This commit is contained in:
sin 2013-09-04 13:31:06 +01:00
parent ff85b15939
commit 2b767016b3
2 changed files with 49 additions and 0 deletions

View File

@ -22,6 +22,7 @@ SRC = \
clear.c \
df.c \
dmesg.c \
eject.c \
fallocate.c \
free.c \
halt.c \

48
eject.c Normal file
View File

@ -0,0 +1,48 @@
/* See LICENSE file for copyright and license details. */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#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;
}