]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/file_internal.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / sys / file_internal.h
CommitLineData
91447636 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
91447636 5 *
6601e61a
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
8f6c56a5 11 *
6601e61a
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
91447636
A
21 */
22/* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
23/*
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)file.h 8.3 (Berkeley) 1/9/95
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 * Kernel descriptor table.
82 * One entry for each open kernel vnode and socket.
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/* defns of close_internal */
105#define CLOSEINT_LOCKED 1
106#define CLOSEINT_WAITONCLOSE 2
107#define CLOSEINT_NOFDRELSE 4
108#define CLOSEINT_NOFDNOREF 8
8f6c56a5
A
109
110/* file types */
111typedef enum {
112 DTYPE_VNODE = 1, /* file */
113 DTYPE_SOCKET, /* communications endpoint */
114 DTYPE_PSXSHM, /* POSIX Shared memory */
115 DTYPE_PSXSEM, /* POSIX Semaphores */
116 DTYPE_KQUEUE, /* kqueue */
117 DTYPE_PIPE, /* pipe */
118 DTYPE_FSEVENTS /* fsevents */
119} file_type_t;
120
121/* defines for fg_lflags */
122#define FG_TERM 0x01 /* the fileglob is terminating .. */
123#define FG_INSMSGQ 0x02 /* insert to msgqueue pending .. */
124#define FG_WINSMSGQ 0x04 /* wait for the fielglob is in msgque */
125#define FG_RMMSGQ 0x08 /* the fileglob is being removed from msgqueue */
126#define FG_WRMMSGQ 0x10 /* wait for the fileglob to be removed from msgqueue */
127
91447636
A
128
129struct fileglob {
130 LIST_ENTRY(fileglob) f_list;/* list of active files */
131 LIST_ENTRY(fileglob) f_msglist;/* list of active files */
132 int32_t fg_flag; /* see fcntl.h */
8f6c56a5 133 file_type_t fg_type; /* descriptor type */
91447636
A
134 int32_t fg_count; /* reference count */
135 int32_t fg_msgcount; /* references from message queue */
136 struct ucred *fg_cred; /* credentials associated with descriptor */
137 struct fileops {
138 int (*fo_read) __P((struct fileproc *fp, struct uio *uio,
139 struct ucred *cred, int flags,
140 struct proc *p));
141 int (*fo_write) __P((struct fileproc *fp, struct uio *uio,
142 struct ucred *cred, int flags,
143 struct proc *p));
13fec989
A
144#define FOF_OFFSET 0x00000001 /* offset supplied to vn_write */
145#define FOF_PCRED 0x00000002 /* cred from proc, not current thread */
91447636
A
146 int (*fo_ioctl) __P((struct fileproc *fp, u_long com,
147 caddr_t data, struct proc *p));
148 int (*fo_select) __P((struct fileproc *fp, int which,
149 void *wql, struct proc *p));
150 int (*fo_close) __P((struct fileglob *fg, struct proc *p));
151 int (*fo_kqfilter) __P((struct fileproc *fp, struct knote *kn,
152 struct proc *p));
153 int (*fo_drain) (struct fileproc *fp, struct proc *p);
154 } *fg_ops;
155 off_t fg_offset;
156 caddr_t fg_data; /* vnode or socket or SHM or semaphore */
157 lck_mtx_t fg_lock;
158 int32_t fg_lflags; /* file global flags */
159 unsigned int fg_lockpc[4];
160 unsigned int fg_unlockpc[4];
161};
162
91447636
A
163#ifdef __APPLE_API_PRIVATE
164LIST_HEAD(filelist, fileglob);
165LIST_HEAD(fmsglist, fileglob);
166extern struct filelist filehead; /* head of list of open files */
167extern struct fmsglist fmsghead; /* head of list of open files */
168extern int maxfiles; /* kernel limit on number of open files */
169extern int nfiles; /* actual number of open files */
170#endif /* __APPLE_API_PRIVATE */
171
172
173__BEGIN_DECLS
174int fo_read(struct fileproc *fp, struct uio *uio,
175 struct ucred *cred, int flags, struct proc *p);
176int fo_write(struct fileproc *fp, struct uio *uio,
177 struct ucred *cred, int flags, struct proc *p);
178int fo_ioctl(struct fileproc *fp, u_long com, caddr_t data,
179 struct proc *p);
180int fo_select(struct fileproc *fp, int which, void *wql,
181 struct proc *p);
182int fo_close(struct fileglob *fg, struct proc *p);
183int fo_kqfilter(struct fileproc *fp, struct knote *kn,
184 struct proc *p);
185void fileproc_drain(proc_t, struct fileproc *);
186void fp_setflags(proc_t, struct fileproc *, int);
187void fp_clearflags(proc_t, struct fileproc *, int);
188int fp_drop(struct proc *p, int fd, struct fileproc *fp, int locked);
189int fp_drop_written(proc_t p, int fd, struct fileproc *fp);
190int fp_drop_event(proc_t p, int fd, struct fileproc *fp);
191int fp_free(struct proc * p, int fd, struct fileproc * fp);
192struct kqueue;
193int fp_getfkq(struct proc *p, int fd, struct fileproc **resultfp, struct kqueue **resultkq);
194struct psemnode;
195int fp_getfpsem(struct proc *p, int fd, struct fileproc **resultfp, struct psemnode **resultpsem);
0c530ab8
A
196struct pshmnode;
197int fp_getfpshm(struct proc *p, int fd, struct fileproc **resultfp, struct pshmnode **resultpshm);
198struct pipe;
199int fp_getfpipe(struct proc *p, int fd, struct fileproc **resultfp, struct pipe **resultpipe);
200struct atalk;
201int fp_getfatalk(struct proc *p, int fd, struct fileproc **resultfp, struct atalk **resultatalk);
91447636
A
202struct vnode;
203int fp_getfvp(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp);
0c530ab8 204int fp_getfvpandvid(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp, uint32_t * vidp);
91447636
A
205struct socket;
206int fp_getfsock(struct proc *p, int fd, struct fileproc **resultfp, struct socket **results);
207int fp_lookup(struct proc *p, int fd, struct fileproc **resultfp, int locked);
208int close_internal(struct proc *p, int fd, struct fileproc *fp, int flags);
209int closef_locked(struct fileproc *fp, struct fileglob *fg, struct proc *p);
210void fg_insertuipc(struct fileglob * fg);
211void fg_removeuipc(struct fileglob * fg);
6601e61a
A
212void unp_gc_wait(void);
213void procfdtbl_reservefd(struct proc * p, int fd);
214void procfdtbl_markclosefd(struct proc * p, int fd);
215void procfdtbl_releasefd(struct proc * p, int fd, struct fileproc * fp);
216void procfdtbl_waitfd(struct proc * p, int fd);
217void procfdtbl_clearfd(struct proc * p, int fd);
91447636
A
218__END_DECLS
219
220#endif /* __APPLE_API_UNSTABLE */
221
222#endif /* KERNEL */
223
224#endif /* !_SYS_FILE_INTERNAL_H_ */