ultrix_pathname.c revision 1.12 1 /* $NetBSD: ultrix_pathname.c,v 1.12 2001/06/14 20:32:46 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 *
45 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
46 *
47 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
48 */
49
50
51 /*
52 * Ultrix emulation filesystem-namespace compatibility module.
53 *
54 * Ultrix system calls that examine the filesysten namespace
55 * are implemented here. Each system call has a wrapper that
56 * first checks if the given file exists at a special `emulation'
57 * pathname: the given path, prefixex with '/emul/ultrix', and
58 * if that pathname exists, it is used instead of the providd pathname.
59 *
60 * Used to locate OS-specific files (shared libraries, config files,
61 * etc) used by emul processes at their `normal' pathnames, without
62 * polluting, or conflicting with, the native filesysten namespace.
63 */
64
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/namei.h>
68 #include <sys/file.h>
69 #include <sys/filedesc.h>
70 #include <sys/ioctl.h>
71 #include <sys/mount.h>
72 #include <sys/stat.h>
73 #include <sys/vnode.h>
74 #include <sys/syscallargs.h>
75 #include <sys/proc.h>
76
77 #include <compat/ultrix/ultrix_syscallargs.h>
78 #include <compat/common/compat_util.h>
79
80 static int ultrixstatfs __P((struct statfs *sp, caddr_t buf));
81
82 int
83 ultrix_sys_creat(p, v, retval)
84 struct proc *p;
85 void *v;
86 register_t *retval;
87 {
88 struct ultrix_sys_creat_args *uap = v;
89 struct sys_open_args ap;
90
91 caddr_t sg = stackgap_init(p->p_emul);
92 CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
93
94 SCARG(&ap, path) = SCARG(uap, path);
95 SCARG(&ap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
96 SCARG(&ap, mode) = SCARG(uap, mode);
97
98 return (sys_open(p, &ap, retval));
99 }
100
101
102 int
103 ultrix_sys_access(p, v, retval)
104 struct proc *p;
105 void *v;
106 register_t *retval;
107 {
108 struct ultrix_sys_access_args *uap = v;
109 caddr_t sg = stackgap_init(p->p_emul);
110 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
111
112 return (sys_access(p, uap, retval));
113 }
114
115 int
116 ultrix_sys_stat(p, v, retval)
117 struct proc *p;
118 void *v;
119 register_t *retval;
120 {
121 struct ultrix_sys_stat_args *uap = v;
122 caddr_t sg = stackgap_init(p->p_emul);
123 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
124
125 return (compat_43_sys_stat(p, uap, retval));
126 }
127
128 int
129 ultrix_sys_lstat(p, v, retval)
130 struct proc *p;
131 void *v;
132 register_t *retval;
133 {
134 struct ultrix_sys_lstat_args *uap = v;
135 caddr_t sg = stackgap_init(p->p_emul);
136 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
137
138 return (compat_43_sys_lstat(p, uap, retval));
139 }
140
141 int
142 ultrix_sys_execv(p, v, retval)
143 struct proc *p;
144 void *v;
145 register_t *retval;
146 {
147 struct ultrix_sys_execv_args /* {
148 syscallarg(const char *) path;
149 syscallarg(char **) argv;
150 } */ *uap = v;
151 struct sys_execve_args ap;
152 caddr_t sg;
153
154 sg = stackgap_init(p->p_emul);
155 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
156
157 SCARG(&ap, path) = SCARG(uap, path);
158 SCARG(&ap, argp) = SCARG(uap, argp);
159 SCARG(&ap, envp) = NULL;
160
161 return (sys_execve(p, &ap, retval));
162 }
163
164 int
165 ultrix_sys_execve(p, v, retval)
166 struct proc *p;
167 void *v;
168 register_t *retval;
169 {
170 struct ultrix_sys_execve_args /* {
171 syscallarg(const char *) path;
172 syscallarg(char **) argv;
173 syscallarg(char **) envp;
174 } */ *uap = v;
175 struct sys_execve_args ap;
176 caddr_t sg;
177
178 sg = stackgap_init(p->p_emul);
179 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
180
181 SCARG(&ap, path) = SCARG(uap, path);
182 SCARG(&ap, argp) = SCARG(uap, argp);
183 SCARG(&ap, envp) = SCARG(uap, envp);
184
185 return (sys_execve(p, &ap, retval));
186 }
187
188 int
189 ultrix_sys_open(p, v, retval)
190 struct proc *p;
191 void *v;
192 register_t *retval;
193 {
194 struct ultrix_sys_open_args *uap = v;
195 int l, r;
196 int noctty;
197 int ret;
198
199 caddr_t sg = stackgap_init(p->p_emul);
200
201 /* convert open flags into NetBSD flags */
202 l = SCARG(uap, flags);
203 noctty = l & 0x8000;
204 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
205 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
206 r |= ((l & 0x0080) ? O_SHLOCK : 0);
207 r |= ((l & 0x0100) ? O_EXLOCK : 0);
208 r |= ((l & 0x2000) ? O_FSYNC : 0);
209
210 if (r & O_CREAT)
211 CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
212 else
213 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
214 SCARG(uap, flags) = r;
215 ret = sys_open(p, (struct sys_open_args *)uap, retval);
216
217 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
218 struct filedesc *fdp = p->p_fd;
219 struct file *fp;
220
221 fp = fd_getfile(fdp, *retval);
222
223 /* ignore any error, just give it a try */
224 if (fp != NULL && fp->f_type == DTYPE_VNODE)
225 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
226 }
227 return ret;
228 }
229
230
231 struct ultrix_statfs {
232 long f_type; /* type of info, zero for now */
233 long f_bsize; /* fundamental file system block size */
234 long f_blocks; /* total blocks in file system */
235 long f_bfree; /* free blocks */
236 long f_bavail; /* free blocks available to non-super-user */
237 long f_files; /* total file nodes in file system */
238 long f_ffree; /* free file nodes in fs */
239 fsid_t f_fsid; /* file system id */
240 long f_spare[7]; /* spare for later */
241 };
242
243 /*
244 * Custruct ultrix statfs result from native.
245 * XXX should this be the same as returned by Ultrix getmnt(2)?
246 * XXX Ultrix predates DEV_BSIZE. Is conversion of disk space from 1k
247 * block units to DEV_BSIZE necessary?
248 */
249 static int
250 ultrixstatfs(sp, buf)
251 struct statfs *sp;
252 caddr_t buf;
253 {
254 struct ultrix_statfs ssfs;
255
256 memset(&ssfs, 0, sizeof ssfs);
257 ssfs.f_type = 0;
258 ssfs.f_bsize = sp->f_bsize;
259 ssfs.f_blocks = sp->f_blocks;
260 ssfs.f_bfree = sp->f_bfree;
261 ssfs.f_bavail = sp->f_bavail;
262 ssfs.f_files = sp->f_files;
263 ssfs.f_ffree = sp->f_ffree;
264 ssfs.f_fsid = sp->f_fsid;
265 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
266 }
267
268
269 int
270 ultrix_sys_statfs(p, v, retval)
271 struct proc *p;
272 void *v;
273 register_t *retval;
274 {
275 struct ultrix_sys_statfs_args *uap = v;
276 struct mount *mp;
277 struct statfs *sp;
278 int error;
279 struct nameidata nd;
280
281 caddr_t sg = stackgap_init(p->p_emul);
282 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
283
284 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
285 if ((error = namei(&nd)) != 0)
286 return (error);
287
288 mp = nd.ni_vp->v_mount;
289 sp = &mp->mnt_stat;
290 vrele(nd.ni_vp);
291 if ((error = VFS_STATFS(mp, sp, p)) != 0)
292 return (error);
293 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
294 return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
295 }
296
297 /*
298 * sys_fstatfs() takes an fd, not a path, and so needs no emul
299 * pathname processing; but it's similar enough to sys_statfs() that
300 * it goes here anyway.
301 */
302 int
303 ultrix_sys_fstatfs(p, v, retval)
304 struct proc *p;
305 void *v;
306 register_t *retval;
307 {
308 struct ultrix_sys_fstatfs_args *uap = v;
309 struct file *fp;
310 struct mount *mp;
311 struct statfs *sp;
312 int error;
313
314 /* getvnode() will use the descriptor for us */
315 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
316 return (error);
317 mp = ((struct vnode *)fp->f_data)->v_mount;
318 sp = &mp->mnt_stat;
319 if ((error = VFS_STATFS(mp, sp, p)) != 0)
320 goto out;
321 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
322 error = ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
323 out:
324 FILE_UNUSE(fp, p);
325 return (error);
326 }
327
328 int
329 ultrix_sys_mknod(p, v, retval)
330 struct proc *p;
331 void *v;
332 register_t *retval;
333 {
334 struct ultrix_sys_mknod_args *uap = v;
335
336 caddr_t sg = stackgap_init(p->p_emul);
337 CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
338
339 if (S_ISFIFO(SCARG(uap, mode)))
340 return sys_mkfifo(p, uap, retval);
341
342 return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
343 }
344