* Copyright (c) 1994 The Regents of the University of California.
* Copyright (c) 1994 Jan-Simon Pendry.
* This code is derived from software donated to Berkeley by
* %sccs.include.redist.c%
* @(#)union_vfsops.c 2.1 (Berkeley) %G%
#include <sys/filedesc.h>
union_mount(mp
, path
, data
, ndp
, p
)
struct vnode
*lowerrootvp
= NULLVP
;
struct vnode
*upperrootvp
= NULLVP
;
printf("union_mount(mp = %x)\n", mp
);
if (mp
->mnt_flag
& MNT_UPDATE
) {
* 1. a way to convert between rdonly and rdwr mounts.
* 2. support for nfs exports.
* Take a copy of the process's credentials. This isn't
* quite right since the euid will always be zero and we
* want to get the "real" users credentials. So fix up
* the uid field after taking the copy.
cred
= crdup(p
->p_ucred
);
cred
->cr_uid
= p
->p_cred
->p_ruid
;
* Ensure the *real* user has write permission on the
* mounted-on directory. This allows the mount_union
* command to be made setuid root so allowing anyone
* to do union mounts onto any directory on which they
error
= VOP_ACCESS(mp
->mnt_vnodecovered
, VWRITE
, cred
, p
);
if (error
= copyin(data
, (caddr_t
)&args
, sizeof(struct union_args
)))
lowerrootvp
= mp
->mnt_vnodecovered
;
NDINIT(ndp
, LOOKUP
, FOLLOW
|WANTPARENT
,
UIO_USERSPACE
, args
.target
, p
);
upperrootvp
= ndp
->ni_vp
;
if (upperrootvp
->v_type
!= VDIR
) {
um
= (struct union_mount
*) malloc(sizeof(struct union_mount
),
M_UFSMNT
, M_WAITOK
); /* XXX */
* Keep a held reference to the target vnodes.
* They are vrele'd in union_unmount.
* Depending on the _BELOW flag, the filesystems are
* viewed in a different order. In effect, this is the
* same as providing a mount under option to the mount syscall.
switch (args
.mntflags
& UNMNT_OPMASK
) {
um
->um_lowervp
= lowerrootvp
;
um
->um_uppervp
= upperrootvp
;
um
->um_lowervp
= upperrootvp
;
um
->um_uppervp
= lowerrootvp
;
um
->um_uppervp
= upperrootvp
;
um
->um_lowervp
= lowerrootvp
;
um
->um_cmode
= UN_DIRMODE
&~ p
->p_fd
->fd_cmask
;
* Depending on what you think the MNT_LOCAL flag might mean,
* you may want the && to be || on the conditional below.
* At the moment it has been defined that the filesystem is
* only local if it is all local, ie the MNT_LOCAL flag implies
* that the entire namespace is local. If you think the MNT_LOCAL
* flag implies that some of the files might be stored locally
* then you will want to change the conditional.
if (((um
->um_lowervp
== NULLVP
) ||
(um
->um_lowervp
->v_mount
->mnt_flag
& MNT_LOCAL
)) &&
(um
->um_uppervp
->v_mount
->mnt_flag
& MNT_LOCAL
))
mp
->mnt_flag
|= MNT_LOCAL
;
* Copy in the upper layer's RDONLY flag. This is for the benefit
* of lookup() which explicitly checks the flag, rather than asking
* the filesystem for it's own opinion. This means, that an update
* mount of the underlying filesystem to go from rdonly to rdwr
* will leave the unioned view as read-only.
mp
->mnt_flag
|= (um
->um_uppervp
->v_mount
->mnt_flag
& MNT_RDONLY
);
mp
->mnt_data
= (qaddr_t
) um
;
getnewfsid(mp
, MOUNT_UNION
);
(void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
switch (args
.mntflags
& UNMNT_OPMASK
) {
bcopy(cp
, mp
->mnt_stat
.f_mntfromname
, len
);
cp
= mp
->mnt_stat
.f_mntfromname
+ len
;
(void) copyinstr(args
.target
, cp
, len
- 1, &size
);
bzero(cp
+ size
, len
- size
);
printf("union_mount: from %s, on %s\n",
mp
->mnt_stat
.f_mntfromname
, mp
->mnt_stat
.f_mntonname
);
* VFS start. Nothing needed here - the start routine
* on the underlying filesystem(s) will have been called
* when that filesystem was mounted.
union_start(mp
, flags
, p
)
* Free reference to union layer
union_unmount(mp
, mntflags
, p
)
struct union_mount
*um
= MOUNTTOUNIONMOUNT(mp
);
printf("union_unmount(mp = %x)\n", mp
);
if (mntflags
& MNT_FORCE
) {
/* union can never be rootfs so don't check for it */
if (error
= union_root(mp
, &um_rootvp
))
if (um_rootvp
->v_usecount
> 1) {
if (error
= vflush(mp
, um_rootvp
, flags
)) {
vprint("alias root of lower", um_rootvp
);
* Discard references to upper and lower target vnodes.
* Release reference on underlying root vnode
* And blow it away for future re-use
* Finally, throw away the union_mount structure
free(mp
->mnt_data
, M_UFSMNT
); /* XXX */
struct union_mount
*um
= MOUNTTOUNIONMOUNT(mp
);
printf("union_root(mp = %x, lvp = %x, uvp = %x)\n", mp
,
* Return locked reference to root.
VOP_LOCK(um
->um_uppervp
);
error
= union_allocvp(vpp
, mp
,
(struct componentname
*) 0,
union_quotactl(mp
, cmd
, uid
, arg
, p
)
struct union_mount
*um
= MOUNTTOUNIONMOUNT(mp
);
printf("union_statfs(mp = %x, lvp = %x, uvp = %x)\n", mp
,
bzero(&mstat
, sizeof(mstat
));
error
= VFS_STATFS(um
->um_lowervp
->v_mount
, &mstat
, p
);
/* now copy across the "interesting" information and fake the rest */
sbp
->f_type
= mstat
.f_type
;
sbp
->f_flags
= mstat
.f_flags
;
sbp
->f_bsize
= mstat
.f_bsize
;
sbp
->f_iosize
= mstat
.f_iosize
;
sbp
->f_blocks
= mstat
.f_blocks
;
sbp
->f_bfree
= mstat
.f_bfree
;
sbp
->f_bavail
= mstat
.f_bavail
;
sbp
->f_files
= mstat
.f_files
;
sbp
->f_ffree
= mstat
.f_ffree
;
error
= VFS_STATFS(um
->um_uppervp
->v_mount
, &mstat
, p
);
sbp
->f_type
= mstat
.f_type
;
sbp
->f_flags
= mstat
.f_flags
;
sbp
->f_bsize
= mstat
.f_bsize
;
sbp
->f_iosize
= mstat
.f_iosize
;
* if the lower and upper blocksizes differ, then frig the
* block counts so that the sizes reported by df make some
* kind of sense. none of this makes sense though.
if (mstat
.f_bsize
!= lbsize
) {
sbp
->f_blocks
= sbp
->f_blocks
* lbsize
/ mstat
.f_bsize
;
sbp
->f_bfree
= sbp
->f_bfree
* lbsize
/ mstat
.f_bsize
;
sbp
->f_bavail
= sbp
->f_bavail
* lbsize
/ mstat
.f_bsize
;
sbp
->f_blocks
+= mstat
.f_blocks
;
sbp
->f_bfree
+= mstat
.f_bfree
;
sbp
->f_bavail
+= mstat
.f_bavail
;
sbp
->f_files
+= mstat
.f_files
;
sbp
->f_ffree
+= mstat
.f_ffree
;
if (sbp
!= &mp
->mnt_stat
) {
bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
union_sync(mp
, waitfor
, cred
, p
)
* XXX - Assumes no data cached at union layer.
union_fhtovp(mp
, fidp
, nam
, vpp
, exflagsp
, credanonp
)
struct ucred
**credanonp
;
int union_init
__P((void));
struct vfsops union_vfsops
= {