xref: /illumos-gate/usr/src/uts/common/sys/fs/namenode.h (revision 8950e535f42dd006f8cfb2122c94f6b7557757e0)
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 /*
30  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
31  */
32 
33 #ifndef	_SYS_FS_NAMENODE_H
34 #define	_SYS_FS_NAMENODE_H
35 
36 #if defined(_KERNEL)
37 #include <sys/vnode.h>
38 #include <sys/vfs_opreg.h>
39 #endif
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * This structure is used to pass a file descriptor from user
47  * level to the kernel. It is first used by fattach() and then
48  * be NAMEFS.
49  */
50 struct namefd {
51 	int fd;
52 };
53 
54 #if defined(_KERNEL)
55 /*
56  * Each NAMEFS object is identified by a struct namenode/vnode pair.
57  */
58 struct namenode {
59 	struct vnode    *nm_vnode;	/* represents mounted file desc. */
60 	int		nm_flag;	/* flags defined below */
61 	struct vattr    nm_vattr;	/* attributes of mounted file desc. */
62 	struct vnode	*nm_filevp;	/* file desc. prior to mounting */
63 	struct file	*nm_filep;	/* file pointer of nm_filevp */
64 	struct vnode	*nm_mountpt;	/* mount point prior to mounting */
65 	struct namenode *nm_nextp;	/* next link in the linked list */
66 	kmutex_t	nm_lock;	/* protects nm_vattr */
67 };
68 
69 /*
70  * Valid flags for namenodes.
71  */
72 #define	NMNMNT		0x01	/* namenode not mounted */
73 
74 /*
75  * Macros to convert a vnode to a namenode, and vice versa.
76  */
77 #define	VTONM(vp) ((struct namenode *)((vp)->v_data))
78 #define	NMTOV(nm) ((nm)->nm_vnode)
79 
80 #define	NM_FILEVP_HASH_SIZE	64
81 #define	NM_FILEVP_HASH_MASK	(NM_FILEVP_HASH_SIZE - 1)
82 #define	NM_FILEVP_HASH_SHIFT	7
83 #define	NM_FILEVP_HASH(vp)	(&nm_filevp_hash[(((uintptr_t)vp) >> \
84 	NM_FILEVP_HASH_SHIFT) & NM_FILEVP_HASH_MASK])
85 
86 extern struct namenode *nm_filevp_hash[NM_FILEVP_HASH_SIZE];
87 extern struct vfs namevfs;
88 
89 extern int nameinit(int, char *);
90 extern int nm_unmountall(struct vnode *, struct cred *);
91 extern void nameinsert(struct namenode *);
92 extern void nameremove(struct namenode *);
93 extern struct namenode *namefind(struct vnode *, struct vnode *);
94 extern uint64_t namenodeno_alloc(void);
95 extern void namenodeno_free(uint64_t);
96 extern struct vnodeops *nm_vnodeops;
97 extern const struct fs_operation_def nm_vnodeops_template[];
98 extern kmutex_t ntable_lock;
99 
100 typedef int nm_walk_mounts_f(const struct namenode *, cred_t *, void *);
101 extern int nm_walk_mounts(const vnode_t *, nm_walk_mounts_f *, cred_t *,
102     void *);
103 
104 #endif /* _KERNEL */
105 
106 #ifdef	__cplusplus
107 }
108 #endif
109 
110 #endif	/* _SYS_FS_NAMENODE_H */
111