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