LINUX.ORG.RU

поиском на ЛОРе. Эта тема поднималась по-крупному два раза и по-мелочи еще пару-тройку раз

sdio ★★★★★
()
Ответ на: комментарий от sdio

$ cat testcd.pl

#!/usr/bin/perl -w

use Fcntl;
use strict;

sysopen(CD,'/dev/cdrom',O_RDONLY | O_NONBLOCK) || die "Can not access /dev/cdrom: $!";
my $retval = ioctl(CD, 0x5326, 0); #Get tray position, etc.
close (CD);
# is tray open?
if ($retval == 2) {
        print "The tray is open \n";
} elsif ($retval == 1) {
        print "The tray is closed \n";
} else {
        print "Other: retval = $retval \n";
}




$ eject
$ ./testcd.pl
The tray is open

$ eject -t
$ ./testcd.pl
The tray is closed




---------------------------
see /usr/src/linux-headers-`uname -r`/include/linux/cdrom.h


/*
 * These ioctls are implemented through the uniform CD-ROM driver
 * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
 * drivers are eventually ported to the uniform CD-ROM driver interface.
 */
#define CDROMCLOSETRAY      0x5319  /* pendant of CDROMEJECT */
#define CDROM_SET_OPTIONS   0x5320  /* Set behavior options */
#define CDROM_CLEAR_OPTIONS 0x5321  /* Clear behavior options */
#define CDROM_SELECT_SPEED  0x5322  /* Set the CD-ROM speed */
#define CDROM_SELECT_DISC   0x5323  /* Select disc (for juke-boxes) */
#define CDROM_MEDIA_CHANGED 0x5325  /* Check is media changed  */
#define CDROM_DRIVE_STATUS  0x5326  /* Get tray position, etc. */
#define CDROM_DISC_STATUS   0x5327  /* Get disc type, etc. */
#define CDROM_CHANGER_NSLOTS    0x5328  /* Get number of slots */
#define CDROM_LOCKDOOR      0x5329  /* lock or unlock door */
#define CDROM_DEBUG     0x5330  /* Turn debug messages on/off */
#define CDROM_GET_CAPABILITY    0x5331  /* get capabilities */

/* Note that scsi/scsi_ioctl.h also uses 0x5382 - 0x5386.
 * Future CDROM ioctls should be kept below 0x537F

sdio ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.