Keywords: Patches applied: * [email protected]/bin-applications--fixes--0.1--base-0 tag of [email protected]/bin-applications--mainline--0.1--base-0 * [email protected]/bin-applications--fixes--0.1--patch-1 Fix warning * [email protected]/bin-applications--fixes--0.1--patch-2 Fix warning in roster.cpp * [email protected]/bin-applications--fixes--0.1--patch-3 Fix warning in clipboard.cpp * [email protected]/bin-applications--fixes--0.1--patch-4 Fix warning in shutdown.cpp (trivial) * [email protected]/bin-applications--fixes--0.1--patch-5 Fix warnings in chop.c (trivial) * [email protected]/bin-applications--fixes--0.1--patch-6 Trivial warning fix in eject.c * [email protected]/bin-applications--fixes--0.1--patch-7 Trivial warning fix in hd.c * [email protected]/bin-applications--fixes--0.1--patch-8 Trivial warning fixes in listarea.c * [email protected]/bin-applications--fixes--0.1--patch-9 TRIVIAL: Fix warning in listimage.c * [email protected]/bin-applications--fixes--0.1--patch-10 TRIVIAL warning fix in listport.c * [email protected]/bin-applications--fixes--0.1--patch-11 TRIVIAL fix in listsem.c * [email protected]/bin-applications--fixes--0.1--patch-12 TRIVIAL fix in mount.c * [email protected]/bin-applications--fixes--0.1--patch-13 Trivial fix in prio.c * [email protected]/bin-applications--fixes--0.1--patch-14 TRIVIAL changes in ps.c * [email protected]/bin-applications--fixes--0.1--patch-15 TRIVIAL fix in renice.c * [email protected]/bin-applications--fixes--0.1--patch-16 TRIVIAL fix for rescan * [email protected]/bin-applications--fixes--0.1--patch-17 TRIVIAL fix in sysinfo.c * [email protected]/bin-applications--fixes--0.1--patch-18 TRIVIAL fix in unchop.c * [email protected]/bin-applications--fixes--0.1--patch-19 TRIVIAL fix in chkbfs * [email protected]/bin-applications--fixes--0.1--patch-20 TRIVIAL fixes for listdev * [email protected]/bin-applications--fixes--0.1--patch-21 TRIVIAL fixes in pc git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5557 a95241bf-73f2-0310-859d-f6bbb57e9c96
128 lines
2.5 KiB
C
128 lines
2.5 KiB
C
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
|
//
|
|
// Copyright (c) 2003, OpenBeOS
|
|
//
|
|
// This software is part of the OpenBeOS distribution and is covered
|
|
// by the OpenBeOS license.
|
|
//
|
|
//
|
|
// File: eject.c
|
|
// Author: François Revol ([email protected])
|
|
// Description: ejects physical media from a drive.
|
|
// This version also loads a media and can query for the status.
|
|
//
|
|
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
|
|
|
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <Drivers.h>
|
|
|
|
static int usage(char *prog)
|
|
{
|
|
printf("usage: eject [-q|-l|-s] /dev/disk/.../raw\n");
|
|
printf(" eject the device, or:\n");
|
|
printf(" -l: load it (close the tray)\n");
|
|
printf(" -q: query for media status\n");
|
|
printf(" -s: swap tray position (close/eject)\n");
|
|
return 0;
|
|
}
|
|
|
|
static int do_eject(char operation, char *device);
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char *device = NULL;
|
|
char operation = 'e';
|
|
int i;
|
|
int ret;
|
|
for (i = 1; i < argc; i++) {
|
|
if (strncmp(argv[i], "-", 1) == 0) {
|
|
if (strlen(argv[i]) > 1)
|
|
operation = argv[i][1];
|
|
else {
|
|
usage("eject");
|
|
return 1;
|
|
}
|
|
} else if (strncmp(argv[i], "--h", 2) == 0)
|
|
return usage("eject");
|
|
else {
|
|
device = argv[i];
|
|
ret = do_eject(operation, device);
|
|
if (ret != 0)
|
|
return ret;
|
|
}
|
|
}
|
|
if (device == NULL)
|
|
return do_eject(operation, "/dev/disk/floppy/raw");
|
|
}
|
|
static int do_eject(char operation, char *device)
|
|
{
|
|
int fd;
|
|
status_t devstatus;
|
|
fd = open(device, O_RDONLY);
|
|
if (fd < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
switch (operation) {
|
|
case 'h':
|
|
return usage("eject");
|
|
case 'e':
|
|
if (ioctl(fd, B_EJECT_DEVICE) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
break;
|
|
case 'l':
|
|
if (ioctl(fd, B_LOAD_MEDIA) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
break;
|
|
case 'q':
|
|
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
switch (devstatus) {
|
|
case B_NO_ERROR:
|
|
puts("Media present");
|
|
break;
|
|
default:
|
|
puts(strerror(devstatus));
|
|
}
|
|
break;
|
|
case 's':
|
|
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
switch (devstatus) {
|
|
case B_NO_ERROR:
|
|
case B_DEV_NO_MEDIA:
|
|
if (ioctl(fd, B_EJECT_DEVICE) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
break;
|
|
case B_DEV_DOOR_OPEN:
|
|
if (ioctl(fd, B_LOAD_MEDIA) < 0) {
|
|
perror(device);
|
|
return 1;
|
|
}
|
|
break;
|
|
default:
|
|
perror(device);
|
|
}
|
|
break;
|
|
default:
|
|
usage("eject");
|
|
return 1;
|
|
}
|
|
close(fd);
|
|
return 0;
|
|
}
|
|
|