xref: /freebsd/sys/fs/devfs/devfs_int.h (revision 0ac9e27ba964b4d29ed180d5e546873de638822c)
19c0af131SPoul-Henning Kamp /*-
2d63027b6SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3d63027b6SPedro F. Giffuni  *
49c0af131SPoul-Henning Kamp  * Copyright (c) 2005 Poul-Henning Kamp.  All rights reserved.
59c0af131SPoul-Henning Kamp  *
69c0af131SPoul-Henning Kamp  * Redistribution and use in source and binary forms, with or without
79c0af131SPoul-Henning Kamp  * modification, are permitted provided that the following conditions
89c0af131SPoul-Henning Kamp  * are met:
99c0af131SPoul-Henning Kamp  * 1. Redistributions of source code must retain the above copyright
109c0af131SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer.
119c0af131SPoul-Henning Kamp  * 2. Neither the name of the University nor the names of its contributors
129c0af131SPoul-Henning Kamp  *    may be used to endorse or promote products derived from this software
139c0af131SPoul-Henning Kamp  *    without specific prior written permission.
149c0af131SPoul-Henning Kamp  *
159c0af131SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
169c0af131SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179c0af131SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189c0af131SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199c0af131SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209c0af131SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219c0af131SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229c0af131SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239c0af131SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249c0af131SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259c0af131SPoul-Henning Kamp  * SUCH DAMAGE.
269c0af131SPoul-Henning Kamp  *
279c0af131SPoul-Henning Kamp  * $FreeBSD$
289c0af131SPoul-Henning Kamp  */
299c0af131SPoul-Henning Kamp 
309c0af131SPoul-Henning Kamp /*
319c0af131SPoul-Henning Kamp  * This file documents a private interface and it SHALL only be used
329c0af131SPoul-Henning Kamp  * by kern/kern_conf.c and fs/devfs/...
339c0af131SPoul-Henning Kamp  */
349c0af131SPoul-Henning Kamp 
359c0af131SPoul-Henning Kamp #ifndef _FS_DEVFS_DEVFS_INT_H_
369c0af131SPoul-Henning Kamp #define	_FS_DEVFS_DEVFS_INT_H_
379c0af131SPoul-Henning Kamp 
389c0af131SPoul-Henning Kamp #include <sys/queue.h>
399c0af131SPoul-Henning Kamp 
409c0af131SPoul-Henning Kamp #ifdef _KERNEL
419c0af131SPoul-Henning Kamp 
42e606a3c6SPoul-Henning Kamp struct devfs_dirent;
43d318c565SJaakko Heinonen struct devfs_mount;
44e606a3c6SPoul-Henning Kamp 
4582f4d640SKonstantin Belousov struct cdev_privdata {
4682f4d640SKonstantin Belousov 	struct file		*cdpd_fp;
4782f4d640SKonstantin Belousov 	void			*cdpd_data;
4882f4d640SKonstantin Belousov 	void			(*cdpd_dtr)(void *);
4982f4d640SKonstantin Belousov 	LIST_ENTRY(cdev_privdata) cdpd_list;
5082f4d640SKonstantin Belousov };
5182f4d640SKonstantin Belousov 
52e606a3c6SPoul-Henning Kamp struct cdev_priv {
53e606a3c6SPoul-Henning Kamp 	struct cdev		cdp_c;
54e606a3c6SPoul-Henning Kamp 	TAILQ_ENTRY(cdev_priv)	cdp_list;
55e606a3c6SPoul-Henning Kamp 
56e606a3c6SPoul-Henning Kamp 	u_int			cdp_inode;
57e606a3c6SPoul-Henning Kamp 
58e606a3c6SPoul-Henning Kamp 	u_int			cdp_flags;
59e606a3c6SPoul-Henning Kamp #define CDP_ACTIVE		(1 << 0)
60de10ffa5SKonstantin Belousov #define CDP_SCHED_DTR		(1 << 1)
613b50dff5SKonstantin Belousov #define	CDP_UNREF_DTR		(1 << 2)
62e606a3c6SPoul-Henning Kamp 
63e606a3c6SPoul-Henning Kamp 	u_int			cdp_inuse;
64e606a3c6SPoul-Henning Kamp 	u_int			cdp_maxdirent;
65e606a3c6SPoul-Henning Kamp 	struct devfs_dirent	**cdp_dirents;
66e606a3c6SPoul-Henning Kamp 	struct devfs_dirent	*cdp_dirent0;
67de10ffa5SKonstantin Belousov 
68de10ffa5SKonstantin Belousov 	TAILQ_ENTRY(cdev_priv)	cdp_dtr_list;
69de10ffa5SKonstantin Belousov 	void			(*cdp_dtr_cb)(void *);
70de10ffa5SKonstantin Belousov 	void			*cdp_dtr_cb_arg;
7182f4d640SKonstantin Belousov 
7282f4d640SKonstantin Belousov 	LIST_HEAD(, cdev_privdata) cdp_fdpriv;
73a02cab33SMateusz Guzik 
74a02cab33SMateusz Guzik 	struct mtx		cdp_threadlock;
75e606a3c6SPoul-Henning Kamp };
76e606a3c6SPoul-Henning Kamp 
777cbef24eSEd Schouten #define	cdev2priv(c)	__containerof(c, struct cdev_priv, cdp_c)
7805427aafSKonstantin Belousov 
79d2ba618aSKonstantin Belousov struct cdev	*devfs_alloc(int);
8047bcfb64SJaakko Heinonen int	devfs_dev_exists(const char *);
81e606a3c6SPoul-Henning Kamp void	devfs_free(struct cdev *);
8227877c99SJaakko Heinonen void	devfs_create(struct cdev *);
8327877c99SJaakko Heinonen void	devfs_destroy(struct cdev *);
8427877c99SJaakko Heinonen void	devfs_destroy_cdevpriv(struct cdev_privdata *);
859c0af131SPoul-Henning Kamp 
86d318c565SJaakko Heinonen int	devfs_dir_find(const char *);
87d318c565SJaakko Heinonen void	devfs_dir_ref_de(struct devfs_mount *, struct devfs_dirent *);
88d318c565SJaakko Heinonen void	devfs_dir_unref_de(struct devfs_mount *, struct devfs_dirent *);
89d318c565SJaakko Heinonen int	devfs_pathpath(const char *, const char *);
90d318c565SJaakko Heinonen 
91e606a3c6SPoul-Henning Kamp extern struct unrhdr *devfs_inos;
92e606a3c6SPoul-Henning Kamp extern struct mtx devmtx;
93828d6d12SKonstantin Belousov extern struct mtx devfs_de_interlock;
94de10ffa5SKonstantin Belousov extern struct sx clone_drain_lock;
9582f4d640SKonstantin Belousov extern struct mtx cdevpriv_mtx;
96828d6d12SKonstantin Belousov extern TAILQ_HEAD(cdev_priv_list, cdev_priv) cdevp_list;
97e606a3c6SPoul-Henning Kamp 
98*0ac9e27bSConrad Meyer #define	dev_lock_assert_locked()	mtx_assert(&devmtx, MA_OWNED)
99*0ac9e27bSConrad Meyer #define	dev_lock_assert_unlocked()	mtx_assert(&devmtx, MA_NOTOWNED)
100*0ac9e27bSConrad Meyer 
1019c0af131SPoul-Henning Kamp #endif /* _KERNEL */
1029c0af131SPoul-Henning Kamp 
1039c0af131SPoul-Henning Kamp #endif /* !_FS_DEVFS_DEVFS_INT_H_ */
104