home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / DRIVERS / ptxm.lzh / ptxm.txt < prev    next >
Text File  |  1995-03-13  |  5KB  |  224 lines

  1.                          Path Table eXtension Module
  2.                          ---------------------------
  3.  
  4. Copyright (c) 1995  Nick Holgate, Southampton, UK
  5.                     nick@bvmltd.demon.co.uk
  6.  
  7. The  PTXM  is  courtesyware, it is entirly free in the hope that it will be of
  8. some  use, but it would be a nice gesture to let me know if you like it enough
  9. to  use  it.   If  nobody tells me they are using it it's unlikely that I will
  10. continue to maintain it!
  11.  
  12.  
  13. What is it?
  14. -----------
  15.  
  16. PTXM  is a kernel extension module that allows user state processes to open an
  17. unlimited number of I/O paths. 
  18.  
  19. Installation
  20. ------------
  21.  
  22. Installation is straight forward either:
  23.  
  24. 1. Install Ptxm in your bootfile and add Ptxm to the list of system
  25.    extensions in your 'init' module.
  26.  
  27. or
  28.  
  29. 2. Load the Ptxm module into memory then execute the 'ptxminst' utility.
  30.  
  31.  
  32. How it works
  33. ------------
  34.  
  35. PTXM  intercepts  all  the  I$????  calls  that  create or use user state path
  36. numbers  extending the processes path table into system memory when the one in
  37. the process descriptor becomes full. 
  38.  
  39. When  a  user  state  I$Open  or  I$Create call is made PTXM performs the call
  40. system  state  equivalent,  then  records  the system state path number in the
  41. process descriptor like IOMAN would, but if the process descriptors path table
  42. is  full  it  records  the  path  number  internally in a path extension table
  43. allocated from system memory for the calling process. 
  44.  
  45. When  other I/O system calls are made, with the exception of I$Dup, PTXM finds
  46. the  system  state  path  number  that  corresponds  to the supplied user path
  47. number,  from  either  the  process  descriptor  or path extension table, then
  48. passes the call on to the system state dispatch address to be executed. 
  49.  
  50. The I$Dup call is handled entirely by PTXM and does not call on IOMAN at all. 
  51.  
  52. Process  termination  is  handled  with a user accounting subroutine, F$Uacct,
  53. that closes any open paths left by terminating and chained processes. 
  54.  
  55.  
  56. Current Limitations
  57. -------------------
  58.  
  59. Only the first 32 open paths, (i.e.  the ones held in the process descriptor),
  60. may be inherited by a child process. 
  61.  
  62. To  be  able  to  close  user  paths  that  are  left  open when the a process
  63. terminates  it  is  necessary  to  install a user accounting routine.  As OS-9
  64. provides  no  way  to  install  multiple  user  accounting  routines  any user
  65. accounting  software  installed  after the PTXM will likely replace the PTXM's
  66. handler,  however  provided  the  PTXM  is  installed  after  any  other  user
  67. accounting  software  there  should  be no problem, as the PTXM calls the user
  68. accounting handler that it replaced before it returns to the kernel. 
  69.  
  70. Will  not  work  with  OS-9  V3  ATOMIC kernel, as there is no user accounting
  71. support. 
  72.  
  73.  
  74. 'C' Stream I/O
  75. --------------
  76.  
  77. Microware's  standard  stream  I/O  has a fixed size array of 32 FILE buffers,
  78. which  prevents  more  than  32  fopen(),  fdopen()  or  freopen() calls being
  79. performed.   By moving the initialised FILE buffer into malloc'ed memory after
  80. each  path is opened and free'ing it after each path is closed, it is possible
  81. to defeat this limitation. 
  82.  
  83. /*--------------------------------------------------------------------------*/
  84.  
  85. #include <stdio.h>
  86. #if defined(__STDC__) || defined(_ANSI_EXT)
  87. #include <stdlib.h>
  88. #else
  89. #define const /**/
  90. extern void *malloc();
  91. #endif
  92.  
  93. FILE *
  94. ptxm_fopen
  95. (    const char    *fname,
  96.     const char    *action
  97. )
  98. {
  99.     FILE        *fp;
  100.     FILE        *fbuf;
  101.  
  102.     if ((fbuf = malloc(sizeof(FILE))) == NULL)
  103.     {
  104.         return NULL;
  105.     }
  106.     
  107.     if ((fp = fopen(fname, action)) == NULL)
  108.     {
  109.         free(fbuf);
  110.         return NULL;
  111.     }
  112.  
  113.     /* save it in our FILE buffer */
  114.     *fbuf = *fp;
  115.  
  116.     /* make it look unused */
  117.     memset(fp, 0, sizeof(FILE));
  118.  
  119.     return fbuf;
  120. }
  121.  
  122.  
  123. FILE *
  124. ptxm_fdopen
  125. (    int            path,
  126.     char        *action
  127. )
  128. {
  129.     FILE        *fp;
  130.     FILE        *fbuf;
  131.  
  132.     if ((fbuf = malloc(sizeof(FILE))) == NULL)
  133.     {
  134.         return NULL;
  135.     }
  136.  
  137.     if ((fp = fdopen(path, action)) == NULL)
  138.     {
  139.         free(fbuf);
  140.         return NULL;
  141.     }
  142.  
  143.     /* save it in our FILE buffer */
  144.     *fbuf = *fp;
  145.  
  146.     /* make it look unused */
  147.     memset(fp, 0, sizeof(FILE));
  148.  
  149.     return fbuf;
  150. }
  151.  
  152.  
  153. FILE *
  154. ptxm_freopen
  155. (    const char    *fname,
  156.     const char    *action,
  157.     FILE        *oldfp
  158. )
  159. {
  160.     FILE        *fp;
  161.     FILE        *fbuf;
  162.  
  163.     if ((fbuf = malloc(sizeof(FILE))) == NULL)
  164.     {
  165.         /* to be consistant, the original is closed if open fails */
  166.         fclose(oldfp);
  167.         return NULL;
  168.     }
  169.  
  170.     fp = freopen(fname, action, oldfp);
  171.  
  172.     /* use stdin to iron out differences in naming
  173.      * between the K & R compiler (_iob[]) and Ultra 'C' (_niob[])
  174.      */
  175.     if (oldfp < stdin || oldfp >= &stdin[_NFILE])
  176.     {
  177.         free(oldfp);
  178.     }
  179.  
  180.     if (fp == NULL)
  181.     {
  182.         free(fbuf);
  183.         return NULL;
  184.     }
  185.  
  186.     /* save it in our FILE buffer */
  187.     *fbuf = *fp;
  188.  
  189.     /* make it look unused */
  190.     memset(fp, 0, sizeof(FILE));
  191.  
  192.     return fbuf;
  193. }
  194.  
  195.  
  196. int
  197. ptxm_fclose
  198. (    FILE    *fp
  199. )
  200. {
  201.     int        status;
  202.  
  203.     status = fclose(fp);
  204.  
  205.     /* use stdin to iron out differences in naming
  206.      * between the K & R compiler (_iob) and Ultra 'C' (_niob)
  207.      */
  208.     if (fp < stdin || fp >= &stdin[_NFILE])
  209.     {
  210.         free(fp);
  211.     }
  212.  
  213.     return status;
  214. }
  215.  
  216. #define fopen    ptxm_fopen
  217. #define fdopen    ptxm_fdopen
  218. #define freopen    ptxm_freopen
  219. #define fclose    ptxm_fclose
  220.  
  221. /*--------------------------------------------------------------------------*/
  222.  
  223.                                                           Nick Holgate 13.3.95
  224.