xref: /illumos-gate/usr/src/uts/common/sys/fs/namenode.h (revision 8950e535)
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
5d67944fbSScott Rotondo  * Common Development and Distribution License (the "License").
6d67944fbSScott Rotondo  * 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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22b4203d75SMarcel Telka /*	  All Rights Reserved	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
25d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
29*8950e535SAndy Fiddaman /*
30*8950e535SAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
31*8950e535SAndy Fiddaman  */
32*8950e535SAndy Fiddaman 
337c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_NAMENODE_H
347c478bd9Sstevel@tonic-gate #define	_SYS_FS_NAMENODE_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
38d67944fbSScott Rotondo #include <sys/vfs_opreg.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * This structure is used to pass a file descriptor from user
477c478bd9Sstevel@tonic-gate  * level to the kernel. It is first used by fattach() and then
487c478bd9Sstevel@tonic-gate  * be NAMEFS.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate struct namefd {
517c478bd9Sstevel@tonic-gate 	int fd;
527c478bd9Sstevel@tonic-gate };
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Each NAMEFS object is identified by a struct namenode/vnode pair.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate struct namenode {
597c478bd9Sstevel@tonic-gate 	struct vnode    *nm_vnode;	/* represents mounted file desc. */
607c478bd9Sstevel@tonic-gate 	int		nm_flag;	/* flags defined below */
617c478bd9Sstevel@tonic-gate 	struct vattr    nm_vattr;	/* attributes of mounted file desc. */
627c478bd9Sstevel@tonic-gate 	struct vnode	*nm_filevp;	/* file desc. prior to mounting */
637c478bd9Sstevel@tonic-gate 	struct file	*nm_filep;	/* file pointer of nm_filevp */
647c478bd9Sstevel@tonic-gate 	struct vnode	*nm_mountpt;	/* mount point prior to mounting */
657c478bd9Sstevel@tonic-gate 	struct namenode *nm_nextp;	/* next link in the linked list */
667c478bd9Sstevel@tonic-gate 	kmutex_t	nm_lock;	/* protects nm_vattr */
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Valid flags for namenodes.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	NMNMNT		0x01	/* namenode not mounted */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Macros to convert a vnode to a namenode, and vice versa.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	VTONM(vp) ((struct namenode *)((vp)->v_data))
787c478bd9Sstevel@tonic-gate #define	NMTOV(nm) ((nm)->nm_vnode)
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	NM_FILEVP_HASH_SIZE	64
817c478bd9Sstevel@tonic-gate #define	NM_FILEVP_HASH_MASK	(NM_FILEVP_HASH_SIZE - 1)
827c478bd9Sstevel@tonic-gate #define	NM_FILEVP_HASH_SHIFT	7
837c478bd9Sstevel@tonic-gate #define	NM_FILEVP_HASH(vp)	(&nm_filevp_hash[(((uintptr_t)vp) >> \
847c478bd9Sstevel@tonic-gate 	NM_FILEVP_HASH_SHIFT) & NM_FILEVP_HASH_MASK])
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate extern struct namenode *nm_filevp_hash[NM_FILEVP_HASH_SIZE];
877c478bd9Sstevel@tonic-gate extern struct vfs namevfs;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern int nameinit(int, char *);
907c478bd9Sstevel@tonic-gate extern int nm_unmountall(struct vnode *, struct cred *);
917c478bd9Sstevel@tonic-gate extern void nameinsert(struct namenode *);
927c478bd9Sstevel@tonic-gate extern void nameremove(struct namenode *);
937c478bd9Sstevel@tonic-gate extern struct namenode *namefind(struct vnode *, struct vnode *);
947c478bd9Sstevel@tonic-gate extern uint64_t namenodeno_alloc(void);
957c478bd9Sstevel@tonic-gate extern void namenodeno_free(uint64_t);
967c478bd9Sstevel@tonic-gate extern struct vnodeops *nm_vnodeops;
977c478bd9Sstevel@tonic-gate extern const struct fs_operation_def nm_vnodeops_template[];
987c478bd9Sstevel@tonic-gate extern kmutex_t ntable_lock;
997c478bd9Sstevel@tonic-gate 
100*8950e535SAndy Fiddaman typedef int nm_walk_mounts_f(const struct namenode *, cred_t *, void *);
101*8950e535SAndy Fiddaman extern int nm_walk_mounts(const vnode_t *, nm_walk_mounts_f *, cred_t *,
102*8950e535SAndy Fiddaman     void *);
103*8950e535SAndy Fiddaman 
1047c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate #endif
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_NAMENODE_H */
111