]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
ece349050b814200ab2f733951c0c78d5c34ed79
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1995-1998 Apple Computer, Inc.
32 * Created February 20, 1995 by Tuyen Nguyen
33 * Modified for MP, 1996 by Tuyen Nguyen
34 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
36 #include <sys/errno.h>
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <machine/spl.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/proc_internal.h> /* for p_fd in fdflags */
43 #include <sys/filedesc.h>
44 #include <sys/fcntl.h>
46 #include <sys/malloc.h>
47 #include <sys/file_internal.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/sysproto.h>
51 #include <sys/kdebug.h>
52 #include <net/if_var.h>
54 #include <netat/sysglue.h>
55 #include <netat/appletalk.h>
56 #include <netat/at_var.h>
57 #include <netat/at_pcb.h>
58 #include <netat/debug.h>
61 extern at_state_t at_state
; /* global state of AT network */
62 extern at_ifaddr_t
*ifID_home
; /* default interface */
63 extern lck_mtx_t
* atalk_mutex
;
65 #define f_flag f_fglob->fg_flag
66 #define f_type f_fglob->fg_type
67 #define f_msgcount f_fglob->fg_msgcount
68 #define f_cred f_fglob->fg_cred
69 #define f_ops f_fglob->fg_ops
70 #define f_offset f_fglob->fg_offset
71 #define f_data f_fglob->fg_data
73 extern int _ATsocket(int, int *, void *);
74 extern int _ATgetmsg(int, strbuf_t
*, strbuf_t
*, int *, int *, void *);
75 extern int _ATputmsg();
76 extern int _ATPsndreq(), _ATPsndrsp(), _ATPgetreq(), _ATPgetrsp();
79 int ATsocket(proc
, uap
, retval
)
81 struct ATsocket_args
*uap
;
87 /* required check for all AppleTalk system calls */
88 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
92 *retval
= _ATsocket((int)uap
->proto
, (int *)&err
, (void *)proc
);
102 int ATgetmsg(proc
, uap
, retval
)
104 struct ATgetmsg_args
*uap
;
111 /* required check for all AppleTalk system calls */
112 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
117 (*_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
118 uap
->flags
, &err
, proc
);
128 int ATputmsg(proc
, uap
, retval
)
130 struct ATputmsg_args
*uap
;
137 /* required check for all AppleTalk system calls */
138 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
143 _ATputmsg(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
144 uap
->flags
, &err
, proc
);
154 int ATPsndreq(proc
, uap
, retval
)
156 struct ATPsndreq_args
*uap
;
163 /* required check for all AppleTalk system calls */
164 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
169 _ATPsndreq(uap
->fd
, uap
->buf
, uap
->len
,
170 uap
->nowait
, &err
, proc
);
180 int ATPsndrsp(proc
, uap
, retval
)
182 struct ATPsndrsp_args
*uap
;
189 /* required check for all AppleTalk system calls */
190 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
195 _ATPsndrsp(uap
->fd
, uap
->respbuff
,
196 uap
->resplen
, uap
->datalen
, &err
, proc
);
206 int ATPgetreq(proc
, uap
, retval
)
208 struct ATPgetreq_args
*uap
;
215 /* required check for all AppleTalk system calls */
216 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
221 _ATPgetreq(uap
->fd
, uap
->buf
, uap
->buflen
,
232 int ATPgetrsp(proc
, uap
, retval
)
234 struct ATPgetrsp_args
*uap
;
241 /* required check for all AppleTalk system calls */
242 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
247 _ATPgetrsp(uap
->fd
, uap
->bdsp
, &err
, proc
);
257 int atalk_closeref(fg
, grefp
)
261 if ((*grefp
= (gref_t
*)fg
->fg_data
)) {
268 int atalk_openref(gref
, retfd
, proc
)
273 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
274 static struct fileops fileops
=
275 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
, _ATkqfilter
, 0};
279 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
282 if ((err
= falloc_locked(proc
, &fp
, &fd
, 1)) != 0) {
287 fp
->f_flag
= FREAD
|FWRITE
;
288 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
289 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
291 fp
->f_type
= DTYPE_ATALK
+1;
292 fp
->f_ops
= &fileops
;
293 fp
->f_data
= (void *)gref
;
295 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
297 fp_drop(proc
, fd
, fp
, 1);
300 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
306 * go from file descriptor to gref, which has been saved in fp->f_data
308 * This routine returns with an iocount on the fileproc when the fp is null
309 * as it converts fd to fileproc. Callers of this api who pass fp as null
310 * need to drop the iocount when they are done with the fp
312 int atalk_getref(fp
, fd
, grefp
, proc
, droponerr
)
322 error
= atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
);
327 int atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
)
334 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
336 int error
= fp_lookup(proc
, fd
, &fp
, 1);
340 *grefp
= (gref_t
*) 0;
344 *grefp
= (gref_t
*)fp
->f_data
;
345 if (fp
->f_type
!= (DTYPE_ATALK
+1) || *grefp
== 0 || *grefp
== (gref_t
*)(-1)) {
347 fp_drop(proc
, fd
, fp
, 1);
348 printf("atalk_getref_locked EBADF f_data: %x\n", fp
->f_data
);
352 if ((*grefp
)->errno
) {
354 fp_drop(proc
, fd
, fp
, 1);
355 return (int)(*grefp
)->errno
;