LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-05-2005, 12:10 PM   #1
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
Red face How to eject a CD


I'm creating a Cd writing software.

I'm using ,,,,,,,,system("eject"); and system("eject -t");
to eject and load the CD.

Is there any other way to do this without calling "system"?
 
Old 02-05-2005, 12:24 PM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
referencing what language you're using would be a starting place...

is that perl?

http://search.cpan.org/~dgoehrig/SDL...b/SDL/Cdrom.pm
 
Old 02-05-2005, 12:25 PM   #3
masand
Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 58
there is this package called
"eject" which is responsible for the eject command
maybe u should check out the code of it!!

regards
 
Old 02-05-2005, 03:48 PM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
Look at of /usr/src/linux/cdrom.h and man ioctl for more infos
Code:
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <stdio.h>

int main( int argc, char **argv )
{
	int cdrom;	
	int i;		

	/* open device */
	if ((cdrom = open("/dev/hdd",O_RDONLY | O_NONBLOCK)) < 0) {
		perror("open");
		exit(1);
	}
	
	/* eject  */
	if(ioctl(cdrom, CDROMEJECT) < 0) {
		printf("Could not eject cdrom tray\n");
	}
	
	/* close device */
	close(cdrom);
	return 0;
}

Last edited by keefaz; 02-05-2005 at 03:52 PM.
 
Old 11-21-2006, 04:23 AM   #5
zoro0011
LQ Newbie
 
Registered: Nov 2006
Posts: 1

Rep: Reputation: 0
eject cdrom

hi
I am doing a project about Operating system :write a program by C (hay C++) to eject cdrom
please,help me!
if u have source code about it ,please send it to me
my email: zoro0011@gmail.com

thank you,
 
Old 11-24-2011, 11:25 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
The cdrom device file is hard coded in the source file, you haven't to submit an argument just change /dev/hdd with your cdrom device file
 
Old 11-24-2011, 11:43 AM   #7
shariefbe
Member
 
Registered: Aug 2008
Location: Tiruchirappalli, India
Distribution: UBUNTU 11.04
Posts: 368

Rep: Reputation: 31
Now its working for me when i change my device as "/dev/cdrom" the code is
Code:
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv )
{
        int cdrom;
        int i;

        /* open device */
        if ((cdrom = open("/dev/cdrom",O_RDONLY | O_NONBLOCK)) < 0) {
                perror("open");
        exit(1);
        }

        /* eject  */
        if(ioctl(cdrom, CDROMEJECT) < 0) {
                printf("Could not eject cdrom tray\n");
        }

        /* close device */
        close(cdrom);
        return 0;
}
CDROM is ejecting fine. ie its opening. But i dont know how to make my CDROM to close. Can anyone help me..

Last edited by shariefbe; 11-24-2011 at 11:47 AM.
 
Old 11-24-2011, 11:50 AM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
You have all ioctl commands in /usr/include/linux/cdrom.h

Code:
/* close  */
if(ioctl(cdrom, CDROMCLOSETRAY) < 0) {
        printf("Could not close cdrom tray\n");
}
 
  


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
VCD does not eject even eject button pressed ic_torres Linux - Software 4 12-01-2005 06:40 PM
cd eject? mithereal Debian 6 08-09-2005 10:36 AM
can't eject a cd hraposo Slackware 9 05-01-2005 07:44 PM
CD won't eject... Vermis Fedora 4 02-03-2005 10:36 PM
CD Won't Eject With "eject" Command Dr. Ephemeron Slackware 13 11-13-2003 01:27 AM


All times are GMT -5. The time now is 07:39 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration