ultrix_pathname.c revision 1.8 1 /* $NetBSD: ultrix_pathname.c,v 1.8 1999/02/09 20:30:38 christos 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_CREAT(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(const 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(const 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
202 /* convert open flags into NetBSD flags */
203 l = SCARG(uap, flags);
204 noctty = l & 0x8000;
205 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
206 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
207 r |= ((l & 0x0080) ? O_SHLOCK : 0);
208 r |= ((l & 0x0100) ? O_EXLOCK : 0);
209 r |= ((l & 0x2000) ? O_FSYNC : 0);
210
211 if (r & O_CREAT)
212 ULTRIX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
213 else
214 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
215 SCARG(uap, flags) = r;
216 ret = sys_open(p, (struct sys_open_args *)uap, retval);
217
218 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
219 struct filedesc *fdp = p->p_fd;
220 struct file *fp = fdp->fd_ofiles[*retval];
221
222 /* ignore any error, just give it a try */
223 if (fp->f_type == DTYPE_VNODE)
224 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
225 }
226 return ret;
227 }
228
229
230 struct ultrix_statfs {
231 long f_type; /* type of info, zero for now */
232 long f_bsize; /* fundamental file system block size */
233 long f_blocks; /* total blocks in file system */
234 long f_bfree; /* free blocks */
235 long f_bavail; /* free blocks available to non-super-user */
236 long f_files; /* total file nodes in file system */
237 long f_ffree; /* free file nodes in fs */
238 fsid_t f_fsid; /* file system id */
239 long f_spare[7]; /* spare for later */
240 };
241
242 /*
243 * Custruct ultrix statfs result from native.
244 * XXX should this be the same as returned by Ultrix getmnt(2)?
245 * XXX Ultrix predates DEV_BSIZE. Is conversion of disk space from 1k
246 * block units to DEV_BSIZE necessary?
247 */
248 static int
249 ultrixstatfs(sp, buf)
250 struct statfs *sp;
251 caddr_t buf;
252 {
253 struct ultrix_statfs ssfs;
254
255 memset(&ssfs, 0, sizeof ssfs);
256 ssfs.f_type = 0;
257 ssfs.f_bsize = sp->f_bsize;
258 ssfs.f_blocks = sp->f_blocks;
259 ssfs.f_bfree = sp->f_bfree;
260 ssfs.f_bavail = sp->f_bavail;
261 ssfs.f_files = sp->f_files;
262 ssfs.f_ffree = sp->f_ffree;
263 ssfs.f_fsid = sp->f_fsid;
264 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
265 }
266
267
268 int
269 ultrix_sys_statfs(p, v, retval)
270 struct proc *p;
271 void *v;
272 register_t *retval;
273 {
274 struct ultrix_sys_statfs_args *uap = v;
275 register struct mount *mp;
276 register struct statfs *sp;
277 int error;
278 struct nameidata nd;
279
280 caddr_t sg = stackgap_init(p->p_emul);
281 ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
282
283 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
284 if ((error = namei(&nd)) != 0)
285 return (error);
286
287 mp = nd.ni_vp->v_mount;
288 sp = &mp->mnt_stat;
289 vrele(nd.ni_vp);
290 if ((error = VFS_STATFS(mp, sp, p)) != 0)
291 return (error);
292 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
293 return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
294 }
295
296 /*
297 * sys_fstatfs() takes an fd, not a path, and so needs no emul
298 * pathname processing; but it's similar enough to sys_statfs() that
299 * it goes here anyway.
300 */
301 int
302 ultrix_sys_fstatfs(p, v, retval)
303 struct proc *p;
304 void *v;
305 register_t *retval;
306 {
307 struct ultrix_sys_fstatfs_args *uap = v;
308 struct file *fp;
309 struct mount *mp;
310 register struct statfs *sp;
311 int error;
312
313 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
314 return (error);
315 mp = ((struct vnode *)fp->f_data)->v_mount;
316 sp = &mp->mnt_stat;
317 if ((error = VFS_STATFS(mp, sp, p)) != 0)
318 return (error);
319 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
320 return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
321 }
322
323 int
324 ultrix_sys_mknod(p, v, retval)
325 struct proc *p;
326 void *v;
327 register_t *retval;
328 {
329 struct ultrix_sys_mknod_args *uap = v;
330
331 caddr_t sg = stackgap_init(p->p_emul);
332 ULTRIX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
333
334 if (S_ISFIFO(SCARG(uap, mode)))
335 return sys_mkfifo(p, uap, retval);
336
337 return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
338 }
339