[PATCH] eject -T support
Tito
farmatito at tiscali.it
Sun Oct 1 14:15:40 UTC 2006
On Thursday 28 September 2006 23:59, Aurelien Jacobs wrote:
> Hi,
>
> This patch add support for the -T option to eject.
> It allows to open or close the tray depending on it's current state.
> It's very handy on embeded systems where you want to bind a single button
> to the tray opening/closing.
>
> Aurel
>
Hi,
maybe you will take a look to this alternative implementation
that is simpler, less in size (at least accordingly to make bloatcheck)
and seems to do the same job (but i haven't tested it heavily....)
Ciao,
Tito
root at localhost:/dev/pts/1:/root/Desktop/busybox.eject# make bloatcheck
function old new delta
eject_main 172 155 -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-17) Total: -17 bytes
-----------------------------------------------------------------------------------------------------------
#include "busybox.h"
#include <mntent.h>
/* various defines swiped from linux/cdrom.h */
#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
#define CDROMEJECT 0x5309 /* Ejects the cdrom media */
#define DEFAULT_CDROM "/dev/cdrom"
#define FLAG_CLOSE 1
#define FLAG_SMART 2
int eject_main(int argc, char **argv)
{
unsigned long flags;
char *device;
struct mntent *m;
int dev;
/*bb_opt_complementally = "t--T:T--t";*/
flags = bb_getopt_ulflags(argc, argv, "tT");
device = argv[optind] ? : DEFAULT_CDROM;
if ((m = find_mount_point(device, bb_path_mtab_file))) {
if (umount(m->mnt_dir)) {
bb_error_msg_and_die("Can't umount");
} else if (ENABLE_FEATURE_MTAB_SUPPORT) {
erase_mtab(m->mnt_fsname);
}
}
dev = xopen(device, O_RDONLY|O_NONBLOCK);
if (flags & FLAG_CLOSE) goto close_tray;
if (ioctl(dev, CDROMEJECT))
close_tray:
if (ioctl(dev, CDROMCLOSETRAY))
bb_perror_msg_and_die("%s", device);
if (ENABLE_FEATURE_CLEAN_UP) close(dev);
return EXIT_SUCCESS;
}
------------------------------------------------------------------------------------------------
More information about the busybox
mailing list