xref: /titanic_52/usr/src/uts/common/sys/fs/namenode.h (revision 4201a95e0468170d576f82c3aa63afecf718497a)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22 /*	  All Rights Reserved  	*/
23 
24 /*
25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef	_SYS_FS_NAMENODE_H
30 #define	_SYS_FS_NAMENODE_H
31 
32 #if defined(_KERNEL)
33 #include <sys/vnode.h>
34 #include <sys/vfs_opreg.h>
35 #endif
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * This structure is used to pass a file descriptor from user
43  * level to the kernel. It is first used by fattach() and then
44  * be NAMEFS.
45  */
46 struct namefd {
47 	int fd;
48 };
49 
50 #if defined(_KERNEL)
51 /*
52  * Each NAMEFS object is identified by a struct namenode/vnode pair.
53  */
54 struct namenode {
55 	struct vnode    *nm_vnode;	/* represents mounted file desc. */
56 	int		nm_flag;	/* flags defined below */
57 	struct vattr    nm_vattr;	/* attributes of mounted file desc. */
58 	struct vnode	*nm_filevp;	/* file desc. prior to mounting */
59 	struct file	*nm_filep;	/* file pointer of nm_filevp */
60 	struct vnode	*nm_mountpt;	/* mount point prior to mounting */
61 	struct namenode *nm_nextp;	/* next link in the linked list */
62 	kmutex_t	nm_lock;	/* protects nm_vattr */
63 };
64 
65 /*
66  * Valid flags for namenodes.
67  */
68 #define	NMNMNT		0x01	/* namenode not mounted */
69 
70 /*
71  * Macros to convert a vnode to a namenode, and vice versa.
72  */
73 #define	VTONM(vp) ((struct namenode *)((vp)->v_data))
74 #define	NMTOV(nm) ((nm)->nm_vnode)
75 
76 #define	NM_FILEVP_HASH_SIZE	64
77 #define	NM_FILEVP_HASH_MASK	(NM_FILEVP_HASH_SIZE - 1)
78 #define	NM_FILEVP_HASH_SHIFT	7
79 #define	NM_FILEVP_HASH(vp)	(&nm_filevp_hash[(((uintptr_t)vp) >> \
80 	NM_FILEVP_HASH_SHIFT) & NM_FILEVP_HASH_MASK])
81 
82 extern struct namenode *nm_filevp_hash[NM_FILEVP_HASH_SIZE];
83 extern struct vfs namevfs;
84 
85 extern int nameinit(int, char *);
86 extern int nm_unmountall(struct vnode *, struct cred *);
87 extern void nameinsert(struct namenode *);
88 extern void nameremove(struct namenode *);
89 extern struct namenode *namefind(struct vnode *, struct vnode *);
90 extern uint64_t namenodeno_alloc(void);
91 extern void namenodeno_free(uint64_t);
92 extern struct vnodeops *nm_vnodeops;
93 extern const struct fs_operation_def nm_vnodeops_template[];
94 extern kmutex_t ntable_lock;
95 
96 #endif /* _KERNEL */
97 
98 #ifdef	__cplusplus
99 }
100 #endif
101 
102 #endif	/* _SYS_FS_NAMENODE_H */
103