]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1995-1998 Apple Computer, Inc.
34 * Created February 20, 1995 by Tuyen Nguyen
35 * Modified for MP, 1996 by Tuyen Nguyen
36 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
38 #include <sys/errno.h>
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <machine/spl.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/proc_internal.h> /* for p_fd in fdflags */
45 #include <sys/filedesc.h>
46 #include <sys/fcntl.h>
48 #include <sys/malloc.h>
49 #include <sys/file_internal.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <sys/sysproto.h>
53 #include <sys/kdebug.h>
54 #include <net/if_var.h>
56 #include <netat/sysglue.h>
57 #include <netat/appletalk.h>
58 #include <netat/at_var.h>
59 #include <netat/at_pcb.h>
60 #include <netat/debug.h>
62 int (*sys_ATsocket
)() = 0;
63 int (*sys_ATgetmsg
)() = 0;
64 int (*sys_ATputmsg
)() = 0;
65 int (*sys_ATPsndreq
)() = 0;
66 int (*sys_ATPsndrsp
)() = 0;
67 int (*sys_ATPgetreq
)() = 0;
68 int (*sys_ATPgetrsp
)() = 0;
70 extern at_state_t at_state
; /* global state of AT network */
71 extern at_ifaddr_t
*ifID_home
; /* default interface */
72 extern lck_mtx_t
* atalk_mutex
;
74 #define f_flag f_fglob->fg_flag
75 #define f_type f_fglob->fg_type
76 #define f_msgcount f_fglob->fg_msgcount
77 #define f_cred f_fglob->fg_cred
78 #define f_ops f_fglob->fg_ops
79 #define f_offset f_fglob->fg_offset
80 #define f_data f_fglob->fg_data
82 int ATsocket(proc
, uap
, retval
)
84 struct ATsocket_args
*uap
;
90 /* required check for all AppleTalk system calls */
91 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
95 *retval
= (*sys_ATsocket
)(uap
->proto
, &err
, proc
);
105 int ATgetmsg(proc
, uap
, retval
)
107 struct ATgetmsg_args
*uap
;
114 /* required check for all AppleTalk system calls */
115 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
120 (*sys_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
121 uap
->flags
, &err
, proc
);
131 int ATputmsg(proc
, uap
, retval
)
133 struct ATputmsg_args
*uap
;
140 /* required check for all AppleTalk system calls */
141 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
146 (*sys_ATputmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
147 uap
->flags
, &err
, proc
);
157 int ATPsndreq(proc
, uap
, retval
)
159 struct ATPsndreq_args
*uap
;
166 /* required check for all AppleTalk system calls */
167 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
172 (*sys_ATPsndreq
)(uap
->fd
, uap
->buf
, uap
->len
,
173 uap
->nowait
, &err
, proc
);
183 int ATPsndrsp(proc
, uap
, retval
)
185 struct ATPsndrsp_args
*uap
;
192 /* required check for all AppleTalk system calls */
193 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
198 (*sys_ATPsndrsp
)(uap
->fd
, uap
->respbuff
,
199 uap
->resplen
, uap
->datalen
, &err
, proc
);
209 int ATPgetreq(proc
, uap
, retval
)
211 struct ATPgetreq_args
*uap
;
218 /* required check for all AppleTalk system calls */
219 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
224 (*sys_ATPgetreq
)(uap
->fd
, uap
->buf
, uap
->buflen
,
235 int ATPgetrsp(proc
, uap
, retval
)
237 struct ATPgetrsp_args
*uap
;
244 /* required check for all AppleTalk system calls */
245 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
250 (*sys_ATPgetrsp
)(uap
->fd
, uap
->bdsp
, &err
, proc
);
260 int atalk_closeref(fg
, grefp
)
264 if ((*grefp
= (gref_t
*)fg
->fg_data
)) {
271 int atalk_openref(gref
, retfd
, proc
)
276 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
277 static struct fileops fileops
=
278 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
, _ATkqfilter
, 0};
282 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
285 if ((err
= falloc_locked(proc
, &fp
, &fd
, 1)) != 0) {
290 fp
->f_flag
= FREAD
|FWRITE
;
291 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
292 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
294 fp
->f_type
= DTYPE_ATALK
+1;
295 fp
->f_ops
= &fileops
;
296 fp
->f_data
= (void *)gref
;
298 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
300 fp_drop(proc
, fd
, fp
, 1);
303 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
309 * go from file descriptor to gref, which has been saved in fp->f_data
311 * This routine returns with an iocount on the fileproc when the fp is null
312 * as it converts fd to fileproc. Callers of this api who pass fp as null
313 * need to drop the iocount when they are done with the fp
315 int atalk_getref(fp
, fd
, grefp
, proc
, droponerr
)
325 error
= atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
);
330 int atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
)
337 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
339 int error
= fp_lookup(proc
, fd
, &fp
, 1);
343 *grefp
= (gref_t
*) 0;
347 *grefp
= (gref_t
*)fp
->f_data
;
348 if (*grefp
== 0 || *grefp
== (gref_t
*)(-1)) {
350 fp_drop(proc
, fd
, fp
, 1);
351 printf("atalk_getref_locked EBADF f_data: %x\n", fp
->f_data
);
355 if ((*grefp
)->errno
) {
357 fp_drop(proc
, fd
, fp
, 1);
358 return (int)(*grefp
)->errno
;