1 /*        $NetBSD: ptyfs.h,v 1.16 2020/11/27 14:43:57 christos Exp $  */
2 
3 /*
4  * Copyright (c) 1993
5  *        The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *        @(#)procfs.h        8.9 (Berkeley) 5/14/95
35  */
36 
37 /*
38  * Copyright (c) 1993 Jan-Simon Pendry
39  *
40  * This code is derived from software contributed to Berkeley by
41  * Jan-Simon Pendry.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *        This product includes software developed by the University of
54  *        California, Berkeley and its contributors.
55  * 4. Neither the name of the University nor the names of its contributors
56  *    may be used to endorse or promote products derived from this software
57  *    without specific prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  *
71  *        @(#)procfs.h        8.9 (Berkeley) 5/14/95
72  */
73 
74 #ifndef _FS_PTYFS_PTYFS_H_
75 #define _FS_PTYFS_PTYFS_H_
76 
77 #ifdef _KERNEL
78 /*
79  * The different types of node in a ptyfs filesystem
80  */
81 typedef enum {
82           PTYFSpts, /* The slave side of a pty */
83           PTYFSptc, /* The controlling side of a pty */
84           PTYFSroot,          /* the filesystem root */
85 } ptyfstype;
86 
87 /*
88  * control data for the proc file system.
89  */
90 struct ptyfskey {
91           ptyfstype ptk_type; /* type of ptyfs node */
92           int                 ptk_pty;  /* the pty index */
93 };
94 struct ptyfsnode {
95           SLIST_ENTRY(ptyfsnode) ptyfs_hash;      /* hash chain */
96           struct ptyfskey     ptyfs_key;
97 #define ptyfs_type  ptyfs_key.ptk_type
98 #define ptyfs_pty   ptyfs_key.ptk_pty
99           u_long              ptyfs_fileno;       /* unique file id */
100           int                 ptyfs_status;       /* status flag for times */
101 #define   PTYFS_ACCESS        1
102 #define   PTYFS_MODIFY        2
103 #define   PTYFS_CHANGE        4
104           /* Attribute information */
105           uid_t               ptyfs_uid;
106           gid_t               ptyfs_gid;
107           mode_t              ptyfs_mode;
108           int                 ptyfs_flags;
109           struct timespec     ptyfs_ctime, ptyfs_mtime, ptyfs_atime, ptyfs_birthtime;
110 };
111 
112 struct ptyfsmount {
113           kmutex_t pmnt_lock;
114           TAILQ_ENTRY(ptyfsmount) pmnt_le;
115           struct mount *pmnt_mp;
116           gid_t pmnt_gid;
117           mode_t pmnt_mode;
118           int pmnt_flags;
119           int pmnt_bitmap_size;
120           uint8_t *pmnt_bitmap;
121 };
122 
123 #define VFSTOPTY(mp)          ((struct ptyfsmount *)(mp)->mnt_data)
124 
125 #endif /* _KERNEL */
126 
127 struct ptyfs_args {
128           int version;
129           gid_t gid;
130           mode_t mode;
131           int flags;
132 };
133 
134 #define PTYFS_ARGSVERSION     2
135 
136 /*
137  * Kernel stuff follows
138  */
139 #ifdef _KERNEL
140 
141 #define UIO_MX 32
142 
143 #define PTYFS_FILENO(type, pty) \
144     ((type == PTYFSroot) ? 2 : \
145      ((((pty) + 1) * 2 + (((type) == PTYFSpts) ? 1 : 2))))
146 
147 #define PTYFS_MAKEDEV(ptyfs) \
148     pty_makedev((ptyfs)->ptyfs_type == PTYFSpts ? 't' : 'p', (ptyfs)->ptyfs_pty)
149 
150 #define PTYFS_ITIMES(ptyfs, acc, mod, cre) \
151    while ((ptyfs)->ptyfs_status & (PTYFS_ACCESS|PTYFS_CHANGE|PTYFS_MODIFY)) \
152           ptyfs_itimes(ptyfs, acc, mod, cre)
153 /*
154  * Convert between ptyfsnode vnode
155  */
156 #define VTOPTYFS(vp)          ((struct ptyfsnode *)(vp)->v_data)
157 
158 void ptyfs_set_active(struct mount *, int);
159 void ptyfs_clr_active(struct mount *, int);
160 int ptyfs_next_active(struct mount *, int);
161 int ptyfs_allocvp(struct mount *, struct vnode **, ptyfstype, int);
162 void ptyfs_hashinit(void);
163 void ptyfs_hashdone(void);
164 struct ptyfsnode *ptyfs_get_node(ptyfstype, int);
165 void ptyfs_itimes(struct ptyfsnode *, const struct timespec *,
166     const struct timespec *, const struct timespec *);
167 
168 extern int (**ptyfs_vnodeop_p)(void *);
169 extern struct vfsops ptyfs_vfsops;
170 
171 int       ptyfs_root(struct mount *, int, struct vnode **);
172 
173 #endif /* _KERNEL */
174 #endif /* _FS_PTYFS_PTYFS_H_ */
175