xref: /original-bsd/sys/miscfs/union/union.h (revision 4bd8a01e)
1 /*
2  * Copyright (c) 1994 The Regents of the University of California.
3  * Copyright (c) 1994 Jan-Simon Pendry.
4  * All rights reserved.
5  *
6  * This code is derived from software donated to Berkeley by
7  * Jan-Simon Pendry.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)union.h	8.5 (Berkeley) 05/17/94
12  */
13 
14 struct union_args {
15 	char		*target;	/* Target of loopback  */
16 	int		mntflags;	/* Options on the mount */
17 };
18 
19 #define UNMNT_ABOVE	0x0001		/* Target appears below mount point */
20 #define UNMNT_BELOW	0x0002		/* Target appears below mount point */
21 #define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
22 #define UNMNT_OPMASK	0x0003
23 
24 struct union_mount {
25 	struct vnode	*um_uppervp;
26 	struct vnode	*um_lowervp;
27 	struct ucred	*um_cred;	/* Credentials of user calling mount */
28 	int		um_cmode;	/* cmask from mount process */
29 	int		um_op;		/* Operation mode */
30 };
31 
32 #ifdef KERNEL
33 
34 /*
35  * DEFDIRMODE is the mode bits used to create a shadow directory.
36  */
37 #define VRWXMODE (VREAD|VWRITE|VEXEC)
38 #define VRWMODE (VREAD|VWRITE)
39 #define UN_DIRMODE ((VRWXMODE)|(VRWXMODE>>3)|(VRWXMODE>>6))
40 #define UN_FILEMODE ((VRWMODE)|(VRWMODE>>3)|(VRWMODE>>6))
41 
42 /*
43  * A cache of vnode references
44  */
45 struct union_node {
46 	LIST_ENTRY(union_node)	un_cache;	/* Hash chain */
47 	struct vnode		*un_vnode;	/* Back pointer */
48 	struct vnode	        *un_uppervp;	/* overlaying object */
49 	struct vnode	        *un_lowervp;	/* underlying object */
50 	struct vnode		*un_dirvp;	/* Parent dir of uppervp */
51 	char			*un_path;	/* saved component name */
52 	int			un_hash;	/* saved un_path hash value */
53 	int			un_openl;	/* # of opens on lowervp */
54 	unsigned int		un_flags;
55 	off_t			un_uppersz;	/* size of upper object */
56 	off_t			un_lowersz;	/* size of lower object */
57 #ifdef DIAGNOSTIC
58 	pid_t			un_pid;
59 #endif
60 };
61 
62 #define UN_WANT		0x01
63 #define UN_LOCKED	0x02
64 #define UN_ULOCK	0x04		/* Upper node is locked */
65 #define UN_KLOCK	0x08		/* Keep upper node locked on vput */
66 #define UN_CACHED	0x10		/* In union cache */
67 
68 extern int union_allocvp __P((struct vnode **, struct mount *,
69 				struct vnode *, struct vnode *,
70 				struct componentname *, struct vnode *,
71 				struct vnode *));
72 extern int union_copyfile __P((struct vnode *, struct vnode *,
73 					struct ucred *, struct proc *));
74 extern int union_copyup __P((struct union_node *, int, struct ucred *,
75 				struct proc *));
76 extern int union_mkshadow __P((struct union_mount *, struct vnode *,
77 				struct componentname *, struct vnode **));
78 extern int union_vn_create __P((struct vnode **, struct union_node *,
79 				struct proc *));
80 extern int union_cn_close __P((struct vnode *, int, struct ucred *,
81 				struct proc *));
82 extern void union_removed_upper __P((struct union_node *un));
83 extern struct vnode *union_lowervp __P((struct vnode *));
84 extern void union_newlower __P((struct union_node *, struct vnode *));
85 extern void union_newupper __P((struct union_node *, struct vnode *));
86 extern void union_newsize __P((struct vnode *, off_t, off_t));
87 
88 #define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
89 #define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
90 #define	UNIONTOV(un) ((un)->un_vnode)
91 #define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
92 #define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
93 #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
94 
95 extern int (**union_vnodeop_p)();
96 extern struct vfsops union_vfsops;
97 #endif /* KERNEL */
98