This question already has an answer here:
- What is a “loop device” when mounting? 3 answers
I was reading Trouble with understanding the concept of mounting and came across this explanation:
mount -t iso9660 /dev/cdrom /media/cdrom, you tell the system: "take this very long string of bytes that you have in
/dev/cdrom, interpret it as a directory tree in the
iso9660format, and allow me to access it under the location
and other answers along this line. This makes sense and from this logic, I understood that mounting essentially couples a filesystem to a device which interprets the contents of the device in a way that the kernel can fit it into the existing filesystem hierarchy.
If this is indeed the case, why is a loop mount needed?
mount -o loop is technically identical to the operation
mount is meant to do: read a file and interpret its content in the context of a filesystem, why can we not generalize the mount operation without creating a special device?
Edit: I understand that a loop device provides a block-device API to a file. My question is, however, more general. How is reading from a regular file (
iso or similar disk image formats) different from reading from a special file, if they contain the same data?
My mental model of how
mount works is this: given an arbitrary set of bytes exposed by a
/dev/device file which are consequently interpreted by a filesystem driver (
ext4, for example), the
mount command associates it with the root hierarchy so that it appears transparent to the end user.
However, this arbitrary set of bytes can occur anywhere. If interpreted by a filesystem driver they should be recognized as a valid filesystem. What constrains a filesystem driver to read only from a special file and not a regular file?