From 12f43f95f6a8b3cd721a6d8a4818b89ab8bc6f06 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Thu, 12 Apr 2012 11:07:21 +0000 Subject: New system call: getdtablecount(2) returns the number of file descriptors the process currently has open. ok guenther miod gilles ... --- sys/kern/kern_descrip.c | 11 ++++++++++- sys/kern/syscalls.master | 4 ++-- sys/sys/filedesc.h | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'sys') diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ef18b8bef87..dca42ddc9d7 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.90 2012/04/12 11:01:37 deraadt Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.91 2012/04/12 11:07:20 deraadt Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -155,6 +155,7 @@ fd_used(struct filedesc *fdp, int fd) if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; + fdp->fd_openfd++; } static __inline void @@ -175,6 +176,7 @@ fd_unused(struct filedesc *fdp, int fd) #endif if (fd == fdp->fd_lastfile) fdp->fd_lastfile = find_last_set(fdp, fd); + fdp->fd_openfd--; } struct file * @@ -1320,3 +1322,10 @@ sys_closefrom(struct proc *p, void *v, register_t *retval) fdpunlock(fdp); return (0); } + +int +sys_getdtablecount(struct proc *p, void *v, register_t *retval) +{ + *retval = p->p_fd->fd_openfd; + return (0); +} diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index af289aab619..c241438c611 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.120 2012/01/17 02:34:18 guenther Exp $ +; $OpenBSD: syscalls.master,v 1.121 2012/04/12 11:07:19 deraadt Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -72,7 +72,7 @@ 16 STD { int sys_chown(const char *path, uid_t uid, \ gid_t gid); } 17 STD { int sys_obreak(char *nsize); } break -18 OBSOL getfsstat25 +18 STD { int sys_getdtablecount(void); } 19 OBSOL olseek 20 STD NOLOCK { pid_t sys_getpid(void); } 21 STD { int sys_mount(const char *type, const char *path, \ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 876b3bb6b14..92de6f3040e 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filedesc.h,v 1.21 2012/02/15 04:26:27 guenther Exp $ */ +/* $OpenBSD: filedesc.h,v 1.22 2012/04/12 11:07:19 deraadt Exp $ */ /* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */ /* @@ -62,6 +62,7 @@ struct filedesc { struct vnode *fd_cdir; /* current directory */ struct vnode *fd_rdir; /* root directory */ int fd_nfiles; /* number of open files allocated */ + int fd_openfd; /* number of files currently open */ u_int *fd_himap; /* each bit points to 32 fds */ u_int *fd_lomap; /* bitmap of free fds */ int fd_lastfile; /* high-water mark of fd_ofiles */ -- cgit v1.2.3