From owner-freebsd-current@FreeBSD.ORG Fri Mar 5 04:13:26 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A945B16A4CE for ; Fri, 5 Mar 2004 04:13:26 -0800 (PST) Received: from cmsrelay03.mx.net (cmsrelay03.mx.net [165.212.11.112]) by mx1.FreeBSD.org (Postfix) with SMTP id 4FEBB43D41 for ; Fri, 5 Mar 2004 04:13:26 -0800 (PST) (envelope-from noackjr@alumni.rice.edu) Received: from uadvg130.cms.usa.net (165.212.11.130) by cmsoutbound.mx.net with SMTP; 5 Mar 2004 12:13:25 -0000 Received: from optimator.noacks.org [65.69.1.61] by uadvg130.cms.usa.net (ASMTP/noackjr@usa.net) via mtad (C8.MAIN.3.13N) with ESMTP id 679icemNw0300M30; Fri, 05 Mar 2004 12:13:22 GMT X-USANET-Auth: 65.69.1.61 AUTH noackjr@usa.net optimator.noacks.org Received: from localhost (localhost [127.0.0.1]) by optimator.noacks.org (Postfix) with ESMTP id 388E16124 for ; Fri, 5 Mar 2004 06:13:17 -0600 (CST) Received: from optimator.noacks.org ([127.0.0.1]) by localhost (optimator.noacks.org [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 35007-06 for ; Fri, 5 Mar 2004 06:13:16 -0600 (CST) Received: from alumni.rice.edu (compgeek [192.168.1.10]) by optimator.noacks.org (Postfix) with ESMTP id BFB4B611A for ; Fri, 5 Mar 2004 06:13:15 -0600 (CST) Message-ID: <40486F54.1090102@alumni.rice.edu> Date: Fri, 05 Mar 2004 06:15:16 -0600 From: Jon Noack User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-current@freebsd.org Content-Type: multipart/mixed; boundary="------------050808090507040405010706" X-Virus-Scanned: by amavisd-new at noacks.org Subject: /usr/bin/file returning wrong FreeBSD version X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: noackjr@alumni.rice.edu List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2004 12:13:26 -0000 This is a multi-part message in MIME format. --------------050808090507040405010706 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit I noticed (back in the "umount not working" thread) that file returns incorrect version numbers for 5.x. It still assumes x.y(.z) versioning is in the first 3 digits of the __FreeBSD_version value. For example: $ uname -r 5.2.1-RELEASE-p1 $ sysctl -n kern.osreldate 502010 $ file /usr/bin/file /usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), for FreeBSD 5.0.2, dynamically linked (uses shared libs), stripped A quick-and-dirty patch to correct this attached. It should return correct information for every __FreeBSD_version value (I had to hard code some exceptions). When it is an actual release, only the x.y(.z) is shown. Otherwise, the x.y(.z) has a '+' appended and the actual __FreeBSD_version value is show in parentheses. A few examples: I used the Porter's Handbook as a reference: http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/freebsd-versions.html __FreeBSD_version -> output 199608 -> FreeBSD <2.2 (199608) 220000 -> FreeBSD 2.2-2.2.1+ 225000 -> FreeBSD 2.2.5 225001 -> FreeBSD 2.2.5+ (225000) 411001 -> FreeBSD 4.1.1+ (411001) 460000 -> FreeBSD 4.6 460001 -> FreeBSD 4.6+ (460001) 460002 -> FreeBSD 4.6.2 460100 -> FreeBSD 4.6+ (460100) 500000 -> FreeBSD 5.0+ (500000) 500043 -> FreeBSD 5.0+ (500043) 502010 -> FreeBSD 5.2.1 502105 -> FreeBSD 5.2+ (502105) The source is indented a ridiculous amount, so my additions result in some lines over 80 characters (assuming 8 space tabs). Please correct my coding style, etc. This was just a quick hack to see if anyone was interested. Jon Noack --------------050808090507040405010706 Content-Type: text/plain; name="patch-readelf.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-readelf.c" --- src/contrib/file/readelf.c.orig Thu Feb 27 23:19:34 2003 +++ src/contrib/file/readelf.c Fri Mar 5 05:27:52 2004 @@ -282,15 +282,54 @@ * defined by a huge table in the * Porters' Handbook. Happily, the * first three digits are the version - * number, at least in versions of - * FreeBSD that use this note. + * number prior to 5.0, while the + * first, third, and fifth digits are + * the version number for later + * releases. */ - printf(" %d.%d", desc / 100000, - desc / 10000 % 10); - if (desc / 1000 % 10 > 0) - printf(".%d", - desc / 1000 % 10); + if (desc < 220000) { + printf(" <2.2 (%d)", desc); + } else + if (desc == 220000) { + printf(" 2.2-2.2.1+"); + } else + if (desc == 460002) { + printf(" 4.6.2"); + } else + { + printf(" %d.", desc / 100000); + if (desc < 500000) { + printf("%d", desc / 10000 % 10); + if (desc < 460100) { + if (desc / 1000 % 10 > 0) + printf(".%d", + desc / 1000 % 10); + if ((desc % 100 > 0) || + (desc % 100000 == 0)) + printf("+ (%d)", desc); + } else + { + if ((desc / 100 % 10 > 0) || + (desc / 100 % 1000 == 0)) + printf("+ (%d)", desc); + else + if (desc / 1000 % 10 > 0) + printf(".%d", + desc / 1000 % 10); + } + } else + { + printf("%d", desc / 1000 % 10); + if ((desc / 100 % 10 > 0) || + (desc / 100 % 1000 == 0)) + printf("+ (%d)", desc); + else + if (desc / 10 % 10 > 0) + printf(".%d", + desc / 10 % 10); + } + } } if (nh_namesz == 8 && --------------050808090507040405010706--