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