Advertisement

07.11.2006 at 03:04PM PDT, ID: 21915850
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

problem using ioctl , CDROM_DRIVE_STATUS

Asked by spikey_nick in Linux Programming

Tags: ,

Hi,
I'm using the ubuntu version of Linux and C++.  I'm trying to use ioctl to detect the status of the cdrom drive.  according to the documentation http://www.mjmwired.net/kernel/Documentation/ioctl/cdrom.txt (line 682) CDROM_DRIVE_STATUS should return one of 5 states:

CDS_NO_INFO      
CDS_NO_DISC
CDS_TRAY_OPEN
CDS_DRIVE_NOT_READY
CDS_DISC_OK

I have only been able to detect two states: CDS_DISC_OK and CDS_TRAY_OPEN.  I'm getting CDS_TRAY_OPEN when there is no disc in the drive, even when the tray is closed.  I need to know if the tray is closed but there is no disc in the drive.  Is there something I'm doing wrong (my code is below)?


Thanks,
Nick



#include <sys/ioctl.h>
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>


using std::cout;
using std::endl;





int main(char** argv)
{

    int fd;
    int ret,d;


    while(1)
    {
    if ((fd = open("/dev/cdrom",O_RDONLY | O_NONBLOCK)) < 0) {
        perror("open");
        exit(1);
    }
   
   
      ret = ioctl(fd,CDROM_DRIVE_STATUS,0);

      cout<<ret<<endl;

      switch(ret) {
      case CDS_NO_INFO:
          cout<<"CDS_NO_INFO"<<endl;
          break;
      case CDS_NO_DISC:
          cout<<"CDS_NO_DISC"<<endl;
          break;
      case CDS_TRAY_OPEN:
          cout<<"CDS_TRAY_OPEN"<<endl;
          d = ioctl(fd,CDROM_DISC_STATUS,0);
          cout<<d<<endl;
          break;
      case CDS_DRIVE_NOT_READY:
          cout<<"CDS_DRIVE_NOT_READY"<<endl;
          break;
      case CDS_DISC_OK:
          cout<<"CDS_DISC_OK"<<endl;
          d = ioctl(fd,CDROM_DISC_STATUS,0);
          cout<<d<<endl;
          switch(d){
          case CDS_NO_INFO:
            cout<<"CDS_NO_INFO"<<endl;
            break;
          case CDS_AUDIO:
            cout<<"CDS_AUDIO"<<endl;
            break;
          case CDS_XA_2_2:
            cout<<"CDS_XA_2_2"<<endl;
            break;
          case CDS_XA_2_1:
            cout<<"CDS_XA_2_1"<<endl;
            break;
          case CDS_DATA_1:
            cout<<"CDS_DATA_1"<<endl;
            break;
          case CDS_MIXED:
            cout<<"CDS_MIXED"<<endl;
            break;
          default:
            cout<<"SUPER ERROR 2"<<endl;
          }
          break;
      case -1:
          cout<<"ERROR"<<endl;
          cout<<errno<<endl;
          switch(errno) {
          case ENOSYS:
            cout<<"ENOSYS"<<endl;
            break;
          case EINVAL:
            cout<<"EINVAL"<<endl;
            break;
          case ENOMEM:
            cout<<"ENOMEM"<<endl;
            break;
          default:
            cout<<"ERRNO ERROR"<<endl;
          }
          break;
      default:
          cout<<"SUPER ERROR"<<endl;
      }
      usleep(100);
    }
    return 0;

}


Start Free Trial
 
Keywords: problem using ioctl , CDROM_DRIVE…
 
Loading Advertisement...
 
[+][-]07.11.2006 at 07:20PM PDT, ID: 17087215

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.11.2006 at 07:25PM PDT, ID: 17087245

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2006 at 02:55PM PDT, ID: 17095075

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.12.2006 at 07:08PM PDT, ID: 17096239

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Linux Programming
Tags: cdrom_drive_status, ioctl
Sign Up Now!
Solution Provided By: manish_regmi
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43