extract_hostid.c revision ed5289f91b9bf164dccd6c75398362be77a4478d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <ctype.h>
#include <string.h>
#include <elf.h>
/*
* in the ON consolidation. They were used to generate the old style
* hostid that was patched into the sysinit module by install. They
* are reproduced here so that we can read existing hostids from old
* sysinit modules.
*/
#define V1 0x38d4419a
#define V1_K1 0x7a5fd043
#define V1_K2 0x65cb612e
#define A 16807
#define M 2147483647
#define Q 127773
#define R 2836
#define x() if ((s = ((A * (s % Q)) - (R * (s/Q)))) <= 0) s += M
/*
* Private function prototypes
*/
static void Usage();
/*
* extract_hostid - transitional utility designed to pull the existing
* hostid value out of a sysinit module and write it to stdout. Most
* likely useful for use with bfu, when moving from old style hostid
* to new style hostid on non-sparc
*/
int
{
int fd;
int rc = 0;
int opt;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (opt) {
case 'h':
Usage();
break;
default:
Usage();
}
}
return (0);
/* open the module file */
return (rc);
}
/* read the elf header */
offset = 0;
return (rc);
}
/* figure out if 32 or 64 bit */
else
if (rc < 0) {
return (rc);
}
s = value1;
x();
if (value2 == s) {
x();
s %= 1000000000;
} else
s = 0;
(void) printf("%08lx\n", (unsigned long)s);
return (rc);
}
static int
{
int rc;
char name[6];
int i;
/* read the elf header */
offset = 0;
goto out;
}
/* read the section header for the section string table */
goto out;
}
/* save the offset of the section string table */
/* find the .data section header */
/*CSTYLED*/
for (i = 1; ; ) {
goto out;
}
goto out;
}
break;
/* reached end of table */
goto out;
}
}
/* save the offset of the data section */
/* read and check the version number and initial seed values */
goto out;
}
*value1 = t[1];
*value2 = t[2];
rc = 0;
}
static int
{
int rc;
char name[6];
int i;
/* read the elf header */
offset = 0;
goto out;
}
/* read the section header for the section string table */
goto out;
}
/* save the offset of the section string table */
/* find the .data section header */
/*CSTYLED*/
for (i = 1; ; ) {
goto out;
}
goto out;
}
break;
/* reached end of table */
goto out;
}
}
/* save the offset of the data section */
/* read and check the version number and initial seed values */
goto out;
}
*value1 = t[1];
*value2 = t[2];
rc = 0;
}
static void
Usage()
{
exit(1);
}