cdrom_id.c revision 756775814cf69471f74ce853745bba69f2ba94ef
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * cdrom_id - optical drive and media information prober
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2008-2010 Kay Sievers <kay@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is free software: you can redistribute it and/or modify
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * it under the terms of the GNU General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is distributed in the hope that it will be useful,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * GNU General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * You should have received a copy of the GNU General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* device info */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_cd_rom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_cd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_cd_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_rom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_ram;
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poetteringstatic unsigned int cd_dvd_plus_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_plus_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_plus_r_dl;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_dvd_plus_rw_dl;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_bd;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_bd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_bd_re;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_hddvd;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_hddvd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_hddvd_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_mo;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_mrw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_mrw_w;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* media info */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_cd_rom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_cd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_cd_rw;
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poetteringstatic unsigned int cd_media_dvd_rom;
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poetteringstatic unsigned int cd_media_dvd_r;
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poetteringstatic unsigned int cd_media_dvd_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_rw_ro; /* restricted overwrite mode */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_rw_seq; /* sequential mode */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_ram;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_plus_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_plus_rw;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_plus_r_dl;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_dvd_plus_rw_dl;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_bd;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_bd_r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_bd_re;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_hddvd;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic unsigned int cd_media_hddvd_r;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_hddvd_rw;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_mo;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_mrw;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_mrw_w;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_session_next;
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersenstatic unsigned int cd_media_session_count;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_track_count;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_track_count_data;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic unsigned int cd_media_track_count_audio;
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidtstatic unsigned long long int cd_media_session_last_offset;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering#define ERRCODE(s) ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering#define SK(errcode) (((errcode) >> 16) & 0xF)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering#define ASC(errcode) (((errcode) >> 8) & 0xFF)
db97a66aa69925f7403ba3c433e86320d136567dLennart Poetteringstatic bool is_mounted(const char *device)
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering fp = fopen("/proc/self/mountinfo", "re");
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (makedev(maj, min) == statbuf.st_rdev) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringstatic void info_scsi_cmd_err(struct udev *udev, const char *cmd, int err)
1c4baffc1895809bae9ac36b670af90a4cb9cd7dTom Gundersen log_debug("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh", cmd, SK(err), ASC(err), ASCQ(err));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned char u[18];
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic void scsi_cmd_init(struct udev *udev, struct scsi_cmd *cmd)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering cmd->sg_io.mx_sb_len = sizeof(cmd->_sense);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO;
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersenstatic void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, unsigned char arg)
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersenstatic int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t bufsize)
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering cmd->sg_io.dxfer_direction = SG_DXFER_FROM_DEV;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering cmd->sg_io.dxfer_direction = SG_DXFER_NONE;
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersen if ((cmd->sg_io.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (cmd->sg_io.masked_status & CHECK_CONDITION) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int media_lock(struct udev *udev, int fd, bool lock)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* disable the kernel's lock logic */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering err = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK);
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering log_debug("CDROM_CLEAR_OPTIONS, CDO_LOCK failed");
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering err = ioctl(fd, CDROM_LOCKDOOR, lock ? 1 : 0);
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poetteringstatic int media_eject(struct udev *udev, int fd)
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering err = scsi_cmd_run(udev, &sc, fd, NULL, 0);
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering info_scsi_cmd_err(udev, "START_STOP_UNIT", err);
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poetteringstatic int cd_capability_compat(struct udev *udev, int fd)
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poetteringstatic int cd_media_compat(struct udev *udev, int fd)
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK");
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersenstatic int cd_inquiry(struct udev *udev, int fd)
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering err = scsi_cmd_run(udev, &sc, fd, inq, 36);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering log_debug("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void feature_profile_media(struct udev *udev, int cur_profile)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering log_debug("profile 0x%02x ", cur_profile);
d6731e4c7964ee2860d4f5abdb0b52acd7a66960Tom Gundersen log_debug("profile 0x%02x media_cd_rom", cur_profile);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering log_debug("profile 0x%02x media_cd_r", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_cd_rw", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_dvd_ro", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_dvd_r", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_dvd_ram", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_dvd_rw_ro", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_dvd_rw_seq", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_dvd_plus_r", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_dvd_plus_rw", cur_profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("profile 0x%02x media_dvd_plus_rw_dl", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_dvd_plus_r_dl", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_bd", cur_profile);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering log_debug("profile 0x%02x media_bd_r", cur_profile);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering log_debug("profile 0x%02x media_bd_re", cur_profile);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("profile 0x%02x media_hddvd", cur_profile);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering log_debug("profile 0x%02x media_hddvd_r", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x media_hddvd_rw", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x <ignored>", cur_profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int feature_profiles(struct udev *udev, const unsigned char *profiles, size_t size)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned int i;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering profile = profiles[i] << 8 | profiles[i+1];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x cd_rom", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x cd_r", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x cd_rw", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x dvd_rom", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x dvd_ram", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x dvd_rw", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x dvd_plus_r", profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("profile 0x%02x dvd_plus_rw", profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("profile 0x%02x dvd_plus_rw_dl", profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("profile 0x%02x dvd_plus_r_dl", profile);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("profile 0x%02x bd_r", profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("profile 0x%02x bd_re", profile);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering log_debug("profile 0x%02x hddvd", profile);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering log_debug("profile 0x%02x hddvd_r", profile);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering log_debug("profile 0x%02x hddvd_rw", profile);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering log_debug("profile 0x%02x <ignored>", profile);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/* returns 0 if media was detected */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringstatic int cd_profiles_old_mmc(struct udev *udev, int fd)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering scsi_cmd_set(udev, &sc, 8, sizeof(header));
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("no current profile, but disc is present; assuming CD-ROM");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_debug("no current profile, assuming no media");
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering } else if ((header[2] & 3) < 2 && cd_cd_r) {
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poettering/* returns 0 if media was detected */
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poetteringstatic int cd_profiles(struct udev *udev, int fd)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering unsigned int cur_profile = 0;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering unsigned int i;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* First query the current profile */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering err = scsi_cmd_run(udev, &sc, fd, features, 8);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* handle pre-MMC2 drives which do not support GET CONFIGURATION */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (SK(err) == 0x5 && (ASC(err) == 0x20 || ASC(err) == 0x24)) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering log_debug("drive is pre-MMC2 and does not support 46h get configuration command");
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering log_debug("trying to work around the problem");
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering cur_profile = features[6] << 8 | features[7];
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt log_debug("current profile 0x%02x", cur_profile);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering feature_profile_media (udev, cur_profile);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt log_debug("no current profile, assuming no media");
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering log_debug("GET CONFIGURATION: size of features buffer 0x%04x", len);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering log_debug("can not get features in a single query, truncating");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* Now get the full feature buffer */
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering scsi_cmd_set(udev, &sc, 7, ( len >> 8 ) & 0xff);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt err = scsi_cmd_run(udev, &sc, fd, features, len);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* parse the length once more, in case the drive decided to have other features suddenly :) */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("GET CONFIGURATION: size of features buffer 0x%04x", len);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("can not get features in a single query, truncating");
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* device features */
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering for (i = 8; i+4 < len; i += (4 + features[i+3])) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering feature = features[i] << 8 | features[i+1];
7b85d72f824cdf34554b349712b6b8e39095dbd4Lennart Poettering log_debug("GET CONFIGURATION: feature 'profiles', with %i entries", features[i+3] / 4);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering feature_profiles(udev, &features[i]+4, MIN(features[i+3], len - i - 4));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_debug("GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes", feature, features[i+3]);
out:
return ret;
static const char *media_status[] = {
int err;
if ((err != 0)) {
if (!cd_media_cd_rom)
if ((cd_media_dvd_rw_ro || cd_media_dvd_plus_rw || cd_media_dvd_plus_rw_dl || cd_media_dvd_ram) && (header[2] & 3) > 1) {
unsigned char len;
int offset;
if (cd_media_dvd_ram) {
if ((err != 0)) {
goto determined;
if ((err != 0)) {
goto determined;
if ((err != 0)) {
cd_media = 0;
goto determined;
goto determined;
int err;
if ((err != 0)) {
if ((err != 0)) {
unsigned int block;
unsigned int is_data_track;
if (is_data_track)
if ((err != 0)) {
bool eject = false;
bool lock = false;
bool unlock = false;
int cnt;
int rc = 0;
log_open();
goto exit;
int option;
switch (option) {
lock = true;
unlock = true;
eject = true;
log_open();
goto exit;
goto exit;
if (!node) {
goto exit;
if (fd < 0) {
goto exit;
goto exit;
goto work;
goto work;
work:
if (eject) {
if (cd_cd_rom)
if (cd_cd_r)
if (cd_cd_rw)
if (cd_dvd_rom)
if (cd_dvd_r)
if (cd_dvd_rw)
if (cd_dvd_ram)
if (cd_dvd_plus_r)
if (cd_dvd_plus_rw)
if (cd_dvd_plus_r_dl)
if (cd_dvd_plus_rw_dl)
if (cd_bd)
if (cd_bd_r)
if (cd_bd_re)
if (cd_hddvd)
if (cd_hddvd_r)
if (cd_hddvd_rw)
if (cd_mo)
if (cd_mrw)
if (cd_mrw_w)
if (cd_media)
if (cd_media_mo)
if (cd_media_mrw)
if (cd_media_mrw_w)
if (cd_media_cd_rom)
if (cd_media_cd_r)
if (cd_media_cd_rw)
if (cd_media_dvd_rom)
if (cd_media_dvd_r)
if (cd_media_dvd_ram)
if (cd_media_dvd_rw)
if (cd_media_dvd_plus_r)
if (cd_media_dvd_plus_rw)
if (cd_media_bd)
if (cd_media_bd_r)
if (cd_media_bd_re)
if (cd_media_hddvd)
if (cd_media_hddvd_r)
if (cd_media_hddvd_rw)
if (cd_media_session_next > 0)
if (cd_media_session_count > 0)
if (cd_media_track_count > 0)
if (cd_media_track_count_audio > 0)
if (cd_media_track_count_data > 0)
exit:
if (fd >= 0)
log_close();
return rc;