467,077 Members | 1,037 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Interpreting CDROM_GET_CAPABILITIES ioctl

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;
}

Nov 14 '05 #1
  • viewed: 1445
Share:
2 Replies
Chris Johnson wrote:

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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #2
On Wed, 15 Jun 2005 08:32:33 -0700, Chris Johnson wrote:
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

Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Javier | last post: by
1 post views Thread by Peter Luciak | last post: by
reply views Thread by Kyler Laird | last post: by
3 posts views Thread by chris | last post: by
1 post views Thread by chyle.edic@thomson.net | last post: by
1 post views Thread by klappnase@web.de | last post: by
6 posts views Thread by Eran.Yasso@gmail.com | last post: by
1 post views Thread by luca | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.