ultrix_pathname.c revision 1.6 1 /* $NetBSD: ultrix_pathname.c,v 1.6 1997/05/25 05:30:21 jonathan 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/ultrix/ultrix_util.h>
79
80 const char ultrix_emul_path[] = "/emul/ultrix";
81 static int ultrixstatfs __P((struct statfs *sp, caddr_t buf));
82
83 int
84 ultrix_sys_creat(p, v, retval)
85 struct proc *p;
86 void *v;
87 register_t *retval;
88 {
89 struct ultrix_sys_creat_args *uap = v;
90 struct sys_open_args ap;
91
92 caddr_t sg = stackgap_init(p->p_emul);
93 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
94
95 SCARG(&ap, path) = SCARG(uap, path);
96 SCARG(&ap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
97 SCARG(&ap, mode) = SCARG(uap, mode);
98
99 return (sys_open(p, &ap, retval));
100 }
101
102
103 int
104 ultrix_sys_access(p, v, retval)
105 struct proc *p;
106 void *v;
107 register_t *retval;
108 {
109 struct ultrix_sys_access_args *uap = v;
110 caddr_t sg = stackgap_init(p->p_emul);
111 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
112
113 return (sys_access(p, uap, retval));
114 }
115
116 int
117 ultrix_sys_stat(p, v, retval)
118 struct proc *p;
119 void *v;
120 register_t *retval;
121 {
122 struct ultrix_sys_stat_args *uap = v;
123 caddr_t sg = stackgap_init(p->p_emul);
124 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
125
126 return (compat_43_sys_stat(p, uap, retval));
127 }
128
129 int
130 ultrix_sys_lstat(p, v, retval)
131 struct proc *p;
132 void *v;
133 register_t *retval;
134 {
135 struct ultrix_sys_lstat_args *uap = v;
136 caddr_t sg = stackgap_init(p->p_emul);
137 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
138
139 return (compat_43_sys_lstat(p, uap, retval));
140 }
141
142 int
143 ultrix_sys_execv(p, v, retval)
144 struct proc *p;
145 void *v;
146 register_t *retval;
147 {
148 struct ultrix_sys_execv_args /* {
149 syscallarg(char *) path;
150 syscallarg(char **) argv;
151 } */ *uap = v;
152 struct sys_execve_args ap;
153 caddr_t sg;
154
155 sg = stackgap_init(p->p_emul);
156 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
157
158 SCARG(&ap, path) = SCARG(uap, path);
159 SCARG(&ap, argp) = SCARG(uap, argp);
160 SCARG(&ap, envp) = NULL;
161
162 return (sys_execve(p, &ap, retval));
163 }
164
165 int
166 ultrix_sys_execve(p, v, retval)
167 struct proc *p;
168 void *v;
169 register_t *retval;
170 {
171 struct ultrix_sys_execve_args /* {
172 syscallarg(char *) path;
173 syscallarg(char **) argv;
174 syscallarg(char **) envp;
175 } */ *uap = v;
176 struct sys_execve_args ap;
177 caddr_t sg;
178
179 sg = stackgap_init(p->p_emul);
180 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
181
182 SCARG(&ap, path) = SCARG(uap, path);
183 SCARG(&ap, argp) = SCARG(uap, argp);
184 SCARG(&ap, envp) = SCARG(uap, envp);
185
186 return (sys_execve(p, &ap, retval));
187 }
188
189 int
190 ultrix_sys_open(p, v, retval)
191 struct proc *p;
192 void *v;
193 register_t *retval;
194 {
195 struct ultrix_sys_open_args *uap = v;
196 int l, r;
197 int noctty;
198 int ret;
199
200 caddr_t sg = stackgap_init(p->p_emul);
201 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
202
203 /* convert open flags into NetBSD flags */
204 l = SCARG(uap, flags);
205 noctty = l & 0x8000;
206 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
207 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
208 r |= ((l & 0x0080) ? O_SHLOCK : 0);
209 r |= ((l & 0x0100) ? O_EXLOCK : 0);
210 r |= ((l & 0x2000) ? O_FSYNC : 0);
211
212 SCARG(uap, flags) = r;
213 ret = sys_open(p, (struct sys_open_args *)uap, retval);
214
215 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
216 struct filedesc *fdp = p->p_fd;
217 struct file *fp = fdp->fd_ofiles[*retval];
218
219 /* ignore any error, just give it a try */
220 if (fp->f_type == DTYPE_VNODE)
221 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
222 }
223 return ret;
224 }
225
226
227 struct ultrix_statfs {
228 long f_type; /* type of info, zero for now */
229 long f_bsize; /* fundamental file system block size */
230 long f_blocks; /* total blocks in file system */
231 long f_bfree; /* free blocks */
232 long f_bavail; /* free blocks available to non-super-user */
233 long f_files; /* total file nodes in file system */
234 long f_ffree; /* free file nodes in fs */
235 fsid_t f_fsid; /* file system id */
236 long f_spare[7]; /* spare for later */
237 };
238
239 /*
240 * Custruct ultrix statfs result from native.
241 * XXX should this be the same as returned by Ultrix getmnt(2)?
242 * XXX Ultrix predates DEV_BSIZE. Is conversion of disk space from 1k
243 * block units to DEV_BSIZE necessary?
244 */
245 static int
246 ultrixstatfs(sp, buf)
247 struct statfs *sp;
248 caddr_t buf;
249 {
250 struct ultrix_statfs ssfs;
251
252 bzero(&ssfs, sizeof ssfs);
253 ssfs.f_type = 0;
254 ssfs.f_bsize = sp->f_bsize;
255 ssfs.f_blocks = sp->f_blocks;
256 ssfs.f_bfree = sp->f_bfree;
257 ssfs.f_bavail = sp->f_bavail;
258 ssfs.f_files = sp->f_files;
259 ssfs.f_ffree = sp->f_ffree;
260 ssfs.f_fsid = sp->f_fsid;
261 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
262 }
263
264
265 int
266 ultrix_sys_statfs(p, v, retval)
267 struct proc *p;
268 void *v;
269 register_t *retval;
270 {
271 struct ultrix_sys_statfs_args *uap = v;
272 register struct mount *mp;
273 register struct statfs *sp;
274 int error;
275 struct nameidata nd;
276
277 caddr_t sg = stackgap_init(p->p_emul);
278 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
279
280 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
281 if ((error = namei(&nd)) != 0)
282 return (error);
283
284 mp = nd.ni_vp->v_mount;
285 sp = &mp->mnt_stat;
286 vrele(nd.ni_vp);
287 if ((error = VFS_STATFS(mp, sp, p)) != 0)
288 return (error);
289 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
290 return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
291 }
292
293 /*
294 * sys_fstatfs() takes an fd, not a path, and so needs no emul
295 * pathname processing; but it's similar enough to sys_statfs() that
296 * it goes here anyway.
297 */
298 int
299 ultrix_sys_fstatfs(p, v, retval)
300 struct proc *p;
301 void *v;
302 register_t *retval;
303 {
304 struct ultrix_sys_fstatfs_args *uap = v;
305 struct file *fp;
306 struct mount *mp;
307 register struct statfs *sp;
308 int error;
309
310 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
311 return (error);
312 mp = ((struct vnode *)fp->f_data)->v_mount;
313 sp = &mp->mnt_stat;
314 if ((error = VFS_STATFS(mp, sp, p)) != 0)
315 return (error);
316 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
317 return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
318 }
319
320 int
321 ultrix_sys_mknod(p, v, retval)
322 struct proc *p;
323 void *v;
324 register_t *retval;
325 {
326 struct ultrix_sys_mknod_args *uap = v;
327
328 caddr_t sg = stackgap_init(p->p_emul);
329 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
330
331 if (S_ISFIFO(SCARG(uap, mode)))
332 return sys_mkfifo(p, uap, retval);
333
334 return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
335 }
336