Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * eject implementation for busybox |
| 3 | * |
| 4 | * Copyright (C) 2004 Peter Willis <psyphreak@phreaker.net> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This is a simple hack of eject based on something Erik posted in #uclibc. |
| 24 | * Most of the dirty work blatantly ripped off from cat.c =) |
| 25 | */ |
| 26 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 27 | #include <fcntl.h> |
| 28 | #include <sys/ioctl.h> |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame^] | 30 | #include <sys/mount.h> |
| 31 | #include <mntent.h> |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 32 | #include "busybox.h" |
| 33 | |
| 34 | /* various defines swiped from linux/cdrom.h */ |
| 35 | #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ |
| 36 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ |
| 37 | #define DEFAULT_CDROM "/dev/cdrom" |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 38 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 39 | extern int eject_main(int argc, char **argv) |
| 40 | { |
| 41 | unsigned long flags; |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame^] | 42 | char *device; |
| 43 | struct mntent *m; |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 44 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 45 | flags = bb_getopt_ulflags(argc, argv, "t"); |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame^] | 46 | device=argv[optind] ? : DEFAULT_CDROM; |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 47 | |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame^] | 48 | if((m = find_mount_point(device, bb_path_mtab_file))) { |
| 49 | if(umount(m->mnt_dir)) |
| 50 | bb_error_msg_and_die("Can't umount"); |
| 51 | #ifdef CONFIG_FEATURE_MTAB_SUPPORT |
| 52 | else |
| 53 | erase_mtab(m->mnt_fsname); |
| 54 | #endif |
| 55 | } |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 56 | if (ioctl(bb_xopen( device, |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 57 | (O_RDONLY | O_NONBLOCK)), |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 58 | ( flags ? CDROMCLOSETRAY : CDROMEJECT))) |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 59 | { |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 60 | bb_perror_msg_and_die(device); |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 61 | } |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 62 | return(EXIT_SUCCESS); |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 63 | } |