udev/cdrom: make cd_profiles() return positive value if drive has media

This commit is contained in:
Yu Watanabe 2020-12-24 17:24:29 +09:00 committed by Luca Boccassi
parent 138dd9545a
commit 0f0b079135
1 changed files with 14 additions and 15 deletions

View File

@ -635,7 +635,6 @@ static int feature_profiles(const unsigned char *profiles, size_t size) {
return 0; return 0;
} }
/* returns 0 if media was detected */
static int cd_profiles_old_mmc(int fd) { static int cd_profiles_old_mmc(int fd) {
struct scsi_cmd sc; struct scsi_cmd sc;
size_t len; size_t len;
@ -667,7 +666,7 @@ static int cd_profiles_old_mmc(int fd) {
cd_media_cd_rom = 1; cd_media_cd_rom = 1;
cd_media_track_count = 1; cd_media_track_count = 1;
cd_media_track_count_data = 1; cd_media_track_count_data = 1;
return 0; return 1;
} else } else
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM), return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
"no current profile, assuming no media."); "no current profile, assuming no media.");
@ -686,17 +685,17 @@ static int cd_profiles_old_mmc(int fd) {
log_debug("profile 0x08 media_cd_rom"); log_debug("profile 0x08 media_cd_rom");
} }
return 0; return 1;
} }
/* returns 0 if media was detected */
static int cd_profiles(int fd) { static int cd_profiles(int fd) {
struct scsi_cmd sc; struct scsi_cmd sc;
unsigned char features[65530]; unsigned char features[65530];
unsigned cur_profile = 0; unsigned cur_profile = 0;
unsigned len; unsigned len;
unsigned i; unsigned i;
int r, ret = -1; bool has_media = false;
int r;
/* First query the current profile */ /* First query the current profile */
scsi_cmd_init(&sc); scsi_cmd_init(&sc);
@ -719,7 +718,7 @@ static int cd_profiles(int fd) {
if (cur_profile > 0) { if (cur_profile > 0) {
log_debug("current profile 0x%02x", cur_profile); log_debug("current profile 0x%02x", cur_profile);
feature_profile_media(cur_profile); feature_profile_media(cur_profile);
ret = 0; /* we have media */ has_media = true;
} else } else
log_debug("no current profile, assuming no media"); log_debug("no current profile, assuming no media");
@ -768,7 +767,7 @@ static int cd_profiles(int fd) {
} }
} }
return ret; return has_media;
} }
static int cd_media_info(int fd) { static int cd_media_info(int fd) {
@ -1090,16 +1089,16 @@ int main(int argc, char *argv[]) {
goto work; goto work;
/* read drive and possibly current profile */ /* read drive and possibly current profile */
if (cd_profiles(fd) != 0) r = cd_profiles(fd);
goto work; if (r > 0) {
/* at this point we are guaranteed to have media in the drive - find out more about it */
/* at this point we are guaranteed to have media in the drive - find out more about it */ /* get session/track info */
cd_media_toc(fd);
/* get session/track info */ /* get writable media state */
cd_media_toc(fd); cd_media_info(fd);
}
/* get writable media state */
cd_media_info(fd);
work: work:
/* lock the media, so we enable eject button events */ /* lock the media, so we enable eject button events */