Sponsored Content
Full Discussion: cd inserted event
Top Forums Programming cd inserted event Post 46501 by kduffin on Saturday 17th of January 2004 05:53:58 PM
Old 01-17-2004
The link worked for me, but the code base is small enough to post:

// gcc -o cdrom-test cdrom-test.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
int
main (int argc, char **argv)
{
char *program;
char *device;
int fd; /* file descriptor for CD-ROM device */
int status; /* return status for system calls */
int verbose = 0;
program = argv[0];
++argv;
--argc;
if (argc < 1 || argc > 2) {
fprintf (stderr, "usage: %s [-v] <device>\n",
program);
exit (1);
}

if (strcmp (argv[0], "-v") == 0) {
verbose = 1;
++argv;
--argc;
}

device = argv[0];

/* open device */
fd = open(device, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
fprintf (stderr, "%s: open failed for `%s': %s\n",
program, device, strerror (errno));
exit (1);
}
/* Check CD player status */
printf ("Drive status: ");
status = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
if (status<0) {
perror(" CDROM_DRIVE_STATUS");
} else switch(status) {
case CDS_DISC_OK:
printf ("Ready.\n");
break;
case CDS_TRAY_OPEN:
printf ("Tray Open.\n");
break;
case CDS_DRIVE_NOT_READY:
printf ("Drive Not Ready.\n");
break;
default:
printf ("This Should not happen!\n");
break;
}
status = ioctl (fd, CDROM_DRIVE_STATUS, 0);
if (status<0) {
perror(" CDROM_DRIVE_STATUS");
} else switch(status) {
case CDS_DISC_OK:
printf ("Disc present.");
break;
case CDS_NO_DISC:
printf ("Empty slot.");
break;
case CDS_TRAY_OPEN:
printf ("CD-ROM tray open.\n");
break;
case CDS_DRIVE_NOT_READY:
printf ("CD-ROM drive not ready.\n");
break;
case CDS_NO_INFO:
printf ("No Information available.");
break;
default:
printf ("This Should not happen!\n");
break;
}
status = ioctl (fd, CDROM_DISC_STATUS);
if (status<0) {
perror(" CDROM_DISC_STATUS");
}
switch (status) {
case CDS_AUDIO:
printf ("\tAudio disc.\t");
break;
case CDS_DATA_1:
case CDS_DATA_2:
printf ("\tData disc type %d.\t", status-CDS_DATA_1+1);
break;
case CDS_XA_2_1:
case CDS_XA_2_2:
printf ("\tXA data disc type %d.\t", status-CDS_XA_2_1+1);
break;
default:
printf ("\tUnknown disc type 0x%x!\t", status);
break;
}
status = ioctl (fd, CDROM_MEDIA_CHANGED, 0);
if (status<0) {
perror(" CDROM_MEDIA_CHANGED");
}
switch (status) {
case 1:
printf ("Changed.\n");
break;
default:
printf ("\n");
break;
}
{
int foo;
dvd_struct dvd;
dvd.type = DVD_STRUCT_COPYRIGHT;
dvd.copyright.layer_num = 0;
status = ioctl( fd, DVD_READ_STRUCT, &dvd );
foo = dvd.copyright.cpst;
if (status < 0)
{
perror ("Not a DVD");
} else switch (foo) {
case 0:
printf ("DVD not encrypted\n");
break;
case 1:
printf ("DVD encrypted\n");
break;
default:
printf ("Shouldn't happen\n");
break;
}
printf ("RMI is: %#02x\n", dvd.copyright.rmi);
}
/* close device */
status = close (fd);
if (status != 0) {
fprintf (stderr, "%s: close failed for `%s': %s\n",
program, device, strerror (errno));
exit (1);
}

exit (0);
}
 

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help needed with getting last inserted row id

Hi, I am working on a script that inserts one row of data at the time to a table. Among the fields of that table is the “serial” which is the auto increment. I need to be able to retrieve last inserted row id to use it for another insert. To retrieve last row id right after I do successful... (2 Replies)
Discussion started by: arushunter
2 Replies

2. UNIX for Dummies Questions & Answers

Output number of rows inserted, updated...

Hi all, I am new to Unix. I have written pl/sql script to be run in Unix. I have used Merge statement and subsequently would like to know the number of rows updated or inserted. Any suggestions in this regard would be great Thanks in advance Kushal (0 Replies)
Discussion started by: kushal_cog
0 Replies

3. Solaris

Copying existing OS to new inserted drives

Hi, I was wondering if there is an easy / recommended way to do the following: Copy existing OS to 2 NEW drives inserted to server. Netra 440 / Solaris 8 1. install the 2 new physical drives, 2. reconfigure the four drives to a RAID 1 array, and 3. copy the existing 2 drives... (4 Replies)
Discussion started by: kmac22068
4 Replies

4. UNIX for Beginners Questions & Answers

Date from filename inserted into records

Hi Folks, I have below files in one directory: Spiross-MBP:AIRTEMP spirospap$ ls -1 CPK2004001 CPK2004002 CPK2004003 etc... JFK2003001 JFK2003002 JFK2003003 etc... TEB1999001 TEB1999002 TEB1999003 etc... Month/year is in Filename and also in the file Header, first line. (18 Replies)
Discussion started by: spirospap
18 Replies
SDL_CDOpen(3)							 SDL API Reference						     SDL_CDOpen(3)

NAME
SDL_CDOpen - Opens a CD-ROM drive for access. SYNOPSIS
#include "SDL.h" SDL_CD *SDL_CDOpen(int drive); DESCRIPTION
Opens a CD-ROM drive for access. It returns a SDL_CD structure on success, or NULL if the drive was invalid or busy. This newly opened CD- ROM becomes the default CD used when other CD functions are passed a NULL CD-ROM handle. Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. EXAMPLES
SDL_CD *cdrom; int cur_track; int min, sec, frame; SDL_Init(SDL_INIT_CDROM); atexit(SDL_Quit); /* Check for CD drives */ if(!SDL_CDNumDrives()){ /* None found */ fprintf(stderr, "No CDROM devices available "); exit(-1); } /* Open the default drive */ cdrom=SDL_CDOpen(0); /* Did if open? Check if cdrom is NULL */ if(!cdrom){ fprintf(stderr, "Couldn't open drive: %s ", SDL_GetError()); exit(-1); } /* Print Volume info */ printf("Name: %s ", SDL_CDName(0)); printf("Tracks: %d ", cdrom->numtracks); for(cur_track=0;cur_track < cdrom->numtracks; cur_track++){ FRAMES_TO_MSF(cdrom->track[cur_track].length, &min, &sec, &frame); printf(" Track %d: Length %d:%d ", cur_track, min, sec); } SDL_CDClose(cdrom); SEE ALSO
SDL_CD, SDL_CDtrack, SDL_CDClose SDL
Tue 11 Sep 2001, 22:58 SDL_CDOpen(3)
All times are GMT -4. The time now is 02:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy