There's another aspect here - you want to ensure exclusive access to the "real" file system, even from the perspective of PEBCAK-type behaviors, since modifications made directly to the "real" file system could corrupt the filtered one.
So it turns out this is well possible in Linux. The sequence of operations is something like -
mkdir("/tmp/target"); mount("source", "/tmp/target", "ext4", 0, ""); dir = opendir("/tmp/target"); /* open so the umount2 defers */ fd = dirfd(dir); umount2("/tmp/target", MNT_DETACH); rmdir("/tmp/target"); /* fine too */ ... /* do stuff in hidden mounted fs through fd */ closedir(dir); /* finally unmounted on close */ ...In fact, after the MNT_DETACH (deemed a "lazy" umount) you can well rmdir(2) the mount point away (or mount something else on it). Very useful. If you're wondering how you can perform file and directory operations without having a named path, then openat(2) and related are your friends :-).
No comments:
Post a Comment