Tớ đã viết 3 bài về đóng/mở CD/DVDRom trên Windows rồi.
Tham khảo tại đây:
C++ Code:
  1. http://forums.congdongcviet.com/showthread.php?t=17895
  2. http://forums.congdongcviet.com/showthread.php?t=17871
  3. http://forums.congdongcviet.com/showthread.php?t=17773

Giờ thêm một bản đơn giản có giao diện dành cho Linux, có mỗi 2 cái button (Eject - Exit)

Chương trình:CD/DVDRom Ejector
Tác giả: Xcross87
Project: 1 file
GUI: GTK+-2.0



C++ Code:
  1. /*
  2.  * @author Xcross87
  3.  * @date 06-May-2009
  4.  * @file gtk_eject_cdrom.c
  5.  * @note     simple GUI application eject CD/DVD-Rom
  6.  */
  7.  
  8. /* library/header */
  9. #include <gtk/gtk.h>
  10. #include <sys/types.h>
  11. #include <sys/ioctl.h>
  12. #include <linux/cdrom.h>
  13. #include <sys/fcntl.h>
  14.  
  15. /* @function eject_cdrom()
  16.  *        eject cdrom
  17.  */
  18. void eject_cdrom() {
  19.     int fd = open( "/dev/cdrom", O_RDONLY | O_NONBLOCK );
  20.     if( fd == -1 ) { }
  21.     else {
  22.         if( ioctl(fd, CDROMEJECT, 0) == -1 ) { }
  23.     }
  24.     close(fd);
  25. }
  26.  
  27. /*
  28.  * EVENT    btn_eject_clicked
  29.  *        button eject clicked
  30.  */
  31. void btn_eject_clicked(GtkWidget *widget, gpointer data) {
  32.     eject_cdrom(); // eject cd/dvdrom
  33. }
  34.  
  35.  
  36. /* main program */
  37. int main( int argc, char** argv )
  38. {
  39.     // create widget
  40.     GtkWidget *window;
  41.     GtkWidget *vbox;
  42.    
  43.     GtkWidget *btn_eject;
  44.     GtkWidget *btn_exit;
  45.    
  46.     // init gtk app
  47.     gtk_init( &argc, &argv );
  48.    
  49.     // create window
  50.     window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
  51.     gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  52.     gtk_window_set_default_size( GTK_WINDOW(window), 300, 100 );
  53.     gtk_window_set_title( GTK_WINDOW(window), "CD/DVD Ejector by Xcross87" );
  54.     gtk_container_set_border_width( GTK_CONTAINER(window), 5);
  55.    
  56.     // create vbox layout
  57.     vbox = gtk_vbox_new( TRUE, 1 );
  58.     gtk_container_add( GTK_CONTAINER(window), vbox );
  59.    
  60.     // create 2 buttons
  61.     btn_eject = gtk_button_new_with_label( "Eject CD/DVD" );
  62.     btn_exit =  gtk_button_new_with_label( "Exit" );
  63.    
  64.     // pack btns to layout
  65.     gtk_box_pack_start( GTK_BOX(vbox), btn_eject, TRUE, TRUE, 0 );
  66.     gtk_box_pack_start( GTK_BOX(vbox), btn_exit, TRUE, TRUE, 0 );
  67.    
  68.     // event handler
  69.     g_signal_connect( G_OBJECT(btn_eject), "clicked", G_CALLBACK(btn_eject_clicked), NULL );
  70.     g_signal_connect( G_OBJECT(btn_exit), "clicked", G_CALLBACK(gtk_main_quit), NULL );
  71.     g_signal_connect_swapped( G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), G_OBJECT(window) );
  72.    
  73.     // show widget    
  74.     gtk_widget_show_all(window);
  75.    
  76.     // activate app
  77.     gtk_main();
  78.    
  79.     // return
  80.     return 0;
  81.    
  82. }

Chúc vui vẻ :P