[PATCH] clean up chassis_id coding style.

This commit is contained in:
greg@kroah.com 2004-03-31 18:27:02 -08:00 committed by Greg KH
parent fa5acd760d
commit 0bcdc8498c
3 changed files with 158 additions and 174 deletions

View File

@ -1,19 +1,16 @@
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** $Id: chassis_id.c,v 1.8 2004/03/22 23:33:10 atul Exp $
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them.
**
*/
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them
**
*/
#include <stdio.h>
#include <stdlib.h>
@ -25,88 +22,83 @@
int main(int argc, char **argv, char ** envp)
{
int chassis_num, slot_num, retval, host_num;
char disk_snum[255], devpath[255];
char * ptr;
int disk_index;
int chassis_num, slot_num, retval, host_num;
char disk_snum[255], devpath[255];
char *ptr;
int disk_index;
syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", "starting chassis_id" );
syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", "starting chassis_id" );
#if 0
ptr = (char *) getenv( "CHASSIS");
if( ptr == NULL )
return -ERROR_NO_CHASSIS;
ptr = getenv("CHASSIS");
if (ptr == NULL)
return -ERROR_NO_CHASSIS;
sscanf(ptr, "%d", &chassis_num);
#ifdef DEBUG
syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "Chassis %d", chassis_num);
#endif
sscanf(ptr, "%d", &chassis_num);
#ifdef DEBUG
syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "Chassis %d", chassis_num);
#endif
ptr = (char *) getenv( "SLOT" );
if( ptr== NULL )
return -ERROR_NO_SLOT;
ptr = getenv("SLOT");
if (ptr== NULL)
return -ERROR_NO_SLOT;
sscanf(ptr, "%d", &slot_num);
#ifdef DEBUG
syslog( LOG_PID|LOG_DAEMON| LOG_ERR, "Slot %d", slot_num);
#endif
sscanf(ptr, "%d", &slot_num);
#ifdef DEBUG
syslog( LOG_PID|LOG_DAEMON| LOG_ERR, "Slot %d", slot_num);
#endif
#endif
ptr = (char *) getenv( "DEVPATH");
if( ptr == NULL )
return -ERROR_NO_DEVPATH;
ptr = getenv("DEVPATH");
if (ptr == NULL)
return -ERROR_NO_DEVPATH;
sscanf(ptr, "%s", &devpath[0]);
#ifdef DEBUG
syslog( LOG_PID|LOG_DAEMON| LOG_ERR, "Devpath %s", devpath);
#endif
sscanf(ptr, "%s", &devpath[0]);
#ifdef DEBUG
syslog(LOG_PID|LOG_DAEMON| LOG_ERR, "Devpath %s", devpath);
#endif
retval = table_init();
if(retval < 0 )
return -ERROR_BAD_TABLE;
getserial_number( devpath, disk_snum);
retval = table_init();
if (retval < 0)
return -ERROR_BAD_TABLE;
/* Now we open the provisioning table t find actual entry for the serial number*/
disk_index = table_find_disk(disk_snum, &host_num, &chassis_num, &slot_num);
if ( disk_index == -1 )
{
//typical provisioning error
return -ERROR_NO_DISK;
}
else
{
table_select_disk( disk_index );
}
return 0;
getserial_number(devpath, disk_snum);
/* Now we open the provisioning table t find actual entry for the serial number*/
disk_index = table_find_disk(disk_snum, &host_num, &chassis_num, &slot_num);
if ( disk_index == -1 ) {
// typical provisioning error
return -ERROR_NO_DISK;
} else {
table_select_disk( disk_index );
}
return 0;
}
/* Run SCSI id to find serial number of the device */
int getserial_number( char * devpath, char * snumber )
{
FILE *fp;
char vendor [255], model[255], cmd[255];
int retval;
FILE *fp;
char vendor[255], model[255], cmd[255];
int retval;
sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath);
sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath);
fp = popen( cmd, "r");
fp = popen(cmd, "r");
if (fp == NULL)
return -ERROR_BAD_SNUMBER;
if (fp == NULL)
return -ERROR_BAD_SNUMBER;
fscanf( fp, "%s %s %s", vendor, model, snumber);
#ifdef DEBUG
syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", snumber );
#endif
retval = pclose(fp);
if (retval == -1)
return -ERROR_BAD_SNUMBER;
else
return NO_ERROR;
fscanf(fp, "%s %s %s", vendor, model, snumber);
#ifdef DEBUG
syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", snumber );
#endif
retval = pclose(fp);
if (retval == -1)
return -ERROR_BAD_SNUMBER;
else
return NO_ERROR;
}

View File

