您的位置:首页 > 博客中心 > 网络系统 >

Linux下弹出和收回光驱

时间:2022-04-03 10:37

弹出光驱     
#include
#include
#include
#include
#include
#define DEVICE "/dev/cdrom"
int fd = open(DEVICE, O_RDONLY|O_NONBLOCK);
  if (fd < 0) {
    perror("unable to open "DEVICE);
    exit(1);
  }
  if (ioctl(fd, CDROMEJECT) != 0) {
    perror("CDROMEJECT ioctl failed");
    exit(1);
  }
  if (close(fd) != 0) {
    perror("unable to close "DEVICE);
    exit(1);
  }

收回光驱     
#include
#include
#include
#include
#include
#define DEVICE "/dev/cdrom"
int fd = open(DEVICE, O_RDONLY|O_NONBLOCK);
  if (fd < 0) {
    perror("unable to open "DEVICE);
    exit(1);
  }
  if (ioctl(fd, CDROMCLOSETRAY,0) != 0) {
    perror("CDROMCLOSETRAY ioctl failed");
    exit(1);
  }
  if (close(fd) != 0) {
    perror("unable to close "DEVICE);
    exit(1);

本类排行

今日推荐

热门手游