Solved how does mount automagically remember permissions/ownership

I'm mounting a file as a filesystem (via mdconfig and mount) and struggling to understand how "mount" remembers permission.
Before I mount the file, the mount point is owned by my user john:john

First time I mount the file it is owned by root/wheel: drwxr-xr-x 3 root wheel 512 Mar 23 12:55 mnt

I can changed ownership of the mount point: sudo chown -R john:john ./mnt
Everything is cool I could read/write the the the filesystem.

When I unmounted and re-mount the filesystem. Ownership remained with john:john.
I was expecting it would reset to root:wheel.

How does "mount" remember the permissons/ownerhips of previously mount filesystems??
 
Really simple: The same permission/ownership mechanism that applies to all directories and files (and everything else stored in the file system).

Before you mount, there exists a directory called /mnt. It is stored in some file system, probably your root file system. That directory, like anything else stored in the root file system, has ownership stored in its metadata, which is part of the root file system.

Then you mount a second file system. The thing that is now visible as the directory /mnt is actually the root directory "/" of the second file system. Like all file system objects, the root directory of the second file system has ownership stored in the metadata of the second file system.

When you chown (or chmod) the thing visible at /mnt after mounting, you are changing the root object of the second file system; and like all ownership/permission/metadata changes, that is updated and hardened (stored permanently or persistently) in the second file system. The following unmount and remount doesn't change that fact.

All very simple and logical. That's a general design principle of Unix: It was written as the quickest possible hack to get a research operating system going at Bell labs. The original authors didn't add any complexity that was not needed to do their research. A lot of these "keep it as simple as possible" decisions still survive to this day, about 50 years later.
 
Really simple: The same permission/ownership mechanism that applies to all directories and files (and everything else stored in the file system).

Before you mount, there exists a directory called /mnt. It is stored in some file system, probably your root file system. That directory, like anything else stored in the root file system, has ownership stored in its metadata, which is part of the root file system.

Then you mount a second file system. The thing that is now visible as the directory /mnt is actually the root directory "/" of the second file system. Like all file system objects, the root directory of the second file system has ownership stored in the metadata of the second file system.

When you chown (or chmod) the thing visible at /mnt after mounting, you are changing the root object of the second file system; and like all ownership/permission/metadata changes, that is updated and hardened (stored permanently or persistently) in the second file system. The following unmount and remount doesn't change that fact.

All very simple and logical. That's a general design principle of Unix: It was written as the quickest possible hack to get a research operating system going at Bell labs. The original authors didn't add any complexity that was not needed to do their research. A lot of these "keep it as simple as possible" decisions still survive to this day, about 50 years later.
Thank you for the answer. Metadata within file systems is not something I have spend a lot of time with.
Another rabbit hole to look into :)
 
A lot of these "keep it as simple as possible" decisions still survive to this day, about 50 years later.
appending:
Those come from a systematic, so independent, so timeless, so fundamental engineering principle, so also core Unix philosophy:

"Everything shall be made as complex as needed, but as simple as possible."

Or, as Antoine de Saint-Exupéry put it:
"In anything at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away."

When you think about:
It's a fundamental law of nature the larger, the more complicated, and especially the more complex something becomes the more issues it causes. So as long as something works it makes no reasonable sense to complicate it more as it just needs to be.
 
Back
Top