On Mon, May 23, 2011 at 01:42:45AM -0700, Tejinder wrote: Hi, > > I want to get the Hard Disk serial number of SCSI HDD on Solaris.
I would use kstats to be consistent with 'iostat -E'. E.g.: #include <kstat.h> #include <stdio.h> #include <string.h> #include <sys/sysinfo.h> /* Usage: sn disk ... e.g. sn sd0 sd1 */ int main(int argc, char **arg) { kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *ksp_named; char ks_name[KSTAT_STRLEN]; int i; kid_t kcid; kc = kstat_open(); argc--; for (; argc > 0; argc--) { printf("%s: ", arg[argc]); snprintf(ks_name, sizeof(ks_name) - 2, "%s,err", arg[argc]); if (ks_name[0] == 'c') { strcat(ks_name, "or"); /* ide, otherwise assume sdN */ } ksp = kstat_lookup(kc, NULL, -1, ks_name); if (ksp != NULL && ksp->ks_type == KSTAT_TYPE_NAMED) { kcid = kstat_read(kc, ksp, NULL); if (kcid == -1) { printf("error reading kstats \n"); continue; } ksp_named = ksp->ks_data; for (i = 0; i < ksp->ks_ndata; i++, ksp_named++) { if (ksp_named->data_type != KSTAT_DATA_CHAR) { continue; } ksp_named->name[KSTAT_STRLEN - 1] = '\0'; if (strcmp(ksp_named->name, "Vendor") == 0) { printf("Vendor=%s ", ksp_named->value.c); } else if (strcmp(ksp_named->name, "Product") == 0) { printf("Product=%s ", ksp_named->value.c); } else if (strcmp(ksp_named->name, "Serial No") == 0) { printf("S/N=%s ", ksp_named->value.c); } else if (strcmp(ksp_named->name, "Model") == 0) { printf("Model=%s ", ksp_named->value.c); } else if (strcmp(ksp_named->name, "Revision") == 0) { printf("Rev=%s ", ksp_named->value.c); } } printf("\n"); } } (void) kstat_close(kc); return (0); } But there are probably other alternatives ;-) Have fun, jel. -- Otto-von-Guericke University http://www.cs.uni-magdeburg.de/ Department of Computer Science Geb. 29 R 027, Universitaetsplatz 2 39106 Magdeburg, Germany Tel: +49 391 67 12768 _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code