FreeBSD kernel kern code
kern_descrip.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_compat.h"
#include "opt_ddb.h"
#include "opt_ktrace.h"
#include "opt_procdesc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/capability.h>
#include <sys/conf.h>
#include <sys/domain.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/ksem.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/mqueue.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/selinfo.h>
#include <sys/pipe.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/procdesc.h>
#include <sys/protosw.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/sbuf.h>
#include <sys/signalvar.h>
#include <sys/socketvar.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/tty.h>
#include <sys/unistd.h>
#include <sys/un.h>
#include <sys/unpcb.h>
#include <sys/user.h>
#include <sys/vnode.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/in_pcb.h>
#include <security/audit/audit.h>
#include <vm/uma.h>
#include <vm/vm.h>
#include <ddb/ddb.h>

Go to the source code of this file.

Data Structures

struct  freetable
 
struct  filedesc0
 
struct  getdtablesize_args
 
struct  dup2_args
 
struct  dup_args
 
struct  fcntl_args
 
struct  close_args
 
struct  closefrom_args
 
struct  fstat_args
 
struct  nfstat_args
 
struct  fpathconf_args
 
struct  flock_args
 
struct  export_fd_buf
 

Macros

#define DUP_FIXED   0x1 /* Force fixed allocation */
 
#define DUP_FCNTL   0x2 /* fcntl()-style errors */
 
#define DUP_CLOEXEC   0x4 /* Atomically set FD_CLOEXEC. */
 
#define NDFILE   20
 
#define NDSLOTSIZE   sizeof(NDSLOTTYPE)
 
#define NDENTRIES   (NDSLOTSIZE * __CHAR_BIT)
 
#define NDSLOT(x)   ((x) / NDENTRIES)
 
#define NDBIT(x)   ((NDSLOTTYPE)1 << ((x) % NDENTRIES))
 
#define NDSLOTS(x)   (((x) + NDENTRIES - 1) / NDENTRIES)
 
#define OFILESIZE   (sizeof(struct file *) + sizeof(char))
 
#define FGET_GETCAP   0x00000001
 
#define NFFLAGS   (sizeof(fflags_table) / sizeof(*fflags_table))
 
#define FILEDESC_SBUF_SIZE   (sizeof(struct kinfo_file) * 5)
 
#define NVTYPES   (sizeof(vtypes_table) / sizeof(*vtypes_table))
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_FILEDESC,"filedesc","Open file descriptor table")
 
static MALLOC_DEFINE (M_FILEDESC_TO_LEADER,"filedesc_to_leader","file desc to leader structures")
 
static MALLOC_DEFINE (M_SIGIO,"sigio","sigio structures")
 
 MALLOC_DECLARE (M_FADVISE)
 
static int do_dup (struct thread *td, int flags, int old, int new, register_t *retval)
 
static int fd_first_free (struct filedesc *, int, int)
 
static int fd_last_used (struct filedesc *, int, int)
 
static void fdgrowtable (struct filedesc *, int)
 
static void fdunused (struct filedesc *fdp, int fd)
 
static void fdused (struct filedesc *fdp, int fd)
 
static int fill_vnode_info (struct vnode *vp, struct kinfo_file *kif)
 
static int fill_socket_info (struct socket *so, struct kinfo_file *kif)
 
static int fill_pts_info (struct tty *tp, struct kinfo_file *kif)
 
static int fill_pipe_info (struct pipe *pi, struct kinfo_file *kif)
 
static int fill_procdesc_info (struct procdesc *pdp, struct kinfo_file *kif)
 
static int fill_sem_info (struct file *fp, struct kinfo_file *kif)
 
static int fill_shm_info (struct file *fp, struct kinfo_file *kif)
 
static int getmaxfd (struct proc *p)
 
static int fdisused (struct filedesc *fdp, int fd)
 
int sys_getdtablesize (struct thread *td, struct getdtablesize_args *uap)
 
int sys_dup2 (struct thread *td, struct dup2_args *uap)
 
int sys_dup (struct thread *td, struct dup_args *uap)
 
int sys_fcntl (struct thread *td, struct fcntl_args *uap)
 
static struct file * fdtofp (int fd, struct filedesc *fdp)
 
static int fdunwrap (int fd, cap_rights_t rights, struct filedesc *fdp, struct file **fpp)
 
int kern_fcntl (struct thread *td, int fd, int cmd, intptr_t arg)
 
void funsetown (struct sigio **sigiop)
 
void funsetownlst (struct sigiolst *sigiolst)
 
int fsetown (pid_t pgid, struct sigio **sigiop)
 
pid_t fgetown (struct sigio **sigiop)
 
int sys_close (struct thread *td, struct close_args *uap)
 
int kern_close (struct thread *td, int fd)
 
int sys_closefrom (struct thread *td, struct closefrom_args *uap)
 
int sys_fstat (struct thread *td, struct fstat_args *uap)
 
int kern_fstat (struct thread *td, int fd, struct stat *sbp)
 
int sys_nfstat (struct thread *td, struct nfstat_args *uap)
 
int sys_fpathconf (struct thread *td, struct fpathconf_args *uap)
 
int fdalloc (struct thread *td, int minfd, int *result)
 
int fdallocn (struct thread *td, int minfd, int *fds, int n)
 
int fdavail (struct thread *td, int n)
 
int falloc (struct thread *td, struct file **resultfp, int *resultfd, int flags)
 
