From owner-freebsd-hackers@FreeBSD.ORG Tue Jul 10 03:46:34 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3860416A400 for ; Tue, 10 Jul 2007 03:46:34 +0000 (UTC) (envelope-from ighighi@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.178]) by mx1.freebsd.org (Postfix) with ESMTP id EB72C13C458 for ; Tue, 10 Jul 2007 03:46:33 +0000 (UTC) (envelope-from ighighi@gmail.com) Received: by py-out-1112.google.com with SMTP id a73so2277161pye for ; Mon, 09 Jul 2007 20:46:33 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type; b=GjNtVAefcSaP7DnCm/+J/I/Y0/CyE0UWzy2HVAjO0XecEfpbV5TFNvA/oZOXioF/UBImKudSLOR2K9hePTGN2ywJG3aiS7+4VM/sVRu4ViITSGU9sHG/jRVwcSvHDblfijNRlv6BfmCGr1tr01cwirv1RSOO8WTFLPAjzrzUiYA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type; b=DcJXbIpFNZ/WeEml60RR+P29A8CgzGWkMvkYz2jn7A9mz7HVxCJHJKj7oxcJi3vZi6tjallhHuOjQl6imMmPuqSu0wLhnkgwpFf20n7GzmGdpNyQ8xaNOLoxXxKieyQlVgwEDBtlYNKRWjExFmrxTxRwycTx/988qt9kLkg79LM= Received: by 10.35.17.8 with SMTP id u8mr7786471pyi.1184039193288; Mon, 09 Jul 2007 20:46:33 -0700 (PDT) Received: from orion.nebula.mil ( [200.44.87.45]) by mx.google.com with ESMTP id w38sm22972364pyg.2007.07.09.20.46.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 09 Jul 2007 20:46:31 -0700 (PDT) Message-ID: <46930106.3040503@gmail.com> Date: Mon, 09 Jul 2007 23:46:14 -0400 From: Ighighi User-Agent: Thunderbird 2.0.0.4 (X11/20070616) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: multipart/mixed; boundary="------------010005020304020706060506" X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: add closefrom() call X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2007 03:46:34 -0000 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 > >Subject: Re: add closefrom() call >To: Robert Watson > >Cc: FreeBSD Hackers >, d@delphij.net , Julian Elischer >, Ed Schouten > >Message-ID: <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 > 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--