udisksctl: get loop device and mount point without resorting to parsing localized output?
3
votes
1
answer
758
views
udisksctl
is my tool of choice when dealing with file system images ([recent example](https://unix.stackexchange.com/questions/775274/create-fat-formatted-disk-image-that-can-fit-1g-file/775277#775277) , but I've been doing this [all over the place](https://unix.stackexchange.com/search?q=user%3A106650+udisksctl+is%3Aanswer)) .
The dance typically looks like
fallocate -l ${img_size} filesystem.img
mkfs.${fs} filesystem.img
# Set up loop device as regular user
loopback=$(udisksctl loop-setup -b "${img_file}" | sed 's/.* \([^ ]*\)\.$/\1/')
# Mount as regular user
mounted=$(udisksctl mount -b "${loopback}" | sed 's/^.* \([^ ]*\)$/\1/')
# Do the testing/benchmarking/file management
# e.g.:
cp -- "${files[@]}" "${mounted}"
Quite frankly, I have a bad feeling about the way I parse the output of udisksctl
; these are clearly human-aimed strings:
> > Mapped file filesystem.img as /dev/loop0.
> Mounted /dev/loop1 at /run/media/marcus/E954-81FB
>
And I don't think anyone considers their actual format "API". So, my scripts might break in the future! (Not to mention the nasal demons I invite if the image file name contains line breaks.)
udisksctl
doesn't seem to have a "porcelain" output option or similar. Is there an existing method that does udisksctl
's job of loopback mounting with user privilege through udisks2, with a proper, unambiguous output?
Asked by Marcus Müller
(47107 rep)
Apr 29, 2024, 05:44 PM
Last activity: Jun 17, 2024, 02:00 AM
Last activity: Jun 17, 2024, 02:00 AM