Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wrote C that displays info about my hardware on ubuntu. Now I wonder how I can make it more flexible such as querying the hardware directly instead of the file the os updates. So I think I can look what write to /proc/scsi/scsi and do the same so that this code can work also on unices who could have other method than a /proc/scsi/scsi and so that I can learn how to display hardware information.

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char ch, file_name[25] = "/proc/scsi/scsi";
   FILE *fp; 
   fp = fopen(file_name,"r"); // read mode 
   if( fp == NULL )
   {
      perror("Error while opening the file.\n");
      exit(EXIT_FAILURE);
   } 
   printf("The contents of %s file are :\n", file_name); 
   while( ( ch = fgetc(fp) ) != EOF )
      printf("%c",ch); 
   fclose(fp);
   return 0;
}

For me it looked like this

$ cc driveinfo.c;./a.out 
The contents of /proc/scsi/scsi file are :
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: WDC WD2500JS-75N Rev: 10.0
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST3250824AS      Rev: 3.AD
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: TSSTcorp Model: DVD+-RW TS-H653A Rev: D300
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
  Vendor: Optiarc  Model: DVD-ROM DDU1681S Rev: 102A
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: Lexar    Model: USB Flash Drive  Rev: 1100
  Type:   Direct-Access                    ANSI  SCSI revision: 00
Host: scsi5 Channel: 00 Id: 00 Lun: 00
  Vendor: WD       Model: 5000AAKB Externa Rev: l108
  Type:   Direct-Access                    ANSI  SCSI revision: 00

Can it run on other unices e.g. bsd? How can I make it run on ms-windows? Can I query the hardware directly instead of the file /proc/scsi/scsi ?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The /proc filesystem is not real, it is a view into kernel-internal data, exported to look like files. It exists in Linux and in Solaris (from where the idea was shamelessly pilfered), and maybe other Unixy systems. The format is very system-dependent (and has even changed substantially among Linux kernel versions).

There really isn't any halfway portable way of finding out hardware data (and can't be, some Unices and lookalikes run on pretty strange iron).

share|improve this answer
    
Solaris seems to keep only numbers in /proc and a SunOS sun4u sparc SUNW,Ultra-4 doesn't have a /proc/scsi/scsi –  909 Niklas Mar 6 '13 at 22:10
add comment

The /proc filesystem is Linux-centric, so the answer is no. BSD systems use sysctl for this kind of info. As for Windows, this is not the best group to ask, methinks. :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.