home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Examples / DriverKit / SCSITape / PostLoad.tproj / PostLoad.m < prev   
Encoding:
Text File  |  1993-07-29  |  2.8 KB  |  122 lines

  1. /*
  2.  *      Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved. 
  3.  *
  4.  * Post-Load command for ParallelPort.   Checks and installs /dev/pp*.
  5.  *
  6.  * HISTORY
  7.  * 20-Apr-93    Phillip Dibner at NeXT
  8.  *      Created. 
  9.  */
  10.  
  11. #import <driverkit/IODeviceMaster.h>
  12. #import <driverkit/IODevice.h>
  13. #import "SCSITapeTypes.h"
  14. #import <errno.h>
  15. #import <libc.h>
  16.  
  17.  
  18. #define PATH_NAME_SIZE 10
  19. #define DEV_STRING "/dev/"
  20. #define INSTANCE_STRING "Instance="
  21. #define ST_INIT_ERR_STRING "Error initializing SCSI Tape driver"
  22. #define NTAPE_NAMES 4
  23.  
  24. #define DEV_MOD 020666
  25. #define DEV_UMASK 0
  26.  
  27. char path [PATH_NAME_SIZE];
  28. char *scsiTapeNames[] = {"rst", "nrst", "rxt", "nrxt"};
  29. int scsiTapeDevFlags[] = {0, 1, 2, 3}; /* bit 0 = no rewind, bit 1 = Exabyte */
  30.  
  31. int
  32. main(int argc, char **argv)
  33. {
  34.     IOReturn            ret = IO_R_INVALID;
  35.     IOObjectNumber        tag;
  36.     IOString            kind;
  37.     int                major, minor, iUnit, iRet = 0;
  38.     unsigned int        count = 1;
  39.     IODeviceMaster        *devMaster;
  40.     int                i;
  41.  
  42.     devMaster = [IODeviceMaster new];
  43.  
  44.     for (iUnit = 0; iUnit < NST; iUnit ++) {
  45.     bzero (path, PATH_NAME_SIZE);
  46.     sprintf (path, "%s%s%d", DEV_STRING, "st", iUnit);
  47.  
  48.     /*
  49.      * Find this instance of the SCSI Tape driver
  50.      */
  51.  
  52.     ret = [devMaster lookUpByDeviceName: path + strlen (DEV_STRING)
  53.         objectNumber: &tag 
  54.         deviceKind: &kind];
  55.  
  56. #ifdef DEBUG
  57. printf (" unit %d, obj name %s\n", iUnit, path);
  58. printf (" ret = %d\n", ret);
  59. #endif DEBUG
  60.  
  61.     /*
  62.      * Special work to do for the first SCSITape object
  63.      */
  64.     if (iUnit == 0) {
  65.  
  66.         /*
  67.          * If we couldn't find the first one, we will return failure.
  68.          */
  69.         if (ret != IO_R_SUCCESS) {
  70.         printf ("%s: couldn't find driver. Returned %d\n",
  71.             ST_INIT_ERR_STRING, ret);
  72.         iRet = -1;
  73.         } 
  74.  
  75.         /*
  76.          * Query the object for its major device number
  77.          */
  78.         major = -1;
  79.         ret = [devMaster getIntValues:&major 
  80.         forParameter:"IOMajorDevice" objectNumber:tag
  81.         count:&count];
  82.         if (ret != IO_R_SUCCESS) {
  83.         printf ("%s: couldn't get major number:  Returned %d.\n",
  84.             ST_INIT_ERR_STRING, ret);
  85.         iRet = -1;
  86.         }
  87.     }
  88.  
  89.     /*
  90.      * Remove old devs and create new ones for this unit.
  91.      */
  92.     for (i = 0; i < NTAPE_NAMES; i++) {
  93.  
  94.         bzero (path, PATH_NAME_SIZE);
  95.         sprintf (path, "%s%s%d", DEV_STRING, scsiTapeNames [i], iUnit);
  96.  
  97.         if (unlink (path)) {
  98.         if (errno != ENOENT) {
  99.             printf ("%s: could not delete old %s.  Errno is %d\n",
  100.             ST_INIT_ERR_STRING, path, errno);
  101.             iRet = -1; 
  102.         }
  103.         }
  104.  
  105.  
  106.         /*
  107.          * If we found this object, create new device nodes
  108.          */
  109.         if (ret == IO_R_SUCCESS) {
  110.         minor = (iUnit << 3) | scsiTapeDevFlags [i];
  111.  
  112.         umask (DEV_UMASK);
  113.         if (mknod(path, DEV_MOD, (major << 8) | minor)) {
  114.             printf ("%s: could not create %s.  Errno is %d\n",
  115.             ST_INIT_ERR_STRING, path, errno);
  116.             iRet = -1;
  117.         }
  118.         }
  119.     }
  120.     } /* for iUnit */
  121.     return iRet;
  122. }