home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / EDMI5.ZIP / IFSR3.ZIP / R3COMM.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  3KB  |  94 lines

  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** EXR0R3 - A ring 0/ring 3 IFS skeleton
  5. ** Copyright (C) 1993 by Andre Asselin
  6. **
  7. ** R3COMM.C - Ring 3 side of communications
  8. **
  9. ** History:
  10. ** 6/29/93 - created
  11. **
  12. *******************************************************************************
  13. ******************************************************************************/
  14.  
  15. #include "r3inc.h"
  16.  
  17. #pragma argsused
  18. int main(int argc, char **argv, char **envp) {
  19.    INITSTRUC initdata;
  20.    unsigned long leninitdata = sizeof(initdata);
  21.    OPDATA *OpData;
  22.    void *Buf;
  23.    unsigned int rc;
  24.    char name[10];
  25.  
  26.    // Print a banner to let the user know we're running
  27.    printf("EXR0R3 - A ring 0/ring 3 IFS skeleton\n"
  28.           "Copyright (C) 1993 by Andre Asselin\n\n");
  29.  
  30.  
  31.    // Allocate the two buffers
  32.    rc = DosAllocMem(&OpData, sizeof(initdata.OpData),
  33.                     PAG_READ | PAG_WRITE | PAG_COMMIT);
  34.    if (rc != NO_ERROR) {
  35.       printf("alloc failed - OpData: %d\n", rc);
  36.       exit(1);
  37.    }
  38.    rc = DosAllocMem(&Buf, 65536, PAG_READ | PAG_WRITE | PAG_COMMIT);
  39.    if (rc != NO_ERROR) {
  40.       printf("alloc failed - Buf: %d\n", rc);
  41.       exit(1);
  42.    }
  43.  
  44.  
  45.    // Set up the initialization data to be passed to the IFS
  46.    initdata.OpData = OpData;
  47.    initdata.Buf = Buf;
  48.  
  49.    // We want the FS router to route by IFS name, so copy the name into a
  50.    // temporary buffer because the router could destroy the name.
  51.    strncpy(name, FS_NAME, sizeof(name));
  52.  
  53.    // Call the IFS to initialize
  54.    rc = DosFSCtl(NULL, 0, NULL, &initdata, sizeof(initdata), &leninitdata,
  55.                  FSCTL_FUNC_INIT, name, -1, FSCTL_FSDNAME);
  56.    if (rc != NO_ERROR) {
  57.       printf("FSCtl failed - init: %x %d\n", rc, rc & 0x0fff);
  58.       exit(1);
  59.    }
  60.  
  61.  
  62.    // We returned from the IFS-- that means we have an operation waiting.
  63.    // Figure out what it is and route it appropriately.
  64.    while (1) {
  65.       switch (OpData->funccode) {
  66.       case CPFC_ATTACH:
  67.          // Handle FS_ATTACH
  68.          printf("FS_ATTACH\n");
  69.          OpData->rc = FSD_ATTACH(OpData->attach.flag, OpData->attach.Dev,
  70.                                  &OpData->attach.vpfsd, &OpData->attach.cdfsd,
  71.                                  Buf, &OpData->attach.Len);
  72.          break;
  73.  
  74.       // For now, we don't support anything else
  75.       default:
  76.          printf("Unknown IFS function code: %d\n", OpData->funccode);
  77.          OpData->rc = ERROR_NOT_SUPPORTED;
  78.          break;
  79.       }
  80.  
  81.       // We want the FS router to route by IFS name, so copy the name into a
  82.       // temporary buffer because the router could destroy the name.
  83.       strncpy(name, FS_NAME, sizeof(name));
  84.  
  85.       // Say we're done with this one, and wait for next one.
  86.       rc = DosFSCtl(NULL, 0, NULL, NULL, 0, NULL, FSCTL_FUNC_NEXT, name,
  87.                     -1, FSCTL_FSDNAME);
  88.       if (rc != NO_ERROR) {
  89.          printf("FSCtl failed - next: %d\n", rc);
  90.          exit(1);
  91.       }
  92.    }
  93. }
  94.