int falloc_noinstall (struct thread *td, struct file **resultfp)
 
int finstall (struct thread *td, struct file *fp, int *fd, int flags)
 
struct filedesc * fdinit (struct filedesc *fdp)
 
static struct filedesc * fdhold (struct proc *p)
 
static void fddrop (struct filedesc *fdp)
 
struct filedesc * fdshare (struct filedesc *fdp)
 
void fdunshare (struct proc *p, struct thread *td)
 
struct filedesc * fdcopy (struct filedesc *fdp)
 
void fdfree (struct thread *td)
 
static int is_unsafe (struct file *fp)
 
void setugidsafety (struct thread *td)
 
void fdclose (struct filedesc *fdp, struct file *fp, int idx, struct thread *td)
 
void fdcloseexec (struct thread *td)
 
int fdcheckstd (struct thread *td)
 
int closef (struct file *fp, struct thread *td)
 
void finit (struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
 
struct file * fget_unlocked (struct filedesc *fdp, int fd)
 
static __inline int _fget (struct thread *td, int fd, struct file **fpp, int flags, cap_rights_t needrights, cap_rights_t *haverightsp, u_char *maxprotp, int fget_flags)
 
int fget (struct thread *td, int fd, cap_rights_t rights, struct file **fpp)
 
int fget_mmap (struct thread *td, int fd, cap_rights_t rights, u_char *maxprotp, struct file **fpp)
 
int fget_read (struct thread *td, int fd, cap_rights_t rights, struct file **fpp)
 
int fget_write (struct thread *td, int fd, cap_rights_t rights, struct file **fpp)
 
int fgetcap (struct thread *td, int fd, struct file **fpp)
 
static __inline int _fgetvp (struct thread *td, int fd, int flags, cap_rights_t needrights, cap_rights_t *haverightsp, struct vnode **vpp)
 
int fgetvp (struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp)
 
int fgetvp_rights (struct thread *td, int fd, cap_rights_t need, cap_rights_t *have, struct vnode **vpp)
 
int fgetvp_read (struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp)
 
int fgetvp_exec (struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp)
 
int fgetsock (struct thread *td, int fd, cap_rights_t rights, struct socket **spp, u_int *fflagp)
 
void fputsock (struct socket *so)
 
int _fdrop (struct file *fp, struct thread *td)
 
int sys_flock (struct thread *td, struct flock_args *uap)
 
int dupfdopen (struct thread *td, struct filedesc *fdp, int indx, int dfd, int mode, int error)
 
void mountcheckdirs (struct vnode *olddp, struct vnode *newdp)
 
struct filedesc_to_leader * filedesc_to_leader_alloc (struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader)
 
static int sysctl_kern_file (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD, 0, 0, sysctl_kern_file,"S,xfile","Entire file table")
 
static int export_fd_to_sb (void *data, int type, int fd, int fflags, int refcnt, int64_t offset, int fd_is_cap, cap_rights_t fd_cap_rights, struct export_fd_buf *efbuf)
 
int kern_proc_filedesc_out (struct proc *p, struct sbuf *sb, ssize_t maxlen)
 
static int sysctl_kern_proc_filedesc (SYSCTL_HANDLER_ARGS)
 
int vntype_to_kinfo (int vtype)
 
static SYSCTL_NODE (_kern_proc, KERN_PROC_FILEDESC, filedesc, CTLFLAG_RD, sysctl_kern_proc_filedesc,"Process filedesc entries")
 
 SYSCTL_INT (_kern, KERN_MAXFILESPERPROC, maxfilesperproc, CTLFLAG_RW,&maxfilesperproc, 0,"Maximum files allowed open per process")
 
 SYSCTL_INT (_kern, KERN_MAXFILES, maxfiles, CTLFLAG_RW,&maxfiles, 0,"Maximum number of files")
 
 SYSCTL_INT (_kern, OID_AUTO, openfiles, CTLFLAG_RD, __DEVOLATILE(int *,&openfiles), 0,"System-wide number of open files")
 
static void filelistinit (void *dummy)
 
 SYSINIT (select, SI_SUB_LOCK, SI_ORDER_FIRST, filelistinit, NULL)
 
static int badfo_readwrite (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int badfo_truncate (struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
 
static int badfo_ioctl (struct file *fp, u_long com, void *data, struct ucred *active_cred, struct thread *td)
 
static int badfo_poll (struct file *fp, int events, struct ucred *active_cred, struct thread *td)
 
static int badfo_kqfilter (struct file *fp, struct knote *kn)
 
static int badfo_stat (struct file *fp, struct stat *sb, struct ucred *active_cred, struct thread *td)
 
static int badfo_close (struct file *fp, struct thread *td)
 
static int badfo_chmod (struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
 
static int badfo_chown (struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
 
int invfo_chmod (struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
 
int invfo_chown (struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
 
static int fdopen (struct cdev *dev, int mode, int type, struct thread *td)
 
static void fildesc_drvinit (void *unused)
 
 SYSINIT (fildescdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, fildesc_drvinit, NULL)
 

Variables

static uma_zone_t file_zone
 
void(* ksem_info )(struct ksem *ks, char *path, size_t size, uint32_t *value)
 
volatile int openfiles
 
struct mtx sigio_lock
 
void(* mq_fdclose )(struct thread *td, int fd, struct file *fp)
 
static struct mtx fdesc_mtx
 
struct fileops badfileops
 
static struct cdevsw fildesc_cdevsw
 

Macro Definition Documentation

#define DUP_CLOEXEC   0x4 /* Atomically set FD_CLOEXEC. */

Definition at line 119 of file kern_descrip.c.

Referenced by do_dup(), and kern_fcntl().

#define DUP_FCNTL   0x2 /* fcntl()-style errors */

Definition at line 118 of file kern_descrip.c.

Referenced by do_dup(), and kern_fcntl().

#define DUP_FIXED   0x1 /* Force fixed allocation */

Definition at line 117 of file kern_descrip.c.

Referenced by do_dup(), fdcheckstd(), kern_fcntl(), and sys_dup2().

#define FGET_GETCAP   0x00000001

Definition at line 2382 of file kern_descrip.c.

Referenced by _fget(), and fgetcap().

#define FILEDESC_SBUF_SIZE   (sizeof(struct kinfo_file) * 5)

Definition at line 3569 of file kern_descrip.c.

Referenced by sysctl_kern_proc_filedesc().

#define NDBIT (   x)    ((NDSLOTTYPE)1 << ((x) % NDENTRIES))

Definition at line 150 of file kern_descrip.c.

Referenced by fdisused(), fdunused(), and fdused().

#define NDENTRIES   (NDSLOTSIZE * __CHAR_BIT)

Definition at line 148 of file kern_descrip.c.

Referenced by fd_first_free(), fd_last_used(), and fdgrowtable().

#define NDFILE   20

Definition at line 146 of file kern_descrip.c.

Referenced by fdfree(), fdgrowtable(), and fdinit().

#define NDSLOT (   x)    ((x) / NDENTRIES)

Definition at line 149 of file kern_descrip.c.

Referenced by fd_first_free(), fd_last_used(), fdisused(), fdunused(), and fdused().

#define NDSLOTS (   x)    (((x) + NDENTRIES - 1) / NDENTRIES)

Definition at line 151 of file kern_descrip.c.

Referenced by fd_first_free(), fdfree(), and fdgrowtable().

#define NDSLOTSIZE   sizeof(NDSLOTTYPE)

Definition at line 147 of file kern_descrip.c.

Referenced by fdgrowtable().

#define NFFLAGS   (sizeof(fflags_table) / sizeof(*fflags_table))

Referenced by export_fd_to_sb().

#define NVTYPES   (sizeof(vtypes_table) / sizeof(*vtypes_table))

Referenced by vntype_to_kinfo().

#define OFILESIZE   (sizeof(struct file *) + sizeof(char))

Definition at line 156 of file kern_descrip.c.

Referenced by fdgrowtable().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int _fdrop ( struct file *  fp,
struct thread *  td 
)

Definition at line 2656 of file kern_descrip.c.

References badfileops, crfree(), file_zone, free(), openfiles, and panic().

Here is the call graph for this function:

static __inline int _fget ( struct thread *  td,
int  fd,
struct file **  fpp,
int  flags,
cap_rights_t  needrights,
cap_rights_t *  haverightsp,
u_char *  maxprotp,
int  fget_flags 
)
static

Definition at line 2384 of file kern_descrip.c.

References badfileops, cap_funwrap(), cap_funwrap_mmap(), FGET_GETCAP, and fget_unlocked().

Referenced by _fgetvp(), fget(), fget_mmap(), fget_read(), fget_write(), fgetcap(), and fgetsock().

Here is the call graph for this function:

Here is the caller graph for this function:

static __inline int _fgetvp ( struct thread *  td,
int  fd,
int  flags,
cap_rights_t  needrights,
cap_rights_t *  haverightsp,
struct vnode **  vpp 
)
static

Definition at line 2535 of file kern_descrip.c.

References _fget(), and vref().

Referenced by fgetvp(), fgetvp_exec(), fgetvp_read(), and fgetvp_rights().

Here is the call graph for this function:

Here is the caller graph for this function:

static int badfo_chmod ( struct file *  fp,
mode_t  mode,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3989 of file kern_descrip.c.

static int badfo_chown ( struct file *  fp,
uid_t  uid,
gid_t  gid,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3997 of file kern_descrip.c.

static int badfo_close ( struct file *  fp,
struct thread *  td 
)
static

Definition at line 3982 of file kern_descrip.c.

static int badfo_ioctl ( struct file *  fp,
u_long  com,
void *  data,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3951 of file kern_descrip.c.

static int badfo_kqfilter ( struct file *  fp,
struct knote kn 
)
static

Definition at line 3967 of file kern_descrip.c.

static int badfo_poll ( struct file *  fp,
int  events,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3959 of file kern_descrip.c.

static int badfo_readwrite ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 3935 of file kern_descrip.c.

static int badfo_stat ( struct file *  fp,
struct stat *  sb,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3974 of file kern_descrip.c.

static int badfo_truncate ( struct file *  fp,
off_t  length,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 3943 of file kern_descrip.c.

int closef ( struct file *  fp,
struct thread *  td 
)

Definition at line 2237 of file kern_descrip.c.

References cap_funwrap(), and wakeup().

Referenced by do_dup(), fdcloseexec(), fdfree(), kern_close(), setugidsafety(), unp_discard(), and unp_process_defers().

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_dup ( struct thread *  td,
int  flags,
int  old,
int  new,
register_t *  retval 
)
static

Definition at line 828 of file kern_descrip.c.

References closef(), DUP_CLOEXEC, DUP_FCNTL, DUP_FIXED, fdalloc(), fdgrowtable(), fdunused(), fdused(), getmaxfd(), knote_fdclose(), mq_fdclose, racct_set(), and wakeup().

Referenced by fdcheckstd(), kern_fcntl(), sys_dup(), and sys_dup2().

Here is the call graph for this function:

Here is the caller graph for this function:

int dupfdopen ( struct thread *  td,
struct filedesc *  fdp,
int  indx,
int  dfd,
int  mode,
int  error 
)

Definition at line 2733 of file kern_descrip.c.

References fdunused(), and fdused().

Referenced by kern_openat().

Here is the call graph for this function:

Here is the caller graph for this function:

static int export_fd_to_sb ( void *  data,
int  type,
int  fd,
int  fflags,
int  refcnt,
int64_t  offset,
int  fd_is_cap,
cap_rights_t  fd_cap_rights,
struct export_fd_buf efbuf 
)
static

Definition at line 3280 of file kern_descrip.c.

References fd, export_fd_buf::fdp, fill_pipe_info(), fill_procdesc_info(), fill_pts_info(), fill_sem_info(), fill_shm_info(), fill_socket_info(), fill_vnode_info(), export_fd_buf::kif, NFFLAGS, export_fd_buf::remainder, export_fd_buf::sb, sbuf_bcat(), type, and vrele().

Referenced by kern_proc_filedesc_out().

Here is the call graph for this function:

Here is the caller graph for this function:

int falloc ( struct thread *  td,
struct file **  resultfp,
int *  resultfd,
int  flags 
)

Definition at line 1666 of file kern_descrip.c.

References falloc_noinstall(), fd, and finstall().

Referenced by do_pipe(), fork1(), kern_accept(), kern_kmq_open(), kern_socketpair(), ksem_create(), sys_fhopen(), sys_kqueue(), sys_posix_openpt(), sys_sctp_peeloff(), sys_shm_open(), and sys_socket().

Here is the call graph for this function:

Here is the caller graph for this function:

int falloc_noinstall ( struct thread *  td,
struct file **  resultfp 
)

Definition at line 1696 of file kern_descrip.c.

References badfileops, crhold(), file_zone, maxfiles, openfiles, ppsratecheck(), printf(), and priv_check().

Referenced by falloc(), and kern_openat().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fd_first_free ( struct filedesc *  fdp,
int  low,
int  size 
)
static

Definition at line 200 of file kern_descrip.c.

References mask, NDENTRIES, NDSLOT, and NDSLOTS.

Referenced by fdalloc(), and fdused().

Here is the caller graph for this function:

static int fd_last_used ( struct filedesc *  fdp,
int  low,
int  size 
)
static

Definition at line 227 of file kern_descrip.c.

References mask, NDENTRIES, and NDSLOT.

Referenced by fdunused().

Here is the caller graph for this function:

int fdalloc ( struct thread *  td,
int  minfd,
int *  result 
)

Definition at line 1547 of file kern_descrip.c.

References fd, fd_first_free(), fdgrowtable(), fdisused(), fdused(), getmaxfd(), and racct_set().

Referenced by do_dup(), fdallocn(), and finstall().

Here is the call graph for this function:

Here is the caller graph for this function:

int fdallocn ( struct thread *  td,
int  minfd,
int *  fds,
int  n 
)

Definition at line 1603 of file kern_descrip.c.

References fdalloc(), fdavail(), and fdunused().

Referenced by unp_externalize().

Here is the call graph for this function:

Here is the caller graph for this function:

int fdavail ( struct thread *  td,
int  n 
)

Definition at line 1632 of file kern_descrip.c.

References getmaxfd().

Referenced by fdallocn().

Here is the call graph for this function:

Here is the caller graph for this function:

int fdcheckstd ( struct thread *  td)

Definition at line 2195 of file kern_descrip.c.

References do_dup(), DUP_FIXED, and kern_open().

Referenced by do_execve().

Here is the call graph for this function:

Here is the caller graph for this function:

void fdclose ( struct filedesc *  fdp,
struct file *  fp,
int  idx,
struct thread *  td 
)

Definition at line 2129 of file kern_descrip.c.

References fdunused().

Referenced by accept1(), do_pipe(), kern_accept(), kern_kmq_open(), kern_openat(), kern_socketpair(), ksem_create(), sys_fhopen(), sys_posix_openpt(), sys_sctp_peeloff(), sys_shm_open(), and sys_socket().

Here is the call graph for this function:

Here is the caller graph for this function:

void fdcloseexec ( struct thread *  td)

Definition at line 2146 of file kern_descrip.c.

References closef(), fdunused(), knote_fdclose(), and mq_fdclose.

Referenced by do_execve().

Here is the call graph for this function:

Here is the caller graph for this function:

struct filedesc* fdcopy ( struct filedesc *  fdp)

Definition at line 1859 of file kern_descrip.c.

References badfileops, fdgrowtable(), fdinit(), fdisused(), and fdused().

Referenced by do_fork(), and fdunshare().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fddrop ( struct filedesc *  fdp)
static

Definition at line 1801 of file kern_descrip.c.

References fdesc_mtx, free(), and freetable::ft_table.

Referenced by fdfree(), kern_proc_filedesc_out(), mountcheckdirs(), and sysctl_kern_file().

Here is the call graph for this function:

Here is the caller graph for this function:

void fdfree ( struct thread *  td)

Definition at line 1908 of file kern_descrip.c.

References closef(), fddrop(), fdesc_mtx, free(), NDFILE, NDSLOTS, racct_set(), and vrele().

Referenced by exit1(), fdunshare(), and fork_norfproc().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fdgrowtable ( struct filedesc *  fdp,
int  nfd 
)
static

Definition at line 1472 of file kern_descrip.c.

References free(), freetable::ft_table, malloc(), NDENTRIES, NDFILE, NDSLOTS, NDSLOTSIZE, and OFILESIZE.

Referenced by do_dup(), fdalloc(), and fdcopy().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct filedesc* fdhold ( struct proc *  p)
static

Definition at line 1788 of file kern_descrip.c.

References fdesc_mtx.

Referenced by kern_proc_filedesc_out(), mountcheckdirs(), and sysctl_kern_file().

Here is the caller graph for this function:

struct filedesc* fdinit ( struct filedesc *  fdp)

Definition at line 1755 of file kern_descrip.c.

References filedesc0::fd_fd, malloc(), and NDFILE.

Referenced by do_fork(), fdcopy(), fork_norfproc(), and proc0_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fdisused ( struct filedesc *  fdp,
int  fd 
)
static

Definition at line 250 of file kern_descrip.c.

References NDBIT, and NDSLOT.

Referenced by fdalloc(), fdcopy(), fdunused(), and fdused().

Here is the caller graph for this function:

static int fdopen ( struct cdev *  dev,
int  mode,
int  type,
struct thread *  td 
)
static

Definition at line 4048 of file kern_descrip.c.

struct filedesc* fdshare ( struct filedesc *  fdp)

Definition at line 1826 of file kern_descrip.c.

Referenced by do_fork().

Here is the caller graph for this function:

static struct file* fdtofp ( int  fd,
struct filedesc *  fdp 
)
static

Definition at line 437 of file kern_descrip.c.

Referenced by fdunwrap(), and kern_fcntl().

Here is the caller graph for this function:

void fdunshare ( struct proc *  p,
struct thread *  td 
)

Definition at line 1839 of file kern_descrip.c.

References fdcopy(), and fdfree().

Referenced by do_execve(), and fork_norfproc().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fdunused ( struct filedesc *  fdp,
int  fd 
)
static

Definition at line 279 of file kern_descrip.c.

References fd, fd_last_used(), fdisused(), NDBIT, and NDSLOT.

Referenced by do_dup(), dupfdopen(), fdallocn(), fdclose(), fdcloseexec(), kern_close(), and setugidsafety().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fdunwrap ( int  fd,
cap_rights_t  rights,
struct filedesc *  fdp,
struct file **  fpp 
)
inlinestatic

Definition at line 449 of file kern_descrip.c.

References cap_funwrap(), and fdtofp().

Referenced by kern_fcntl().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fdused ( struct filedesc *  fdp,
int  fd 
)
static

Definition at line 261 of file kern_descrip.c.

References fd, fd_first_free(), fdisused(), NDBIT, and NDSLOT.

Referenced by do_dup(), dupfdopen(), fdalloc(), and fdcopy().

Here is the call graph for this function:

Here is the caller graph for this function:

int fget ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct file **  fpp 
)

Definition at line 2486 of file kern_descrip.c.

References _fget().

Referenced by aio_aqueue(), getmq(), kern_fstat(), kern_ftruncate(), kern_ioctl(), kern_kevent(), kern_posix_fadvise(), kern_posix_fallocate(), kqfd_register(), kqueue_register(), ksem_get(), sys_aio_cancel(), sys_fchmod(), sys_fchown(), sys_flock(), sys_fpathconf(), and sys_lseek().

Here is the call graph for this function:

Here is the caller graph for this function:

int fget_mmap ( struct thread *  td,
int  fd,
cap_rights_t  rights,
u_char *  maxprotp,
struct file **  fpp 
)

Definition at line 2493 of file kern_descrip.c.

References _fget().

Here is the call graph for this function:

int fget_read ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct file **  fpp 
)

Definition at line 2501 of file kern_descrip.c.

References _fget().

Referenced by aio_aqueue(), getmq_read(), kern_preadv(), and kern_readv().

Here is the call graph for this function:

Here is the caller graph for this function:

struct file* fget_unlocked ( struct filedesc *  fdp,
int  fd 
)

Definition at line 2330 of file kern_descrip.c.

References count, and fd.

Referenced by _fget(), getselfd_cap(), getsock_cap(), getvnode(), and ttyhook_register().

Here is the caller graph for this function:

int fget_write ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct file **  fpp 
)

Definition at line 2508 of file kern_descrip.c.

References _fget().

Referenced by aio_aqueue(), getmq_write(), kern_pwritev(), and kern_writev().

Here is the call graph for this function:

Here is the caller graph for this function:

int fgetcap ( struct thread *  td,
int  fd,
struct file **  fpp 
)

Definition at line 2520 of file kern_descrip.c.

References _fget(), and FGET_GETCAP.

Here is the call graph for this function:

pid_t fgetown ( struct sigio **  sigiop)

Definition at line 1192 of file kern_descrip.c.

Referenced by kern_accept(), kqueue_ioctl(), logioctl(), pipe_ioctl(), soo_ioctl(), sys_sctp_peeloff(), and tty_generic_ioctl().

Here is the caller graph for this function:

int fgetsock ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct socket **  spp,
u_int *  fflagp 
)

Definition at line 2606 of file kern_descrip.c.

References _fget().

Referenced by sys_sctp_peeloff().

Here is the call graph for this function:

Here is the caller graph for this function:

int fgetvp ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct vnode **  vpp 
)

Definition at line 2557 of file kern_descrip.c.

References _fgetvp().

Here is the call graph for this function:

int fgetvp_exec ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct vnode **  vpp 
)

Definition at line 2578 of file kern_descrip.c.

References _fgetvp().

Referenced by do_execve().

Here is the call graph for this function:

Here is the caller graph for this function:

int fgetvp_read ( struct thread *  td,
int  fd,
cap_rights_t  rights,
struct vnode **  vpp 
)

Definition at line 2571 of file kern_descrip.c.

References _fgetvp().

Referenced by kern_sendfile().

Here is the call graph for this function:

Here is the caller graph for this function:

int fgetvp_rights ( struct thread *  td,
int  fd,
cap_rights_t  need,
cap_rights_t *  have,
struct vnode **  vpp 
)

Definition at line 2564 of file kern_descrip.c.

References _fgetvp().

Referenced by namei().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fildesc_drvinit ( void *  unused)
static

Definition at line 4070 of file kern_descrip.c.

References make_dev_alias(), and make_dev_credf().

Here is the call graph for this function:

struct filedesc_to_leader* filedesc_to_leader_alloc ( struct filedesc_to_leader *  old,
struct filedesc *  fdp,
struct proc *  leader 
)

Definition at line 2882 of file kern_descrip.c.

References malloc().

Referenced by do_fork().

Here is the call graph for this function:

Here is the caller graph for this function:

static void filelistinit ( void *  dummy)
static

Definition at line 3922 of file kern_descrip.c.

References fdesc_mtx, file_zone, mtx_init(), and sigio_lock.

Here is the call graph for this function:

static int fill_pipe_info ( struct pipe *  pi,
struct kinfo_file *  kif 
)
static

Definition at line 3738 of file kern_descrip.c.

Referenced by export_fd_to_sb().

Here is the caller graph for this function:

static int fill_procdesc_info ( struct procdesc *  pdp,
struct kinfo_file *  kif 
)
static

Definition at line 3750 of file kern_descrip.c.

Referenced by export_fd_to_sb().

Here is the caller graph for this function:

static int fill_pts_info ( struct tty *  tp,
struct kinfo_file *  kif 
)
static

Definition at line 3727 of file kern_descrip.c.

References tty_udev().

Referenced by export_fd_to_sb().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fill_sem_info ( struct file *  fp,
struct kinfo_file *  kif 
)
static

Definition at line 3760 of file kern_descrip.c.

References ksem_info.

Referenced by export_fd_to_sb().

Here is the caller graph for this function:

static int fill_shm_info ( struct file *  fp,
struct kinfo_file *  kif 
)
static

Definition at line 3779 of file kern_descrip.c.

References shm_path().

Referenced by export_fd_to_sb().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fill_socket_info ( struct socket *  so,
struct kinfo_file *  kif 
)
static

Definition at line 3673 of file kern_descrip.c.

References free().

Referenced by export_fd_to_sb().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fill_vnode_info ( struct vnode *  vp,
struct kinfo_file *  kif 
)
static

Definition at line 3630 of file kern_descrip.c.

References free(), vn_fullpath(), and vntype_to_kinfo().

Referenced by export_fd_to_sb().

Here is the call graph for this function:

Here is the caller graph for this function:

void finit ( struct file *  fp,
u_int  flag,
short  type,
void *  data,
struct fileops *  ops 
)

Definition at line 2321 of file kern_descrip.c.

References flag, and type.

Referenced by do_pipe(), kern_accept(), kern_kmq_open(), kern_openat(), kern_socketpair(), ksem_create(), pts_alloc(), pts_alloc_external(), sys_fhopen(), sys_kqueue(), sys_sctp_peeloff(), sys_shm_open(), and sys_socket().

Here is the caller graph for this function:

int finstall ( struct thread *  td,
struct file *  fp,
int *  fd,
int  flags 
)

Definition at line 1729 of file kern_descrip.c.

References fd, and fdalloc().

Referenced by falloc(), and kern_openat().

Here is the call graph for this function:

Here is the caller graph for this function:

void fputsock ( struct socket *  so)

Definition at line 2639 of file kern_descrip.c.

Referenced by sys_sctp_peeloff().

Here is the caller graph for this function:

int fsetown ( pid_t  pgid,
struct sigio **  sigiop 
)

Definition at line 1087 of file kern_descrip.c.

References crfree(), crhold(), free(), funsetown(), malloc(), pfind(), pgfind(), and proctree_lock.

Referenced by kern_accept(), kqueue_ioctl(), logioctl(), logopen(), pipe_ioctl(), soo_ioctl(), sys_sctp_peeloff(), and tty_generic_ioctl().

Here is the call graph for this function:

Here is the caller graph for this function:

void funsetown ( struct sigio **  sigiop)

Definition at line 990 of file kern_descrip.c.

References crfree(), and free().

Referenced by fsetown(), kqueue_close(), logclose(), pipe_close(), soclose(), and ttydev_leave().

Here is the call graph for this function:

Here is the caller graph for this function:

void funsetownlst ( struct sigiolst *  sigiolst)

Definition at line 1026 of file kern_descrip.c.

References crfree(), and free().

Referenced by exit1(), and pgdelete().

Here is the call graph for this function:

Here is the caller graph for this function:

static int getmaxfd ( struct proc *  p)
static

Definition at line 813 of file kern_descrip.c.

References lim_cur(), and maxfilesperproc.

Referenced by do_dup(), fdalloc(), and fdavail().

Here is the call graph for this function:

Here is the caller graph for this function:

int invfo_chmod ( struct file *  fp,
mode_t  mode,
struct ucred *  active_cred,
struct thread *  td 
)

Definition at line 4018 of file kern_descrip.c.

int invfo_chown ( struct file *  fp,
uid_t  uid,
gid_t  gid,
struct ucred *  active_cred,
struct thread *  td 
)

Definition at line 4026 of file kern_descrip.c.

static int is_unsafe ( struct file *  fp)
static

Definition at line 2068 of file kern_descrip.c.

Referenced by setugidsafety().

Here is the caller graph for this function:

int kern_close ( struct thread *  td,
int  fd 
)

Definition at line 1222 of file kern_descrip.c.

References cap_funwrap(), closef(), fd, fdunused(), knote_fdclose(), mq_fdclose, and wakeup().

Referenced by parse_dir_md(), sys_close(), sys_closefrom(), sys_ksem_close(), sys_ksem_destroy(), and sys_socketpair().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_fcntl ( struct thread *  td,
int  fd,
int  cmd,
intptr_t  arg 
)

Definition at line 469 of file kern_descrip.c.

References do_dup(), DUP_CLOEXEC, DUP_FCNTL, DUP_FIXED, fd, fdtofp(), fdunwrap(), and priv_check().

Referenced by sys_fcntl().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_fstat ( struct thread *  td,
int  fd,
struct stat *  sbp 
)

Definition at line 1372 of file kern_descrip.c.

References fget().

Referenced by sys_fstat(), and sys_nfstat().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_proc_filedesc_out ( struct proc *  p,
struct sbuf *  sb,
ssize_t  maxlen 
)

Definition at line 3394 of file kern_descrip.c.

References cap_funwrap(), export_fd_to_sb(), fddrop(), fdhold(), export_fd_buf::fdp, free(), malloc(), export_fd_buf::remainder, export_fd_buf::sb, type, and vref().

Referenced by note_procstat_files(), and sysctl_kern_proc_filedesc().

Here is the call graph for this function:

Here is the caller graph for this function:

MALLOC_DECLARE ( M_FADVISE  )
static MALLOC_DEFINE ( M_FILEDESC  ,
"filedesc"  ,
"Open file descriptor table"   
)
static
static MALLOC_DEFINE ( M_FILEDESC_TO_LEADER  ,
"filedesc_to_leader"  ,
"file desc to leader structures"   
)
static
static MALLOC_DEFINE ( M_SIGIO  ,
"sigio"  ,
"sigio structures"   
)
static
void mountcheckdirs ( struct vnode *  olddp,
struct vnode *  newdp 
)

Definition at line 2819 of file kern_descrip.c.

References allprison, allprison_lock, allproc_lock, fddrop(), fdhold(), pr, prison0, rootvnode, vref(), vrefcnt(), and vrele().

Referenced by dounmount(), and vfs_domount_first().

Here is the call graph for this function:

Here is the caller graph for this function:

void setugidsafety ( struct thread *  td)

Definition at line 2083 of file kern_descrip.c.

References closef(), fdunused(), is_unsafe(), and knote_fdclose().

Referenced by do_execve().

Here is the call graph for this function:

Here is the caller graph for this function:

int sys_close ( struct thread *  td,
struct close_args uap 
)

Definition at line 1213 of file kern_descrip.c.

References close_args::fd, and kern_close().

Here is the call graph for this function:

int sys_closefrom ( struct thread *  td,
struct closefrom_args uap 
)

Definition at line 1296 of file kern_descrip.c.

References fd, kern_close(), and closefrom_args::lowfd.

Here is the call graph for this function:

int sys_dup ( struct thread *  td,
struct dup_args uap 
)

Definition at line 351 of file kern_descrip.c.

References do_dup(), and dup_args::fd.

Here is the call graph for this function:

int sys_dup2 ( struct thread *  td,
struct dup2_args uap 
)

Definition at line 334 of file kern_descrip.c.

References do_dup(), DUP_FIXED, dup2_args::from, and dup2_args::to.

Here is the call graph for this function:

int sys_fcntl ( struct thread *  td,
struct fcntl_args uap 
)

Definition at line 369 of file kern_descrip.c.

References fcntl_args::arg, fcntl_args::cmd, fcntl_args::fd, and kern_fcntl().

Here is the call graph for this function:

int sys_flock ( struct thread *  td,
struct flock_args uap 
)

Definition at line 2687 of file kern_descrip.c.

References flock_args::fd, fget(), and flock_args::how.

Here is the call graph for this function:

int sys_fpathconf ( struct thread *  td,
struct fpathconf_args uap 
)

Definition at line 1429 of file kern_descrip.c.

References async_io_version, fpathconf_args::fd, fget(), and fpathconf_args::name.

Here is the call graph for this function:

int sys_fstat ( struct thread *  td,
struct fstat_args uap 
)

Definition at line 1360 of file kern_descrip.c.

References fstat_args::fd, kern_fstat(), and fstat_args::sb.

Here is the call graph for this function:

int sys_getdtablesize ( struct thread *  td,
struct getdtablesize_args uap 
)

Definition at line 305 of file kern_descrip.c.

References lim_cur(), maxfilesperproc, and racct_get_limit().

Here is the call graph for this function:

int sys_nfstat ( struct thread *  td,
struct nfstat_args uap 
)

Definition at line 1404 of file kern_descrip.c.

References cvtnstat(), nfstat_args::fd, kern_fstat(), and nfstat_args::sb.

Here is the call graph for this function:

SYSCTL_INT ( _kern  ,
KERN_MAXFILESPERPROC  ,
maxfilesperproc  ,
CTLFLAG_RW  ,
maxfilesperproc,
,
"Maximum files allowed open per process"   
)
SYSCTL_INT ( _kern  ,
KERN_MAXFILES  ,
maxfiles  ,
CTLFLAG_RW  ,
maxfiles,
,
"Maximum number of files"   
)
SYSCTL_INT ( _kern  ,
OID_AUTO  ,
openfiles  ,
CTLFLAG_RD  ,
__DEVOLATILE(int *,&openfiles ,
,
"System-wide number of open files"   
)
static int sysctl_kern_file ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 2911 of file kern_descrip.c.

References allproc_lock, fddrop(), fdhold(), p_cansee(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

static int sysctl_kern_proc_filedesc ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 3575 of file kern_descrip.c.

References FILEDESC_SBUF_SIZE, kern_proc_filedesc_out(), name, pget(), sbuf_delete(), sbuf_finish(), and sbuf_new_for_sysctl().

Here is the call graph for this function:

static SYSCTL_NODE ( _kern_proc  ,
KERN_PROC_FILEDESC  ,
filedesc  ,
CTLFLAG_RD  ,
sysctl_kern_proc_filedesc  ,
"Process filedesc entries"   
)
static
SYSCTL_PROC ( _kern  ,
KERN_FILE  ,
file  ,
CTLTYPE_OPAQUE|  CTLFLAG_RD,
,
,
sysctl_kern_file  ,
S,
xfile"  ,
"Entire file table"   
)
SYSINIT ( select  ,
SI_SUB_LOCK  ,
SI_ORDER_FIRST  ,
filelistinit  ,
NULL   
)
SYSINIT ( fildescdev  ,
SI_SUB_DRIVERS  ,
SI_ORDER_MIDDLE  ,
fildesc_drvinit  ,
NULL   
)
int vntype_to_kinfo ( int  vtype)

Definition at line 3598 of file kern_descrip.c.

References NVTYPES.

Referenced by fill_vnode_info(), and kern_proc_vmmap_out().

Here is the caller graph for this function:

Variable Documentation

struct fileops badfileops
Initial value:
= {
.fo_read = badfo_readwrite,
.fo_write = badfo_readwrite,
.fo_truncate = badfo_truncate,
.fo_ioctl = badfo_ioctl,
.fo_poll = badfo_poll,
.fo_kqfilter = badfo_kqfilter,
.fo_stat = badfo_stat,
.fo_close = badfo_close,
.fo_chmod = badfo_chmod,
.fo_chown = badfo_chown,
}
static int badfo_readwrite(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
static int badfo_stat(struct file *fp, struct stat *sb, struct ucred *active_cred, struct thread *td)
static int badfo_close(struct file *fp, struct thread *td)
static int badfo_ioctl(struct file *fp, u_long com, void *data, struct ucred *active_cred, struct thread *td)
static int badfo_poll(struct file *fp, int events, struct ucred *active_cred, struct thread *td)
static int badfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
static int badfo_kqfilter(struct file *fp, struct knote *kn)
static int badfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
static int badfo_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)

Definition at line 4004 of file kern_descrip.c.

Referenced by _fdrop(), _fget(), falloc_noinstall(), fdcopy(), getvnode(), kern_openat(), mqf_close(), pipe_close(), soo_close(), ttyhook_register(), and vn_closefile().

struct mtx fdesc_mtx
static

Definition at line 193 of file kern_descrip.c.

Referenced by fddrop(), fdfree(), fdhold(), and filelistinit().

struct cdevsw fildesc_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_open = fdopen,
.d_name = "FD",
}
static int fdopen(struct cdev *dev, int mode, int type, struct thread *td)

Definition at line 4063 of file kern_descrip.c.

uma_zone_t file_zone
static

Definition at line 112 of file kern_descrip.c.

Referenced by _fdrop(), falloc_noinstall(), and filelistinit().

void(* ksem_info) (struct ksem *ks, char *path, size_t size, uint32_t *value)

Definition at line 114 of file kern_descrip.c.

Referenced by fill_sem_info(), ksem_module_destroy(), and ksem_module_init().

void(* mq_fdclose) (struct thread *td, int fd, struct file *fp)

Definition at line 190 of file kern_descrip.c.

Referenced by do_dup(), fdcloseexec(), kern_close(), and mqfs_init().

volatile int openfiles

Definition at line 188 of file kern_descrip.c.

Referenced by _fdrop(), and falloc_noinstall().

struct mtx sigio_lock

Definition at line 189 of file kern_descrip.c.

Referenced by filelistinit().