Commit | Line | Data |
---|---|---|
46f6d677 | 1 | /* |
ad787160 C |
2 | * Copyright (c) 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
46f6d677 KU |
4 | * |
5 | * This software was developed by the Computer Systems Engineering group | |
6 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | |
7 | * contributed to Berkeley. | |
8 | * | |
ad787160 C |
9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * 3. All advertising materials mentioning features or use of this software | |
18 | * must display the following acknowledgement: | |
19 | * This product includes software developed by the University of | |
20 | * California, Berkeley and its contributors. | |
21 | * 4. Neither the name of the University nor the names of its contributors | |
22 | * may be used to endorse or promote products derived from this software | |
23 | * without specific prior written permission. | |
46f6d677 | 24 | * |
ad787160 C |
25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
35 | * SUCH DAMAGE. | |
36 | * | |
37 | * @(#)news_compat.c 8.1 (Berkeley) 6/11/93 | |
46f6d677 KU |
38 | * |
39 | * from: $Hdr: sun_misc.c,v 1.12 92/07/12 13:26:10 torek Exp $ | |
40 | */ | |
41 | ||
42 | /* | |
43 | * NEWS-OS compatibility module. | |
44 | * | |
45 | * NEWS-OS system calls that are implemented differently in BSD are | |
46 | * handled here. | |
47 | */ | |
48 | ||
49 | #include <sys/param.h> | |
50 | #include <sys/systm.h> | |
51 | #include <sys/proc.h> | |
52 | #include <sys/file.h> | |
53 | #include <sys/filedesc.h> | |
54 | #include <sys/ioctl.h> | |
55 | #include <sys/malloc.h> | |
56 | #include <sys/mbuf.h> | |
57 | #include <sys/mman.h> | |
58 | #include <sys/mount.h> | |
59 | #include <sys/resource.h> | |
60 | #include <sys/resourcevar.h> | |
61 | #include <sys/signal.h> | |
62 | #include <sys/signalvar.h> | |
63 | #include <sys/socket.h> | |
64 | #include <sys/vnode.h> | |
65 | #include <sys/uio.h> | |
66 | #include <sys/wait.h> | |
67 | ||
68 | #include <miscfs/specfs/specdev.h> | |
69 | ||
70 | #include <vm/vm.h> | |
71 | ||
72 | #if 0 | |
73 | /* here is the sun layout (not used directly): */ | |
74 | struct sun_dirent { | |
75 | long d_off; | |
76 | u_long d_fileno; | |
77 | u_short d_reclen; | |
78 | u_short d_namlen; | |
79 | char d_name[256]; | |
80 | }; | |
81 | #endif | |
82 | /* and the BSD layout: */ | |
83 | struct bsd_dirent { | |
84 | u_long d_fileno; | |
85 | u_short d_reclen; | |
86 | u_short d_namlen; | |
87 | char d_name[256]; | |
88 | }; | |
89 | ||
90 | /* | |
91 | * Read Sun-style directory entries. We suck them into kernel space so | |
92 | * that they can be massaged before being copied out to user code. Like | |
93 | * SunOS, we squish out `empty' entries. | |
94 | * | |
95 | * This is quite ugly, but what do you expect from compatibility code? | |
96 | */ | |
97 | struct sun_getdents_args { | |
98 | int fd; | |
99 | char *buf; | |
100 | int nbytes; | |
101 | }; | |
102 | sun_getdents(p, uap, retval) | |
103 | struct proc *p; | |
104 | register struct sun_getdents_args *uap; | |
105 | int *retval; | |
106 | { | |
107 | register struct vnode *vp; | |
108 | register caddr_t inp, buf; /* BSD-format */ | |
109 | register int len, reclen; /* BSD-format */ | |
110 | register caddr_t outp; /* Sun-format */ | |
111 | register int resid; /* Sun-format */ | |
112 | struct file *fp; | |
113 | struct uio auio; | |
114 | struct iovec aiov; | |
115 | off_t off; /* true file offset */ | |
116 | long soff; /* Sun file offset */ | |
117 | int buflen, error, eofflag; | |
118 | #define SUN_RECLEN(reclen) (reclen + sizeof(long)) | |
119 | ||
120 | if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0) | |
121 | return (error); | |
122 | if ((fp->f_flag & FREAD) == 0) | |
123 | return (EBADF); | |
124 | vp = (struct vnode *)fp->f_data; | |
125 | if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */ | |
126 | return (EINVAL); | |
127 | buflen = min(MAXBSIZE, uap->nbytes); | |
128 | buf = malloc(buflen, M_TEMP, M_WAITOK); | |
129 | VOP_LOCK(vp); | |
130 | off = fp->f_offset; | |
131 | again: | |
132 | aiov.iov_base = buf; | |
133 | aiov.iov_len = buflen; | |
134 | auio.uio_iov = &aiov; | |
135 | auio.uio_iovcnt = 1; | |
136 | auio.uio_rw = UIO_READ; | |
137 | auio.uio_segflg = UIO_SYSSPACE; | |
138 | auio.uio_procp = p; | |
139 | auio.uio_resid = buflen; | |
140 | auio.uio_offset = off; | |
141 | /* | |
142 | * First we read into the malloc'ed buffer, then | |
143 | * we massage it into user space, one record at a time. | |
144 | */ | |
145 | if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag)) | |
146 | goto out; | |
147 | inp = buf; | |
148 | outp = uap->buf; | |
149 | resid = uap->nbytes; | |
150 | if ((len = buflen - auio.uio_resid) == 0) | |
151 | goto eof; | |
152 | for (; len > 0; len -= reclen) { | |
153 | reclen = ((struct bsd_dirent *)inp)->d_reclen; | |
154 | if (reclen & 3) | |
155 | panic("sun_getdents"); | |
156 | off += reclen; /* each entry points to next */ | |
157 | if (((struct bsd_dirent *)inp)->d_fileno == 0) { | |
158 | inp += reclen; /* it is a hole; squish it out */ | |
159 | continue; | |
160 | } | |
161 | if (reclen > len || resid < SUN_RECLEN(reclen)) { | |
162 | /* entry too big for buffer, so just stop */ | |
163 | outp++; | |
164 | break; | |
165 | } | |
166 | /* copy out a Sun-shaped dirent */ | |
167 | ((struct bsd_dirent *)inp)->d_reclen = SUN_RECLEN(reclen); | |
168 | soff = off; | |
169 | if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 || | |
170 | (error = copyout(inp, outp + sizeof soff, reclen)) != 0) | |
171 | goto out; | |
172 | /* advance past this real entry */ | |
173 | inp += reclen; | |
174 | /* advance output past Sun-shaped entry */ | |
175 | outp += SUN_RECLEN(reclen); | |
176 | resid -= SUN_RECLEN(reclen); | |
177 | } | |
178 | /* if we squished out the whole block, try again */ | |
179 | if (outp == uap->buf) | |
180 | goto again; | |
181 | fp->f_offset = off; /* update the vnode offset */ | |
182 | eof: | |
183 | *retval = uap->nbytes - resid; | |
184 | out: | |
185 | VOP_UNLOCK(vp); | |
186 | free(buf, M_TEMP); | |
187 | return (error); | |
188 | } | |
189 | ||
190 | #define MAXDOMAINNAME 64 | |
191 | char sun_domainname[MAXDOMAINNAME]; | |
192 | int sun_domainnamelen = 1; | |
193 | ||
194 | struct sun_getdomainname_args { | |
195 | char *name; | |
196 | int namelen; | |
197 | }; | |
198 | sun_getdomainname(p, uap, retval) | |
199 | struct proc *p; | |
200 | struct sun_getdomainname_args *uap; | |
201 | int *retval; | |
202 | { | |
203 | register int l = min(uap->namelen, sun_domainnamelen + 1); | |
204 | ||
205 | return (copyout(sun_domainname, uap->name, l)); | |
206 | } | |
207 | ||
208 | struct sun_setdomainname_args { | |
209 | char *name; | |
210 | int namelen; | |
211 | }; | |
212 | sun_setdomainname(p, uap, retval) | |
213 | struct proc *p; | |
214 | struct sun_setdomainname_args *uap; | |
215 | int *retval; | |
216 | { | |
217 | register int l = uap->namelen, error; | |
218 | ||
219 | if (l >= MAXDOMAINNAME) | |
220 | return (EINVAL); /* ??? ENAMETOOLONG? */ | |
221 | if (error = suser(p->p_ucred, &p->p_acflag)) | |
222 | return (error); | |
223 | if (error = copyin(uap->name, sun_domainname, l)) | |
224 | return (error); | |
225 | sun_domainname[l] = 0; | |
226 | return (0); | |
227 | } | |
228 | ||
229 | /* | |
230 | * setenvp system call | |
231 | */ | |
232 | struct news_setenvp_args { | |
233 | char **envp; | |
234 | }; | |
235 | news_setenvp(p, args, retval) | |
236 | struct proc *p; | |
237 | struct news_setenvp_args *args; | |
238 | int *retval; | |
239 | { | |
240 | ||
241 | return (0); | |
242 | } | |
243 | ||
244 | /* | |
245 | * sysnews system call | |
246 | */ | |
247 | struct news_sysnews_args { | |
248 | int ctrltype; | |
249 | int arg1, arg2, arg3, arg4; | |
250 | }; | |
251 | news_sysnews(p, args, retval) | |
252 | struct proc *p; | |
253 | struct news_sysnews_args *args; | |
254 | int *retval; | |
255 | { | |
256 | ||
257 | return (0); | |
258 | } |