]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /* |
2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
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. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
91447636 | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
91447636 A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
91447636 A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */ | |
24 | /* | |
25 | * Copyright (c) 1982, 1986, 1989, 1993 | |
26 | * The Regents of the University of California. All rights reserved. | |
27 | * | |
28 | * Redistribution and use in source and binary forms, with or without | |
29 | * modification, are permitted provided that the following conditions | |
30 | * are met: | |
31 | * 1. Redistributions of source code must retain the above copyright | |
32 | * notice, this list of conditions and the following disclaimer. | |
33 | * 2. Redistributions in binary form must reproduce the above copyright | |
34 | * notice, this list of conditions and the following disclaimer in the | |
35 | * documentation and/or other materials provided with the distribution. | |
36 | * 3. All advertising materials mentioning features or use of this software | |
37 | * must display the following acknowledgement: | |
38 | * This product includes software developed by the University of | |
39 | * California, Berkeley and its contributors. | |
40 | * 4. Neither the name of the University nor the names of its contributors | |
41 | * may be used to endorse or promote products derived from this software | |
42 | * without specific prior written permission. | |
43 | * | |
44 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
45 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
47 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
50 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
51 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
53 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
54 | * SUCH DAMAGE. | |
55 | * | |
56 | * @(#)file.h 8.3 (Berkeley) 1/9/95 | |
57 | */ | |
58 | ||
59 | #ifndef _SYS_FILE_INTERNAL_H_ | |
60 | #define _SYS_FILE_INTERNAL_H_ | |
61 | ||
62 | #include <sys/appleapiopts.h> | |
63 | #include <sys/fcntl.h> | |
64 | #include <sys/unistd.h> | |
65 | ||
66 | #ifdef KERNEL | |
67 | #include <sys/errno.h> | |
68 | #include <sys/queue.h> | |
69 | #include <sys/cdefs.h> | |
70 | #include <sys/lock.h> | |
71 | #include <sys/file.h> | |
72 | ||
73 | struct proc; | |
74 | struct uio; | |
75 | struct knote; | |
76 | #ifdef __APPLE_API_UNSTABLE | |
77 | ||
78 | struct file; | |
79 | ||
80 | ||
81 | /* | |
82 | * Kernel descriptor table. | |
83 | * One entry for each open kernel vnode and socket. | |
84 | */ | |
85 | struct fileproc { | |
86 | int32_t f_flags; | |
87 | int32_t f_iocount; | |
88 | struct fileglob * f_fglob; | |
89 | void * f_waddr; | |
90 | }; | |
91 | ||
92 | #define FILEPROC_NULL (struct fileproc *)0 | |
93 | ||
94 | #define FP_INCREATE 0x0001 | |
95 | #define FP_INCLOSE 0x0002 | |
96 | #define FP_INSELECT 0x0004 | |
97 | #define FP_INCHRREAD 0x0008 | |
98 | #define FP_WRITTEN 0x0010 | |
99 | #define FP_CLOSING 0x0020 | |
100 | #define FP_WAITCLOSE 0x0040 | |
101 | #define FP_AIOISSUED 0x0080 | |
102 | #define FP_WAITEVENT 0x0100 | |
103 | ||
104 | ||
105 | /* defns of close_internal */ | |
106 | #define CLOSEINT_LOCKED 1 | |
107 | #define CLOSEINT_WAITONCLOSE 2 | |
108 | #define CLOSEINT_NOFDRELSE 4 | |
109 | #define CLOSEINT_NOFDNOREF 8 | |
110 | ||
111 | struct fileglob { | |
112 | LIST_ENTRY(fileglob) f_list;/* list of active files */ | |
113 | LIST_ENTRY(fileglob) f_msglist;/* list of active files */ | |
114 | int32_t fg_flag; /* see fcntl.h */ | |
115 | int32_t fg_type; /* descriptor type */ | |
116 | int32_t fg_count; /* reference count */ | |
117 | int32_t fg_msgcount; /* references from message queue */ | |
118 | struct ucred *fg_cred; /* credentials associated with descriptor */ | |
119 | struct fileops { | |
120 | int (*fo_read) __P((struct fileproc *fp, struct uio *uio, | |
121 | struct ucred *cred, int flags, | |
122 | struct proc *p)); | |
123 | int (*fo_write) __P((struct fileproc *fp, struct uio *uio, | |
124 | struct ucred *cred, int flags, | |
125 | struct proc *p)); | |
126 | #define FOF_OFFSET 1 | |
127 | int (*fo_ioctl) __P((struct fileproc *fp, u_long com, | |
128 | caddr_t data, struct proc *p)); | |
129 | int (*fo_select) __P((struct fileproc *fp, int which, | |
130 | void *wql, struct proc *p)); | |
131 | int (*fo_close) __P((struct fileglob *fg, struct proc *p)); | |
132 | int (*fo_kqfilter) __P((struct fileproc *fp, struct knote *kn, | |
133 | struct proc *p)); | |
134 | int (*fo_drain) (struct fileproc *fp, struct proc *p); | |
135 | } *fg_ops; | |
136 | off_t fg_offset; | |
137 | caddr_t fg_data; /* vnode or socket or SHM or semaphore */ | |
138 | lck_mtx_t fg_lock; | |
139 | int32_t fg_lflags; /* file global flags */ | |
140 | unsigned int fg_lockpc[4]; | |
141 | unsigned int fg_unlockpc[4]; | |
142 | }; | |
143 | ||
144 | /* file types */ | |
145 | #define DTYPE_VNODE 1 /* file */ | |
146 | #define DTYPE_SOCKET 2 /* communications endpoint */ | |
147 | #define DTYPE_PSXSHM 3 /* POSIX Shared memory */ | |
148 | #define DTYPE_PSXSEM 4 /* POSIX Semaphores */ | |
149 | #define DTYPE_KQUEUE 5 /* kqueue */ | |
150 | #define DTYPE_PIPE 6 /* pipe */ | |
151 | #define DTYPE_FSEVENTS 7 /* fsevents */ | |
152 | ||
153 | /* defines for fg_lflags */ | |
154 | #define FG_TERM 0x01 /* the fileglob is terminating .. */ | |
155 | #define FG_INSMSGQ 0x02 /* insert to msgqueue pending .. */ | |
156 | #define FG_WINSMSGQ 0x04 /* wait for the fielglob is in msgque */ | |
157 | #define FG_RMMSGQ 0x08 /* the fileglob is being removed from msgqueue */ | |
158 | #define FG_WRMMSGQ 0x10 /* wait for the fileglob to be removed from msgqueue */ | |
159 | ||
160 | ||
161 | #ifdef __APPLE_API_PRIVATE | |
162 | LIST_HEAD(filelist, fileglob); | |
163 | LIST_HEAD(fmsglist, fileglob); | |
164 | extern struct filelist filehead; /* head of list of open files */ | |
165 | extern struct fmsglist fmsghead; /* head of list of open files */ | |
166 | extern int maxfiles; /* kernel limit on number of open files */ | |
167 | extern int nfiles; /* actual number of open files */ | |
168 | #endif /* __APPLE_API_PRIVATE */ | |
169 | ||
170 | ||
171 | __BEGIN_DECLS | |
172 | int fo_read(struct fileproc *fp, struct uio *uio, | |
173 | struct ucred *cred, int flags, struct proc *p); | |
174 | int fo_write(struct fileproc *fp, struct uio *uio, | |
175 | struct ucred *cred, int flags, struct proc *p); | |
176 | int fo_ioctl(struct fileproc *fp, u_long com, caddr_t data, | |
177 | struct proc *p); | |
178 | int fo_select(struct fileproc *fp, int which, void *wql, | |
179 | struct proc *p); | |
180 | int fo_close(struct fileglob *fg, struct proc *p); | |
181 | int fo_kqfilter(struct fileproc *fp, struct knote *kn, | |
182 | struct proc *p); | |
183 | void fileproc_drain(proc_t, struct fileproc *); | |
184 | void fp_setflags(proc_t, struct fileproc *, int); | |
185 | void fp_clearflags(proc_t, struct fileproc *, int); | |
186 | int fp_drop(struct proc *p, int fd, struct fileproc *fp, int locked); | |
187 | int fp_drop_written(proc_t p, int fd, struct fileproc *fp); | |
188 | int fp_drop_event(proc_t p, int fd, struct fileproc *fp); | |
189 | int fp_free(struct proc * p, int fd, struct fileproc * fp); | |
190 | struct kqueue; | |
191 | int fp_getfkq(struct proc *p, int fd, struct fileproc **resultfp, struct kqueue **resultkq); | |
192 | struct psemnode; | |
193 | int fp_getfpsem(struct proc *p, int fd, struct fileproc **resultfp, struct psemnode **resultpsem); | |
194 | struct vnode; | |
195 | int fp_getfvp(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp); | |
196 | struct socket; | |
197 | int fp_getfsock(struct proc *p, int fd, struct fileproc **resultfp, struct socket **results); | |
198 | int fp_lookup(struct proc *p, int fd, struct fileproc **resultfp, int locked); | |
199 | int close_internal(struct proc *p, int fd, struct fileproc *fp, int flags); | |
200 | int closef_locked(struct fileproc *fp, struct fileglob *fg, struct proc *p); | |
201 | void fg_insertuipc(struct fileglob * fg); | |
202 | void fg_removeuipc(struct fileglob * fg); | |
203 | __END_DECLS | |
204 | ||
205 | #endif /* __APPLE_API_UNSTABLE */ | |
206 | ||
207 | #endif /* KERNEL */ | |
208 | ||
209 | #endif /* !_SYS_FILE_INTERNAL_H_ */ |