]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
2 * Copyright (c) 2000 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>
63 extern at_state_t at_state
; /* global state of AT network */
64 extern at_ifaddr_t
*ifID_home
; /* default interface */
65 extern lck_mtx_t
* atalk_mutex
;
67 #define f_flag f_fglob->fg_flag
68 #define f_type f_fglob->fg_type
69 #define f_msgcount f_fglob->fg_msgcount
70 #define f_cred f_fglob->fg_cred
71 #define f_ops f_fglob->fg_ops
72 #define f_offset f_fglob->fg_offset
73 #define f_data f_fglob->fg_data
75 extern int _ATsocket(int, int *, void *);
76 extern int _ATgetmsg(int, strbuf_t
*, strbuf_t
*, int *, int *, void *);
77 extern int _ATputmsg();
78 extern int _ATPsndreq(), _ATPsndrsp(), _ATPgetreq(), _ATPgetrsp();
81 int ATsocket(proc
, uap
, retval
)
83 struct ATsocket_args
*uap
;
89 /* required check for all AppleTalk system calls */
90 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
94 *retval
= _ATsocket((int)uap
->proto
, (int *)&err
, (void *)proc
);
104 int ATgetmsg(proc
, uap
, retval
)
106 struct ATgetmsg_args
*uap
;
113 /* required check for all AppleTalk system calls */
114 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
119 (*_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
120 uap
->flags
, &err
, proc
);
130 int ATputmsg(proc
, uap
, retval
)
132 struct ATputmsg_args
*uap
;
139 /* required check for all AppleTalk system calls */
140 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
145 _ATputmsg(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
146 uap
->flags
, &err
, proc
);
156 int ATPsndreq(proc
, uap
, retval
)
158 struct ATPsndreq_args
*uap
;
165 /* required check for all AppleTalk system calls */
166 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
171 _ATPsndreq(uap
->fd
, uap
->buf
, uap
->len
,
172 uap
->nowait
, &err
, proc
);
182 int ATPsndrsp(proc
, uap
, retval
)
184 struct ATPsndrsp_args
*uap
;
191 /* required check for all AppleTalk system calls */
192 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
197 _ATPsndrsp(uap
->fd
, uap
->respbuff
,
198 uap
->resplen
, uap
->datalen
, &err
, proc
);
208 int ATPgetreq(proc
, uap
, retval
)
210 struct ATPgetreq_args
*uap
;
217 /* required check for all AppleTalk system calls */
218 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
223 _ATPgetreq(uap
->fd
, uap
->buf
, uap
->buflen
,
234 int ATPgetrsp(proc
, uap
, retval
)
236 struct ATPgetrsp_args
*uap
;
243 /* required check for all AppleTalk system calls */
244 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
249 _ATPgetrsp(uap
->fd
, uap
->bdsp
, &err
, proc
);
259 int atalk_closeref(fg
, grefp
)
263 if ((*grefp
= (gref_t
*)fg
->fg_data
)) {
270 int atalk_openref(gref
, retfd
, proc
)
275 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
276 static struct fileops fileops
=
277 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
, _ATkqfilter
, 0};
281 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
284 if ((err
= falloc_locked(proc
, &fp
, &fd
, 1)) != 0) {
289 fp
->f_flag
= FREAD
|FWRITE
;
290 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
291 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
293 fp
->f_type
= DTYPE_ATALK
+1;
294 fp
->f_ops
= &fileops
;
295 fp
->f_data
= (void *)gref
;
297 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
299 fp_drop(proc
, fd
, fp
, 1);
302 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
308 * go from file descriptor to gref, which has been saved in fp->f_data
310 * This routine returns with an iocount on the fileproc when the fp is null
311 * as it converts fd to fileproc. Callers of this api who pass fp as null
312 * need to drop the iocount when they are done with the fp
314 int atalk_getref(fp
, fd
, grefp
, proc
, droponerr
)
324 error
= atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
);
329 int atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
)
336 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
338 int error
= fp_lookup(proc
, fd
, &fp
, 1);
342 *grefp
= (gref_t
*) 0;
346 *grefp
= (gref_t
*)fp
->f_data
;
347 if (*grefp
== 0 || *grefp
== (gref_t
*)(-1)) {
349 fp_drop(proc
, fd
, fp
, 1);
350 printf("atalk_getref_locked EBADF f_data: %x\n", fp
->f_data
);
354 if ((*grefp
)->errno
) {
356 fp_drop(proc
, fd
, fp
, 1);
357 return (int)(*grefp
)->errno
;