How Mounting Works
Block devices differ from char devices and normal files in that
they can be mounted on the computer’s filesystem. This is different
from the normal access through a struct file, where the
structure is bound to a specific process and exists only from
open to close. When a filesystem is mounted,
there’s no process holding a filp.
When the kernel mounts a device in the filesystem, it invokes
the normal open method to access the driver. However, in
this case the filp argument to open is a
dummy variable, almost a placeholder, whose only meaningful field is
f_mode. The remaining fields hold random values and should
not be used. The value of f_mode tells the driver whether
the device is to be mounted read-only (f_mode == FMODE_READ) or read/write (f_mode == (FMODE_READ|FMODE_WRITE)). A dummy variable is used instead of a
file structure because a real struct file
would be released at process termination, while a mounted filesystem
survives after the mount command has done its job.
At mount time, the only thing that is invoked in the driver is the
open method. While
the disk is mounted, the kernel invokes the read and write
methods in the device (which map to request_fn) to manage files
in the filesystem. The driver can’t tell if request_fn is
servicing a process (like fsck) or the filesystem layer of the
kernel.
As far as umount is concerned, it just flushes the buffer
cache and calls the release (close) driver method. Since
there is no meaningful filp to pass to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access