| @@ -1,973 +1,973 @@ | | | @@ -1,973 +1,973 @@ |
1 | /* $NetBSD: ptyfs_vnops.c,v 1.65 2021/07/18 23:57:14 dholland Exp $ */ | | 1 | /* $NetBSD: ptyfs_vnops.c,v 1.66 2021/07/18 23:57:34 dholland Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1993, 1995 | | 4 | * Copyright (c) 1993, 1995 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Jan-Simon Pendry. | | 8 | * Jan-Simon Pendry. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of the University nor the names of its contributors | | 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 | | 19 | * may be used to endorse or promote products derived from this software |
20 | * without specific prior written permission. | | 20 | * without specific prior written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 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 | | 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 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 | | 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 | | 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 | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | * | | 33 | * |
34 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 | | 34 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | /* | | 37 | /* |
38 | * Copyright (c) 1993 Jan-Simon Pendry | | 38 | * Copyright (c) 1993 Jan-Simon Pendry |
39 | * | | 39 | * |
40 | * This code is derived from software contributed to Berkeley by | | 40 | * This code is derived from software contributed to Berkeley by |
41 | * Jan-Simon Pendry. | | 41 | * Jan-Simon Pendry. |
42 | * | | 42 | * |
43 | * Redistribution and use in source and binary forms, with or without | | 43 | * Redistribution and use in source and binary forms, with or without |
44 | * modification, are permitted provided that the following conditions | | 44 | * modification, are permitted provided that the following conditions |
45 | * are met: | | 45 | * are met: |
46 | * 1. Redistributions of source code must retain the above copyright | | 46 | * 1. Redistributions of source code must retain the above copyright |
47 | * notice, this list of conditions and the following disclaimer. | | 47 | * notice, this list of conditions and the following disclaimer. |
48 | * 2. Redistributions in binary form must reproduce the above copyright | | 48 | * 2. Redistributions in binary form must reproduce the above copyright |
49 | * notice, this list of conditions and the following disclaimer in the | | 49 | * notice, this list of conditions and the following disclaimer in the |
50 | * documentation and/or other materials provided with the distribution. | | 50 | * documentation and/or other materials provided with the distribution. |
51 | * 3. All advertising materials mentioning features or use of this software | | 51 | * 3. All advertising materials mentioning features or use of this software |
52 | * must display the following acknowledgement: | | 52 | * must display the following acknowledgement: |
53 | * This product includes software developed by the University of | | 53 | * This product includes software developed by the University of |
54 | * California, Berkeley and its contributors. | | 54 | * California, Berkeley and its contributors. |
55 | * 4. Neither the name of the University nor the names of 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 | | 56 | * may be used to endorse or promote products derived from this software |
57 | * without specific prior written permission. | | 57 | * without specific prior written permission. |
58 | * | | 58 | * |
59 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 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 | | 60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
65 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 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 | | 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 | | 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 | | 68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
69 | * SUCH DAMAGE. | | 69 | * SUCH DAMAGE. |
70 | * | | 70 | * |
71 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 | | 71 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 |
72 | */ | | 72 | */ |
73 | | | 73 | |
74 | /* | | 74 | /* |
75 | * ptyfs vnode interface | | 75 | * ptyfs vnode interface |
76 | */ | | 76 | */ |
77 | | | 77 | |
78 | #include <sys/cdefs.h> | | 78 | #include <sys/cdefs.h> |
79 | __KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.65 2021/07/18 23:57:14 dholland Exp $"); | | 79 | __KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.66 2021/07/18 23:57:34 dholland Exp $"); |
80 | | | 80 | |
81 | #include <sys/param.h> | | 81 | #include <sys/param.h> |
82 | #include <sys/systm.h> | | 82 | #include <sys/systm.h> |
83 | #include <sys/time.h> | | 83 | #include <sys/time.h> |
84 | #include <sys/kernel.h> | | 84 | #include <sys/kernel.h> |
85 | #include <sys/file.h> | | 85 | #include <sys/file.h> |
86 | #include <sys/filedesc.h> | | 86 | #include <sys/filedesc.h> |
87 | #include <sys/proc.h> | | 87 | #include <sys/proc.h> |
88 | #include <sys/vnode.h> | | 88 | #include <sys/vnode.h> |
89 | #include <sys/namei.h> | | 89 | #include <sys/namei.h> |
90 | #include <sys/malloc.h> | | 90 | #include <sys/malloc.h> |
91 | #include <sys/mount.h> | | 91 | #include <sys/mount.h> |
92 | #include <sys/select.h> | | 92 | #include <sys/select.h> |
93 | #include <sys/dirent.h> | | 93 | #include <sys/dirent.h> |
94 | #include <sys/resourcevar.h> | | 94 | #include <sys/resourcevar.h> |
95 | #include <sys/stat.h> | | 95 | #include <sys/stat.h> |
96 | #include <sys/conf.h> | | 96 | #include <sys/conf.h> |
97 | #include <sys/tty.h> | | 97 | #include <sys/tty.h> |
98 | #include <sys/pty.h> | | 98 | #include <sys/pty.h> |
99 | #include <sys/kauth.h> | | 99 | #include <sys/kauth.h> |
100 | | | 100 | |
101 | #include <uvm/uvm_extern.h> /* for PAGE_SIZE */ | | 101 | #include <uvm/uvm_extern.h> /* for PAGE_SIZE */ |
102 | | | 102 | |
103 | #include <machine/reg.h> | | 103 | #include <machine/reg.h> |
104 | | | 104 | |
105 | #include <fs/ptyfs/ptyfs.h> | | 105 | #include <fs/ptyfs/ptyfs.h> |
106 | #include <miscfs/genfs/genfs.h> | | 106 | #include <miscfs/genfs/genfs.h> |
107 | #include <miscfs/specfs/specdev.h> | | 107 | #include <miscfs/specfs/specdev.h> |
108 | | | 108 | |
109 | MALLOC_DECLARE(M_PTYFSTMP); | | 109 | MALLOC_DECLARE(M_PTYFSTMP); |
110 | | | 110 | |
111 | /* | | 111 | /* |
112 | * Vnode Operations. | | 112 | * Vnode Operations. |
113 | * | | 113 | * |
114 | */ | | 114 | */ |
115 | | | 115 | |
116 | int ptyfs_lookup (void *); | | 116 | int ptyfs_lookup (void *); |
117 | int ptyfs_open (void *); | | 117 | int ptyfs_open (void *); |
118 | int ptyfs_close (void *); | | 118 | int ptyfs_close (void *); |
119 | int ptyfs_access (void *); | | 119 | int ptyfs_access (void *); |
120 | int ptyfs_getattr (void *); | | 120 | int ptyfs_getattr (void *); |
121 | int ptyfs_setattr (void *); | | 121 | int ptyfs_setattr (void *); |
122 | int ptyfs_read (void *); | | 122 | int ptyfs_read (void *); |
123 | int ptyfs_write (void *); | | 123 | int ptyfs_write (void *); |
124 | int ptyfs_ioctl (void *); | | 124 | int ptyfs_ioctl (void *); |
125 | int ptyfs_poll (void *); | | 125 | int ptyfs_poll (void *); |
126 | int ptyfs_kqfilter (void *); | | 126 | int ptyfs_kqfilter (void *); |
127 | int ptyfs_readdir (void *); | | 127 | int ptyfs_readdir (void *); |
128 | int ptyfs_reclaim (void *); | | 128 | int ptyfs_reclaim (void *); |
129 | int ptyfs_inactive (void *); | | 129 | int ptyfs_inactive (void *); |
130 | int ptyfs_print (void *); | | 130 | int ptyfs_print (void *); |
131 | int ptyfs_pathconf (void *); | | 131 | int ptyfs_pathconf (void *); |
132 | int ptyfs_advlock (void *); | | 132 | int ptyfs_advlock (void *); |
133 | | | 133 | |
134 | static int ptyfs_update(struct vnode *, const struct timespec *, | | 134 | static int ptyfs_update(struct vnode *, const struct timespec *, |
135 | const struct timespec *, int); | | 135 | const struct timespec *, int); |
136 | static int ptyfs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t, | | 136 | static int ptyfs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t, |
137 | struct lwp *); | | 137 | struct lwp *); |
138 | static int ptyfs_chmod(struct vnode *, mode_t, kauth_cred_t, struct lwp *); | | 138 | static int ptyfs_chmod(struct vnode *, mode_t, kauth_cred_t, struct lwp *); |
139 | static int atoi(const char *, size_t); | | 139 | static int atoi(const char *, size_t); |
140 | | | 140 | |
141 | /* | | 141 | /* |
142 | * ptyfs vnode operations. | | 142 | * ptyfs vnode operations. |
143 | */ | | 143 | */ |
144 | int (**ptyfs_vnodeop_p)(void *); | | 144 | int (**ptyfs_vnodeop_p)(void *); |
145 | const struct vnodeopv_entry_desc ptyfs_vnodeop_entries[] = { | | 145 | const struct vnodeopv_entry_desc ptyfs_vnodeop_entries[] = { |
146 | { &vop_default_desc, vn_default_error }, | | 146 | { &vop_default_desc, vn_default_error }, |
147 | { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */ | | 147 | { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */ |
148 | { &vop_lookup_desc, ptyfs_lookup }, /* lookup */ | | 148 | { &vop_lookup_desc, ptyfs_lookup }, /* lookup */ |
149 | { &vop_create_desc, genfs_eopnotsupp }, /* create */ | | 149 | { &vop_create_desc, genfs_eopnotsupp }, /* create */ |
150 | { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */ | | 150 | { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */ |
151 | { &vop_open_desc, ptyfs_open }, /* open */ | | 151 | { &vop_open_desc, ptyfs_open }, /* open */ |
152 | { &vop_close_desc, ptyfs_close }, /* close */ | | 152 | { &vop_close_desc, ptyfs_close }, /* close */ |
153 | { &vop_access_desc, ptyfs_access }, /* access */ | | 153 | { &vop_access_desc, ptyfs_access }, /* access */ |
154 | { &vop_accessx_desc, genfs_accessx }, /* accessx */ | | 154 | { &vop_accessx_desc, genfs_accessx }, /* accessx */ |
155 | { &vop_getattr_desc, ptyfs_getattr }, /* getattr */ | | 155 | { &vop_getattr_desc, ptyfs_getattr }, /* getattr */ |
156 | { &vop_setattr_desc, ptyfs_setattr }, /* setattr */ | | 156 | { &vop_setattr_desc, ptyfs_setattr }, /* setattr */ |
157 | { &vop_read_desc, ptyfs_read }, /* read */ | | 157 | { &vop_read_desc, ptyfs_read }, /* read */ |
158 | { &vop_write_desc, ptyfs_write }, /* write */ | | 158 | { &vop_write_desc, ptyfs_write }, /* write */ |
159 | { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ | | 159 | { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ |
160 | { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ | | 160 | { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ |
161 | { &vop_ioctl_desc, ptyfs_ioctl }, /* ioctl */ | | 161 | { &vop_ioctl_desc, ptyfs_ioctl }, /* ioctl */ |
162 | { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ | | 162 | { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ |
163 | { &vop_poll_desc, ptyfs_poll }, /* poll */ | | 163 | { &vop_poll_desc, ptyfs_poll }, /* poll */ |
164 | { &vop_kqfilter_desc, ptyfs_kqfilter }, /* kqfilter */ | | 164 | { &vop_kqfilter_desc, ptyfs_kqfilter }, /* kqfilter */ |
165 | { &vop_revoke_desc, genfs_revoke }, /* revoke */ | | 165 | { &vop_revoke_desc, genfs_revoke }, /* revoke */ |
166 | { &vop_mmap_desc, genfs_eopnotsupp }, /* mmap */ | | 166 | { &vop_mmap_desc, genfs_eopnotsupp }, /* mmap */ |
167 | { &vop_fsync_desc, genfs_nullop }, /* fsync */ | | 167 | { &vop_fsync_desc, genfs_nullop }, /* fsync */ |
168 | { &vop_seek_desc, genfs_nullop }, /* seek */ | | 168 | { &vop_seek_desc, genfs_nullop }, /* seek */ |
169 | { &vop_remove_desc, genfs_eopnotsupp }, /* remove */ | | 169 | { &vop_remove_desc, genfs_eopnotsupp }, /* remove */ |
170 | { &vop_link_desc, genfs_abortop }, /* link */ | | 170 | { &vop_link_desc, genfs_eopnotsupp }, /* link */ |
171 | { &vop_rename_desc, genfs_eopnotsupp }, /* rename */ | | 171 | { &vop_rename_desc, genfs_eopnotsupp }, /* rename */ |
172 | { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */ | | 172 | { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */ |
173 | { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */ | | 173 | { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */ |
174 | { &vop_symlink_desc, genfs_abortop }, /* symlink */ | | 174 | { &vop_symlink_desc, genfs_eopnotsupp }, /* symlink */ |
175 | { &vop_readdir_desc, ptyfs_readdir }, /* readdir */ | | 175 | { &vop_readdir_desc, ptyfs_readdir }, /* readdir */ |
176 | { &vop_readlink_desc, genfs_eopnotsupp }, /* readlink */ | | 176 | { &vop_readlink_desc, genfs_eopnotsupp }, /* readlink */ |
177 | { &vop_abortop_desc, genfs_abortop }, /* abortop */ | | 177 | { &vop_abortop_desc, genfs_abortop }, /* abortop */ |
178 | { &vop_inactive_desc, ptyfs_inactive }, /* inactive */ | | 178 | { &vop_inactive_desc, ptyfs_inactive }, /* inactive */ |
179 | { &vop_reclaim_desc, ptyfs_reclaim }, /* reclaim */ | | 179 | { &vop_reclaim_desc, ptyfs_reclaim }, /* reclaim */ |
180 | { &vop_lock_desc, genfs_lock }, /* lock */ | | 180 | { &vop_lock_desc, genfs_lock }, /* lock */ |
181 | { &vop_unlock_desc, genfs_unlock }, /* unlock */ | | 181 | { &vop_unlock_desc, genfs_unlock }, /* unlock */ |
182 | { &vop_bmap_desc, genfs_eopnotsupp }, /* bmap */ | | 182 | { &vop_bmap_desc, genfs_eopnotsupp }, /* bmap */ |
183 | { &vop_strategy_desc, genfs_badop }, /* strategy */ | | 183 | { &vop_strategy_desc, genfs_badop }, /* strategy */ |
184 | { &vop_print_desc, ptyfs_print }, /* print */ | | 184 | { &vop_print_desc, ptyfs_print }, /* print */ |
185 | { &vop_islocked_desc, genfs_islocked }, /* islocked */ | | 185 | { &vop_islocked_desc, genfs_islocked }, /* islocked */ |
186 | { &vop_pathconf_desc, ptyfs_pathconf }, /* pathconf */ | | 186 | { &vop_pathconf_desc, ptyfs_pathconf }, /* pathconf */ |
187 | { &vop_advlock_desc, ptyfs_advlock }, /* advlock */ | | 187 | { &vop_advlock_desc, ptyfs_advlock }, /* advlock */ |
188 | { &vop_bwrite_desc, genfs_eopnotsupp }, /* bwrite */ | | 188 | { &vop_bwrite_desc, genfs_eopnotsupp }, /* bwrite */ |
189 | { &vop_putpages_desc, genfs_null_putpages }, /* putpages */ | | 189 | { &vop_putpages_desc, genfs_null_putpages }, /* putpages */ |
190 | { NULL, NULL } | | 190 | { NULL, NULL } |
191 | }; | | 191 | }; |
192 | const struct vnodeopv_desc ptyfs_vnodeop_opv_desc = | | 192 | const struct vnodeopv_desc ptyfs_vnodeop_opv_desc = |
193 | { &ptyfs_vnodeop_p, ptyfs_vnodeop_entries }; | | 193 | { &ptyfs_vnodeop_p, ptyfs_vnodeop_entries }; |
194 | | | 194 | |
195 | /* | | 195 | /* |
196 | * free any private data and remove the node | | 196 | * free any private data and remove the node |
197 | * from any private lists. | | 197 | * from any private lists. |
198 | */ | | 198 | */ |
199 | int | | 199 | int |
200 | ptyfs_reclaim(void *v) | | 200 | ptyfs_reclaim(void *v) |
201 | { | | 201 | { |
202 | struct vop_reclaim_v2_args /* { | | 202 | struct vop_reclaim_v2_args /* { |
203 | struct vnode *a_vp; | | 203 | struct vnode *a_vp; |
204 | } */ *ap = v; | | 204 | } */ *ap = v; |
205 | struct vnode *vp = ap->a_vp; | | 205 | struct vnode *vp = ap->a_vp; |
206 | | | 206 | |
207 | VOP_UNLOCK(vp); | | 207 | VOP_UNLOCK(vp); |
208 | | | 208 | |
209 | vp->v_data = NULL; | | 209 | vp->v_data = NULL; |
210 | return 0; | | 210 | return 0; |
211 | } | | 211 | } |
212 | | | 212 | |
213 | int | | 213 | int |
214 | ptyfs_inactive(void *v) | | 214 | ptyfs_inactive(void *v) |
215 | { | | 215 | { |
216 | struct vop_inactive_v2_args /* { | | 216 | struct vop_inactive_v2_args /* { |
217 | struct vnode *a_vp; | | 217 | struct vnode *a_vp; |
218 | bool *a_recycle; | | 218 | bool *a_recycle; |
219 | } */ *ap = v; | | 219 | } */ *ap = v; |
220 | struct vnode *vp = ap->a_vp; | | 220 | struct vnode *vp = ap->a_vp; |
221 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 221 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
222 | | | 222 | |
223 | if (ptyfs->ptyfs_type == PTYFSptc) | | 223 | if (ptyfs->ptyfs_type == PTYFSptc) |
224 | ptyfs_clr_active(vp->v_mount, ptyfs->ptyfs_pty); | | 224 | ptyfs_clr_active(vp->v_mount, ptyfs->ptyfs_pty); |
225 | | | 225 | |
226 | return 0; | | 226 | return 0; |
227 | } | | 227 | } |
228 | | | 228 | |
229 | /* | | 229 | /* |
230 | * Return POSIX pathconf information applicable to special devices. | | 230 | * Return POSIX pathconf information applicable to special devices. |
231 | */ | | 231 | */ |
232 | int | | 232 | int |
233 | ptyfs_pathconf(void *v) | | 233 | ptyfs_pathconf(void *v) |
234 | { | | 234 | { |
235 | struct vop_pathconf_args /* { | | 235 | struct vop_pathconf_args /* { |
236 | struct vnode *a_vp; | | 236 | struct vnode *a_vp; |
237 | int a_name; | | 237 | int a_name; |
238 | register_t *a_retval; | | 238 | register_t *a_retval; |
239 | } */ *ap = v; | | 239 | } */ *ap = v; |
240 | | | 240 | |
241 | switch (ap->a_name) { | | 241 | switch (ap->a_name) { |
242 | case _PC_LINK_MAX: | | 242 | case _PC_LINK_MAX: |
243 | *ap->a_retval = LINK_MAX; | | 243 | *ap->a_retval = LINK_MAX; |
244 | return 0; | | 244 | return 0; |
245 | case _PC_MAX_CANON: | | 245 | case _PC_MAX_CANON: |
246 | *ap->a_retval = MAX_CANON; | | 246 | *ap->a_retval = MAX_CANON; |
247 | return 0; | | 247 | return 0; |
248 | case _PC_MAX_INPUT: | | 248 | case _PC_MAX_INPUT: |
249 | *ap->a_retval = MAX_INPUT; | | 249 | *ap->a_retval = MAX_INPUT; |
250 | return 0; | | 250 | return 0; |
251 | case _PC_PIPE_BUF: | | 251 | case _PC_PIPE_BUF: |
252 | *ap->a_retval = PIPE_BUF; | | 252 | *ap->a_retval = PIPE_BUF; |
253 | return 0; | | 253 | return 0; |
254 | case _PC_CHOWN_RESTRICTED: | | 254 | case _PC_CHOWN_RESTRICTED: |
255 | *ap->a_retval = 1; | | 255 | *ap->a_retval = 1; |
256 | return 0; | | 256 | return 0; |
257 | case _PC_VDISABLE: | | 257 | case _PC_VDISABLE: |
258 | *ap->a_retval = _POSIX_VDISABLE; | | 258 | *ap->a_retval = _POSIX_VDISABLE; |
259 | return 0; | | 259 | return 0; |
260 | case _PC_SYNC_IO: | | 260 | case _PC_SYNC_IO: |
261 | *ap->a_retval = 1; | | 261 | *ap->a_retval = 1; |
262 | return 0; | | 262 | return 0; |
263 | default: | | 263 | default: |
264 | return genfs_pathconf(ap); | | 264 | return genfs_pathconf(ap); |
265 | } | | 265 | } |
266 | } | | 266 | } |
267 | | | 267 | |
268 | /* | | 268 | /* |
269 | * _print is used for debugging. | | 269 | * _print is used for debugging. |
270 | * just print a readable description | | 270 | * just print a readable description |
271 | * of (vp). | | 271 | * of (vp). |
272 | */ | | 272 | */ |
273 | int | | 273 | int |
274 | ptyfs_print(void *v) | | 274 | ptyfs_print(void *v) |
275 | { | | 275 | { |
276 | struct vop_print_args /* { | | 276 | struct vop_print_args /* { |
277 | struct vnode *a_vp; | | 277 | struct vnode *a_vp; |
278 | } */ *ap = v; | | 278 | } */ *ap = v; |
279 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); | | 279 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); |
280 | | | 280 | |
281 | printf("tag VT_PTYFS, type %d, pty %d\n", | | 281 | printf("tag VT_PTYFS, type %d, pty %d\n", |
282 | ptyfs->ptyfs_type, ptyfs->ptyfs_pty); | | 282 | ptyfs->ptyfs_type, ptyfs->ptyfs_pty); |
283 | return 0; | | 283 | return 0; |
284 | } | | 284 | } |
285 | | | 285 | |
286 | /* | | 286 | /* |
287 | * support advisory locking on pty nodes | | 287 | * support advisory locking on pty nodes |
288 | */ | | 288 | */ |
289 | int | | 289 | int |
290 | ptyfs_advlock(void *v) | | 290 | ptyfs_advlock(void *v) |
291 | { | | 291 | { |
292 | struct vop_print_args /* { | | 292 | struct vop_print_args /* { |
293 | struct vnode *a_vp; | | 293 | struct vnode *a_vp; |
294 | } */ *ap = v; | | 294 | } */ *ap = v; |
295 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); | | 295 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); |
296 | | | 296 | |
297 | switch (ptyfs->ptyfs_type) { | | 297 | switch (ptyfs->ptyfs_type) { |
298 | case PTYFSpts: | | 298 | case PTYFSpts: |
299 | case PTYFSptc: | | 299 | case PTYFSptc: |
300 | return spec_advlock(v); | | 300 | return spec_advlock(v); |
301 | default: | | 301 | default: |
302 | return EOPNOTSUPP; | | 302 | return EOPNOTSUPP; |
303 | } | | 303 | } |
304 | } | | 304 | } |
305 | | | 305 | |
306 | /* | | 306 | /* |
307 | * Invent attributes for ptyfsnode (vp) and store | | 307 | * Invent attributes for ptyfsnode (vp) and store |
308 | * them in (vap). | | 308 | * them in (vap). |
309 | * Directories lengths are returned as zero since | | 309 | * Directories lengths are returned as zero since |
310 | * any real length would require the genuine size | | 310 | * any real length would require the genuine size |
311 | * to be computed, and nothing cares anyway. | | 311 | * to be computed, and nothing cares anyway. |
312 | * | | 312 | * |
313 | * this is relatively minimal for ptyfs. | | 313 | * this is relatively minimal for ptyfs. |
314 | */ | | 314 | */ |
315 | int | | 315 | int |
316 | ptyfs_getattr(void *v) | | 316 | ptyfs_getattr(void *v) |
317 | { | | 317 | { |
318 | struct vop_getattr_args /* { | | 318 | struct vop_getattr_args /* { |
319 | struct vnode *a_vp; | | 319 | struct vnode *a_vp; |
320 | struct vattr *a_vap; | | 320 | struct vattr *a_vap; |
321 | kauth_cred_t a_cred; | | 321 | kauth_cred_t a_cred; |
322 | } */ *ap = v; | | 322 | } */ *ap = v; |
323 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); | | 323 | struct ptyfsnode *ptyfs = VTOPTYFS(ap->a_vp); |
324 | struct vattr *vap = ap->a_vap; | | 324 | struct vattr *vap = ap->a_vap; |
325 | | | 325 | |
326 | PTYFS_ITIMES(ptyfs, NULL, NULL, NULL); | | 326 | PTYFS_ITIMES(ptyfs, NULL, NULL, NULL); |
327 | | | 327 | |
328 | /* start by zeroing out the attributes */ | | 328 | /* start by zeroing out the attributes */ |
329 | vattr_null(vap); | | 329 | vattr_null(vap); |
330 | | | 330 | |
331 | /* next do all the common fields */ | | 331 | /* next do all the common fields */ |
332 | vap->va_type = ap->a_vp->v_type; | | 332 | vap->va_type = ap->a_vp->v_type; |
333 | vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0]; | | 333 | vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0]; |
334 | vap->va_fileid = ptyfs->ptyfs_fileno; | | 334 | vap->va_fileid = ptyfs->ptyfs_fileno; |
335 | vap->va_gen = 0; | | 335 | vap->va_gen = 0; |
336 | vap->va_flags = 0; | | 336 | vap->va_flags = 0; |
337 | vap->va_blocksize = PAGE_SIZE; | | 337 | vap->va_blocksize = PAGE_SIZE; |
338 | | | 338 | |
339 | vap->va_atime = ptyfs->ptyfs_atime; | | 339 | vap->va_atime = ptyfs->ptyfs_atime; |
340 | vap->va_mtime = ptyfs->ptyfs_mtime; | | 340 | vap->va_mtime = ptyfs->ptyfs_mtime; |
341 | vap->va_ctime = ptyfs->ptyfs_ctime; | | 341 | vap->va_ctime = ptyfs->ptyfs_ctime; |
342 | vap->va_birthtime = ptyfs->ptyfs_birthtime; | | 342 | vap->va_birthtime = ptyfs->ptyfs_birthtime; |
343 | vap->va_mode = ptyfs->ptyfs_mode; | | 343 | vap->va_mode = ptyfs->ptyfs_mode; |
344 | vap->va_flags = ptyfs->ptyfs_flags; | | 344 | vap->va_flags = ptyfs->ptyfs_flags; |
345 | vap->va_uid = ptyfs->ptyfs_uid; | | 345 | vap->va_uid = ptyfs->ptyfs_uid; |
346 | vap->va_gid = ptyfs->ptyfs_gid; | | 346 | vap->va_gid = ptyfs->ptyfs_gid; |
347 | | | 347 | |
348 | switch (ptyfs->ptyfs_type) { | | 348 | switch (ptyfs->ptyfs_type) { |
349 | case PTYFSpts: | | 349 | case PTYFSpts: |
350 | case PTYFSptc: | | 350 | case PTYFSptc: |
351 | if (pty_isfree(ptyfs->ptyfs_pty, 1)) | | 351 | if (pty_isfree(ptyfs->ptyfs_pty, 1)) |
352 | return ENOENT; | | 352 | return ENOENT; |
353 | vap->va_bytes = vap->va_size = 0; | | 353 | vap->va_bytes = vap->va_size = 0; |
354 | vap->va_rdev = ap->a_vp->v_rdev; | | 354 | vap->va_rdev = ap->a_vp->v_rdev; |
355 | vap->va_nlink = 1; | | 355 | vap->va_nlink = 1; |
356 | break; | | 356 | break; |
357 | case PTYFSroot: | | 357 | case PTYFSroot: |
358 | vap->va_rdev = 0; | | 358 | vap->va_rdev = 0; |
359 | vap->va_bytes = vap->va_size = DEV_BSIZE; | | 359 | vap->va_bytes = vap->va_size = DEV_BSIZE; |
360 | vap->va_nlink = 2; | | 360 | vap->va_nlink = 2; |
361 | break; | | 361 | break; |
362 | default: | | 362 | default: |
363 | return EOPNOTSUPP; | | 363 | return EOPNOTSUPP; |
364 | } | | 364 | } |
365 | | | 365 | |
366 | return 0; | | 366 | return 0; |
367 | } | | 367 | } |
368 | | | 368 | |
369 | /*ARGSUSED*/ | | 369 | /*ARGSUSED*/ |
370 | int | | 370 | int |
371 | ptyfs_setattr(void *v) | | 371 | ptyfs_setattr(void *v) |
372 | { | | 372 | { |
373 | struct vop_setattr_args /* { | | 373 | struct vop_setattr_args /* { |
374 | struct vnodeop_desc *a_desc; | | 374 | struct vnodeop_desc *a_desc; |
375 | struct vnode *a_vp; | | 375 | struct vnode *a_vp; |
376 | struct vattr *a_vap; | | 376 | struct vattr *a_vap; |
377 | kauth_cred_t a_cred; | | 377 | kauth_cred_t a_cred; |
378 | } */ *ap = v; | | 378 | } */ *ap = v; |
379 | struct vnode *vp = ap->a_vp; | | 379 | struct vnode *vp = ap->a_vp; |
380 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 380 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
381 | struct vattr *vap = ap->a_vap; | | 381 | struct vattr *vap = ap->a_vap; |
382 | kauth_cred_t cred = ap->a_cred; | | 382 | kauth_cred_t cred = ap->a_cred; |
383 | struct lwp *l = curlwp; | | 383 | struct lwp *l = curlwp; |
384 | int error; | | 384 | int error; |
385 | kauth_action_t action = KAUTH_VNODE_WRITE_FLAGS; | | 385 | kauth_action_t action = KAUTH_VNODE_WRITE_FLAGS; |
386 | bool changing_sysflags = false; | | 386 | bool changing_sysflags = false; |
387 | | | 387 | |
388 | if (vap->va_size != VNOVALSIZE) { | | 388 | if (vap->va_size != VNOVALSIZE) { |
389 | switch (ptyfs->ptyfs_type) { | | 389 | switch (ptyfs->ptyfs_type) { |
390 | case PTYFSroot: | | 390 | case PTYFSroot: |
391 | return EISDIR; | | 391 | return EISDIR; |
392 | case PTYFSpts: | | 392 | case PTYFSpts: |
393 | case PTYFSptc: | | 393 | case PTYFSptc: |
394 | break; | | 394 | break; |
395 | default: | | 395 | default: |
396 | return EINVAL; | | 396 | return EINVAL; |
397 | } | | 397 | } |
398 | } | | 398 | } |
399 | | | 399 | |
400 | if (vap->va_flags != VNOVALFLAGS) { | | 400 | if (vap->va_flags != VNOVALFLAGS) { |
401 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | | 401 | if (vp->v_mount->mnt_flag & MNT_RDONLY) |
402 | return EROFS; | | 402 | return EROFS; |
403 | | | 403 | |
404 | /* Immutable and append-only flags are not supported on ptyfs. */ | | 404 | /* Immutable and append-only flags are not supported on ptyfs. */ |
405 | if (vap->va_flags & (IMMUTABLE | APPEND)) | | 405 | if (vap->va_flags & (IMMUTABLE | APPEND)) |
406 | return EINVAL; | | 406 | return EINVAL; |
407 | | | 407 | |
408 | /* Snapshot flag cannot be set or cleared */ | | 408 | /* Snapshot flag cannot be set or cleared */ |
409 | if ((vap->va_flags & SF_SNAPSHOT) != (ptyfs->ptyfs_flags & SF_SNAPSHOT)) | | 409 | if ((vap->va_flags & SF_SNAPSHOT) != (ptyfs->ptyfs_flags & SF_SNAPSHOT)) |
410 | return EPERM; | | 410 | return EPERM; |
411 | | | 411 | |
412 | if ((ptyfs->ptyfs_flags & SF_SETTABLE) != (vap->va_flags & SF_SETTABLE)) { | | 412 | if ((ptyfs->ptyfs_flags & SF_SETTABLE) != (vap->va_flags & SF_SETTABLE)) { |
413 | changing_sysflags = true; | | 413 | changing_sysflags = true; |
414 | action |= KAUTH_VNODE_WRITE_SYSFLAGS; | | 414 | action |= KAUTH_VNODE_WRITE_SYSFLAGS; |
415 | } | | 415 | } |
416 | | | 416 | |
417 | error = kauth_authorize_vnode(cred, action, vp, NULL, | | 417 | error = kauth_authorize_vnode(cred, action, vp, NULL, |
418 | genfs_can_chflags(vp, cred, ptyfs->ptyfs_uid, | | 418 | genfs_can_chflags(vp, cred, ptyfs->ptyfs_uid, |
419 | changing_sysflags)); | | 419 | changing_sysflags)); |
420 | if (error) | | 420 | if (error) |
421 | return error; | | 421 | return error; |
422 | | | 422 | |
423 | if (changing_sysflags) { | | 423 | if (changing_sysflags) { |
424 | ptyfs->ptyfs_flags = vap->va_flags; | | 424 | ptyfs->ptyfs_flags = vap->va_flags; |
425 | } else { | | 425 | } else { |
426 | ptyfs->ptyfs_flags &= SF_SETTABLE; | | 426 | ptyfs->ptyfs_flags &= SF_SETTABLE; |
427 | ptyfs->ptyfs_flags |= (vap->va_flags & UF_SETTABLE); | | 427 | ptyfs->ptyfs_flags |= (vap->va_flags & UF_SETTABLE); |
428 | } | | 428 | } |
429 | ptyfs->ptyfs_status |= PTYFS_CHANGE; | | 429 | ptyfs->ptyfs_status |= PTYFS_CHANGE; |
430 | } | | 430 | } |
431 | | | 431 | |
432 | /* | | 432 | /* |
433 | * Go through the fields and update iff not VNOVAL. | | 433 | * Go through the fields and update iff not VNOVAL. |
434 | */ | | 434 | */ |
435 | if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) { | | 435 | if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) { |
436 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | | 436 | if (vp->v_mount->mnt_flag & MNT_RDONLY) |
437 | return EROFS; | | 437 | return EROFS; |
438 | error = ptyfs_chown(vp, vap->va_uid, vap->va_gid, cred, l); | | 438 | error = ptyfs_chown(vp, vap->va_uid, vap->va_gid, cred, l); |
439 | if (error) | | 439 | if (error) |
440 | return error; | | 440 | return error; |
441 | } | | 441 | } |
442 | | | 442 | |
443 | if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL || | | 443 | if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL || |
444 | vap->va_birthtime.tv_sec != VNOVAL) { | | 444 | vap->va_birthtime.tv_sec != VNOVAL) { |
445 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | | 445 | if (vp->v_mount->mnt_flag & MNT_RDONLY) |
446 | return EROFS; | | 446 | return EROFS; |
447 | if ((ptyfs->ptyfs_flags & SF_SNAPSHOT) != 0) | | 447 | if ((ptyfs->ptyfs_flags & SF_SNAPSHOT) != 0) |
448 | return EPERM; | | 448 | return EPERM; |
449 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp, | | 449 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp, |
450 | NULL, genfs_can_chtimes(vp, cred, ptyfs->ptyfs_uid, | | 450 | NULL, genfs_can_chtimes(vp, cred, ptyfs->ptyfs_uid, |
451 | vap->va_vaflags)); | | 451 | vap->va_vaflags)); |
452 | if (error) | | 452 | if (error) |
453 | return (error); | | 453 | return (error); |
454 | if (vap->va_atime.tv_sec != VNOVAL) | | 454 | if (vap->va_atime.tv_sec != VNOVAL) |
455 | if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) | | 455 | if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) |
456 | ptyfs->ptyfs_status |= PTYFS_ACCESS; | | 456 | ptyfs->ptyfs_status |= PTYFS_ACCESS; |
457 | if (vap->va_mtime.tv_sec != VNOVAL) { | | 457 | if (vap->va_mtime.tv_sec != VNOVAL) { |
458 | ptyfs->ptyfs_status |= PTYFS_CHANGE | PTYFS_MODIFY; | | 458 | ptyfs->ptyfs_status |= PTYFS_CHANGE | PTYFS_MODIFY; |
459 | if (vp->v_mount->mnt_flag & MNT_RELATIME) | | 459 | if (vp->v_mount->mnt_flag & MNT_RELATIME) |
460 | ptyfs->ptyfs_status |= PTYFS_ACCESS; | | 460 | ptyfs->ptyfs_status |= PTYFS_ACCESS; |
461 | } | | 461 | } |
462 | if (vap->va_birthtime.tv_sec != VNOVAL) | | 462 | if (vap->va_birthtime.tv_sec != VNOVAL) |
463 | ptyfs->ptyfs_birthtime = vap->va_birthtime; | | 463 | ptyfs->ptyfs_birthtime = vap->va_birthtime; |
464 | ptyfs->ptyfs_status |= PTYFS_CHANGE; | | 464 | ptyfs->ptyfs_status |= PTYFS_CHANGE; |
465 | error = ptyfs_update(vp, &vap->va_atime, &vap->va_mtime, 0); | | 465 | error = ptyfs_update(vp, &vap->va_atime, &vap->va_mtime, 0); |
466 | if (error) | | 466 | if (error) |
467 | return error; | | 467 | return error; |
468 | } | | 468 | } |
469 | if (vap->va_mode != (mode_t)VNOVAL) { | | 469 | if (vap->va_mode != (mode_t)VNOVAL) { |
470 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | | 470 | if (vp->v_mount->mnt_flag & MNT_RDONLY) |
471 | return EROFS; | | 471 | return EROFS; |
472 | if ((ptyfs->ptyfs_flags & SF_SNAPSHOT) != 0 && | | 472 | if ((ptyfs->ptyfs_flags & SF_SNAPSHOT) != 0 && |
473 | (vap->va_mode & | | 473 | (vap->va_mode & |
474 | (S_IXUSR|S_IWUSR|S_IXGRP|S_IWGRP|S_IXOTH|S_IWOTH))) | | 474 | (S_IXUSR|S_IWUSR|S_IXGRP|S_IWGRP|S_IXOTH|S_IWOTH))) |
475 | return EPERM; | | 475 | return EPERM; |
476 | error = ptyfs_chmod(vp, vap->va_mode, cred, l); | | 476 | error = ptyfs_chmod(vp, vap->va_mode, cred, l); |
477 | if (error) | | 477 | if (error) |
478 | return error; | | 478 | return error; |
479 | } | | 479 | } |
480 | VN_KNOTE(vp, NOTE_ATTRIB); | | 480 | VN_KNOTE(vp, NOTE_ATTRIB); |
481 | return 0; | | 481 | return 0; |
482 | } | | 482 | } |
483 | | | 483 | |
484 | /* | | 484 | /* |
485 | * Change the mode on a file. | | 485 | * Change the mode on a file. |
486 | * Inode must be locked before calling. | | 486 | * Inode must be locked before calling. |
487 | */ | | 487 | */ |
488 | static int | | 488 | static int |
489 | ptyfs_chmod(struct vnode *vp, mode_t mode, kauth_cred_t cred, struct lwp *l) | | 489 | ptyfs_chmod(struct vnode *vp, mode_t mode, kauth_cred_t cred, struct lwp *l) |
490 | { | | 490 | { |
491 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 491 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
492 | int error; | | 492 | int error; |
493 | | | 493 | |
494 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp, | | 494 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp, |
495 | NULL, genfs_can_chmod(vp, cred, ptyfs->ptyfs_uid, ptyfs->ptyfs_gid, | | 495 | NULL, genfs_can_chmod(vp, cred, ptyfs->ptyfs_uid, ptyfs->ptyfs_gid, |
496 | mode)); | | 496 | mode)); |
497 | if (error) | | 497 | if (error) |
498 | return (error); | | 498 | return (error); |
499 | | | 499 | |
500 | ptyfs->ptyfs_mode &= ~ALLPERMS; | | 500 | ptyfs->ptyfs_mode &= ~ALLPERMS; |
501 | ptyfs->ptyfs_mode |= (mode & ALLPERMS); | | 501 | ptyfs->ptyfs_mode |= (mode & ALLPERMS); |
502 | return 0; | | 502 | return 0; |
503 | } | | 503 | } |
504 | | | 504 | |
505 | /* | | 505 | /* |
506 | * Perform chown operation on inode ip; | | 506 | * Perform chown operation on inode ip; |
507 | * inode must be locked prior to call. | | 507 | * inode must be locked prior to call. |
508 | */ | | 508 | */ |
509 | static int | | 509 | static int |
510 | ptyfs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred, | | 510 | ptyfs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred, |
511 | struct lwp *l) | | 511 | struct lwp *l) |
512 | { | | 512 | { |
513 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 513 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
514 | int error; | | 514 | int error; |
515 | | | 515 | |
516 | if (uid == (uid_t)VNOVAL) | | 516 | if (uid == (uid_t)VNOVAL) |
517 | uid = ptyfs->ptyfs_uid; | | 517 | uid = ptyfs->ptyfs_uid; |
518 | if (gid == (gid_t)VNOVAL) | | 518 | if (gid == (gid_t)VNOVAL) |
519 | gid = ptyfs->ptyfs_gid; | | 519 | gid = ptyfs->ptyfs_gid; |
520 | | | 520 | |
521 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp, | | 521 | error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp, |
522 | NULL, genfs_can_chown(vp, cred, ptyfs->ptyfs_uid, ptyfs->ptyfs_gid, | | 522 | NULL, genfs_can_chown(vp, cred, ptyfs->ptyfs_uid, ptyfs->ptyfs_gid, |
523 | uid, gid)); | | 523 | uid, gid)); |
524 | if (error) | | 524 | if (error) |
525 | return (error); | | 525 | return (error); |
526 | | | 526 | |
527 | ptyfs->ptyfs_gid = gid; | | 527 | ptyfs->ptyfs_gid = gid; |
528 | ptyfs->ptyfs_uid = uid; | | 528 | ptyfs->ptyfs_uid = uid; |
529 | return 0; | | 529 | return 0; |
530 | } | | 530 | } |
531 | | | 531 | |
532 | /* | | 532 | /* |
533 | * implement access checking. | | 533 | * implement access checking. |
534 | * | | 534 | * |
535 | * actually, the check for super-user is slightly | | 535 | * actually, the check for super-user is slightly |
536 | * broken since it will allow read access to write-only | | 536 | * broken since it will allow read access to write-only |
537 | * objects. this doesn't cause any particular trouble | | 537 | * objects. this doesn't cause any particular trouble |
538 | * but does mean that the i/o entry points need to check | | 538 | * but does mean that the i/o entry points need to check |
539 | * that the operation really does make sense. | | 539 | * that the operation really does make sense. |
540 | */ | | 540 | */ |
541 | int | | 541 | int |
542 | ptyfs_access(void *v) | | 542 | ptyfs_access(void *v) |
543 | { | | 543 | { |
544 | struct vop_access_args /* { | | 544 | struct vop_access_args /* { |
545 | struct vnode *a_vp; | | 545 | struct vnode *a_vp; |
546 | accmode_t a_accmode; | | 546 | accmode_t a_accmode; |
547 | kauth_cred_t a_cred; | | 547 | kauth_cred_t a_cred; |
548 | } */ *ap = v; | | 548 | } */ *ap = v; |
549 | struct vattr va; | | 549 | struct vattr va; |
550 | int error; | | 550 | int error; |
551 | | | 551 | |
552 | if ((error = VOP_GETATTR(ap->a_vp, &va, ap->a_cred)) != 0) | | 552 | if ((error = VOP_GETATTR(ap->a_vp, &va, ap->a_cred)) != 0) |
553 | return error; | | 553 | return error; |
554 | | | 554 | |
555 | return kauth_authorize_vnode(ap->a_cred, | | 555 | return kauth_authorize_vnode(ap->a_cred, |
556 | KAUTH_ACCESS_ACTION(ap->a_accmode, ap->a_vp->v_type, va.va_mode), | | 556 | KAUTH_ACCESS_ACTION(ap->a_accmode, ap->a_vp->v_type, va.va_mode), |
557 | ap->a_vp, NULL, genfs_can_access(ap->a_vp, ap->a_cred, va.va_uid, | | 557 | ap->a_vp, NULL, genfs_can_access(ap->a_vp, ap->a_cred, va.va_uid, |
558 | va.va_gid, va.va_mode, NULL, ap->a_accmode)); | | 558 | va.va_gid, va.va_mode, NULL, ap->a_accmode)); |
559 | } | | 559 | } |
560 | | | 560 | |
561 | /* | | 561 | /* |
562 | * lookup. this is incredibly complicated in the | | 562 | * lookup. this is incredibly complicated in the |
563 | * general case, however for most pseudo-filesystems | | 563 | * general case, however for most pseudo-filesystems |
564 | * very little needs to be done. | | 564 | * very little needs to be done. |
565 | * | | 565 | * |
566 | * Locking isn't hard here, just poorly documented. | | 566 | * Locking isn't hard here, just poorly documented. |
567 | * | | 567 | * |
568 | * If we're looking up ".", just vref the parent & return it. | | 568 | * If we're looking up ".", just vref the parent & return it. |
569 | * | | 569 | * |
570 | * If we're looking up "..", unlock the parent, and lock "..". If everything | | 570 | * If we're looking up "..", unlock the parent, and lock "..". If everything |
571 | * went ok, try to re-lock the parent. We do this to prevent lock races. | | 571 | * went ok, try to re-lock the parent. We do this to prevent lock races. |
572 | * | | 572 | * |
573 | * For anything else, get the needed node. | | 573 | * For anything else, get the needed node. |
574 | * | | 574 | * |
575 | * We try to exit with the parent locked in error cases. | | 575 | * We try to exit with the parent locked in error cases. |
576 | */ | | 576 | */ |
577 | int | | 577 | int |
578 | ptyfs_lookup(void *v) | | 578 | ptyfs_lookup(void *v) |
579 | { | | 579 | { |
580 | struct vop_lookup_v2_args /* { | | 580 | struct vop_lookup_v2_args /* { |
581 | struct vnode * a_dvp; | | 581 | struct vnode * a_dvp; |
582 | struct vnode ** a_vpp; | | 582 | struct vnode ** a_vpp; |
583 | struct componentname * a_cnp; | | 583 | struct componentname * a_cnp; |
584 | } */ *ap = v; | | 584 | } */ *ap = v; |
585 | struct componentname *cnp = ap->a_cnp; | | 585 | struct componentname *cnp = ap->a_cnp; |
586 | struct vnode **vpp = ap->a_vpp; | | 586 | struct vnode **vpp = ap->a_vpp; |
587 | struct vnode *dvp = ap->a_dvp; | | 587 | struct vnode *dvp = ap->a_dvp; |
588 | const char *pname = cnp->cn_nameptr; | | 588 | const char *pname = cnp->cn_nameptr; |
589 | struct ptyfsnode *ptyfs; | | 589 | struct ptyfsnode *ptyfs; |
590 | int pty, error; | | 590 | int pty, error; |
591 | | | 591 | |
592 | *vpp = NULL; | | 592 | *vpp = NULL; |
593 | | | 593 | |
594 | if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME) | | 594 | if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME) |
595 | return EROFS; | | 595 | return EROFS; |
596 | | | 596 | |
597 | if (cnp->cn_namelen == 1 && *pname == '.') { | | 597 | if (cnp->cn_namelen == 1 && *pname == '.') { |
598 | *vpp = dvp; | | 598 | *vpp = dvp; |
599 | vref(dvp); | | 599 | vref(dvp); |
600 | return 0; | | 600 | return 0; |
601 | } | | 601 | } |
602 | | | 602 | |
603 | ptyfs = VTOPTYFS(dvp); | | 603 | ptyfs = VTOPTYFS(dvp); |
604 | switch (ptyfs->ptyfs_type) { | | 604 | switch (ptyfs->ptyfs_type) { |
605 | case PTYFSroot: | | 605 | case PTYFSroot: |
606 | /* | | 606 | /* |
607 | * Shouldn't get here with .. in the root node. | | 607 | * Shouldn't get here with .. in the root node. |
608 | */ | | 608 | */ |
609 | if (cnp->cn_flags & ISDOTDOT) | | 609 | if (cnp->cn_flags & ISDOTDOT) |
610 | return EIO; | | 610 | return EIO; |
611 | | | 611 | |
612 | pty = atoi(pname, cnp->cn_namelen); | | 612 | pty = atoi(pname, cnp->cn_namelen); |
613 | if (pty < 0 || ptyfs_next_active(dvp->v_mount, pty) != pty) | | 613 | if (pty < 0 || ptyfs_next_active(dvp->v_mount, pty) != pty) |
614 | break; | | 614 | break; |
615 | error = ptyfs_allocvp(dvp->v_mount, vpp, PTYFSpts, pty); | | 615 | error = ptyfs_allocvp(dvp->v_mount, vpp, PTYFSpts, pty); |
616 | if (error) | | 616 | if (error) |
617 | return error; | | 617 | return error; |
618 | if (ptyfs_next_active(dvp->v_mount, pty) != pty) { | | 618 | if (ptyfs_next_active(dvp->v_mount, pty) != pty) { |
619 | vrele(*vpp); | | 619 | vrele(*vpp); |
620 | *vpp = NULL; | | 620 | *vpp = NULL; |
621 | return ENOENT; | | 621 | return ENOENT; |
622 | } | | 622 | } |
623 | return 0; | | 623 | return 0; |
624 | | | 624 | |
625 | default: | | 625 | default: |
626 | return ENOTDIR; | | 626 | return ENOTDIR; |
627 | } | | 627 | } |
628 | | | 628 | |
629 | return cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS; | | 629 | return cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS; |
630 | } | | 630 | } |
631 | | | 631 | |
632 | /* | | 632 | /* |
633 | * readdir returns directory entries from ptyfsnode (vp). | | 633 | * readdir returns directory entries from ptyfsnode (vp). |
634 | * | | 634 | * |
635 | * the strategy here with ptyfs is to generate a single | | 635 | * the strategy here with ptyfs is to generate a single |
636 | * directory entry at a time (struct dirent) and then | | 636 | * directory entry at a time (struct dirent) and then |
637 | * copy that out to userland using uiomove. a more efficent | | 637 | * copy that out to userland using uiomove. a more efficent |
638 | * though more complex implementation, would try to minimize | | 638 | * though more complex implementation, would try to minimize |
639 | * the number of calls to uiomove(). for ptyfs, this is | | 639 | * the number of calls to uiomove(). for ptyfs, this is |
640 | * hardly worth the added code complexity. | | 640 | * hardly worth the added code complexity. |
641 | * | | 641 | * |
642 | * this should just be done through read() | | 642 | * this should just be done through read() |
643 | */ | | 643 | */ |
644 | int | | 644 | int |
645 | ptyfs_readdir(void *v) | | 645 | ptyfs_readdir(void *v) |
646 | { | | 646 | { |
647 | struct vop_readdir_args /* { | | 647 | struct vop_readdir_args /* { |
648 | struct vnode *a_vp; | | 648 | struct vnode *a_vp; |
649 | struct uio *a_uio; | | 649 | struct uio *a_uio; |
650 | kauth_cred_t a_cred; | | 650 | kauth_cred_t a_cred; |
651 | int *a_eofflag; | | 651 | int *a_eofflag; |
652 | off_t **a_cookies; | | 652 | off_t **a_cookies; |
653 | int *a_ncookies; | | 653 | int *a_ncookies; |
654 | } */ *ap = v; | | 654 | } */ *ap = v; |
655 | struct uio *uio = ap->a_uio; | | 655 | struct uio *uio = ap->a_uio; |
656 | struct dirent *dp; | | 656 | struct dirent *dp; |
657 | struct ptyfsnode *ptyfs; | | 657 | struct ptyfsnode *ptyfs; |
658 | off_t i; | | 658 | off_t i; |
659 | int error; | | 659 | int error; |
660 | off_t *cookies = NULL; | | 660 | off_t *cookies = NULL; |
661 | int ncookies; | | 661 | int ncookies; |
662 | struct vnode *vp; | | 662 | struct vnode *vp; |
663 | int n, nc = 0; | | 663 | int n, nc = 0; |
664 | | | 664 | |
665 | vp = ap->a_vp; | | 665 | vp = ap->a_vp; |
666 | ptyfs = VTOPTYFS(vp); | | 666 | ptyfs = VTOPTYFS(vp); |
667 | | | 667 | |
668 | if (uio->uio_resid < UIO_MX) | | 668 | if (uio->uio_resid < UIO_MX) |
669 | return EINVAL; | | 669 | return EINVAL; |
670 | if (uio->uio_offset < 0) | | 670 | if (uio->uio_offset < 0) |
671 | return EINVAL; | | 671 | return EINVAL; |
672 | | | 672 | |
673 | dp = malloc(sizeof(struct dirent), M_PTYFSTMP, M_WAITOK | M_ZERO); | | 673 | dp = malloc(sizeof(struct dirent), M_PTYFSTMP, M_WAITOK | M_ZERO); |
674 | | | 674 | |
675 | error = 0; | | 675 | error = 0; |
676 | i = uio->uio_offset; | | 676 | i = uio->uio_offset; |
677 | dp->d_reclen = UIO_MX; | | 677 | dp->d_reclen = UIO_MX; |
678 | ncookies = uio->uio_resid / UIO_MX; | | 678 | ncookies = uio->uio_resid / UIO_MX; |
679 | | | 679 | |
680 | if (ptyfs->ptyfs_type != PTYFSroot) { | | 680 | if (ptyfs->ptyfs_type != PTYFSroot) { |
681 | error = ENOTDIR; | | 681 | error = ENOTDIR; |
682 | goto out; | | 682 | goto out; |
683 | } | | 683 | } |
684 | | | 684 | |
685 | if (i >= npty) | | 685 | if (i >= npty) |
686 | goto out; | | 686 | goto out; |
687 | | | 687 | |
688 | if (ap->a_ncookies) { | | 688 | if (ap->a_ncookies) { |
689 | ncookies = uimin(ncookies, (npty + 2 - i)); | | 689 | ncookies = uimin(ncookies, (npty + 2 - i)); |
690 | cookies = malloc(ncookies * sizeof (off_t), | | 690 | cookies = malloc(ncookies * sizeof (off_t), |
691 | M_TEMP, M_WAITOK); | | 691 | M_TEMP, M_WAITOK); |
692 | *ap->a_cookies = cookies; | | 692 | *ap->a_cookies = cookies; |
693 | } | | 693 | } |
694 | | | 694 | |
695 | for (; i < 2; i++) { | | 695 | for (; i < 2; i++) { |
696 | /* `.' and/or `..' */ | | 696 | /* `.' and/or `..' */ |
697 | dp->d_fileno = PTYFS_FILENO(PTYFSroot, 0); | | 697 | dp->d_fileno = PTYFS_FILENO(PTYFSroot, 0); |
698 | dp->d_namlen = i + 1; | | 698 | dp->d_namlen = i + 1; |
699 | (void)memcpy(dp->d_name, "..", dp->d_namlen); | | 699 | (void)memcpy(dp->d_name, "..", dp->d_namlen); |
700 | dp->d_name[i + 1] = '\0'; | | 700 | dp->d_name[i + 1] = '\0'; |
701 | dp->d_type = DT_DIR; | | 701 | dp->d_type = DT_DIR; |
702 | if ((error = uiomove(dp, UIO_MX, uio)) != 0) | | 702 | if ((error = uiomove(dp, UIO_MX, uio)) != 0) |
703 | goto out; | | 703 | goto out; |
704 | if (cookies) | | 704 | if (cookies) |
705 | *cookies++ = i + 1; | | 705 | *cookies++ = i + 1; |
706 | nc++; | | 706 | nc++; |
707 | } | | 707 | } |
708 | while (uio->uio_resid >= UIO_MX) { | | 708 | while (uio->uio_resid >= UIO_MX) { |
709 | /* check for used ptys */ | | 709 | /* check for used ptys */ |
710 | n = ptyfs_next_active(vp->v_mount, i - 2); | | 710 | n = ptyfs_next_active(vp->v_mount, i - 2); |
711 | if (n < 0) | | 711 | if (n < 0) |
712 | break; | | 712 | break; |
713 | dp->d_fileno = PTYFS_FILENO(PTYFSpts, n); | | 713 | dp->d_fileno = PTYFS_FILENO(PTYFSpts, n); |
714 | dp->d_namlen = snprintf(dp->d_name, sizeof(dp->d_name), | | 714 | dp->d_namlen = snprintf(dp->d_name, sizeof(dp->d_name), |
715 | "%lld", (long long)(n)); | | 715 | "%lld", (long long)(n)); |
716 | dp->d_type = DT_CHR; | | 716 | dp->d_type = DT_CHR; |
717 | if ((error = uiomove(dp, UIO_MX, uio)) != 0) | | 717 | if ((error = uiomove(dp, UIO_MX, uio)) != 0) |
718 | goto out; | | 718 | goto out; |
719 | i = n + 3; | | 719 | i = n + 3; |
720 | if (cookies) | | 720 | if (cookies) |
721 | *cookies++ = i; | | 721 | *cookies++ = i; |
722 | nc++; | | 722 | nc++; |
723 | } | | 723 | } |
724 | | | 724 | |
725 | out: | | 725 | out: |
726 | /* not pertinent in error cases */ | | 726 | /* not pertinent in error cases */ |
727 | ncookies = nc; | | 727 | ncookies = nc; |
728 | | | 728 | |
729 | if (ap->a_ncookies) { | | 729 | if (ap->a_ncookies) { |
730 | if (error) { | | 730 | if (error) { |
731 | if (cookies) | | 731 | if (cookies) |
732 | free(*ap->a_cookies, M_TEMP); | | 732 | free(*ap->a_cookies, M_TEMP); |
733 | *ap->a_ncookies = 0; | | 733 | *ap->a_ncookies = 0; |
734 | *ap->a_cookies = NULL; | | 734 | *ap->a_cookies = NULL; |
735 | } else | | 735 | } else |
736 | *ap->a_ncookies = ncookies; | | 736 | *ap->a_ncookies = ncookies; |
737 | } | | 737 | } |
738 | uio->uio_offset = i; | | 738 | uio->uio_offset = i; |
739 | free(dp, M_PTYFSTMP); | | 739 | free(dp, M_PTYFSTMP); |
740 | return error; | | 740 | return error; |
741 | } | | 741 | } |
742 | | | 742 | |
743 | int | | 743 | int |
744 | ptyfs_open(void *v) | | 744 | ptyfs_open(void *v) |
745 | { | | 745 | { |
746 | struct vop_open_args /* { | | 746 | struct vop_open_args /* { |
747 | struct vnode *a_vp; | | 747 | struct vnode *a_vp; |
748 | int a_mode; | | 748 | int a_mode; |
749 | kauth_cred_t a_cred; | | 749 | kauth_cred_t a_cred; |
750 | } */ *ap = v; | | 750 | } */ *ap = v; |
751 | struct vnode *vp = ap->a_vp; | | 751 | struct vnode *vp = ap->a_vp; |
752 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 752 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
753 | | | 753 | |
754 | switch (ptyfs->ptyfs_type) { | | 754 | switch (ptyfs->ptyfs_type) { |
755 | case PTYFSpts: | | 755 | case PTYFSpts: |
756 | case PTYFSptc: | | 756 | case PTYFSptc: |
757 | return spec_open(v); | | 757 | return spec_open(v); |
758 | case PTYFSroot: | | 758 | case PTYFSroot: |
759 | return 0; | | 759 | return 0; |
760 | default: | | 760 | default: |
761 | return EINVAL; | | 761 | return EINVAL; |
762 | } | | 762 | } |
763 | } | | 763 | } |
764 | | | 764 | |
765 | int | | 765 | int |
766 | ptyfs_close(void *v) | | 766 | ptyfs_close(void *v) |
767 | { | | 767 | { |
768 | struct vop_close_args /* { | | 768 | struct vop_close_args /* { |
769 | struct vnode *a_vp; | | 769 | struct vnode *a_vp; |
770 | int a_fflag; | | 770 | int a_fflag; |
771 | kauth_cred_t a_cred; | | 771 | kauth_cred_t a_cred; |
772 | } */ *ap = v; | | 772 | } */ *ap = v; |
773 | struct vnode *vp = ap->a_vp; | | 773 | struct vnode *vp = ap->a_vp; |
774 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 774 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
775 | | | 775 | |
776 | mutex_enter(vp->v_interlock); | | 776 | mutex_enter(vp->v_interlock); |
777 | if (vrefcnt(vp) > 1) | | 777 | if (vrefcnt(vp) > 1) |
778 | PTYFS_ITIMES(ptyfs, NULL, NULL, NULL); | | 778 | PTYFS_ITIMES(ptyfs, NULL, NULL, NULL); |
779 | mutex_exit(vp->v_interlock); | | 779 | mutex_exit(vp->v_interlock); |
780 | | | 780 | |
781 | switch (ptyfs->ptyfs_type) { | | 781 | switch (ptyfs->ptyfs_type) { |
782 | case PTYFSpts: | | 782 | case PTYFSpts: |
783 | case PTYFSptc: | | 783 | case PTYFSptc: |
784 | return spec_close(v); | | 784 | return spec_close(v); |
785 | case PTYFSroot: | | 785 | case PTYFSroot: |
786 | return 0; | | 786 | return 0; |
787 | default: | | 787 | default: |
788 | return EINVAL; | | 788 | return EINVAL; |
789 | } | | 789 | } |
790 | } | | 790 | } |
791 | | | 791 | |
792 | int | | 792 | int |
793 | ptyfs_read(void *v) | | 793 | ptyfs_read(void *v) |
794 | { | | 794 | { |
795 | struct vop_read_args /* { | | 795 | struct vop_read_args /* { |
796 | struct vnode *a_vp; | | 796 | struct vnode *a_vp; |
797 | struct uio *a_uio; | | 797 | struct uio *a_uio; |
798 | int a_ioflag; | | 798 | int a_ioflag; |
799 | kauth_cred_t a_cred; | | 799 | kauth_cred_t a_cred; |
800 | } */ *ap = v; | | 800 | } */ *ap = v; |
801 | struct timespec ts; | | 801 | struct timespec ts; |
802 | struct vnode *vp = ap->a_vp; | | 802 | struct vnode *vp = ap->a_vp; |
803 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 803 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
804 | int error; | | 804 | int error; |
805 | | | 805 | |
806 | if (vp->v_type == VDIR) | | 806 | if (vp->v_type == VDIR) |
807 | return EISDIR; | | 807 | return EISDIR; |
808 | | | 808 | |
809 | ptyfs->ptyfs_status |= PTYFS_ACCESS; | | 809 | ptyfs->ptyfs_status |= PTYFS_ACCESS; |
810 | /* hardclock() resolution is good enough for ptyfs */ | | 810 | /* hardclock() resolution is good enough for ptyfs */ |
811 | getnanotime(&ts); | | 811 | getnanotime(&ts); |
812 | (void)ptyfs_update(vp, &ts, &ts, 0); | | 812 | (void)ptyfs_update(vp, &ts, &ts, 0); |
813 | | | 813 | |
814 | switch (ptyfs->ptyfs_type) { | | 814 | switch (ptyfs->ptyfs_type) { |
815 | case PTYFSpts: | | 815 | case PTYFSpts: |
816 | case PTYFSptc: | | 816 | case PTYFSptc: |
817 | VOP_UNLOCK(vp); | | 817 | VOP_UNLOCK(vp); |
818 | error = cdev_read(vp->v_rdev, ap->a_uio, ap->a_ioflag); | | 818 | error = cdev_read(vp->v_rdev, ap->a_uio, ap->a_ioflag); |
819 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); | | 819 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); |
820 | return error; | | 820 | return error; |
821 | default: | | 821 | default: |
822 | return EOPNOTSUPP; | | 822 | return EOPNOTSUPP; |
823 | } | | 823 | } |
824 | } | | 824 | } |
825 | | | 825 | |
826 | int | | 826 | int |
827 | ptyfs_write(void *v) | | 827 | ptyfs_write(void *v) |
828 | { | | 828 | { |
829 | struct vop_write_args /* { | | 829 | struct vop_write_args /* { |
830 | struct vnode *a_vp; | | 830 | struct vnode *a_vp; |
831 | struct uio *a_uio; | | 831 | struct uio *a_uio; |
832 | int a_ioflag; | | 832 | int a_ioflag; |
833 | kauth_cred_t a_cred; | | 833 | kauth_cred_t a_cred; |
834 | } */ *ap = v; | | 834 | } */ *ap = v; |
835 | struct timespec ts; | | 835 | struct timespec ts; |
836 | struct vnode *vp = ap->a_vp; | | 836 | struct vnode *vp = ap->a_vp; |
837 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 837 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
838 | int error; | | 838 | int error; |
839 | | | 839 | |
840 | ptyfs->ptyfs_status |= PTYFS_MODIFY; | | 840 | ptyfs->ptyfs_status |= PTYFS_MODIFY; |
841 | getnanotime(&ts); | | 841 | getnanotime(&ts); |
842 | (void)ptyfs_update(vp, &ts, &ts, 0); | | 842 | (void)ptyfs_update(vp, &ts, &ts, 0); |
843 | | | 843 | |
844 | switch (ptyfs->ptyfs_type) { | | 844 | switch (ptyfs->ptyfs_type) { |
845 | case PTYFSpts: | | 845 | case PTYFSpts: |
846 | case PTYFSptc: | | 846 | case PTYFSptc: |
847 | VOP_UNLOCK(vp); | | 847 | VOP_UNLOCK(vp); |
848 | error = cdev_write(vp->v_rdev, ap->a_uio, ap->a_ioflag); | | 848 | error = cdev_write(vp->v_rdev, ap->a_uio, ap->a_ioflag); |
849 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); | | 849 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); |
850 | return error; | | 850 | return error; |
851 | default: | | 851 | default: |
852 | return EOPNOTSUPP; | | 852 | return EOPNOTSUPP; |
853 | } | | 853 | } |
854 | } | | 854 | } |
855 | | | 855 | |
856 | int | | 856 | int |
857 | ptyfs_ioctl(void *v) | | 857 | ptyfs_ioctl(void *v) |
858 | { | | 858 | { |
859 | struct vop_ioctl_args /* { | | 859 | struct vop_ioctl_args /* { |
860 | struct vnode *a_vp; | | 860 | struct vnode *a_vp; |
861 | u_long a_command; | | 861 | u_long a_command; |
862 | void *a_data; | | 862 | void *a_data; |
863 | int a_fflag; | | 863 | int a_fflag; |
864 | kauth_cred_t a_cred; | | 864 | kauth_cred_t a_cred; |
865 | } */ *ap = v; | | 865 | } */ *ap = v; |
866 | struct vnode *vp = ap->a_vp; | | 866 | struct vnode *vp = ap->a_vp; |
867 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 867 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
868 | | | 868 | |
869 | switch (ptyfs->ptyfs_type) { | | 869 | switch (ptyfs->ptyfs_type) { |
870 | case PTYFSpts: | | 870 | case PTYFSpts: |
871 | case PTYFSptc: | | 871 | case PTYFSptc: |
872 | return cdev_ioctl(vp->v_rdev, ap->a_command, | | 872 | return cdev_ioctl(vp->v_rdev, ap->a_command, |
873 | ap->a_data, ap->a_fflag, curlwp); | | 873 | ap->a_data, ap->a_fflag, curlwp); |
874 | default: | | 874 | default: |
875 | return EOPNOTSUPP; | | 875 | return EOPNOTSUPP; |
876 | } | | 876 | } |
877 | } | | 877 | } |
878 | | | 878 | |
879 | int | | 879 | int |
880 | ptyfs_poll(void *v) | | 880 | ptyfs_poll(void *v) |
881 | { | | 881 | { |
882 | struct vop_poll_args /* { | | 882 | struct vop_poll_args /* { |
883 | struct vnode *a_vp; | | 883 | struct vnode *a_vp; |
884 | int a_events; | | 884 | int a_events; |
885 | } */ *ap = v; | | 885 | } */ *ap = v; |
886 | struct vnode *vp = ap->a_vp; | | 886 | struct vnode *vp = ap->a_vp; |
887 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 887 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
888 | | | 888 | |
889 | switch (ptyfs->ptyfs_type) { | | 889 | switch (ptyfs->ptyfs_type) { |
890 | case PTYFSpts: | | 890 | case PTYFSpts: |
891 | case PTYFSptc: | | 891 | case PTYFSptc: |
892 | return cdev_poll(vp->v_rdev, ap->a_events, curlwp); | | 892 | return cdev_poll(vp->v_rdev, ap->a_events, curlwp); |
893 | default: | | 893 | default: |
894 | return genfs_poll(v); | | 894 | return genfs_poll(v); |
895 | } | | 895 | } |
896 | } | | 896 | } |
897 | | | 897 | |
898 | int | | 898 | int |
899 | ptyfs_kqfilter(void *v) | | 899 | ptyfs_kqfilter(void *v) |
900 | { | | 900 | { |
901 | struct vop_kqfilter_args /* { | | 901 | struct vop_kqfilter_args /* { |
902 | struct vnode *a_vp; | | 902 | struct vnode *a_vp; |
903 | struct knote *a_kn; | | 903 | struct knote *a_kn; |
904 | } */ *ap = v; | | 904 | } */ *ap = v; |
905 | struct vnode *vp = ap->a_vp; | | 905 | struct vnode *vp = ap->a_vp; |
906 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 906 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
907 | | | 907 | |
908 | switch (ptyfs->ptyfs_type) { | | 908 | switch (ptyfs->ptyfs_type) { |
909 | case PTYFSpts: | | 909 | case PTYFSpts: |
910 | case PTYFSptc: | | 910 | case PTYFSptc: |
911 | return cdev_kqfilter(vp->v_rdev, ap->a_kn); | | 911 | return cdev_kqfilter(vp->v_rdev, ap->a_kn); |
912 | default: | | 912 | default: |
913 | return genfs_kqfilter(v); | | 913 | return genfs_kqfilter(v); |
914 | } | | 914 | } |
915 | } | | 915 | } |
916 | | | 916 | |
917 | static int | | 917 | static int |
918 | ptyfs_update(struct vnode *vp, const struct timespec *acc, | | 918 | ptyfs_update(struct vnode *vp, const struct timespec *acc, |
919 | const struct timespec *mod, int flags) | | 919 | const struct timespec *mod, int flags) |
920 | { | | 920 | { |
921 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | | 921 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); |
922 | | | 922 | |
923 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | | 923 | if (vp->v_mount->mnt_flag & MNT_RDONLY) |
924 | return 0; | | 924 | return 0; |
925 | | | 925 | |
926 | PTYFS_ITIMES(ptyfs, acc, mod, NULL); | | 926 | PTYFS_ITIMES(ptyfs, acc, mod, NULL); |
927 | return 0; | | 927 | return 0; |
928 | } | | 928 | } |
929 | | | 929 | |
930 | void | | 930 | void |
931 | ptyfs_itimes(struct ptyfsnode *ptyfs, const struct timespec *acc, | | 931 | ptyfs_itimes(struct ptyfsnode *ptyfs, const struct timespec *acc, |
932 | const struct timespec *mod, const struct timespec *cre) | | 932 | const struct timespec *mod, const struct timespec *cre) |
933 | { | | 933 | { |
934 | struct timespec now; | | 934 | struct timespec now; |
935 | | | 935 | |
936 | KASSERT(ptyfs->ptyfs_status & (PTYFS_ACCESS|PTYFS_CHANGE|PTYFS_MODIFY)); | | 936 | KASSERT(ptyfs->ptyfs_status & (PTYFS_ACCESS|PTYFS_CHANGE|PTYFS_MODIFY)); |
937 | | | 937 | |
938 | getnanotime(&now); | | 938 | getnanotime(&now); |
939 | if (ptyfs->ptyfs_status & PTYFS_ACCESS) { | | 939 | if (ptyfs->ptyfs_status & PTYFS_ACCESS) { |
940 | if (acc == NULL) | | 940 | if (acc == NULL) |
941 | acc = &now; | | 941 | acc = &now; |
942 | ptyfs->ptyfs_atime = *acc; | | 942 | ptyfs->ptyfs_atime = *acc; |
943 | } | | 943 | } |
944 | if (ptyfs->ptyfs_status & PTYFS_MODIFY) { | | 944 | if (ptyfs->ptyfs_status & PTYFS_MODIFY) { |
945 | if (mod == NULL) | | 945 | if (mod == NULL) |
946 | mod = &now; | | 946 | mod = &now; |
947 | ptyfs->ptyfs_mtime = *mod; | | 947 | ptyfs->ptyfs_mtime = *mod; |
948 | } | | 948 | } |
949 | if (ptyfs->ptyfs_status & PTYFS_CHANGE) { | | 949 | if (ptyfs->ptyfs_status & PTYFS_CHANGE) { |
950 | if (cre == NULL) | | 950 | if (cre == NULL) |
951 | cre = &now; | | 951 | cre = &now; |
952 | ptyfs->ptyfs_ctime = *cre; | | 952 | ptyfs->ptyfs_ctime = *cre; |
953 | } | | 953 | } |
954 | ptyfs->ptyfs_status &= ~(PTYFS_ACCESS|PTYFS_CHANGE|PTYFS_MODIFY); | | 954 | ptyfs->ptyfs_status &= ~(PTYFS_ACCESS|PTYFS_CHANGE|PTYFS_MODIFY); |
955 | } | | 955 | } |
956 | | | 956 | |
957 | /* | | 957 | /* |
958 | * convert decimal ascii to int | | 958 | * convert decimal ascii to int |
959 | */ | | 959 | */ |
960 | static int | | 960 | static int |
961 | atoi(const char *b, size_t len) | | 961 | atoi(const char *b, size_t len) |
962 | { | | 962 | { |
963 | int p = 0; | | 963 | int p = 0; |
964 | | | 964 | |
965 | while (len--) { | | 965 | while (len--) { |
966 | char c = *b++; | | 966 | char c = *b++; |
967 | if (c < '0' || c > '9') | | 967 | if (c < '0' || c > '9') |
968 | return -1; | | 968 | return -1; |
969 | p = 10 * p + (c - '0'); | | 969 | p = 10 * p + (c - '0'); |
970 | } | | 970 | } |
971 | | | 971 | |
972 | return p; | | 972 | return p; |
973 | } | | 973 | } |