Add a DIOCTUR (test unit ready) ioctl, to allow userland to easily

(and silently) check for presence of media. While this would be easy
to implement via SCIOCCOMMAND, our kernel has quirks for this
command, which otherwise would not be readily available to userland
applications.
This commit is contained in:
martin 2010-03-22 16:49:41 +00:00
parent 8b8ee0c1f1
commit b1400f8892
2 changed files with 16 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd.c,v 1.298 2010/03/11 04:00:36 mrg Exp $ */ /* $NetBSD: cd.c,v 1.299 2010/03/22 16:49:41 martin Exp $ */
/*- /*-
* Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation, * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@ -50,7 +50,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.298 2010/03/11 04:00:36 mrg Exp $"); __KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.299 2010/03/22 16:49:41 martin Exp $");
#include "rnd.h" #include "rnd.h"
@ -1270,6 +1270,7 @@ cdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
case ODIOCEJECT: case ODIOCEJECT:
case DIOCEJECT: case DIOCEJECT:
case DIOCCACHESYNC: case DIOCCACHESYNC:
case DIOCTUR:
case SCIOCIDENTIFY: case SCIOCIDENTIFY:
case OSCIOCIDENTIFY: case OSCIOCIDENTIFY:
case SCIOCCOMMAND: case SCIOCCOMMAND:
@ -1397,6 +1398,15 @@ cdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
return error; return error;
#endif #endif
case DIOCTUR: {
/* test unit ready */
error = scsipi_test_unit_ready(cd->sc_periph, XS_CTL_SILENT);
*((int*)addr) = (error == 0);
if (error == ENODEV || error == EIO || error == 0)
return 0;
return error;
}
case CDIOCPLAYTRACKS: { case CDIOCPLAYTRACKS: {
/* PLAY_MSF command */ /* PLAY_MSF command */
struct ioc_play_track *args = addr; struct ioc_play_track *args = addr;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dkio.h,v 1.15 2009/12/22 18:55:25 pooka Exp $ */ /* $NetBSD: dkio.h,v 1.16 2010/03/22 16:49:41 martin Exp $ */
/* /*
* Copyright (c) 1987, 1988, 1993 * Copyright (c) 1987, 1988, 1993
@ -105,4 +105,7 @@
/* get disk-info dictionary */ /* get disk-info dictionary */
#define DIOCGDISKINFO _IOR('d', 127, struct plistref) #define DIOCGDISKINFO _IOR('d', 127, struct plistref)
#define DIOCTUR _IOR('d', 128, int) /* test unit ready */
#endif /* _SYS_DKIO_H_ */ #endif /* _SYS_DKIO_H_ */