LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-27-2004, 09:31 PM   #16
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53

the eject command simple won't work if there is no disk in the drive
the call to get the file descriptor will fail
you can get some info using
int test = (ioctl(fdcdrom, CDROM_DRIVE_STATUS));
but it doesn't do any good unless you want to close it if it's open or something
no matter how you implement it or in what language it won't open with no disk in it so you are covered
Code:
#include <fcntl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main () {
  int fd;
  if ((fd = open("dev/cdrom",O_RDONLY ))==-1)
    return 0;
  ioctl (fd, CDROMEJECT);
  close (fd);
  return 0;
}

Last edited by foo_bar_foo; 08-27-2004 at 09:41 PM.
 
Old 08-28-2004, 09:11 AM   #17
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Original Poster
Rep: Reputation: 15
Yes, actually that's a good idea. Actually, while that may be true for the eject ioctl call, it isn't true for the eject command. When I type "eject" at a shell and there's no CD in my drive, the tray pops out. I think the difference is that you haven't passed the O_NONBLOCK flag to the open command; the "eject" program does, as does my program. But your program is probably useful and is simpler than mine too.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
how to check disk SlipAway172 Mandriva 2 03-01-2005 03:16 AM
Disk check question XPediTioN Slackware 2 06-23-2004 09:07 AM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM
Forced disk check nabil Linux - General 7 05-25-2001 12:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration