Hy.

I'm new in this programming and i wish to work with some device like cd-rom.

So i wish to know how to open device.

I know that i must work with socketfd but i just need some guidnes.

Tnx

You need to check device driver apis for your cd rom.

You need to check device driver apis for your cd rom.

Sorry, but what this means?

Look in the folder /dev. In that folder you will see a whole bunch of files. Beleive it or not, those files are the link to your hardware on a low level. If you wish to access the device an a low level, just read and write from the corresponding file.

If you want a higher level api for linux, check out this.
Good luck.

Sorry, but what this means?

You need to check device driver apis for your cd rom.

At last i succed to open device.

It goes like this:

int main(int argc, char** argv) 
{

        FILE CDROM;
        int cdrom_fd;
        char* device_name = argv[1];
	char* cd_rom = "/dev/cdrom";
        
        if ((cdrom_fd = open(cd_rom,O_RDONLY))==-1) 
        {
		       perror(cd_rom);  
	}
       return 0;
}

Does anyone can tell me how to read data from CD?

just read, not copy?

Look in the folder /dev. In that folder you will see a whole bunch of files. Beleive it or not, those files are the link to your hardware on a low level. If you wish to access the device an a low level, just read and write from the corresponding file.

If you want a higher level api for linux, check out this.
Good luck.

Tnx men, i'm getting somewhere!

Fix post #5 (with the "EDIT THIS POST" button). Use [CODE=C]<code here> [/code] to make it easer to read.

The code in post #5 will open the device in a low level, which means you have to first "ask the device" for the data on the cd. The way you "ask the device" varies between cd-rom drives, which is why you need drivers. linux/drivers.h should give you access to the cd-rom "after" the drivers, so you don't have to worry about writting messy code to support all cd drives.

Good luck. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.