Open Flavius12 opened 1 year ago
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.
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.
Hi, how can i distinguish if disk type is an hard disk or a cd/dvd? Is there any flag?