.SH "THE LOOP DEVICE"
One further possible type is a mount via the loop device. For example,
the command
-
-.nf
-.B " mount /tmp/fdimage /mnt -t vfat -o loop=/dev/loop3
-.fi
-
+.RS
+.sp
+.B "mount /tmp/disk.img /mnt -t vfat -o loop=/dev/loop"
+.sp
+.RE
will set up the loop device
.I /dev/loop3
to correspond to the file
-.IR /tmp/fdimage ,
+.IR /tmp/disk.img ,
and then mount this device on
.IR /mnt .
+If no explicit loop device is mentioned
+(but just an option `\fB\-o loop\fP' is given), then
+.B mount
+will try to find some unused loop device and use that, for example
+.RS
+.sp
+.B "mount /tmp/disk.img /mnt -o loop"
+.sp
+.RE
+The mount command
+.B automatically
+creates a loop device from a regular file if a filesystem type is
+not specified, for example:
+.RS
+.sp
+.B "mount /tmp/disk.img /mnt"
+.sp
+.RE
+
This type of mount knows about four options, namely
.BR loop ", " offset ", " sizelimit " and " encryption ,
that are really options to
(These options can be used in addition to those specific
to the filesystem type.)
-If no explicit loop device is mentioned
-(but just an option `\fB\-o loop\fP' is given), then
-.B mount
-will try to find some unused loop device and use that.
-
Since Linux 2.6.25 is supported auto-destruction of loop devices and
then any loop device allocated by
.B mount
*loop = ((*flags & MS_LOOP) || *loopdev || opt_offset || opt_sizelimit || opt_encryption);
*loopfile = *spec;
+ /* Automatically create a loop device from a regular file if a filesystem
+ * is not specified.
+ *
+ * Note that there is not a restriction (on kernel side) that prevents regular
+ * file as a mount(2) source argument. A filesystem that is able to mount
+ * regular files could be implemented.
+ *
+ * If the filesystem type is specified than "-o loop" is required to create a
+ * loop device.
+ */
+ if (!*loop && (!*type || strcmp(*type, "auto") == 0)) {
+ struct stat st;
+ if (stat(*loopfile, &st) == 0)
+ *loop = S_ISREG(st.st_mode);
+ }
+
if (*loop) {
*flags |= MS_LOOP;
if (fake) {