From 919b5e5c20ddabf443fc0758691c5b8b119a42a4 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Thu, 17 Sep 2020 18:51:55 +0000 Subject: [PATCH] Provide better error message when there's no CD in the drive Fixes #385. Signed-off-by: JoeLametta --- whipper/command/cd.py | 3 +++ whipper/common/drive.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index a9516e06..1e13aac5 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -94,6 +94,9 @@ def do(self): utils.load_device(self.device) utils.unmount_device(self.device) + # Exit and inform the user if there's no CD in the disk drive + if drive.get_cdrom_drive_status(self.device): # rc == 1 means no disc + raise OSError("no CD detected, please insert one and retry") # first, read the normal TOC, which is fast self.ittoc = self.program.getFastToc(self.runner, self.device) diff --git a/whipper/common/drive.py b/whipper/common/drive.py index 21d02ff4..486be8b8 100644 --- a/whipper/common/drive.py +++ b/whipper/common/drive.py @@ -19,6 +19,7 @@ # along with whipper. If not, see . import os +from fcntl import ioctl import logging logger = logging.getLogger(__name__) @@ -69,3 +70,10 @@ def getDeviceInfo(path): _, vendor, model, release = device.get_hwinfo() return vendor, model, release + + +def get_cdrom_drive_status(drive_path): + fd = os.open(drive_path, os.O_RDONLY | os.O_NONBLOCK) + rc = ioctl(fd, 0x5326) # AKA 'CDROM_DRIVE_STATUS' + os.close(fd) + return rc