diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index ebb822c124..e2009cd237 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -31,6 +31,7 @@ StdBinCommands StdBinCommands chop.c echo.c + eject.c hd.c listarea.c listimage.c diff --git a/src/apps/bin/eject.c b/src/apps/bin/eject.c new file mode 100644 index 0000000000..edc661ee83 --- /dev/null +++ b/src/apps/bin/eject.c @@ -0,0 +1,92 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// 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 (mmu_man@users.sf.net) +// Description: ejects physical media from a drive. +// This version also loads a media and can query for the status. +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include + +int usage(char *prog) +{ + printf("usage: eject [-q|-l] /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"); + return 0; +} + +int main(int argc, char **argv) +{ + char *device = "/dev/disk/floppy/raw"; + char operation = 'e'; + int fd, i; + status_t devstatus; + for (i = 1; i < argc; i++) { + if (strncmp(argv[i], "-", 1) == 0) { + if (strlen(argv[i]) > 1) + operation = argv[i][1]; + else { + usage(argv[0]); + return 1; + } + } else if (strncmp(argv[i], "--h", 2) == 0) + return usage(argv[0]); + else { + device = argv[i]; + break; + } + } + fd = open(device, O_RDONLY); + if (fd < 0) { + perror(device); + return 1; + } + switch (operation) { + case 'h': + return usage(argv[0]); + 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; + default: + usage(argv[0]); + return 1; + } + close(fd); + return 0; +} +