8 #include <linux/cdrom.h>
14 static int cdrom_open(const char *devpath, const char *loc)
18 fd = open(devpath, O_RDONLY | O_NONBLOCK);
20 pb_log("%s: can't open %s: %s\n", loc, devpath,
26 void cdrom_init(const char *devpath)
30 fd = cdrom_open(devpath, __func__);
34 /* We disable autoclose so that any attempted mount() operation doesn't
35 * close the tray, and disable CDO_LOCK to prevent the lock status
36 * changing on open()/close()
38 rc = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK | CDO_AUTO_CLOSE);
40 pb_debug("%s: CLEAR CDO_LOCK|CDO_AUTO_CLOSE failed: %s\n",
41 __func__, strerror(errno));
46 bool cdrom_media_present(const char *devpath)
50 fd = cdrom_open(devpath, __func__);
54 rc = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
58 return rc == CDS_DISC_OK;
61 void cdrom_eject(const char *devpath)
65 fd = cdrom_open(devpath, __func__);
69 /* unlock cdrom device */
70 rc = ioctl(fd, CDROM_LOCKDOOR, 0);
72 pb_log("%s: CDROM_LOCKDOOR(unlock) failed: %s\n",
73 __func__, strerror(errno));
75 rc = ioctl(fd, CDROMEJECT, 0);
77 pb_log("%s: CDROM_EJECT failed: %s\n",
78 __func__, strerror(errno));