4 * Copyright (C) 2004 Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License v 2.0 as published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 021110-1307, USA.
20 * Authors: Atul Sabharwal
28 #include "chassis_id.h"
32 /* Run SCSI id to find serial number of the device */
33 static int getserial_number(char * devpath, char * snumber)
36 char vendor[255], model[255], cmd[255];
39 sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath);
44 return -ERROR_BAD_SNUMBER;
46 fscanf(fp, "%s %s %s", vendor, model, snumber);
48 syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", snumber );
53 return -ERROR_BAD_SNUMBER;
58 int main(int argc, char **argv, char **envp)
60 int chassis_num, slot_num, retval;
61 char disk_snum[255], devpath[255];
65 syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", "starting chassis_id" );
67 ptr = getenv("DEVPATH");
69 return -ERROR_NO_DEVPATH;
71 sscanf(ptr, "%s", &devpath[0]);
73 syslog(LOG_PID|LOG_DAEMON| LOG_ERR, "Devpath %s", devpath);
76 retval = table_init();
78 return -ERROR_BAD_TABLE;
80 getserial_number(devpath, disk_snum);
82 /* Now we open the provisioning table t find actual entry for the serial number*/
83 disk_index = table_find_disk(disk_snum, &chassis_num, &slot_num);
84 if ( disk_index == -1 ) {
85 // typical provisioning error
86 return -ERROR_NO_DISK;
88 table_select_disk( disk_index );