Date: Mon, 09 Jul 2007 23:46:14 -0400 From: Ighighi <ighighi@gmail.com> To: freebsd-hackers@freebsd.org Subject: Re: add closefrom() call Message-ID: <46930106.3040503@gmail.com>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------010005020304020706060506 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >Date: Mon, 09 Jul 2007 15:00:21 +0800 >From: LI Xin <delphij@delphij.net <mailto:delphij@delphij.net>> >Subject: Re: add closefrom() call >To: Robert Watson <rwatson@FreeBSD.org <mailto:rwatson@FreeBSD.org>> >Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org <mailto:freebsd-hackers@freebsd.org>>, d@delphij.net <mailto:d@delphij.net>, Julian Elischer <julian@elischer.org <mailto:julian@elischer.org>>, Ed Schouten <ed@fxq.nl <mailto:ed@fxq.nl>> >Message-ID: <4691DD05.2090407@delphij.net <mailto:4691DD05.2090407@delphij.net>> >Content-Type: text/plain; charset="iso-8859-1" LI Xin wrote: >Nope. > >I will try to see if we have some way to expose lastfile to userland, or >whether we have some better approach to implement this in userland next >week if I would have some spare time... F_MAXFD is easy to implement... Attached is a diff that should work for CURRENT. I'm working on a 6-STABLE. See closefrom.c for an implementation based on F_MAXFD. Still, it doesn't pay to implement it this way... Calling F_MAXFD everytime we close a file descriptor would be heavy having too much fd's. On the other hand, it wouldn't make much a difference to just start from getdtablesize() - 1. >Cheers, >-- >Xin LI <delphij@delphij.net <mailto:delphij@delphij.net>> http://www.delphij.net/ >FreeBSD - The Power to Serve! --------------010005020304020706060506 Content-Type: text/x-patch; name="maxfd.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="maxfd.diff" --- src/sys/kern/kern_descrip.c.orig Tue Jul 3 22:27:19 2007 +++ src/sys/kern/kern_descrip.c Mon Jul 9 22:19:35 2007 @@ -623,6 +623,13 @@ vfslocked = 0; fdrop(fp, td); break; + + case F_MAXFD: + FILEDESC_SLOCK(fdp); + td->td_retval[0] = fdp->fd_lastfile; + FILEDESC_SUNLOCK(fdp); + break; + default: error = EINVAL; break; --- src/sys/sys/fcntl.h.orig Wed Apr 7 00:19:49 2004 +++ src/sys/sys/fcntl.h Mon Jul 9 22:26:27 2007 @@ -176,6 +176,9 @@ #define F_GETLK 7 /* get record locking information */ #define F_SETLK 8 /* set record locking information */ #define F_SETLKW 9 /* F_SETLK; wait if blocked */ +#if __BSD_VISIBLE +#define F_MAXFD 11 /* return the max open fd (NetBSD) */ +#endif /* file descriptor flags (F_GETFD, F_SETFD) */ #define FD_CLOEXEC 1 /* close-on-exec flag */ --------------010005020304020706060506--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46930106.3040503>