1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58#ifndef _SYS_FILE_INTERNAL_H_
59#define _SYS_FILE_INTERNAL_H_
60
61#include <sys/appleapiopts.h>
62#include <sys/fcntl.h>
63#include <sys/unistd.h>
64
65#ifdef KERNEL
66#include <sys/errno.h>
67#include <sys/queue.h>
68#include <sys/cdefs.h>
69#include <sys/lock.h>
70#include <sys/file.h>
71
72struct proc;
73struct uio;
74struct knote;
75#ifdef __APPLE_API_UNSTABLE
76
77struct file;
78
79
80
81
82
83
84struct fileproc {
85 int32_t f_flags;
86 int32_t f_iocount;
87 struct fileglob * f_fglob;
88 void * f_waddr;
89};
90
91#define FILEPROC_NULL (struct fileproc *)0
92
93#define FP_INCREATE 0x0001
94#define FP_INCLOSE 0x0002
95#define FP_INSELECT 0x0004
96#define FP_INCHRREAD 0x0008
97#define FP_WRITTEN 0x0010
98#define FP_CLOSING 0x0020
99#define FP_WAITCLOSE 0x0040
100#define FP_AIOISSUED 0x0080
101#define FP_WAITEVENT 0x0100
102
103
104
105#define CLOSEINT_LOCKED 1
106#define CLOSEINT_WAITONCLOSE 2
107#define CLOSEINT_NOFDRELSE 4
108#define CLOSEINT_NOFDNOREF 8
109
110struct fileglob {
111 LIST_ENTRY(fileglob) f_list;
112 LIST_ENTRY(fileglob) f_msglist;
113 int32_t fg_flag;
114 int32_t fg_type;
115 int32_t fg_count;
116 int32_t fg_msgcount;
117 struct ucred *fg_cred;
118 struct fileops {
119 int (*fo_read) __P((struct fileproc *fp, struct uio *uio,
120 struct ucred *cred, int flags,
121 struct proc *p));
122 int (*fo_write) __P((struct fileproc *fp, struct uio *uio,
123 struct ucred *cred, int flags,
124 struct proc *p));
125#define FOF_OFFSET 0x00000001
126#define FOF_PCRED 0x00000002
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;
138 lck_mtx_t fg_lock;
139 int32_t fg_lflags;
140 unsigned int fg_lockpc[4];
141 unsigned int fg_unlockpc[4];
142};
143
144
145#define DTYPE_VNODE 1
146#define DTYPE_SOCKET 2
147#define DTYPE_PSXSHM 3
148#define DTYPE_PSXSEM 4
149#define DTYPE_KQUEUE 5
150#define DTYPE_PIPE 6
151#define DTYPE_FSEVENTS 7
152
153
154#define FG_TERM 0x01
155#define FG_INSMSGQ 0x02
156#define FG_WINSMSGQ 0x04
157#define FG_RMMSGQ 0x08
158#define FG_WRMMSGQ 0x10
159
160
161#ifdef __APPLE_API_PRIVATE
162LIST_HEAD(filelist, fileglob);
163LIST_HEAD(fmsglist, fileglob);
164extern struct filelist filehead;
165extern struct fmsglist fmsghead;
166extern int maxfiles;
167extern int nfiles;
168#endif
169
170
171__BEGIN_DECLS
172int fo_read(struct fileproc *fp, struct uio *uio,
173 struct ucred *cred, int flags, struct proc *p);
174int fo_write(struct fileproc *fp, struct uio *uio,
175 struct ucred *cred, int flags, struct proc *p);
176int fo_ioctl(struct fileproc *fp, u_long com, caddr_t data,
177 struct proc *p);
178int fo_select(struct fileproc *fp, int which, void *wql,
179 struct proc *p);
180int fo_close(struct fileglob *fg, struct proc *p);
181int fo_kqfilter(struct fileproc *fp, struct knote *kn,
182 struct proc *p);
183void fileproc_drain(proc_t, struct fileproc *);
184void fp_setflags(proc_t, struct fileproc *, int);
185void fp_clearflags(proc_t, struct fileproc *, int);
186int fp_drop(struct proc *p, int fd, struct fileproc *fp, int locked);
187int fp_drop_written(proc_t p, int fd, struct fileproc *fp);
188int fp_drop_event(proc_t p, int fd, struct fileproc *fp);
189int fp_free(struct proc * p, int fd, struct fileproc * fp);
190struct kqueue;
191int fp_getfkq(struct proc *p, int fd, struct fileproc **resultfp, struct kqueue **resultkq);
192struct psemnode;
193int fp_getfpsem(struct proc *p, int fd, struct fileproc **resultfp, struct psemnode **resultpsem);
194struct vnode;
195int fp_getfvp(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp);
196struct socket;
197int fp_getfsock(struct proc *p, int fd, struct fileproc **resultfp, struct socket **results);
198int fp_lookup(struct proc *p, int fd, struct fileproc **resultfp, int locked);
199int close_internal(struct proc *p, int fd, struct fileproc *fp, int flags);
200int closef_locked(struct fileproc *fp, struct fileglob *fg, struct proc *p);
201void fg_insertuipc(struct fileglob * fg);
202void fg_removeuipc(struct fileglob * fg);
203__END_DECLS
204
205#endif
206
207#endif
208
209#endif
210