#ifndef _SYS_FILE_INTERNAL_H_
#define _SYS_FILE_INTERNAL_H_
#include <sys/appleapiopts.h>
#include <sys/fcntl.h>
#include <sys/unistd.h>
#ifdef KERNEL
#include <sys/errno.h>
#include <sys/queue.h>
#include <sys/cdefs.h>
#include <sys/lock.h>
#include <sys/file.h>
struct proc;
struct uio;
struct knote;
#ifdef __APPLE_API_UNSTABLE
struct file;
struct fileproc {
int32_t f_flags;
int32_t f_iocount;
struct fileglob * f_fglob;
void * f_waddr;
};
#define FILEPROC_NULL (struct fileproc *)0
#define FP_INCREATE 0x0001
#define FP_INCLOSE 0x0002
#define FP_INSELECT 0x0004
#define FP_INCHRREAD 0x0008
#define FP_WRITTEN 0x0010
#define FP_CLOSING 0x0020
#define FP_WAITCLOSE 0x0040
#define FP_AIOISSUED 0x0080
#define FP_WAITEVENT 0x0100
#define CLOSEINT_LOCKED 1
#define CLOSEINT_WAITONCLOSE 2
#define CLOSEINT_NOFDRELSE 4
#define CLOSEINT_NOFDNOREF 8
struct fileglob {
LIST_ENTRY(fileglob) f_list;
LIST_ENTRY(fileglob) f_msglist;
int32_t fg_flag;
int32_t fg_type;
int32_t fg_count;
int32_t fg_msgcount;
struct ucred *fg_cred;
struct fileops {
int (*fo_read) __P((struct fileproc *fp, struct uio *uio,
struct ucred *cred, int flags,
struct proc *p));
int (*fo_write) __P((struct fileproc *fp, struct uio *uio,
struct ucred *cred, int flags,
struct proc *p));
#define FOF_OFFSET 1
int (*fo_ioctl) __P((struct fileproc *fp, u_long com,
caddr_t data, struct proc *p));
int (*fo_select) __P((struct fileproc *fp, int which,
void *wql, struct proc *p));
int (*fo_close) __P((struct fileglob *fg, struct proc *p));
int (*fo_kqfilter) __P((struct fileproc *fp, struct knote *kn,
struct proc *p));
int (*fo_drain) (struct fileproc *fp, struct proc *p);
} *fg_ops;
off_t fg_offset;
caddr_t fg_data;
lck_mtx_t fg_lock;
int32_t fg_lflags;
unsigned int fg_lockpc[4];
unsigned int fg_unlockpc[4];
};
#define DTYPE_VNODE 1
#define DTYPE_SOCKET 2
#define DTYPE_PSXSHM 3
#define DTYPE_PSXSEM 4
#define DTYPE_KQUEUE 5
#define DTYPE_PIPE 6
#define DTYPE_FSEVENTS 7
#define FG_TERM 0x01
#define FG_INSMSGQ 0x02
#define FG_WINSMSGQ 0x04
#define FG_RMMSGQ 0x08
#define FG_WRMMSGQ 0x10
#ifdef __APPLE_API_PRIVATE
LIST_HEAD(filelist, fileglob);
LIST_HEAD(fmsglist, fileglob);
extern struct filelist filehead;
extern struct fmsglist fmsghead;
extern int maxfiles;
extern int nfiles;
#endif
__BEGIN_DECLS
int fo_read(struct fileproc *fp, struct uio *uio,
struct ucred *cred, int flags, struct proc *p);
int fo_write(struct fileproc *fp, struct uio *uio,
struct ucred *cred, int flags, struct proc *p);
int fo_ioctl(struct fileproc *fp, u_long com, caddr_t data,
struct proc *p);
int fo_select(struct fileproc *fp, int which, void *wql,
struct proc *p);
int fo_close(struct fileglob *fg, struct proc *p);
int fo_kqfilter(struct fileproc *fp, struct knote *kn,
struct proc *p);
void fileproc_drain(proc_t, struct fileproc *);
void fp_setflags(proc_t, struct fileproc *, int);
void fp_clearflags(proc_t, struct fileproc *, int);
int fp_drop(struct proc *p, int fd, struct fileproc *fp, int locked);
int fp_drop_written(proc_t p, int fd, struct fileproc *fp);
int fp_drop_event(proc_t p, int fd, struct fileproc *fp);
int fp_free(struct proc * p, int fd, struct fileproc * fp);
struct kqueue;
int fp_getfkq(struct proc *p, int fd, struct fileproc **resultfp, struct kqueue **resultkq);
struct psemnode;
int fp_getfpsem(struct proc *p, int fd, struct fileproc **resultfp, struct psemnode **resultpsem);
struct vnode;
int fp_getfvp(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp);
struct socket;
int fp_getfsock(struct proc *p, int fd, struct fileproc **resultfp, struct socket **results);
int fp_lookup(struct proc *p, int fd, struct fileproc **resultfp, int locked);
int close_internal(struct proc *p, int fd, struct fileproc *fp, int flags);
int closef_locked(struct fileproc *fp, struct fileglob *fg, struct proc *p);
void fg_insertuipc(struct fileglob * fg);
void fg_removeuipc(struct fileglob * fg);
__END_DECLS
#endif
#endif
#endif