Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i distinguish if disk type is an hard disk or a cd/dvd? #102

Open
Flavius12 opened this issue Jun 22, 2023 · 2 comments
Open

How can i distinguish if disk type is an hard disk or a cd/dvd? #102

Flavius12 opened this issue Jun 22, 2023 · 2 comments
Assignees
Labels

Comments

@Flavius12
Copy link

Flavius12 commented Jun 22, 2023

Hi,
how can i distinguish if disk type is an hard disk or a cd/dvd?
Is there any flag?

@dcantrell
Copy link
Owner

libparted does not offer that level of granularity. In the case of a PC, hard disks and optical drives are going to show up as SCSI most likely (or ATA). It is possible to have a partitioned optical disk. It's rare, but not unheard of. And libparted should not be determining which devices are available based on whether or not they can be partitioned. Reading partitioning info is fine and a user may want to do that.

What I would suggest is that for the Device type in pyparted, look at the readOnly attribute. For an optical volume this should be True. However, I noticed on the linked archlinux issue that readOnly reports as False. This information comes from libparted, so maybe it is an issue there.

@bcl should optical drives in libparted report as device type SCSI (or ATA) and have read only report True? In this example that is not happening, so I'm wondering if that should be addressed in libparted or if there is simply no way to determine that at the libparted level. The linked archlinux issue shows some lsblk output and such, but I don't think we need to go down that route.

@dcantrell dcantrell self-assigned this Aug 31, 2023
@bcl
Copy link
Contributor

bcl commented Aug 31, 2023

The readOnly attribute is set to true when opening the device for r/w fails. On my desktop here parted -l does that:

Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0
has been opened read-only.

But that doesn't happen until it tries to open for write so depending on when you check it, it may not really reflect the underlying device. False is the default state for that value, so the only thing you can depend on is that if it is True libparted cannot open it for write.

And as David mentioned, there are also iso's with partitions so just checking for a previous partition type isn't enough. The best example I can think of for previous work in this area is https://github.com/storaged-project/blivet which is the storage library used by Anaconda, the Fedora and Red Hat Enterprise Linux installer. Here's the function it uses to determine if something is a disk - https://github.com/storaged-project/blivet/blob/3.8-devel/blivet/udev.py#L389 which may help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants