Friday, 15 August 2014

cd rom - CD-Rom eject by C code -



cd rom - CD-Rom eject by C code -

im trying eject cd rom via c code.and dont want work. ioctl returned "5" i/o error, problem?

#include <stdio.h> #include <fcntl.h> #include <linux/cdrom.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> int eject_cdrom() { char path_to_cdrom[20]="/dev/cdrom"; int fd = open("/dev/cdrom", o_rdonly| o_nonblock); printf("%d\n",fd ); int lala = ioctl(fd, cdromeject); printf("%d\n",lala); close(fd); homecoming lala; } int main(int argc, char* argv[]) { //eject_cdrom_system(); int value = eject_cdrom(); printf("%d\n",value ); if (value == -1) { int errsv = errno; printf("somecall() failed\n"); printf("%d\n",errsv ); } homecoming 0; }

when tried function

void eject_cdrom_system() { system("/usr/bin/eject"); }

it works perfectly. want first function (eject_cdrom).

output strace:

strace -f ./cdrom

execve("./cdrom", ["./cdrom"], [/* 76 vars */]) = 0 brk(0) = 0xf9c000 access("/etc/ld.so.nohwcap", f_ok) = -1 enoent (no such file or directory) mmap(null, 8192, prot_read|prot_write, map_private|map_anonymous, -1, 0) = 0x7fcb50cd7000 access("/etc/ld.so.preload", r_ok) = -1 enoent (no such file or directory) open("/etc/ld.so.cache", o_rdonly|o_cloexec) = 3 fstat(3, {st_mode=s_ifreg|0644, st_size=131512, ...}) = 0 mmap(null, 131512, prot_read, map_private, 3, 0) = 0x7fcb50cb6000 close(3) = 0 access("/etc/ld.so.nohwcap", f_ok) = -1 enoent (no such file or directory) open("/lib/x86_64-linux-gnu/libc.so.6", o_rdonly|o_cloexec) = 3 read(3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\37\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=s_ifreg|0755, st_size=1845024, ...}) = 0 mmap(null, 3953344, prot_read|prot_exec, map_private|map_denywrite, 3, 0) = 0x7fcb506f1000 mprotect(0x7fcb508ad000, 2093056, prot_none) = 0 mmap(0x7fcb50aac000, 24576, prot_read|prot_write, map_private|map_fixed|map_denywrite, 3, 0x1bb000) = 0x7fcb50aac000 mmap(0x7fcb50ab2000, 17088, prot_read|prot_write, map_private|map_fixed|map_anonymous, -1, 0) = 0x7fcb50ab2000 close(3) = 0 mmap(null, 4096, prot_read|prot_write, map_private|map_anonymous, -1, 0) = 0x7fcb50cb5000 mmap(null, 8192, prot_read|prot_write, map_private|map_anonymous, -1, 0) = 0x7fcb50cb3000 arch_prctl(arch_set_fs, 0x7fcb50cb3740) = 0 mprotect(0x7fcb50aac000, 16384, prot_read) = 0 mprotect(0x600000, 4096, prot_read) = 0 mprotect(0x7fcb50cd9000, 4096, prot_read) = 0 munmap(0x7fcb50cb6000, 131512) = 0 open("/dev/cdrom", o_rdonly|o_nonblock) = 3 ioctl(3, cdromeject, 0) = -1 eio (input/output error) close(3) = 0 exit_group(0) = ? +++ exited 0 +++

c cd-rom eject

No comments:

Post a Comment