[parted-devel] How to read partition table read-only with libparted?
Konstantin Kharlamov
hi-angel at yandex.ru
Fri Jan 13 08:21:35 GMT 2023
Sorry if it's an unsuitable for questions ML, I've only found this one and the bugs-related.
We have a simple usecase of reading a partition table, and checking its properties, like `ped_partition_get_name()`.
The problem is: to get a partition table you need to call `ped_disk_new()` first. Which opens a disk in O_RDWR mode, resulting in dozens of excess events, including "remove/add" on older kernels, and just a lot of "change" ones with a newer kernel.
I tried setting `dev->read_only = 1` before calling a `ped_disk_new(dev)`, but the field seems ignored and the disk still gets opened with O_RDWR.
While using libparted with some other software at work, these events spam the system, causing UDEV to get overloaded with events which weren't supposed to happen in the first place. We were carrying some local patches to an older libparted that works around that by modifying an API, but I'd like to see if it's possible to get rid of that and just use the vanilla libparted.
So, any suggestions, how one can make `ped_disk_new()` open a device in read-only mode? Is that currently possible or does that require making changes to libparted?
More information about the parted-devel
mailing list