Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 05 Mar 2004 06:15:16 -0600
From:      Jon Noack <noackjr@alumni.rice.edu>
To:        freebsd-current@freebsd.org
Subject:   /usr/bin/file returning wrong FreeBSD version
Message-ID:  <40486F54.1090102@alumni.rice.edu>

next in thread | raw e-mail | index | archive | help
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40486F54.1090102>