xref: /titanic_51/usr/src/uts/common/sys/fs/dv_node.h (revision f95bda13672da09ae973b76683e47b094188903a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_DV_NODE_H
28 #define	_SYS_DV_NODE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * dv_nodes are the file-system specific part of the
34  * vnodes for the device filesystem.
35  *
36  * The device filesystem exports two node types:
37  *
38  * VDIR	nodes		to represent nexus drivers
39  * VCHR & VBLK nodes	to represent devices
40  */
41 
42 #include <sys/dirent.h>
43 #include <sys/sunddi.h>
44 #include <sys/devops.h>
45 #include <sys/ddi_impldefs.h>
46 #include <sys/devpolicy.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 #ifdef _KERNEL
53 
54 /*
55  * Here's the focal point of this filesystem
56  */
57 typedef struct dv_node {
58 	char		*dv_name;	/* pointer to name */
59 	size_t		dv_namelen;	/* strlen(dv_name) */
60 
61 	struct vnode	*dv_vnode;	/* vnode for this dv_node */
62 
63 	/*
64 	 * The dv_contents lock should be held (read) before looking at
65 	 * any of the fields below, and held (write) before modifying them.
66 	 */
67 	krwlock_t	dv_contents;	/* held while anything is changing */
68 
69 	dev_info_t	*dv_devi;	/* VDIR: underlying devinfo node */
70 					/* has ndi_devi_hold on device */
71 
72 	struct dv_node	*dv_dotdot;	/* parent: my parent dv_node */
73 	struct dv_node	*dv_dot;	/* child: VDIR: head of children */
74 	struct dv_node	*dv_next;	/* sibling: next in this directory */
75 
76 	struct vnode	*dv_attrvp;	/* persistent attribute store */
77 	struct vattr	*dv_attr;	/* attributes not yet persistent */
78 
79 	ino64_t		dv_ino;		/* fake inode */
80 	int		dv_flags;	/* state bits and stuff */
81 	uint_t		dv_nlink;	/* link count */
82 	uint_t		dv_busy;	/* directory busy count */
83 	devplcy_t	*dv_priv;	/* access privilege */
84 	mode_t		dv_dflt_mode;	/* create_priv_minor_node mode */
85 } dvnode_t;
86 
87 #define	DV_BUILD	0x1		/* directory out-of-date */
88 #define	DV_NO_FSPERM	0x2		/* ignore fs permissions */
89 #define	DV_INTERNAL	0x04		/* internal node */
90 #define	DV_ACL		0x08		/* node has acl */
91 #define	DV_DFLT_MODE	0x010		/* dv_dflt_mode set */
92 
93 #define	DV_ROOTINO	((ino_t)2)	/* root inode no. for devfs */
94 
95 #define	DVTOV(n)	((struct vnode *)(n)->dv_vnode)
96 #define	VTODV(vp)	((struct dv_node *)(vp)->v_data)
97 #define	DV_STALE(dv)	(dv->dv_devi == NULL)
98 
99 #define	DV_UID_DEFAULT	0	/* default uid for devs and dirs */
100 #define	DV_GID_DEFAULT	3	/* default gid for devs and dirs */
101 #define	DV_DIRMODE_DEFAULT	(S_IFDIR | 0755)	/* directories */
102 #define	DV_DEVMODE_DEFAULT	(0600)			/* special files */
103 #define	DV_DEVMODE_PRIV		(0666)		/* priv based access only */
104 
105 /* flags for devfs_clean() */
106 #define	DV_CLEAN_FORCE	0x01	/* force clean of refed directories */
107 #define	DV_RESET_PERM	0x02	/* force resetting of node permission */
108 #define	DV_CLEANDIR_LCK	0x04	/* dv_contents already held */
109 
110 struct devfs_data {
111 	struct	dv_node	*devfs_root;
112 	struct	vfs	*devfs_vfsp;
113 };
114 
115 #define	VFSTODVFS(vfsp)	((struct devfs_data *)((vfsp)->vfs_data))
116 
117 /* dv_fid overlays the fid structure (for VFS_VGET) */
118 struct dv_fid {
119 	uint16_t	dvfid_len;
120 	ino32_t		dvfid_ino;
121 	int32_t		dvfid_gen;
122 };
123 
124 /*
125  * Compare a vattr's and mperm_t's minor permissions (uid, gid & mode)
126  */
127 #define	VATTRP_MP_CMP(attrp, mp)				\
128 	(!((attrp->va_uid == mp.mp_uid) &&			\
129 	(attrp->va_gid == mp.mp_gid) &&				\
130 	((attrp->va_mode & S_IAMB) == (mp.mp_mode & S_IAMB))))
131 
132 /*
133  * Merge an mperm_t's minor permissions into a vattr
134  */
135 #define	VATTR_MP_MERGE(attr, mp)				\
136 	attr.va_uid = mp.mp_uid;				\
137 	attr.va_gid = mp.mp_gid;				\
138 	attr.va_mode = 						\
139 	    (attr.va_mode & ~S_IAMB) | (mp.mp_mode & S_IAMB);
140 
141 #define	VATTRP_MP_MERGE(attrp, mp)				\
142 	attrp->va_uid = mp.mp_uid;				\
143 	attrp->va_gid = mp.mp_gid;				\
144 	attrp->va_mode = 					\
145 	    (attrp->va_mode & ~S_IAMB) | (mp.mp_mode & S_IAMB);
146 
147 /*
148  * dv_shadow_node flags
149  */
150 #define	DV_SHADOW_CREATE	0x01		/* create attribute node */
151 #define	DV_SHADOW_WRITE_HELD	0x02		/* dv_contents write held */
152 
153 
154 extern uint_t devfs_clean_key;	/* tsd key */
155 extern const char dvnm[];	/* share some space.. */
156 extern struct dv_node *dvroot;	/* devfs root node */
157 
158 extern void dv_node_cache_init(void);
159 extern void dv_node_cache_fini(void);
160 extern struct dv_node *dv_mkdir(struct dv_node *, dev_info_t *, char *);
161 extern struct dv_node *dv_mkroot(struct vfs *, dev_t);
162 extern void dv_destroy(struct dv_node *, uint_t);
163 extern struct dv_node *dv_findbyname(struct dv_node *, char *);
164 extern void dv_insert(struct dv_node *, struct dv_node *);
165 extern void dv_shadow_node(struct vnode *, char *nm, struct vnode *,
166     struct pathname *, struct vnode *, struct cred *, int);
167 extern int dv_find(struct dv_node *, char *, struct vnode **,
168     struct pathname *, struct vnode *, struct cred *, uint_t);
169 extern void dv_filldir(struct dv_node *);
170 extern int dv_cleandir(struct dv_node *, char *, uint_t);
171 extern void dv_vattr_merge(struct dv_node *, struct vattr *);
172 extern void dv_walk(struct dv_node *, char *,
173     void (*f)(struct dv_node *, void *), void *);
174 
175 extern int devfs_clean(dev_info_t *, char *, uint_t);
176 extern int devfs_lookupname(char *, vnode_t **, vnode_t **);
177 extern int devfs_walk(char *, void (*f)(struct dv_node *, void *), void *);
178 extern int devfs_devpolicy(vnode_t *, devplcy_t **);
179 
180 extern struct dv_node *devfs_dip_to_dvnode(dev_info_t *);
181 extern int devfs_reset_perm(uint_t);
182 extern int devfs_remdrv_cleanup(const char *, const char *);
183 
184 extern struct vnodeops *dv_vnodeops;
185 extern const struct fs_operation_def dv_vnodeops_template[];
186 
187 
188 #ifdef DEBUG
189 extern int devfs_debug;
190 #define	DV_DEBUG	0x01
191 #define	DV_DEBUG2	0x02
192 #define	DV_DEBUG3	0x04
193 #define	DV_DEBUG4	0x08
194 #define	DV_DEBUG5	0x10
195 #define	DV_SYSERR	0x1000
196 #define	DV_SYSTRACE	0x2000
197 #define	dcmn_err(args) if (devfs_debug & DV_DEBUG) printf args
198 #define	dcmn_err2(args) if (devfs_debug & DV_DEBUG2) printf args
199 #define	dcmn_err3(args) if (devfs_debug & DV_DEBUG3) printf args
200 #define	dcmn_err4(args) if (devfs_debug & DV_DEBUG4) printf args
201 #define	dcmn_err5(args) if (devfs_debug & DV_DEBUG5) printf args
202 
203 #define	dsysdebug(err, args)				\
204 	if ((err && (devfs_debug & DV_SYSERR)) ||	\
205 	    (devfs_debug & DV_SYSTRACE)) printf args
206 #else
207 #define	dcmn_err(args) /* nothing */
208 #define	dcmn_err2(args) /* nothing */
209 #define	dcmn_err3(args) /* nothing */
210 #define	dcmn_err4(args) /* nothing */
211 #define	dcmn_err5(args) /* nothing */
212 #define	dsysdebug(err, args) /* nothing */
213 #endif
214 
215 
216 #endif	/* _KERNEL */
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif	/* _SYS_DV_NODE_H */
223