xref: /titanic_52/usr/src/uts/common/sys/fs/namenode.h (revision 9512fe850e98fdd448c638ca63fdd92a8a510255)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 /*
26  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef	_SYS_FS_NAMENODE_H
31 #define	_SYS_FS_NAMENODE_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.4	*/
34 
35 #if defined(_KERNEL)
36 #include <sys/vnode.h>
37 #endif
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * This structure is used to pass a file descriptor from user
45  * level to the kernel. It is first used by fattach() and then
46  * be NAMEFS.
47  */
48 struct namefd {
49 	int fd;
50 };
51 
52 #if defined(_KERNEL)
53 /*
54  * Each NAMEFS object is identified by a struct namenode/vnode pair.
55  */
56 struct namenode {
57 	struct vnode    *nm_vnode;	/* represents mounted file desc. */
58 	int		nm_flag;	/* flags defined below */
59 	struct vattr    nm_vattr;	/* attributes of mounted file desc. */
60 	struct vnode	*nm_filevp;	/* file desc. prior to mounting */
61 	struct file	*nm_filep;	/* file pointer of nm_filevp */
62 	struct vnode	*nm_mountpt;	/* mount point prior to mounting */
63 	struct namenode *nm_nextp;	/* next link in the linked list */
64 	kmutex_t	nm_lock;	/* protects nm_vattr */
65 };
66 
67 /*
68  * Valid flags for namenodes.
69  */
70 #define	NMNMNT		0x01	/* namenode not mounted */
71 
72 /*
73  * Macros to convert a vnode to a namenode, and vice versa.
74  */
75 #define	VTONM(vp) ((struct namenode *)((vp)->v_data))
76 #define	NMTOV(nm) ((nm)->nm_vnode)
77 
78 #define	NM_FILEVP_HASH_SIZE	64
79 #define	NM_FILEVP_HASH_MASK	(NM_FILEVP_HASH_SIZE - 1)
80 #define	NM_FILEVP_HASH_SHIFT	7
81 #define	NM_FILEVP_HASH(vp)	(&nm_filevp_hash[(((uintptr_t)vp) >> \
82 	NM_FILEVP_HASH_SHIFT) & NM_FILEVP_HASH_MASK])
83 
84 extern struct namenode *nm_filevp_hash[NM_FILEVP_HASH_SIZE];
85 extern struct vfs namevfs;
86 
87 extern int nameinit(int, char *);
88 extern int nm_unmountall(struct vnode *, struct cred *);
89 extern void nameinsert(struct namenode *);
90 extern void nameremove(struct namenode *);
91 extern struct namenode *namefind(struct vnode *, struct vnode *);
92 extern uint64_t namenodeno_alloc(void);
93 extern void namenodeno_free(uint64_t);
94 extern struct vnodeops *nm_vnodeops;
95 extern const struct fs_operation_def nm_vnodeops_template[];
96 extern kmutex_t ntable_lock;
97 
98 #endif /* _KERNEL */
99 
100 #ifdef	__cplusplus
101 }
102 #endif
103 
104 #endif	/* _SYS_FS_NAMENODE_H */
105