Use CDIOCEJECT instead of DIOCEJECT for cdrom devices (this one allows

opening the tray without media). While I'm there add 'sd' to the
device list (so that I can eject my MO easily).
This commit is contained in:
bouyer 1999-03-25 16:50:51 +00:00
parent dab3a74af9
commit 3dcf0c67c3
1 changed files with 21 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: eject.c,v 1.10 1999/02/18 20:02:43 tron Exp $ */
/* $NetBSD: eject.c,v 1.11 1999/03/25 16:50:51 bouyer Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
#endif /* not lint */
#ifndef lint
__RCSID("$NetBSD: eject.c,v 1.10 1999/02/18 20:02:43 tron Exp $");
__RCSID("$NetBSD: eject.c,v 1.11 1999/03/25 16:50:51 bouyer Exp $");
#endif /* not lint */
#include <ctype.h>
@ -68,6 +68,7 @@ struct nicknames_s {
what ioctl to use. */
#define TAPE 0x10
#define DISK 0x20
#define CDROM 0x40
/* OR one of the above with one of the below: */
#define NOTLOADABLE 0x00
#define LOADABLE 0x01
@ -76,9 +77,10 @@ struct nicknames_s {
{ "diskette", "fd", DISK | NOTLOADABLE },
{ "floppy", "fd", DISK | NOTLOADABLE },
{ "fd", "fd", DISK | NOTLOADABLE },
{ "cdrom", "cd", DISK | LOADABLE },
{ "cd", "cd", DISK | LOADABLE },
{ "mcd", "mcd", DISK | LOADABLE }, /* XXX Is this true? */
{ "sd", "sd", DISK | NOTLOADABLE },
{ "cdrom", "cd", CDROM | LOADABLE },
{ "cd", "cd", CDROM | LOADABLE },
{ "mcd", "mcd", CDROM | LOADABLE }, /* XXX Is this true? */
{ "tape", "st", TAPE | NOTLOADABLE },
{ "st", "st", TAPE | NOTLOADABLE },
{ "dat", "st", TAPE | NOTLOADABLE },
@ -94,7 +96,7 @@ struct devtypes_s {
} devtypes[] = {
{ "diskette", DISK | NOTLOADABLE },
{ "floppy", DISK | NOTLOADABLE },
{ "cdrom", DISK | LOADABLE },
{ "cdrom", CDROM | LOADABLE },
{ "disk", DISK | NOTLOADABLE },
{ "tape", TAPE | NOTLOADABLE },
};
@ -110,7 +112,7 @@ char *nick2rdev __P((char *));
int guess_devtype __P((char *));
char *guess_nickname __P((char *));
void eject_tape __P((char *));
void eject_disk __P((char *));
void eject_disk __P((char *, int));
void unmount_dev __P((char *));
int
@ -192,11 +194,11 @@ main(int argc,
if(umount_f)
unmount_dev(devname);
/* XXX Tapes and disks have different ioctl's: */
/* XXX Tapes, cdroms and disks have different ioctl's: */
if((devtype & TYPEMASK) == TAPE)
eject_tape(devname);
else
eject_disk(devname);
eject_disk(devname, devtype & TYPEMASK);
if(verbose_f)
printf("done.\n");
@ -373,7 +375,7 @@ eject_tape(char *name)
}
void
eject_disk(char *name)
eject_disk(char *name, int type)
{
int fd;
char *dn;
@ -401,10 +403,15 @@ eject_disk(char *name)
printf("Ejecting %s...\n", dn);
arg = 0;
if(ioctl(fd, DIOCLOCK, (char *)&arg) == -1)
err(1, "ioctl: DIOCLOCK: %s", dn);
if(ioctl(fd, DIOCEJECT, &arg) == -1)
err(1, "ioctl: DIOCEJECT: %s", dn);
if (type == CDROM) {
if(ioctl(fd, CDIOCEJECT, &arg) == -1)
err(1, "ioctl: CDIOCEJECT: %s", dn);
} else {
if(ioctl(fd, DIOCLOCK, (char *)&arg) == -1)
err(1, "ioctl: DIOCLOCK: %s", dn);
if(ioctl(fd, DIOCEJECT, &arg) == -1)
err(1, "ioctl: DIOCEJECT: %s", dn);
}
}
close(fd);