Invert the default position, so that directory becomes the lower layer and uniondir becomes the upper layer. However, uniondir remains the mount point.
Options are specified with a -o flag followed by a comma separated string of options. See the mount(8) man page for possible options and their meanings.
Hide the lower layer completely in the same way as mounting with mount_nullfs(8).
To enforce file system security, the user mounting the file system must be superuser or else have write permission on the mounted-on directory. In addition, the vfs.usermountsysctl(8) variable must be set to 1 to permit file system mounting by ordinary users.
Filenames are looked up in the upper layer and then in the lower layer. If a directory is found in the lower layer, and there is no entry in the upper layer, then a shadow directory will be created in the upper layer. It will be owned by the user who originally did the union mount, with mode "rwxrwxrwx" (0777) modified by the umask in effect at that time.
If a file exists in the upper layer then there is no way to access a file with the same name in the lower layer. If necessary, a combination of loopback and union mounts can be made which will still allow the lower files to be accessed by a different pathname.
Except in the case of a directory, access to an object is granted via the normal file system access checks. For directories, the current user must have access to both the upper and lower directories (should they both exist).
Requests to create or modify objects in uniondir are passed to the upper layer with the exception of a few special cases. An attempt to open for writing a file which exists in the lower layer causes a copy of the entire file to be made to the upper layer, and then for the upper layer copy to be opened. Similarly, an attempt to truncate a lower layer file to zero length causes an empty file to be created in the upper layer. Any other operation which would ultimately require modification to the lower layer fails with EROFS.
The union file system manipulates the namespace, rather than individual file systems. The union operation applies recursively down the directory tree now rooted at uniondir. Thus any file systems which are mounted under uniondir will take part in the union operation. This differs from the union option to mount(8) which only applies the union operation to the mount point itself, and then only for lookups.