Interpreting CDROM_GET_CAPABILITIES ioctl

C

Chris Johnson

I have need to determine the capabilities of an optical drive. Right
now I'm using SDL to find the drives, and ioctl to get the
capabilities. Unfortunately, based on the output that I'm getting,
either my method of interpretation is bad or these drives are
misrepresenting themselves (which they shouldn't be, as other programs
can use the abilites they would here appear to be lacking). If anyone
has experience with the CDROM_GET_CAPABILITIES ioctl, could you please
tell me where I am going amiss?

Thanks,
Chris

#include <stdio.h>
#include <SDL.h>
#include <linux/cdrom.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>


int main(){
/* Initialize CDROM subsystem */
int init = SDL_Init(SDL_INIT_CDROM);

/* Get number of drives */
int num = SDL_CDNumDrives();
printf("Initialized: %d\nNumber of Drives: %d\n",init,num);


int i;
for(i=0;i < num; ++i){
/* System-dependent drive name (i.e. /dev/cdrom or E:)*/
const char *name = SDL_CDName(i);
printf("Name: %s\nID: %d\n",name,i);

/* Open device */
int drive = open(name,0);
if(drive < 0){
printf("Cannot open drive: %s.\n",name);
return 1;
}

/* Pointer to hold output */
int *argp;

/* Get drive capabilities, store in argp */
int retvalue = ioctl(drive,CDROM_GET_CAPABILITY,argp);

/* First attempt at argp interpretation */
if(*argp & CDC_CD_R)
printf("Can write CD-Rs\n");
if(*argp & CDC_CD_RW)
printf("Can write CD-RWs\n");
if(*argp & CDC_DVD)
printf("Can read DVDs\n");
if(*argp & CDC_DVD_R)
printf("Can write DVD-Rs\n");
if(*argp & CDC_DVD_RAM)
printf("Can write DVD-RAMs\n");

/* Most likely gibberish output, but I still want to see it. */
printf("Return: %d\nArgp: %Ld\n",retvalue,argp);
close(drive);
}
return 0;
}
 
C

CBFalconer

Chris said:
I have need to determine the capabilities of an optical drive. Right
now I'm using SDL to find the drives, and ioctl to get the
capabilities. Unfortunately, based on the output that I'm getting,
either my method of interpretation is bad or these drives are
misrepresenting themselves (which they shouldn't be, as other programs
can use the abilites they would here appear to be lacking). If anyone
has experience with the CDROM_GET_CAPABILITIES ioctl, could you please
tell me where I am going amiss?

You are going amiss by expecting an answer here. Those things are
peculiar to the system and compiler you are using, so ask in a
newsgroup that deals with them. c.l.c deals with the PORTABLE C
language, which knows nothing about drives, ioctl, etc.
 
L

Lawrence Kirby

I have need to determine the capabilities of an optical drive. Right
now I'm using SDL to find the drives, and ioctl to get the
capabilities. Unfortunately, based on the output that I'm getting,
either my method of interpretation is bad or these drives are
misrepresenting themselves (which they shouldn't be, as other programs
can use the abilites they would here appear to be lacking). If anyone
has experience with the CDROM_GET_CAPABILITIES ioctl, could you please
tell me where I am going amiss?

The C language doesn't define SDL or ioctl, these are extensions provided
by your platform and are not portable.

Your code appears to be including a linux related header. A good place to
discuss Linux related features is comp.os.linux.development.apps.

Lawrence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top