Annotation of sys/compat/osf1/osf1_descrip.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: osf1_descrip.c,v 1.8 2002/02/13 19:08:06 art Exp $ */
2: /* $NetBSD: osf1_descrip.c,v 1.5 1999/06/26 01:24:41 cgd Exp $ */
3:
4: /*
5: * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Christopher G. Demetriou
18: * for the NetBSD Project.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: /*
35: * Copyright (c) 1994, 1995 Carnegie-Mellon University.
36: * All rights reserved.
37: *
38: * Author: Chris G. Demetriou
39: *
40: * Permission to use, copy, modify and distribute this software and
41: * its documentation is hereby granted, provided that both the copyright
42: * notice and this permission notice appear in all copies of the
43: * software, derivative works or modified versions, and any portions
44: * thereof, and that both notices appear in supporting documentation.
45: *
46: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49: *
50: * Carnegie Mellon requests users of this software to return to
51: *
52: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53: * School of Computer Science
54: * Carnegie Mellon University
55: * Pittsburgh PA 15213-3890
56: *
57: * any improvements or extensions that they make and grant Carnegie the
58: * rights to redistribute these changes.
59: */
60:
61: #include <sys/param.h>
62: #include <sys/systm.h>
63: #include <sys/namei.h>
64: #include <sys/proc.h>
65: #include <sys/file.h>
66: #include <sys/stat.h>
67: #include <sys/filedesc.h>
68: #include <sys/kernel.h>
69: #include <sys/malloc.h>
70: #include <sys/mman.h>
71: #include <sys/mount.h>
72: #include <sys/signal.h>
73: #include <sys/signalvar.h>
74: #include <sys/reboot.h>
75: #include <sys/syscallargs.h>
76: #include <sys/exec.h>
77: #include <sys/vnode.h>
78: #include <sys/socketvar.h>
79: #include <sys/resource.h>
80: #include <sys/resourcevar.h>
81: #include <sys/wait.h>
82:
83: #include <compat/osf1/osf1.h>
84: #include <compat/osf1/osf1_syscallargs.h>
85: #include <compat/osf1/osf1_cvt.h>
86:
87: int
88: osf1_sys_fcntl(p, v, retval)
89: struct proc *p;
90: void *v;
91: register_t *retval;
92: {
93: struct osf1_sys_fcntl_args *uap = v;
94: struct sys_fcntl_args a;
95: struct osf1_flock oflock;
96: struct flock nflock;
97: unsigned long xfl, leftovers;
98: caddr_t sg;
99: int error;
100:
101: sg = stackgap_init(p->p_emul);
102:
103: SCARG(&a, fd) = SCARG(uap, fd);
104:
105: leftovers = 0;
106: switch (SCARG(uap, cmd)) {
107: case OSF1_F_DUPFD:
108: SCARG(&a, cmd) = F_DUPFD;
109: SCARG(&a, arg) = SCARG(uap, arg);
110: break;
111:
112: case OSF1_F_GETFD:
113: SCARG(&a, cmd) = F_GETFD;
114: SCARG(&a, arg) = 0; /* ignored */
115: break;
116:
117: case OSF1_F_SETFD:
118: SCARG(&a, cmd) = F_SETFD;
119: SCARG(&a, arg) = (void *)emul_flags_translate(
120: osf1_fcntl_getsetfd_flags_xtab,
121: (unsigned long)SCARG(uap, arg), &leftovers);
122: break;
123:
124: case OSF1_F_GETFL:
125: SCARG(&a, cmd) = F_GETFL;
126: SCARG(&a, arg) = 0; /* ignored */
127: break;
128:
129: case OSF1_F_SETFL:
130: SCARG(&a, cmd) = F_SETFL;
131: xfl = emul_flags_translate(osf1_open_flags_xtab,
132: (unsigned long)SCARG(uap, arg), &leftovers);
133: xfl |= emul_flags_translate(osf1_fcntl_getsetfl_flags_xtab,
134: leftovers, &leftovers);
135: SCARG(&a, arg) = (void *)xfl;
136: break;
137:
138: case OSF1_F_GETOWN: /* XXX not yet supported */
139: case OSF1_F_SETOWN: /* XXX not yet supported */
140: /* XXX translate. */
141: return (EINVAL);
142:
143: case OSF1_F_GETLK:
144: case OSF1_F_SETLK:
145: case OSF1_F_SETLKW:
146: if (SCARG(uap, cmd) == OSF1_F_GETLK)
147: SCARG(&a, cmd) = F_GETLK;
148: else if (SCARG(uap, cmd) == OSF1_F_SETLK)
149: SCARG(&a, cmd) = F_SETLK;
150: else if (SCARG(uap, cmd) == OSF1_F_SETLKW)
151: SCARG(&a, cmd) = F_SETLKW;
152: SCARG(&a, arg) = stackgap_alloc(&sg, sizeof nflock);
153:
154: error = copyin(SCARG(uap, arg), &oflock, sizeof oflock);
155: if (error == 0)
156: error = osf1_cvt_flock_to_native(&oflock, &nflock);
157: if (error == 0)
158: error = copyout(&nflock, SCARG(&a, arg),
159: sizeof nflock);
160: if (error != 0)
161: return (error);
162: break;
163:
164: case OSF1_F_RGETLK: /* [lock mgr op] XXX not supported */
165: case OSF1_F_RSETLK: /* [lock mgr op] XXX not supported */
166: case OSF1_F_CNVT: /* [lock mgr op] XXX not supported */
167: case OSF1_F_RSETLKW: /* [lock mgr op] XXX not supported */
168: case OSF1_F_PURGEFS: /* [lock mgr op] XXX not supported */
169: case OSF1_F_PURGENFS: /* [DECsafe op] XXX not supported */
170: default:
171: /* XXX syslog? */
172: return (EINVAL);
173: }
174: if (leftovers != 0)
175: return (EINVAL);
176:
177: error = sys_fcntl(p, &a, retval);
178:
179: if (error)
180: return error;
181:
182: switch (SCARG(uap, cmd)) {
183: case OSF1_F_GETFD:
184: retval[0] = emul_flags_translate(
185: osf1_fcntl_getsetfd_flags_rxtab, retval[0], NULL);
186: break;
187:
188: case OSF1_F_GETFL:
189: xfl = emul_flags_translate(osf1_open_flags_rxtab,
190: retval[0], &leftovers);
191: xfl |= emul_flags_translate(osf1_fcntl_getsetfl_flags_rxtab,
192: leftovers, NULL);
193: retval[0] = xfl;
194: break;
195:
196: case OSF1_F_GETLK:
197: error = copyin(SCARG(&a, arg), &nflock, sizeof nflock);
198: if (error == 0) {
199: osf1_cvt_flock_from_native(&nflock, &oflock);
200: error = copyout(&oflock, SCARG(uap, arg),
201: sizeof oflock);
202: }
203: break;
204: }
205:
206: return error;
207: }
208:
209: int
210: osf1_sys_fpathconf(p, v, retval)
211: struct proc *p;
212: void *v;
213: register_t *retval;
214: {
215: struct osf1_sys_fpathconf_args *uap = v;
216: struct sys_fpathconf_args a;
217: int error;
218:
219: SCARG(&a, fd) = SCARG(uap, fd);
220:
221: error = osf1_cvt_pathconf_name_to_native(SCARG(uap, name),
222: &SCARG(&a, name));
223:
224: if (error == 0)
225: error = sys_fpathconf(p, &a, retval);
226:
227: return (error);
228: }
229:
230: /*
231: * Return status information about a file descriptor.
232: */
233: int
234: osf1_sys_fstat(p, v, retval)
235: struct proc *p;
236: void *v;
237: register_t *retval;
238: {
239: struct osf1_sys_fstat_args *uap = v;
240: struct filedesc *fdp = p->p_fd;
241: struct file *fp;
242: struct stat ub;
243: struct osf1_stat oub;
244: int error;
245:
246: if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
247: return (EBADF);
248:
249: FREF(fp);
250: error = (*fp->f_ops->fo_stat)(fp, &ub, p);
251: FRELE(fp);
252: osf1_cvt_stat_from_native(&ub, &oub);
253: if (error == 0)
254: error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb),
255: sizeof (oub));
256:
257: return (error);
258: }
259:
260: int
261: osf1_sys_ftruncate(p, v, retval)
262: struct proc *p;
263: void *v;
264: register_t *retval;
265: {
266: struct osf1_sys_ftruncate_args *uap = v;
267: struct sys_ftruncate_args a;
268:
269: SCARG(&a, fd) = SCARG(uap, fd);
270: SCARG(&a, pad) = 0;
271: SCARG(&a, length) = SCARG(uap, length);
272:
273: return sys_ftruncate(p, &a, retval);
274: }
275:
276: int
277: osf1_sys_lseek(p, v, retval)
278: struct proc *p;
279: void *v;
280: register_t *retval;
281: {
282: struct osf1_sys_lseek_args *uap = v;
283: struct sys_lseek_args a;
284:
285: SCARG(&a, fd) = SCARG(uap, fd);
286: SCARG(&a, pad) = 0;
287: SCARG(&a, offset) = SCARG(uap, offset);
288: SCARG(&a, whence) = SCARG(uap, whence);
289:
290: return sys_lseek(p, &a, retval);
291: }
CVSweb