From 4c79468569930506b3dcde8ee25404cbc058fec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 29 Aug 2003 09:12:29 +0000 Subject: [PATCH] Added /bin/eject; has improvements over the R5 one. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4398 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/Jamfile | 1 + src/apps/bin/eject.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/apps/bin/eject.c 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; +} +