/usr/bin/file returning wrong FreeBSD version

From: Jon Noack <noackjr_at_alumni.rice.edu>
Date: Fri, 05 Mar 2004 06:15:16 -0600
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

--- 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
_at__at_ -282,15 +282,54 _at__at_
 					 * 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 &&
Received on Fri Mar 05 2004 - 03:13:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:46 UTC