#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 {
unsigned int 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 0x0000
#define FP_WRITTEN 0x0010
#define FP_CLOSING 0x0020
#define FP_WAITCLOSE 0x0040
#define FP_AIOISSUED 0x0080
#define FP_WAITEVENT 0x0100
#define FP_VALID_FLAGS (FP_INCREATE | FP_INCLOSE | FP_INSELECT | FP_INCHRREAD | FP_WRITTEN | FP_WRITTEN | FP_CLOSING | FP_WAITCLOSE | FP_AIOISSUED | FP_WAITEVENT)
#ifndef _KAUTH_CRED_T
#define _KAUTH_CRED_T
struct ucred;
typedef struct ucred *kauth_cred_t;
#endif
typedef enum {
DTYPE_VNODE = 1,
DTYPE_SOCKET,
DTYPE_PSXSHM,
DTYPE_PSXSEM,
DTYPE_KQUEUE,
DTYPE_PIPE,
DTYPE_FSEVENTS
} file_type_t;
#define FG_TERM 0x01
#define FG_INSMSGQ 0x02
#define FG_WINSMSGQ 0x04
#define FG_RMMSGQ 0x08
#define FG_WRMMSGQ 0x10
#define FG_PORTMADE 0x20
struct fileglob {
LIST_ENTRY(fileglob) f_list;
LIST_ENTRY(fileglob) f_msglist;
int32_t fg_flag;
file_type_t fg_type;
int32_t fg_count;
int32_t fg_msgcount;
kauth_cred_t fg_cred;
struct fileops {
int (*fo_read) (struct fileproc *fp, struct uio *uio,
int flags, vfs_context_t ctx);
int (*fo_write) (struct fileproc *fp, struct uio *uio,
int flags, vfs_context_t ctx);
#define FOF_OFFSET 0x00000001
#define FOF_PCRED 0x00000002
int (*fo_ioctl) (struct fileproc *fp, u_long com,
caddr_t data, vfs_context_t ctx);
int (*fo_select) (struct fileproc *fp, int which,
void *wql, vfs_context_t ctx);
int (*fo_close) (struct fileglob *fg, vfs_context_t ctx);
int (*fo_kqfilter) (struct fileproc *fp, struct knote *kn,
vfs_context_t ctx);
int (*fo_drain) (struct fileproc *fp, vfs_context_t ctx);
} *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];
#if CONFIG_MACF
struct label *fg_label;
#endif
};
#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;
extern int maxfilesperproc;
#endif
__BEGIN_DECLS
int fo_read(struct fileproc *fp, struct uio *uio, int flags, vfs_context_t ctx);
int fo_write(struct fileproc *fp, struct uio *uio, int flags,
vfs_context_t ctx);
int fo_ioctl(struct fileproc *fp, u_long com, caddr_t data, vfs_context_t ctx);
int fo_select(struct fileproc *fp, int which, void *wql, vfs_context_t ctx);
int fo_close(struct fileglob *fg, vfs_context_t ctx);
int fo_kqfilter(struct fileproc *fp, struct knote *kn, vfs_context_t ctx);
void fileproc_drain(proc_t, struct fileproc *);
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 pshmnode;
int fp_getfpshm(struct proc *p, int fd, struct fileproc **resultfp, struct pshmnode **resultpshm);
struct pipe;
int fp_getfpipe(struct proc *p, int fd, struct fileproc **resultfp, struct pipe **resultpipe);
struct atalk;
int fp_getfatalk(struct proc *p, int fd, struct fileproc **resultfp, struct atalk **resultatalk);
struct vnode;
int fp_getfvp(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp);
int fp_getfvpandvid(struct proc *p, int fd, struct fileproc **resultfp, struct vnode **resultvp, uint32_t * vidp);
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 closef_locked(struct fileproc *fp, struct fileglob *fg, struct proc *p);
void fg_insertuipc(struct fileglob * fg);
void fg_removeuipc(struct fileglob * fg);
void unp_gc_wait(void);
void procfdtbl_reservefd(struct proc * p, int fd);
void procfdtbl_markclosefd(struct proc * p, int fd);
void procfdtbl_releasefd(struct proc * p, int fd, struct fileproc * fp);
void procfdtbl_waitfd(struct proc * p, int fd);
void procfdtbl_clearfd(struct proc * p, int fd);
boolean_t filetype_issendable(file_type_t type);
extern int fdgetf_noref(proc_t, int, struct fileproc **);
__END_DECLS
#endif
#endif
#endif