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> |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 5 | * Copyright (C) 2005 Tito Ragusa <farmatito@tiscali.it> |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 6 | * |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 8 | * |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This is a simple hack of eject based on something Erik posted in #uclibc. |
| 13 | * Most of the dirty work blatantly ripped off from cat.c =) |
| 14 | */ |
| 15 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 16 | #include <fcntl.h> |
| 17 | #include <sys/ioctl.h> |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 18 | #include <unistd.h> |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame] | 19 | #include <sys/mount.h> |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 20 | #include <mntent.h> |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 21 | #include "busybox.h" |
| 22 | |
| 23 | /* various defines swiped from linux/cdrom.h */ |
| 24 | #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ |
| 25 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ |
| 26 | #define DEFAULT_CDROM "/dev/cdrom" |
Rob Landley | 9ea8836 | 2005-05-14 00:46:18 +0000 | [diff] [blame] | 27 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 28 | extern int eject_main(int argc, char **argv) |
| 29 | { |
| 30 | unsigned long flags; |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame] | 31 | char *device; |
| 32 | struct mntent *m; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 33 | |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 34 | flags = bb_getopt_ulflags(argc, argv, "t"); |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 35 | device = argv[optind] ? : DEFAULT_CDROM; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 36 | |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 37 | if ((m = find_mount_point(device, bb_path_mtab_file))) { |
| 38 | if (umount(m->mnt_dir)) { |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame] | 39 | bb_error_msg_and_die("Can't umount"); |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 40 | } else if (ENABLE_FEATURE_MTAB_SUPPORT) { |
| 41 | erase_mtab(m->mnt_fsname); |
| 42 | } |
Rob Landley | 4079b00 | 2005-05-15 01:32:47 +0000 | [diff] [blame] | 43 | } |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 44 | if (ioctl(bb_xopen(device, (O_RDONLY | O_NONBLOCK)), |
| 45 | (flags ? CDROMCLOSETRAY : CDROMEJECT))) { |
"Vladimir N. Oleynik" | 73804d6 | 2006-02-28 08:23:27 +0000 | [diff] [blame] | 46 | bb_perror_msg_and_die("%s", device); |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 47 | } |
Rob Landley | 2fe4eac | 2006-02-28 04:45:24 +0000 | [diff] [blame] | 48 | return (EXIT_SUCCESS); |
Mike Frysinger | 55e2cf6 | 2005-05-11 00:25:47 +0000 | [diff] [blame] | 49 | } |