home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / MISC / SRC / INSTALL / SCSI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-23  |  1.8 KB  |  96 lines

  1. #include <errno.h>
  2. #include <fcntl.h>
  3. #include <newt.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7.  
  8. #include "devices.h"
  9. #include "install.h"
  10. #include "log.h"
  11. #include "scsi.h"
  12.  
  13. static int scsiChoicePanel(int * addSCSI);
  14.  
  15. static int scsiChoicePanel(int * addSCSI) {
  16.     newtComponent label, f, answer;
  17.     newtComponent yes, no;
  18.  
  19.     newtOpenWindow(21, 7, 35, 9, "SCSI Configuration");
  20.  
  21.     label = newtLabel(2, 2, "Do you have any SCSI adapters?");
  22.  
  23.     yes = newtButton(5, 5, "Yes");
  24.     no = newtButton(22, 5, "No");
  25.  
  26.     f = newtForm(NULL, NULL, 0);
  27.     newtFormAddComponents(f, label, yes, no, NULL);
  28.     newtFormSetCurrent(f, no);
  29.     
  30.     answer = newtRunForm(f);
  31.     if (answer == f) 
  32.     answer = newtFormGetCurrent(f);
  33.  
  34.     newtFormDestroy(f);
  35.     newtPopWindow();
  36.  
  37.     if (answer == no) 
  38.     *addSCSI = 0;
  39.     else
  40.     *addSCSI = 1;
  41.  
  42.     return 0;
  43. }
  44.  
  45.  
  46. int setupSCSIInterfaces(int forceConfig, struct driversLoaded ** dl) {
  47.     int rc;
  48.     int hasscsi;
  49.  
  50.     if (scsiDeviceAvailable()) return 0;
  51.  
  52.     do {
  53.     if (forceConfig)
  54.         forceConfig = 0;
  55.     else {
  56.         scsiChoicePanel(&hasscsi);
  57.         if (!hasscsi) return 0;
  58.     }
  59.  
  60.         rc = loadDeviceDriver(DRIVER_SCSI, dl);
  61.     if (rc == INST_ERROR) return INST_ERROR;
  62.     } while (rc);
  63.  
  64.     return 0;
  65. }
  66.  
  67. int scsiDeviceAvailable(void) {
  68.     int fd;
  69.     char buf[80];
  70.     int i;
  71.  
  72.     fd = open("/proc/scsi/scsi", O_RDONLY);
  73.     if (fd < 0) {
  74.     logMessage("failed to open /proc/scsi/scsi: %s", strerror(errno));
  75.     return 0;
  76.     }
  77.     
  78.     i = read(fd, buf, sizeof(buf) - 1);
  79.     if (i < 1) {
  80.     logMessage("failed to read /proc/scsi/scsi: %s", strerror(errno));
  81.     return 0;
  82.     }
  83.     close(fd);
  84.     buf[i] = '\0';
  85.  
  86.     logMessage("/proc/scsi/scsi: %s", buf);
  87.  
  88.     if (strstr(buf, "devices: none")) {
  89.     logMessage("no scsi devices are available");
  90.     return 0;
  91.     }
  92.  
  93.     logMessage("scsi devices are available");
  94.     return 1;
  95. }
  96.