@ -1,33 +1,30 @@
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** $Id: chassis_id.h,v 1.1 2004/03/16 18:24:44 atul Exp $
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them.
**
*/
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them.
**
*/
#ifndef _CHASSIS_ID_H
#define _CHASSIS_ID_H
//#define DEBUG 1
#define ERROR 1
#define ERROR_NO_SLOT 2
#define ERROR_NO_CHASSIS 3
#define ERROR_NO_DEVPATH 4
#define ERROR_BAD_SNUMBER 5
#define ERROR_NO_DISK 6
#define ERROR_BAD_TABLE 7
#define ERROR_BAD_SCAN 8
#define NO_ERROR 0
//#define DEBUG 1
#define ERROR 1
#define ERROR_NO_SLOT 2
#define ERROR_NO_CHASSIS 3
#define ERROR_NO_DEVPATH 4
#define ERROR_BAD_SNUMBER 5
#define ERROR_NO_DISK 6
#define ERROR_BAD_TABLE 7
#define ERROR_BAD_SCAN 8
#define NO_ERROR 0
extern int table_init();

View File

@ -1,33 +1,33 @@
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** $Id: table.c,v 1.4 2004/03/18 21:56:24 atul Exp $
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them.
**
*/
/* -*-c-*-:
**
** (C) 2003 Intel Corporation
** Atul Sabharwal <atul.sabharwal@intel.com>
**
** $Id: table.c,v 1.4 2004/03/18 21:56:24 atul Exp $
**
** Distributed under the terms of the GNU Public License, v2.0 or
** later.
**
** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
** with his permission, they have been re-licensed GPL, and his
** copyright still applies on them.
**
*/
#include <stdio.h>
#define TABLE_SIZE 100
#define PROVISION_DB "/usr/local/bin/provision.tbl"
struct provision_record
{
int id;
int host_num; //port # or adaptor number
int num_disks;
int chassis_num;
int slot_num;
char serial_num[32];
char name[32];
int id;
int host_num; //port # or adaptor number
int num_disks;
int chassis_num;
int slot_num;
char serial_num[32];
char name[32];
} ptable[TABLE_SIZE];
int ptable_size;
@ -36,67 +36,62 @@ int ptable_size;
Return error if something does not work appropriately. */
int table_init()
{
FILE *fp;
char ptr[255];
int i;
fp=fopen( PROVISION_DB, "r");
FILE *fp;
char ptr[255];
int i;
if ((fp== NULL) || feof(fp))
return -1;
fp = fopen( PROVISION_DB, "r");
//skip the first line of text which contains descriptive details.
fgets(ptr, 80, fp);
i = 0;
while (!feof(fp))
{
fgets(ptr, 80, fp);
sscanf( ptr, "%d %d %d %d %d %s %s", &ptable[i].id, &ptable[i].host_num,
&ptable[i].num_disks, &ptable[i].chassis_num, &ptable[i].slot_num,
ptable[i].serial_num, ptable[i].name );
i++;
}
if ((fp== NULL) || feof(fp))
return -1;
ptable_size = i;
fclose(fp);
return 0;
// skip the first line of text which contains descriptive details.
fgets(ptr, 80, fp);
i = 0;
while (!feof(fp)) {
fgets(ptr, 80, fp);
sscanf(ptr, "%d %d %d %d %d %s %s", &ptable[i].id,
&ptable[i].host_num, &ptable[i].num_disks,
&ptable[i].chassis_num, &ptable[i].slot_num,
ptable[i].serial_num, ptable[i].name);
i++;
}
ptable_size = i;
fclose(fp);
return 0;
}
/* return -1 when no disk found. Otherwise return index of disk */
/* return -1 when no disk found. Otherwise return index of disk */
int table_find_disk( char * serialnumber , int * host_num, int * chassis_num, int *slot_num)
{
int i;
for(i = 0; i < ptable_size; i++)
{
int i;
if(strcmp(ptable[i].serial_num, serialnumber) == 0)
{
for (i = 0; i < ptable_size; i++) {
if (strcmp(ptable[i].serial_num, serialnumber) == 0) {
*host_num = ptable[i].host_num;
*chassis_num = ptable[i].chassis_num;
*slot_num = ptable[i].slot_num;
break;
}
}
*host_num = ptable[i].host_num;
*chassis_num = ptable[i].chassis_num;
*slot_num = ptable[i].slot_num;
break;
}
}
if(i == ptable_size)
return -1;
else
return i;
if (i == ptable_size)
return -1;
else
return i;
}
/* This function is primarily there for passing the selected disk entry to udev so that *
* it can create descriptive GDN for it. So, for that we need to output this data to *
* stdout. */
/* This function is primarily there for passing the selected disk entry to udev
* so that it can create descriptive GDN for it. So, for that we need to output
* this data to stdout.
*/
int table_select_disk( int diskindex )
{
printf("%d ", ptable[diskindex].chassis_num);
printf("%d ", ptable[diskindex].slot_num);
printf("%d ", ptable[diskindex].host_num);
printf("%s ", ptable[diskindex].name);
printf("%d ", ptable[diskindex].chassis_num);
printf("%d ", ptable[diskindex].slot_num);
printf("%d ", ptable[diskindex].host_num);
printf("%s ", ptable[diskindex].name);
}