xref: /titanic_52/usr/src/uts/common/sys/fs/dv_node.h (revision 3c5e027b0f15017d4b6afff01915ea70ae476223)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5facf4a8dSllai1  * Common Development and Distribution License (the "License").
6facf4a8dSllai1  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_DV_NODE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_DV_NODE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * dv_nodes are the file-system specific part of the
317c478bd9Sstevel@tonic-gate  * vnodes for the device filesystem.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * The device filesystem exports two node types:
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * VDIR	nodes		to represent nexus drivers
367c478bd9Sstevel@tonic-gate  * VCHR & VBLK nodes	to represent devices
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/dirent.h>
407c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
417c478bd9Sstevel@tonic-gate #include <sys/devops.h>
427c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
43*3c5e027bSEric Taylor #include <sys/fs/sdev_impl.h>
447c478bd9Sstevel@tonic-gate #include <sys/devpolicy.h>
45aac43a5fSjg #include <sys/avl.h>
467c478bd9Sstevel@tonic-gate 
47d67944fbSScott Rotondo #ifdef _KERNEL
48d67944fbSScott Rotondo #include <sys/vfs_opreg.h>
49d67944fbSScott Rotondo #endif
50d67944fbSScott Rotondo 
517c478bd9Sstevel@tonic-gate #ifdef __cplusplus
527c478bd9Sstevel@tonic-gate extern "C" {
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifdef _KERNEL
567c478bd9Sstevel@tonic-gate 
57d67944fbSScott Rotondo 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * Here's the focal point of this filesystem
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate typedef struct dv_node {
627c478bd9Sstevel@tonic-gate 	char		*dv_name;	/* pointer to name */
637c478bd9Sstevel@tonic-gate 	size_t		dv_namelen;	/* strlen(dv_name) */
647c478bd9Sstevel@tonic-gate 	struct vnode	*dv_vnode;	/* vnode for this dv_node */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/*
677c478bd9Sstevel@tonic-gate 	 * The dv_contents lock should be held (read) before looking at
687c478bd9Sstevel@tonic-gate 	 * any of the fields below, and held (write) before modifying them.
697c478bd9Sstevel@tonic-gate 	 */
707c478bd9Sstevel@tonic-gate 	krwlock_t	dv_contents;	/* held while anything is changing */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	dev_info_t	*dv_devi;	/* VDIR: underlying devinfo node */
737c478bd9Sstevel@tonic-gate 					/* has ndi_devi_hold on device */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	struct dv_node	*dv_dotdot;	/* parent: my parent dv_node */
76aac43a5fSjg 	avl_tree_t	dv_entries;	/* VDIR: contents as avl tree */
77aac43a5fSjg 	avl_node_t	dv_avllink;	/* avl node linkage */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	struct vnode	*dv_attrvp;	/* persistent attribute store */
807c478bd9Sstevel@tonic-gate 	struct vattr	*dv_attr;	/* attributes not yet persistent */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	ino64_t		dv_ino;		/* fake inode */
837c478bd9Sstevel@tonic-gate 	int		dv_flags;	/* state bits and stuff */
847c478bd9Sstevel@tonic-gate 	uint_t		dv_nlink;	/* link count */
857c478bd9Sstevel@tonic-gate 	uint_t		dv_busy;	/* directory busy count */
867c478bd9Sstevel@tonic-gate 	devplcy_t	*dv_priv;	/* access privilege */
877c478bd9Sstevel@tonic-gate 	mode_t		dv_dflt_mode;	/* create_priv_minor_node mode */
88facf4a8dSllai1 	struct sdev_dv	*dv_sdev;	/* sdev node[s] if exists */
897c478bd9Sstevel@tonic-gate } dvnode_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	DV_BUILD	0x1		/* directory out-of-date */
927c478bd9Sstevel@tonic-gate #define	DV_NO_FSPERM	0x2		/* ignore fs permissions */
937c478bd9Sstevel@tonic-gate #define	DV_INTERNAL	0x04		/* internal node */
947c478bd9Sstevel@tonic-gate #define	DV_ACL		0x08		/* node has acl */
957c478bd9Sstevel@tonic-gate #define	DV_DFLT_MODE	0x010		/* dv_dflt_mode set */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	DV_ROOTINO	((ino_t)2)	/* root inode no. for devfs */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	DVTOV(n)	((struct vnode *)(n)->dv_vnode)
1007c478bd9Sstevel@tonic-gate #define	VTODV(vp)	((struct dv_node *)(vp)->v_data)
1017c478bd9Sstevel@tonic-gate #define	DV_STALE(dv)	(dv->dv_devi == NULL)
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	DV_UID_DEFAULT	0	/* default uid for devs and dirs */
1047c478bd9Sstevel@tonic-gate #define	DV_GID_DEFAULT	3	/* default gid for devs and dirs */
1057c478bd9Sstevel@tonic-gate #define	DV_DIRMODE_DEFAULT	(S_IFDIR | 0755)	/* directories */
1067c478bd9Sstevel@tonic-gate #define	DV_DEVMODE_DEFAULT	(0600)			/* special files */
1077c478bd9Sstevel@tonic-gate #define	DV_DEVMODE_PRIV		(0666)		/* priv based access only */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* flags for devfs_clean() */
1107c478bd9Sstevel@tonic-gate #define	DV_CLEAN_FORCE	0x01	/* force clean of refed directories */
1117c478bd9Sstevel@tonic-gate #define	DV_RESET_PERM	0x02	/* force resetting of node permission */
11245a9d961Scth #define	DV_CLEANDIR_LCK	0x04	/* dv_contents already held */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate struct devfs_data {
1157c478bd9Sstevel@tonic-gate 	struct	dv_node	*devfs_root;
1167c478bd9Sstevel@tonic-gate 	struct	vfs	*devfs_vfsp;
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	VFSTODVFS(vfsp)	((struct devfs_data *)((vfsp)->vfs_data))
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /* dv_fid overlays the fid structure (for VFS_VGET) */
1227c478bd9Sstevel@tonic-gate struct dv_fid {
1237c478bd9Sstevel@tonic-gate 	uint16_t	dvfid_len;
1247c478bd9Sstevel@tonic-gate 	ino32_t		dvfid_ino;
1257c478bd9Sstevel@tonic-gate 	int32_t		dvfid_gen;
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Compare a vattr's and mperm_t's minor permissions (uid, gid & mode)
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	VATTRP_MP_CMP(attrp, mp)				\
1327c478bd9Sstevel@tonic-gate 	(!((attrp->va_uid == mp.mp_uid) &&			\
1337c478bd9Sstevel@tonic-gate 	(attrp->va_gid == mp.mp_gid) &&				\
1347c478bd9Sstevel@tonic-gate 	((attrp->va_mode & S_IAMB) == (mp.mp_mode & S_IAMB))))
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Merge an mperm_t's minor permissions into a vattr
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	VATTR_MP_MERGE(attr, mp)				\
1407c478bd9Sstevel@tonic-gate 	attr.va_uid = mp.mp_uid;				\
1417c478bd9Sstevel@tonic-gate 	attr.va_gid = mp.mp_gid;				\
1427c478bd9Sstevel@tonic-gate 	attr.va_mode = 						\
1437c478bd9Sstevel@tonic-gate 	    (attr.va_mode & ~S_IAMB) | (mp.mp_mode & S_IAMB);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #define	VATTRP_MP_MERGE(attrp, mp)				\
1467c478bd9Sstevel@tonic-gate 	attrp->va_uid = mp.mp_uid;				\
1477c478bd9Sstevel@tonic-gate 	attrp->va_gid = mp.mp_gid;				\
1487c478bd9Sstevel@tonic-gate 	attrp->va_mode = 					\
1497c478bd9Sstevel@tonic-gate 	    (attrp->va_mode & ~S_IAMB) | (mp.mp_mode & S_IAMB);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * dv_shadow_node flags
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate #define	DV_SHADOW_CREATE	0x01		/* create attribute node */
1557c478bd9Sstevel@tonic-gate #define	DV_SHADOW_WRITE_HELD	0x02		/* dv_contents write held */
1567c478bd9Sstevel@tonic-gate 
157aac43a5fSjg /*
158aac43a5fSjg  * Directory tree traversal
159aac43a5fSjg  */
160aac43a5fSjg #define	DV_FIRST_ENTRY(ddv)	avl_first(&(ddv)->dv_entries)
161aac43a5fSjg #define	DV_NEXT_ENTRY(ddv, dv)	AVL_NEXT(&(ddv)->dv_entries, (dv))
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate extern uint_t devfs_clean_key;	/* tsd key */
1647c478bd9Sstevel@tonic-gate extern const char dvnm[];	/* share some space.. */
1657c478bd9Sstevel@tonic-gate extern struct dv_node *dvroot;	/* devfs root node */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate extern void dv_node_cache_init(void);
1687c478bd9Sstevel@tonic-gate extern void dv_node_cache_fini(void);
1697c478bd9Sstevel@tonic-gate extern struct dv_node *dv_mkdir(struct dv_node *, dev_info_t *, char *);
1707c478bd9Sstevel@tonic-gate extern struct dv_node *dv_mkroot(struct vfs *, dev_t);
1717c478bd9Sstevel@tonic-gate extern void dv_destroy(struct dv_node *, uint_t);
1727c478bd9Sstevel@tonic-gate extern void dv_insert(struct dv_node *, struct dv_node *);
1737c478bd9Sstevel@tonic-gate extern void dv_shadow_node(struct vnode *, char *nm, struct vnode *,
1747c478bd9Sstevel@tonic-gate     struct pathname *, struct vnode *, struct cred *, int);
1757c478bd9Sstevel@tonic-gate extern int dv_find(struct dv_node *, char *, struct vnode **,
1767c478bd9Sstevel@tonic-gate     struct pathname *, struct vnode *, struct cred *, uint_t);
1777c478bd9Sstevel@tonic-gate extern void dv_filldir(struct dv_node *);
1787c478bd9Sstevel@tonic-gate extern int dv_cleandir(struct dv_node *, char *, uint_t);
1797c478bd9Sstevel@tonic-gate extern void dv_vattr_merge(struct dv_node *, struct vattr *);
1807c478bd9Sstevel@tonic-gate extern void dv_walk(struct dv_node *, char *,
1817c478bd9Sstevel@tonic-gate     void (*f)(struct dv_node *, void *), void *);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate extern int devfs_clean(dev_info_t *, char *, uint_t);
1847c478bd9Sstevel@tonic-gate extern int devfs_lookupname(char *, vnode_t **, vnode_t **);
1857c478bd9Sstevel@tonic-gate extern int devfs_walk(char *, void (*f)(struct dv_node *, void *), void *);
1867c478bd9Sstevel@tonic-gate extern int devfs_devpolicy(vnode_t *, devplcy_t **);
187facf4a8dSllai1 extern void devfs_get_defattr(vnode_t *, struct vattr *, int *);
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate extern struct dv_node *devfs_dip_to_dvnode(dev_info_t *);
1907c478bd9Sstevel@tonic-gate extern int devfs_reset_perm(uint_t);
1917c478bd9Sstevel@tonic-gate extern int devfs_remdrv_cleanup(const char *, const char *);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate extern struct vnodeops *dv_vnodeops;
1947c478bd9Sstevel@tonic-gate extern const struct fs_operation_def dv_vnodeops_template[];
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #ifdef DEBUG
1987c478bd9Sstevel@tonic-gate extern int devfs_debug;
1997c478bd9Sstevel@tonic-gate #define	DV_DEBUG	0x01
2007c478bd9Sstevel@tonic-gate #define	DV_DEBUG2	0x02
2017c478bd9Sstevel@tonic-gate #define	DV_DEBUG3	0x04
2027c478bd9Sstevel@tonic-gate #define	DV_DEBUG4	0x08
2037c478bd9Sstevel@tonic-gate #define	DV_DEBUG5	0x10
2047c478bd9Sstevel@tonic-gate #define	DV_SYSERR	0x1000
2057c478bd9Sstevel@tonic-gate #define	DV_SYSTRACE	0x2000
2067c478bd9Sstevel@tonic-gate #define	dcmn_err(args) if (devfs_debug & DV_DEBUG) printf args
2077c478bd9Sstevel@tonic-gate #define	dcmn_err2(args) if (devfs_debug & DV_DEBUG2) printf args
2087c478bd9Sstevel@tonic-gate #define	dcmn_err3(args) if (devfs_debug & DV_DEBUG3) printf args
2097c478bd9Sstevel@tonic-gate #define	dcmn_err4(args) if (devfs_debug & DV_DEBUG4) printf args
2107c478bd9Sstevel@tonic-gate #define	dcmn_err5(args) if (devfs_debug & DV_DEBUG5) printf args
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	dsysdebug(err, args)				\
2137c478bd9Sstevel@tonic-gate 	if ((err && (devfs_debug & DV_SYSERR)) ||	\
2147c478bd9Sstevel@tonic-gate 	    (devfs_debug & DV_SYSTRACE)) printf args
2157c478bd9Sstevel@tonic-gate #else
2167c478bd9Sstevel@tonic-gate #define	dcmn_err(args) /* nothing */
2177c478bd9Sstevel@tonic-gate #define	dcmn_err2(args) /* nothing */
2187c478bd9Sstevel@tonic-gate #define	dcmn_err3(args) /* nothing */
2197c478bd9Sstevel@tonic-gate #define	dcmn_err4(args) /* nothing */
2207c478bd9Sstevel@tonic-gate #define	dcmn_err5(args) /* nothing */
2217c478bd9Sstevel@tonic-gate #define	dsysdebug(err, args) /* nothing */
2227c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate #endif
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate #endif	/* _SYS_DV_NODE_H */
232