14cc62415SBruce Evans /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3d63027b6SPedro F. Giffuni * 43f54a085SPoul-Henning Kamp * Copyright (c) 1992, 1993 53f54a085SPoul-Henning Kamp * The Regents of the University of California. All rights reserved. 63f54a085SPoul-Henning Kamp * Copyright (c) 2000 73f54a085SPoul-Henning Kamp * Poul-Henning Kamp. All rights reserved. 8a1dc2096SDima Dorfman * Copyright (c) 2002 9a1dc2096SDima Dorfman * Dima Dorfman. All rights reserved. 103f54a085SPoul-Henning Kamp * 113f54a085SPoul-Henning Kamp * This code is derived from software donated to Berkeley by 123f54a085SPoul-Henning Kamp * Jan-Simon Pendry. 133f54a085SPoul-Henning Kamp * 143f54a085SPoul-Henning Kamp * Redistribution and use in source and binary forms, with or without 153f54a085SPoul-Henning Kamp * modification, are permitted provided that the following conditions 163f54a085SPoul-Henning Kamp * are met: 173f54a085SPoul-Henning Kamp * 1. Redistributions of source code must retain the above copyright 183f54a085SPoul-Henning Kamp * notice, this list of conditions and the following disclaimer. 193f54a085SPoul-Henning Kamp * 2. Neither the name of the University nor the names of its contributors 203f54a085SPoul-Henning Kamp * may be used to endorse or promote products derived from this software 213f54a085SPoul-Henning Kamp * without specific prior written permission. 223f54a085SPoul-Henning Kamp * 233f54a085SPoul-Henning Kamp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 243f54a085SPoul-Henning Kamp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 253f54a085SPoul-Henning Kamp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 263f54a085SPoul-Henning Kamp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 273f54a085SPoul-Henning Kamp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 283f54a085SPoul-Henning Kamp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 293f54a085SPoul-Henning Kamp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 303f54a085SPoul-Henning Kamp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 313f54a085SPoul-Henning Kamp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 323f54a085SPoul-Henning Kamp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 333f54a085SPoul-Henning Kamp * SUCH DAMAGE. 343f54a085SPoul-Henning Kamp * From: FreeBSD: src/sys/miscfs/kernfs/kernfs.h 1.14 353f54a085SPoul-Henning Kamp */ 363f54a085SPoul-Henning Kamp 3793bcdfe2SPoul-Henning Kamp #ifndef _FS_DEVFS_DEVFS_H_ 3893bcdfe2SPoul-Henning Kamp #define _FS_DEVFS_DEVFS_H_ 393f54a085SPoul-Henning Kamp 40a1dc2096SDima Dorfman #define DEVFS_MAGIC 0xdb0a087a 41a1dc2096SDima Dorfman 42a1dc2096SDima Dorfman /* 43a1dc2096SDima Dorfman * Identifiers. The ruleset and rule numbers are 16-bit values. The 44a1dc2096SDima Dorfman * "rule ID" is a combination of the ruleset and rule number; it 45a1dc2096SDima Dorfman * should be able to univocally describe a rule in the system. In 46a1dc2096SDima Dorfman * this implementation, the upper 16 bits of the rule ID is the 47a1dc2096SDima Dorfman * ruleset number; the lower 16 bits, the rule number within the 48a1dc2096SDima Dorfman * aforementioned ruleset. 49a1dc2096SDima Dorfman */ 50a1dc2096SDima Dorfman typedef uint16_t devfs_rnum; 51a1dc2096SDima Dorfman typedef uint16_t devfs_rsnum; 52a1dc2096SDima Dorfman typedef uint32_t devfs_rid; 53a1dc2096SDima Dorfman 54a1dc2096SDima Dorfman /* 55a1dc2096SDima Dorfman * Identifier manipulators. 56a1dc2096SDima Dorfman */ 57a1dc2096SDima Dorfman #define rid2rsn(rid) ((rid) >> 16) 58a1dc2096SDima Dorfman #define rid2rn(rid) ((rid) & 0xffff) 59a1dc2096SDima Dorfman #define mkrid(rsn, rn) ((rn) | ((rsn) << 16)) 60a1dc2096SDima Dorfman 61a1dc2096SDima Dorfman /* 62a1dc2096SDima Dorfman * Plain DEVFS rule. This gets shared between kernel and userland 63a1dc2096SDima Dorfman * verbatim, so it shouldn't contain any pointers or other kernel- or 64a1dc2096SDima Dorfman * userland-specific values. 65a1dc2096SDima Dorfman */ 66a1dc2096SDima Dorfman struct devfs_rule { 67a1dc2096SDima Dorfman uint32_t dr_magic; /* Magic number. */ 68a1dc2096SDima Dorfman devfs_rid dr_id; /* Identifier. */ 69a1dc2096SDima Dorfman 70a1dc2096SDima Dorfman /* 71a1dc2096SDima Dorfman * Conditions under which this rule should be applied. These 72a1dc2096SDima Dorfman * are ANDed together since OR can be simulated by using 73a1dc2096SDima Dorfman * multiple rules. dr_icond determines which of the other 74a1dc2096SDima Dorfman * variables we should process. 75a1dc2096SDima Dorfman */ 76a1dc2096SDima Dorfman int dr_icond; 77a1dc2096SDima Dorfman #define DRC_DSWFLAGS 0x001 78a1dc2096SDima Dorfman #define DRC_PATHPTRN 0x002 79a1dc2096SDima Dorfman int dr_dswflags; /* cdevsw flags to match. */ 80a1dc2096SDima Dorfman #define DEVFS_MAXPTRNLEN 200 81a1dc2096SDima Dorfman char dr_pathptrn[DEVFS_MAXPTRNLEN]; /* Pattern to match path. */ 82a1dc2096SDima Dorfman 83a1dc2096SDima Dorfman /* 84a1dc2096SDima Dorfman * Things to change. dr_iacts determines which of the other 85a1dc2096SDima Dorfman * variables we should process. 86a1dc2096SDima Dorfman */ 87a1dc2096SDima Dorfman int dr_iacts; 88a1dc2096SDima Dorfman #define DRA_BACTS 0x001 89a1dc2096SDima Dorfman #define DRA_UID 0x002 90a1dc2096SDima Dorfman #define DRA_GID 0x004 91a1dc2096SDima Dorfman #define DRA_MODE 0x008 92a1dc2096SDima Dorfman #define DRA_INCSET 0x010 93a1dc2096SDima Dorfman int dr_bacts; /* Boolean (on/off) action. */ 94a1dc2096SDima Dorfman #define DRB_HIDE 0x001 /* Hide entry (DE_WHITEOUT). */ 95a1dc2096SDima Dorfman #define DRB_UNHIDE 0x002 /* Unhide entry. */ 96a1dc2096SDima Dorfman uid_t dr_uid; 97a1dc2096SDima Dorfman gid_t dr_gid; 98a1dc2096SDima Dorfman mode_t dr_mode; 99a1dc2096SDima Dorfman devfs_rsnum dr_incset; /* Included ruleset. */ 100a1dc2096SDima Dorfman }; 101a1dc2096SDima Dorfman 102a1dc2096SDima Dorfman /* 103a1dc2096SDima Dorfman * Rule-related ioctls. 104a1dc2096SDima Dorfman */ 105a1dc2096SDima Dorfman #define DEVFSIO_RADD _IOWR('D', 0, struct devfs_rule) 106a1dc2096SDima Dorfman #define DEVFSIO_RDEL _IOW('D', 1, devfs_rid) 107a1dc2096SDima Dorfman #define DEVFSIO_RAPPLY _IOW('D', 2, struct devfs_rule) 108a1dc2096SDima Dorfman #define DEVFSIO_RAPPLYID _IOW('D', 3, devfs_rid) 109a1dc2096SDima Dorfman #define DEVFSIO_RGETNEXT _IOWR('D', 4, struct devfs_rule) 110a1dc2096SDima Dorfman 111a1dc2096SDima Dorfman #define DEVFSIO_SUSE _IOW('D', 10, devfs_rsnum) 112a1dc2096SDima Dorfman #define DEVFSIO_SAPPLY _IOW('D', 11, devfs_rsnum) 113a1dc2096SDima Dorfman #define DEVFSIO_SGETNEXT _IOWR('D', 12, devfs_rsnum) 114a1dc2096SDima Dorfman 115a1dc2096SDima Dorfman /* XXX: DEVFSIO_RS_GET_INFO for refcount, active if any, etc. */ 116a1dc2096SDima Dorfman 117a1dc2096SDima Dorfman #ifdef _KERNEL 1183f54a085SPoul-Henning Kamp 1194cc62415SBruce Evans #ifdef MALLOC_DECLARE 1203f54a085SPoul-Henning Kamp MALLOC_DECLARE(M_DEVFS); 1214cc62415SBruce Evans #endif 1223f54a085SPoul-Henning Kamp 123d485c77fSKonstantin Belousov #endif /* _KERNEL */ 124d485c77fSKonstantin Belousov 1256adc5230SJaakko Heinonen struct componentname; 1266adc5230SJaakko Heinonen 127d318c565SJaakko Heinonen TAILQ_HEAD(devfs_dlist_head, devfs_dirent); 128d318c565SJaakko Heinonen 1293f54a085SPoul-Henning Kamp struct devfs_dirent { 130e606a3c6SPoul-Henning Kamp struct cdev_priv *de_cdp; 1313f54a085SPoul-Henning Kamp int de_inode; 132a481b90bSPoul-Henning Kamp int de_flags; 13364040d39SJaakko Heinonen #define DE_WHITEOUT 0x01 13464040d39SJaakko Heinonen #define DE_DOT 0x02 13564040d39SJaakko Heinonen #define DE_DOTDOT 0x04 13664040d39SJaakko Heinonen #define DE_DOOMED 0x08 13764040d39SJaakko Heinonen #define DE_COVERED 0x10 138d318c565SJaakko Heinonen #define DE_USER 0x20 139e7f9b744SKonstantin Belousov int de_holdcnt; 1403f54a085SPoul-Henning Kamp struct dirent *de_dirent; 1413f54a085SPoul-Henning Kamp TAILQ_ENTRY(devfs_dirent) de_list; 142d318c565SJaakko Heinonen struct devfs_dlist_head de_dlist; 143a481b90bSPoul-Henning Kamp struct devfs_dirent *de_dir; 144a481b90bSPoul-Henning Kamp int de_links; 1453f54a085SPoul-Henning Kamp mode_t de_mode; 1463f54a085SPoul-Henning Kamp uid_t de_uid; 1473f54a085SPoul-Henning Kamp gid_t de_gid; 148eca8a663SRobert Watson struct label *de_label; 1493f54a085SPoul-Henning Kamp struct timespec de_atime; 1503f54a085SPoul-Henning Kamp struct timespec de_mtime; 1513f54a085SPoul-Henning Kamp struct timespec de_ctime; 1523f54a085SPoul-Henning Kamp struct vnode *de_vnode; 1533f54a085SPoul-Henning Kamp char *de_symlink; 1543b444436SMateusz Guzik int de_usecount; 1553f54a085SPoul-Henning Kamp }; 1563f54a085SPoul-Henning Kamp 157d485c77fSKonstantin Belousov #include <sys/_lock.h> 158d485c77fSKonstantin Belousov #include <sys/_sx.h> 159d485c77fSKonstantin Belousov 1603f54a085SPoul-Henning Kamp struct devfs_mount { 161e606a3c6SPoul-Henning Kamp u_int dm_idx; 162990b4b2dSRobert Watson struct mount *dm_mount; 163a481b90bSPoul-Henning Kamp struct devfs_dirent *dm_rootdir; 1643f54a085SPoul-Henning Kamp unsigned dm_generation; 165e7f9b744SKonstantin Belousov int dm_holdcnt; 166e606a3c6SPoul-Henning Kamp struct sx dm_lock; 167a1dc2096SDima Dorfman devfs_rsnum dm_ruleset; 1683f54a085SPoul-Henning Kamp }; 1693f54a085SPoul-Henning Kamp 170e606a3c6SPoul-Henning Kamp #define DEVFS_ROOTINO 2 1715e080af4SPoul-Henning Kamp 172d485c77fSKonstantin Belousov #ifdef _KERNEL 173d485c77fSKonstantin Belousov 174e606a3c6SPoul-Henning Kamp extern unsigned devfs_rule_depth; 175a481b90bSPoul-Henning Kamp 1763f54a085SPoul-Henning Kamp #define VFSTODEVFS(mp) ((struct devfs_mount *)((mp)->mnt_data)) 1773f54a085SPoul-Henning Kamp 178e7f9b744SKonstantin Belousov #define DEVFS_DE_HOLD(de) ((de)->de_holdcnt++) 179e7f9b744SKonstantin Belousov #define DEVFS_DE_DROP(de) (--(de)->de_holdcnt == 0) 180e7f9b744SKonstantin Belousov 181e7f9b744SKonstantin Belousov #define DEVFS_DMP_HOLD(dmp) ((dmp)->dm_holdcnt++) 182e7f9b744SKonstantin Belousov #define DEVFS_DMP_DROP(dmp) (--(dmp)->dm_holdcnt == 0) 183e7f9b744SKonstantin Belousov 184a1c555f4SMateusz Guzik #define DEVFS_DEL_NORECURSE 0x01 18589d10571SJaakko Heinonen 18627877c99SJaakko Heinonen void devfs_rules_apply(struct devfs_mount *, struct devfs_dirent *); 18727877c99SJaakko Heinonen void devfs_rules_cleanup(struct devfs_mount *); 18827877c99SJaakko Heinonen int devfs_rules_ioctl(struct devfs_mount *, u_long, caddr_t, 18927877c99SJaakko Heinonen struct thread *); 19017d84d61SMartin Matuska void devfs_ruleset_set(devfs_rsnum rsnum, struct devfs_mount *dm); 19117d84d61SMartin Matuska void devfs_ruleset_apply(struct devfs_mount *dm); 19227877c99SJaakko Heinonen int devfs_allocv(struct devfs_dirent *, struct mount *, int, 19327877c99SJaakko Heinonen struct vnode **); 1946adc5230SJaakko Heinonen char *devfs_fqpn(char *, struct devfs_mount *, struct devfs_dirent *, 1956adc5230SJaakko Heinonen struct componentname *); 19627877c99SJaakko Heinonen void devfs_delete(struct devfs_mount *, struct devfs_dirent *, int); 19727877c99SJaakko Heinonen void devfs_dirent_free(struct devfs_dirent *); 198ca423b85SMateusz Guzik int devfs_populate_needed(struct devfs_mount *dm); 19927877c99SJaakko Heinonen void devfs_populate(struct devfs_mount *); 20027877c99SJaakko Heinonen void devfs_cleanup(struct devfs_mount *); 20127877c99SJaakko Heinonen void devfs_unmount_final(struct devfs_mount *); 20227877c99SJaakko Heinonen struct devfs_dirent *devfs_newdirent(char *, int); 20327877c99SJaakko Heinonen struct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *); 20427877c99SJaakko Heinonen struct devfs_dirent *devfs_vmkdir(struct devfs_mount *, char *, int, 20527877c99SJaakko Heinonen struct devfs_dirent *, u_int); 20627877c99SJaakko Heinonen struct devfs_dirent *devfs_find(struct devfs_dirent *, const char *, int, 20727877c99SJaakko Heinonen int); 20893bcdfe2SPoul-Henning Kamp 2093b444436SMateusz Guzik void devfs_ctty_ref(struct vnode *); 2103b444436SMateusz Guzik void devfs_ctty_unref(struct vnode *); 2113b444436SMateusz Guzik int devfs_usecount(struct vnode *); 2123b444436SMateusz Guzik 2133f54a085SPoul-Henning Kamp #endif /* _KERNEL */ 2144cc62415SBruce Evans 2154cc62415SBruce Evans #endif /* !_FS_DEVFS_DEVFS_H_ */ 216