poor feedback when misusing `losetup`

Benno Schulenberg <[email protected]> Thu, 9 Oct 2025 11:44:52 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
I've attached an image of some file system to a loop device with:

   # losetup loop2 some.img

Then I wanted to list information about this loop device:

   # losetup loop2
   losetup: loop2: failed to use device: No such device

It results that when setting up a loop device, one can use the short
name, but when doing anything else, one needs to give the full path:

   # losetup /dev/loop2
   /dev/loop2: [66306]:5792049 (/home/ben/some.img)

Wouldn't it be nicer if one can always use the short name -- when
the relevant loop device is located in /dev/?  Because the man page
always says 'loopdev'; it doesn't distinguish between setting up a
device and doing anything else with it.


Then I detach the device, forget that I have detached it, and detach
it again later:

   # losetup -d /dev/loop2
   # losetup -d /dev/loop2
   losetup: /dev/loop2: detach failed: No such device or address

"No such device"?  So I request information about the device:

   # losetup /dev/loop2
   losetup: /dev/loop2: No such file or directory

But it exists alright:

   # ls -l /dev/loop2
   brw-rw---- 1 root disk 7, 2 okt  9 11:29 /dev/loop2

Wouldn't it be better if `losetup` reported "Nothing is attached"
when trying to detach or get info from an unassociated loop device?


Benno
OpenPGP_signature.asc (application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE-----

wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAmjnhBQFAwAAAAAACgkQUUu+Lrjhlh+l
iQ//U/I/ktTASzEgvYGt2S107R8EpjrWsQ5+8Es+zn8q8Hj/T6Za8UaOWdhUsJAe1jOc2njnndot
O5Hd1e0vcXTZimxZoJlejQyriHX47YpBlU7q97ejLVYLCrOq/HQ8W1jiSlBi6Arq28vr4FMTFQcQ
Q2dQx7vrHzD2U1+WGs0VzIRr82/xZqTH4byzQQDnla2VhgPieuP6q+lxN/rXzGcjTZkm6UBCy4tA
ZOPTMi0Uq3f5SKWVzAYyAHjZ9JPq7XtiTbYIM/yVa+9sYmt4pgxMxkaayW8S/hOZND2DOuryblJ5
Eg9jxbgyd2DS4O5SV8b2mIZdvMYV+rNWHtrW2M1hDreSO3+JP+1huiRhKiWW+U1J9uzehCF+pD/r
KCUDGICTllYyuaocIM2pCnRppNZ5gkjOUfZe33bTrtCEcXii5B9wy7hTv+2zBqec8/QquO5ZKCOu
RFCg7uZgSpkYlhI+PWkgBOYi9Fx+ExUoYwVK/QqpHKgQ9yYe3cfZsEo3xCdYUKs1LpHd22pn7yXT
lmGtHNER3VupGdld0kp0Ej/IGVhQ+jjR/5i3p4FsmY/EMJVYpzsVk1H15Yw9pvMGQKUzLTSBXKlj
+d8HuQS8qOFhMxxaTyViryqgZIFvVVf24SvitMzkBiFGyQSwVHLSCJuoRKiKh80lalYaCDnDwv/m
2Eg=
=/2om
-----END PGP SIGNATURE-----