Interpreting CDROM_GET_CAPABILITIES ioctl

Discussion in 'C Programming' started by Chris Johnson, Jun 15, 2005.

  1. 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;
    }
     
    Chris Johnson, Jun 15, 2005
    #1
    1. Advertising

  2. Chris Johnson

    CBFalconer Guest

    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
     
    CBFalconer, Jun 15, 2005
    #2
    1. Advertising

  3. 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
     
    Lawrence Kirby, Jun 22, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger
    Replies:
    1
    Views:
    3,717
    Christophe Vanfleteren
    Oct 22, 2003
  2. Javier
    Replies:
    1
    Views:
    875
    Thomas Heller
    Oct 30, 2003
  3. Peter Luciak

    ioctl(2) ?

    Peter Luciak, Apr 24, 2004, in forum: Python
    Replies:
    1
    Views:
    565
    Peter Hansen
    Apr 24, 2004
  4. Kyler Laird

    ioctl() help needed for video4linux

    Kyler Laird, Dec 24, 2004, in forum: Python
    Replies:
    0
    Views:
    327
    Kyler Laird
    Dec 24, 2004
  5. Using ioctl

    , Feb 9, 2006, in forum: Python
    Replies:
    1
    Views:
    1,632
    Scott David Daniels
    Feb 9, 2006
Loading...

Share This Page